Skip to content

Commit

Permalink
fix(manager): gossip any pending blocks not gossiped before (in case …
Browse files Browse the repository at this point in the history
…of restart or crash) (#1045)

Co-authored-by: Omri <[email protected]>
  • Loading branch information
srene and omritoptix authored Aug 28, 2024
1 parent 6bf24d0 commit e9709f6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta
return fmt.Errorf("save block: %w", err)
}

err := m.saveP2PBlockToBlockSync(block, commit)
if err != nil {
m.logger.Error("save block blocksync", "err", err)
}

responses, err := m.Executor.ExecuteBlock(m.State, block)
if err != nil {
return fmt.Errorf("execute block: %w", err)
Expand Down
14 changes: 14 additions & 0 deletions block/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,17 @@ func (m *Manager) gossipBlock(ctx context.Context, block types.Block, commit typ

return nil
}

// This function adds the block to blocksync store to enable P2P retrievability
func (m *Manager) saveP2PBlockToBlockSync(block *types.Block, commit *types.Commit) error {
gossipedBlock := p2p.BlockData{Block: *block, Commit: *commit}
gossipedBlockBytes, err := gossipedBlock.MarshalBinary()
if err != nil {
return fmt.Errorf("marshal binary: %w: %w", err, ErrNonRecoverable)
}
err = m.P2PClient.SaveBlock(context.Background(), block.Header.Height, gossipedBlockBytes)
if err != nil {
m.logger.Error("Adding block to blocksync store.", "err", err, "height", gossipedBlock.Block.Header.Height)
}
return nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ require (
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.11.0 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/gogoproto v1.5.0 // indirect
github.com/cosmos/gogoproto v1.5.0
github.com/creachadair/taskgroup v0.3.2 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/base58 v1.0.4 // indirect
Expand Down
5 changes: 5 additions & 0 deletions p2p/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ func (c *Client) blockGossipReceived(ctx context.Context, block []byte) {
c.logger.Error("Publishing event.", "err", err)
}
if c.conf.BlockSyncEnabled {
_, err := c.store.LoadBlockCid(gossipedBlock.Block.Header.Height)
// skip block already added to blocksync
if err == nil {
return
}
err = c.SaveBlock(ctx, gossipedBlock.Block.Header.Height, block)
if err != nil {
c.logger.Error("Adding block to blocksync store.", "err", err, "height", gossipedBlock.Block.Header.Height)
Expand Down
2 changes: 1 addition & 1 deletion proto/types/dymint/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ message State {

SequencerSet sequencerSet = 18 [(gogoproto.nullable) = false];
RollappConsensusParams consensus_params = 19 [(gogoproto.nullable) = false];

}

//rollapp params defined in genesis and updated via gov proposal
Expand Down

0 comments on commit e9709f6

Please sign in to comment.