From 7b21b251e7ec35ac2b5211e05c254c076276e6d7 Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Fri, 26 Apr 2024 22:51:42 +0200 Subject: [PATCH 1/5] validate block before applying and not before caching in p2p gossiping --- block/block.go | 5 +++++ block/manager.go | 6 ------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/block/block.go b/block/block.go index 29b9203b3..fd2575df2 100644 --- a/block/block.go +++ b/block/block.go @@ -130,6 +130,11 @@ func (m *Manager) attemptApplyCachedBlocks() error { if !blockExists { break } + if err := m.validateBlock(cachedBlock.Block, cachedBlock.Commit); err != nil { + m.logger.Error("apply cached block, block not valid: dropping it", "err", err, "height", cachedBlock.Block.Header.Height) + /// TODO: can we take an action here such as dropping the peer / reducing their reputation? + return err + } // Note: cached pairs have passed basic validation, so no need to validate again err := m.applyBlock(cachedBlock.Block, cachedBlock.Commit, blockMetaData{source: gossipedBlock}) 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{ From aef9e8d9c45813e7a3dd8fc3d91782e505844ef2 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 26 Apr 2024 20:58:18 +0000 Subject: [PATCH 2/5] Update CHANGELOG.md [skip ci] --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) From 4ac51fb96b9067591525d818b668a9960daff346 Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Fri, 26 Apr 2024 22:59:48 +0200 Subject: [PATCH 3/5] remove comment --- block/block.go | 1 - 1 file changed, 1 deletion(-) diff --git a/block/block.go b/block/block.go index fd2575df2..b7ee1b009 100644 --- a/block/block.go +++ b/block/block.go @@ -136,7 +136,6 @@ func (m *Manager) attemptApplyCachedBlocks() error { return 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) From 6418452865c5cea3eb6c73ce82a034eaa21c66d1 Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Fri, 26 Apr 2024 23:37:21 +0200 Subject: [PATCH 4/5] remove invalid block --- block/block.go | 1 + 1 file changed, 1 insertion(+) diff --git a/block/block.go b/block/block.go index b7ee1b009..8d18436e7 100644 --- a/block/block.go +++ b/block/block.go @@ -132,6 +132,7 @@ func (m *Manager) attemptApplyCachedBlocks() error { } if err := m.validateBlock(cachedBlock.Block, cachedBlock.Commit); err != nil { m.logger.Error("apply cached block, block not valid: dropping it", "err", err, "height", cachedBlock.Block.Header.Height) + delete(m.blockCache, cachedBlock.Block.Header.Height) /// TODO: can we take an action here such as dropping the peer / reducing their reputation? return err } From 6cfc0671e4d4de32f59e34998bfc5e0d0c4b45ff Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Fri, 26 Apr 2024 23:46:30 +0200 Subject: [PATCH 5/5] modifying redundant error log --- block/block.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/block/block.go b/block/block.go index 8d18436e7..02c7ce3c2 100644 --- a/block/block.go +++ b/block/block.go @@ -131,10 +131,9 @@ func (m *Manager) attemptApplyCachedBlocks() error { break } if err := m.validateBlock(cachedBlock.Block, cachedBlock.Commit); err != nil { - m.logger.Error("apply cached block, block not valid: dropping it", "err", err, "height", cachedBlock.Block.Header.Height) delete(m.blockCache, cachedBlock.Block.Header.Height) /// TODO: can we take an action here such as dropping the peer / reducing their reputation? - return err + return fmt.Errorf("block not valid at height %d, dropping it: err:%w", cachedBlock.Block.Header.Height, err) } err := m.applyBlock(cachedBlock.Block, cachedBlock.Commit, blockMetaData{source: gossipedBlock})