-
Notifications
You must be signed in to change notification settings - Fork 185
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
blockmanager.go: use btcd libs to validate headers #263
Conversation
This check was performed for both the reorg and non-reorg cases, but in the reorg case the headers would count for PoW before validating that the headers connected to one another.
This uses btcd's HeaderCtx and ChainCtx interfaces to be able to validate headers, both contextually and context-free. This allows neutrino to call blockchain.CheckBlockHeaderContext and blockchain.CheckBlockHeaderSanity.
febc308
to
ddb3f6a
Compare
@@ -2383,6 +2383,33 @@ func (b *blockManager) handleHeadersMsg(hmsg *headersMsg) { | |||
// atomically in order to improve peformance. | |||
headerWriteBatch := make([]headerfs.BlockHeader, 0, len(msg.Headers)) | |||
|
|||
// Explicitly check that each header in msg.Headers builds off of the |
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.
Can be moved out into a some helper function. Also would have though the functions we exported from btcd
would handle it so we don't need to do it again?
err := b.checkHeaderSanity(blockHeader, maxTimestamp, | ||
false) | ||
false, prevNodeHeight, &prevNodeHeader) |
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.
Can fix line folding here.
|
||
var prevNodeHeader *wire.BlockHeader | ||
|
||
if i+j == 0 { |
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.
So i && j == 0
?
} | ||
return nil | ||
|
||
err = blockchain.CheckBlockHeaderSanity( |
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.
Can just do return
here.
Can be rebased now! |
Replaced by #283, addressed all open review comments there. |
This uses btcd's HeaderCtx and ChainCtx interfaces to be able to validate headers, both contextually and context-free. This allows neutrino to call blockchain.CheckBlockHeaderContext and blockchain.CheckBlockHeaderSanity. Also included is a check to assert that when neutrino receives a p2p headers message, that each header connects to the previous one.
TODO: