Skip to content

Commit

Permalink
update submitted height from batch events
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed Sep 16, 2024
1 parent 2da988f commit aefb982
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ func (m *Manager) Start(ctx context.Context) error {
go uevent.MustSubscribe(ctx, m.Pubsub, "applyGossipedBlocksLoop", p2p.EventQueryNewGossipedBlock, m.onReceivedBlock, m.logger)
go uevent.MustSubscribe(ctx, m.Pubsub, "applyBlockSyncBlocksLoop", p2p.EventQueryNewBlockSyncBlock, m.onReceivedBlock, m.logger)
return nil
} else {
// Subscribe to batch events, to update last submitted height in case batch confirmation was lost (e.g. on restart)
go uevent.MustSubscribe(ctx, m.Pubsub, "updateSubmittedHeightLoop", settlement.EventQueryNewSettlementBatchAccepted, m.UpdateLastSubmittedHeight, m.logger)

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
}

/* ----------------------------- sequencer mode ----------------------------- */
Expand Down
16 changes: 16 additions & 0 deletions block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"time"

"github.com/dymensionxyz/gerr-cosmos/gerrc"
"github.com/tendermint/tendermint/libs/pubsub"
"golang.org/x/sync/errgroup"

"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/types"
uatomic "github.com/dymensionxyz/dymint/utils/atomic"
uchannel "github.com/dymensionxyz/dymint/utils/channel"
Expand Down Expand Up @@ -263,3 +265,17 @@ func (m *Manager) GetUnsubmittedBytes() int {
func (m *Manager) GetUnsubmittedBlocks() uint64 {
return m.State.Height() - m.LastSubmittedHeight.Load()
}

// UpdateLastSubmittedHeight will update last height submitted, in case necessary to avoid edge case issues
func (m *Manager) UpdateLastSubmittedHeight(event pubsub.Message) {
eventData, ok := event.Data().(*settlement.EventDataNewBatchAccepted)
if !ok {
m.logger.Error("onReceivedBatch", "err", "wrong event data received")
return
}
h := eventData.EndHeight
if m.LastSubmittedHeight.Load() < h {
m.LastSubmittedHeight.Store(h)
}

}
1 change: 0 additions & 1 deletion settlement/dymension/dymension.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ func (c *Client) SubmitBatch(batch *types.Batch, daClient da.Client, daResult *d
// this could happen if we timed-out waiting for acceptance in the previous iteration, but the batch was indeed submitted
if errors.Is(err, gerrc.ErrAlreadyExists) {
c.logger.Debug("Batch already accepted", "startHeight", batch.StartHeight(), "endHeight", batch.EndHeight())
return nil
}
return fmt.Errorf("broadcast batch: %w", err)
}
Expand Down

0 comments on commit aefb982

Please sign in to comment.