Skip to content

Commit

Permalink
refactor: refactored handleSubmissionTrigger (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
omritoptix authored Apr 18, 2024
1 parent bc24185 commit 732836a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
1 change: 0 additions & 1 deletion block/produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ func (m *Manager) produceBlock(allowEmpty bool) (*types.Block, *types.Commit, er
pendingBlock, err := m.store.LoadBlock(newHeight)
if err == nil {
// Using an existing block

block = pendingBlock
commit, err = m.store.LoadCommit(newHeight)
if err != nil {
Expand Down
29 changes: 11 additions & 18 deletions block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,23 @@ func (m *Manager) SubmitLoop(ctx context.Context) {
}
}

// handleSubmissionTrigger processes the submission trigger event. It checks if there are new blocks produced since the last submission.
// If there are, it attempts to submit a batch of blocks. It then attempts to produce an empty block to ensure IBC messages
// pass through during the batch submission process due to proofs requires for ibc messages only exist on the next block.
// Finally, it submits the next batch of blocks and updates the sync target to the height of
// the last block in the submitted batch.
func (m *Manager) handleSubmissionTrigger(ctx context.Context) {
// SyncTarget is the height of the last block in the last batch as seen by this node.
syncTarget := m.syncTarget.Load()
height := m.store.Height()
if height <= syncTarget { // no new blocks produced yet
return
}

// Submit batch if we've reached the batch size and there isn't another batch currently in submission process.

if !m.batchInProcess.TryLock() {
if !m.batchInProcess.TryLock() { // Attempt to lock for batch processing
m.logger.Debug("Batch submission already in process, skipping submission")
return
}
defer m.batchInProcess.Unlock() // Ensure unlocking at the end

defer m.batchInProcess.Unlock()

// check again, might have changed since locking
syncTarget = m.syncTarget.Load()
height = m.store.Height()
if height <= syncTarget {
return
// Load current sync target and height to determine if new blocks are available for submission.
syncTarget, height := m.syncTarget.Load(), m.store.Height()
if height <= syncTarget { // Check if there are new blocks since last sync target.
return // Exit if no new blocks are produced.
}

// We try and produce an empty block to make sure relevant ibc messages will pass through during the batch submission: https://github.com/dymensionxyz/research/issues/173.
err := m.produceAndGossipBlock(ctx, true)
if err != nil {
Expand Down

0 comments on commit 732836a

Please sign in to comment.