Skip to content

Commit

Permalink
fix(p2p): validate block before applying and not before caching in p2… (
Browse files Browse the repository at this point in the history
#724)

Co-authored-by: Sergi Rene <[email protected]>
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
3 people authored Apr 26, 2024
1 parent 810b623 commit eb6c27d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Check failure on line 3 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines [Expected: 1; Actual: 2]

Check failure on line 4 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines [Expected: 1; Actual: 3]
# [1.1.0-rc02](https://github.com/dymensionxyz/dymint/compare/v1.1.0-rc01...v1.1.0-rc02) (2024-04-26)

Check failure on line 5 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple top-level headings in the same document [Context: "# [1.1.0-rc02](https://github...."]


Check failure on line 7 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines [Expected: 1; Actual: 2]

Check failure on line 8 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines [Expected: 1; Actual: 3]
Expand Down
6 changes: 5 additions & 1 deletion block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <block,commit> 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)
Expand Down
6 changes: 0 additions & 6 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit eb6c27d

Please sign in to comment.