Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(p2p): validate block before applying and not before caching in p2p gossiping #723

Merged
merged 6 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# [](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]
# [1.1.0-rc01](https://github.com/dymensionxyz/dymint/compare/v1.0.1-alpha...v1.1.0-rc01) (2024-04-25)

Check failure on line 9 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

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


Check failure on line 11 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

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

Check failure on line 12 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Heading levels should only increment by one level at a time [Expected: h2; Actual: h3]

* **block production:** apply block before gossiping ([#695](https://github.com/dymensionxyz/dymint/issues/695)) ([5c496b4](https://github.com/dymensionxyz/dymint/commit/5c496b453e98bbcc67feb6df3a2d4ad340586816))
* **block:** Only register `nodeHealthStatusHandler` for sequencer ([#683](https://github.com/dymensionxyz/dymint/issues/683)) ([da2ff94](https://github.com/dymensionxyz/dymint/commit/da2ff94bcdd064109da703fa885609846a94e180))
Expand Down Expand Up @@ -42,7 +46,7 @@
* **store:** do not discard CAS fail errors ([#705](https://github.com/dymensionxyz/dymint/issues/705)) ([3bcda30](https://github.com/dymensionxyz/dymint/commit/3bcda306203e9e7ec6cf65df70b8086343631ded))
* updated go version and x/net library ([#670](https://github.com/dymensionxyz/dymint/issues/670)) ([b766728](https://github.com/dymensionxyz/dymint/commit/b76672877574cbda3d41961f9b6bcb52a47a8460))


Check failure on line 49 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

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

* **ci:** Add changelog workflow ([#720](https://github.com/dymensionxyz/dymint/issues/720)) ([6361f97](https://github.com/dymensionxyz/dymint/commit/6361f974c5b51f4d6339737812c30b3adc8be980))
Expand All @@ -50,7 +54,7 @@
* **mempool:** add a sanity check ([#690](https://github.com/dymensionxyz/dymint/issues/690)) ([c4379ff](https://github.com/dymensionxyz/dymint/commit/c4379ff97d0e2d2bab5726194528af602904b819))
* **perf:** removed unneeded state-index query ([#650](https://github.com/dymensionxyz/dymint/issues/650)) ([25afe20](https://github.com/dymensionxyz/dymint/commit/25afe20fea420b930a8a221cc4c78620b0a7b510))


Check failure on line 57 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

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

## [1.0.1-alpha](https://github.com/dymensionxyz/dymint/compare/v1.0.0-alpha...v1.0.1-alpha) (2024-03-26)

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

thinking we should delete it and not keep it in cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

block deleted from cache if invalid.

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

height should go at the end
don't need '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
Loading