-
Notifications
You must be signed in to change notification settings - Fork 71
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
Conversation
@@ -130,8 +130,12 @@ func (m *Manager) attemptApplyCachedBlocks() error { | |||
if !blockExists { | |||
break | |||
} | |||
if err := m.validateBlock(cachedBlock.Block, cachedBlock.Commit); err != nil { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this reintroduces a problem found in the audit which is that bad blocks can overwrite good ones in the cache
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) |
There was a problem hiding this comment.
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'
see audit issue #656 |
PR Standards
P2P gossiping tries to validate blocks on reception. However, the validation fails if blocks are received unordered, dropping them, and being unable to sync using p2p for any block received after. This PR fixes the issue validating blocks in order, moving the validation call after caching them, and before applying, once all blocks are received and can be applied in order.
Opening a pull request should be able to meet the following requirements
Close #722
<-- Briefly describe the content of this pull request -->
For Author:
godoc
commentsFor Reviewer:
After reviewer approval: