Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(manager): gossip any pending blocks not gossiped before (in case of restart or crash) #1045

Merged
merged 17 commits into from
Aug 28, 2024
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this for optimization purposes?
if so I see we're missing the AddBlockRecieved method in that case - is that fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this is just to avoid storing the block twice if already stored.

// 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
Loading