From 98371b5220613e70f3274fab5593e02ba532f7db Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Sat, 27 Apr 2024 00:01:59 +0200 Subject: [PATCH] fix(p2p): validate block before applying and not before caching in p2p gossiping (#723) Co-authored-by: github-actions --- CHANGELOG.md | 6 +++++- block/block.go | 6 +++++- block/manager.go | 6 ------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11a154b54..6d18181af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -# [](https://github.com/dymensionxyz/dymint/compare/v1.1.0-rc01...v) (2024-04-26) +# [](https://github.com/dymensionxyz/dymint/compare/v1.1.0-rc02...v) (2024-04-26) + + + +# [1.1.0-rc02](https://github.com/dymensionxyz/dymint/compare/v1.1.0-rc01...v1.1.0-rc02) (2024-04-26) diff --git a/block/block.go b/block/block.go index 29b9203b3..02c7ce3c2 100644 --- a/block/block.go +++ b/block/block.go @@ -130,8 +130,12 @@ func (m *Manager) attemptApplyCachedBlocks() error { if !blockExists { break } + if err := m.validateBlock(cachedBlock.Block, cachedBlock.Commit); err != nil { + delete(m.blockCache, cachedBlock.Block.Header.Height) + /// TODO: can we take an action here such as dropping the peer / reducing their reputation? + return fmt.Errorf("block not valid at height %d, dropping it: err:%w", cachedBlock.Block.Header.Height, err) + } - // Note: cached pairs have passed basic validation, so no need to validate again err := m.applyBlock(cachedBlock.Block, cachedBlock.Commit, blockMetaData{source: gossipedBlock}) if err != nil { return fmt.Errorf("apply cached block: expected height: %d: %w", expectedHeight, err) diff --git a/block/manager.go b/block/manager.go index ccf5f8018..6f7e7b4a7 100644 --- a/block/manager.go +++ b/block/manager.go @@ -243,12 +243,6 @@ func (m *Manager) onNewGossipedBlock(event pubsub.Message) { block := eventData.Block commit := eventData.Commit - if err := m.validateBlock(&block, &commit); err != nil { - m.logger.Error("apply block callback, block not valid: dropping it", "err", err, "height", block.Header.Height) - /// TODO: can we take an action here such as dropping the peer / reducing their reputation? - return - } - nextHeight := m.Store.NextHeight() if block.Header.Height >= nextHeight { m.blockCache[block.Header.Height] = CachedBlock{