Skip to content

Conversation

@jnewbery
Copy link
Contributor

BUILDS ON #17479. PLEASE REVIEW THAT PR FIRST.

If a CMPCTBLOCK is in flight from peer A and we then succesfully
reconstruct it during CMPCTBLOCK processing from peer B, we need to
clear the in-flight state for the block from peer A.

We can only do that once we've ensured that the block hasn't been
mutated (otherwise peer B could interfere with our block relay from peer
A by providing a mutated block).

Mutation-checking used to be done indirectly by checking that the block
had been writted to disk by checking the CBlockIndex. Now that
ProcessNewBlock returns a BlockValidationState, we can check that state
directly to determine whether to mark the block as no longer in-flight.

This PR also renames MarkBlockAsReceived() to MarkBlockAsNotInFlight() since that function can be called when the block has not been received. It also improves the comments for MarkBlockAsNotFlight() and MarkBlockAsNotInFlight()

9fdf05d resolved some lock
inversion warnings in denialofservice_tests, but left in a number
of cs_main locks that are unnecessary (introducing lock inversion
warnings in future changes).
@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 15, 2019

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #17693 (rpc: Add generateblock to mine a custom set of transactions by andrewtoth)
  • #17601 (Validation: Move CheckBlock() mutation guard to AcceptBlock() by jnewbery)
  • #17479 (Return BlockValidationState from ProcessNewBlock if CheckBlock/AcceptBlock fails by jnewbery)
  • #17399 (validation: Templatize ValidationState instead of subclassing by jkczyz)
  • #16442 (Serve BIP 157 compact filters by jimpo)
  • #16411 (BIP-325: Signet support by kallewoof)
  • #15606 ([experimental] UTXO snapshots by jamesob)
  • #15545 ([doc] explain why CheckBlock() is called before AcceptBlock by Sjors)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@jnewbery jnewbery force-pushed the 2019-11-processnewblock-early-return2 branch from b1ede02 to e0f5505 Compare November 15, 2019 13:57
jnewbery and others added 9 commits November 15, 2019 17:17
This is a pure refactor commit.

This commit enables the caller of ProcessNewBlock to access the final
BlockValidationState passed around between CheckBlock(), AcceptBlock(),
and BlockChecked() inside ProcessNewBlock(). This is useful because in a
future commit, we will move the BlockChecked() call out of
ProcessNewBlock(), and BlockChecked() still needs to be able to access
the BlockValidationState.

Co-authored-by: John Newbery <[email protected]>
Co-authored-by: Carl Dong <[email protected]>
This is a pure refactor commit.

Since BlockChecked() doesn't actually depend on all of
PeerLogicValidation but just PeerLogicValidation's CConnman, we can make
a standalone, static function that simply has an extra CConnman
parameter and have the non-static version call the static one.

This also means that, in a future commit, when we move the
BlockChecked() call out of ProcessNewBlock(), the caller of
ProcessNewBlock() can call BlockChecked() directly even if they only
have a CConnman.

Co-authored-by: John Newbery <[email protected]>
Co-authored-by: Carl Dong <[email protected]>
…ProcessNewBlock

Net processing now passes a BlockValidationState object into
ProcessNewBlock(). If CheckBlock() or AcceptBlock() fails, then PNB
returns to net processing without calling the (asynchronous)
BlockChecked Validation Interface method. net processing can use the
invalid BlockValidationState returned to punish peers.

CheckBlock() and AcceptBlock() represent the DoS checks on a block (ie
PoW and malleability). Net processing wants to know about those failed
checks immediately and shouldn't have to wait on a callback. Other
validation interface clients don't care about net processing submitting
bogus malleated blocks to validation, so they don't need to be notified
of BlockChecked.

Furthermore, if PNB returns a valid BlockValidationState, we never need
to try to process (non-malleated) copies of the block from other peers.
That makes it much easier to move the best chain activation logic to a
background thread in future work.

Co-authored-by: John Newbery <[email protected]>
Co-authored-by: Carl Dong <[email protected]>
This is a pure refactor commit.

Co-authored-by: John Newbery <[email protected]>
Co-authored-by: Carl Dong <[email protected]>
The previous name was misleading, since we can call the function even
when the block has not been received.
…tion

If a CMPCTBLOCK is in flight from peer A and we then succesfully
reconstruct it during CMPCTBLOCK processing from peer B, we need to
clear the in-flight state for the block from peer A.

We can only do that once we've ensured that the block hasn't been
mutated (otherwise peer B could interfere with our block relay from peer
A by providing a mutated block).

Mutation-checking used to be done indirectly by checking that the block
had been writted to disk by checking the CBlockIndex. Now that
ProcessNewBlock returns a BlockValidationState, we can check that state
directly to determine whether to mark the block as no longer in-flight.
@jnewbery jnewbery force-pushed the 2019-11-processnewblock-early-return2 branch from e0f5505 to 11b7abd Compare November 18, 2019 16:23
@DrahtBot
Copy link
Contributor

Needs rebase

@jnewbery jnewbery changed the title net processing: Don't reach into CBlockIndex to check for block mutation WIP: net processing: Don't reach into CBlockIndex to check for block mutation Jan 2, 2020
@jnewbery
Copy link
Contributor Author

Closing for now. No need for this to be open while #17479 is not yet merged. Will reopen when #17479 is merged.

@jnewbery jnewbery closed this Mar 13, 2020
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants