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

blockmanager.go: use btcd libs to validate headers #263

Closed
wants to merge 2 commits into from

Conversation

Crypt-iQ
Copy link
Contributor

@Crypt-iQ Crypt-iQ commented Nov 29, 2022

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:

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.
@@ -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
Copy link
Member

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

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

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(
Copy link
Member

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.

@Roasbeef
Copy link
Member

Can be rebased now!

@guggero
Copy link
Member

guggero commented Jul 14, 2023

Replaced by #283, addressed all open review comments there.

@guggero guggero closed this Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants