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

net processing: Only support version 2 compact blocks #20799

Merged
merged 11 commits into from
May 16, 2022

Conversation

jnewbery
Copy link
Contributor

@jnewbery jnewbery commented Dec 29, 2020

Compact blocks are used for efficient relay of blocks, either through High Bandwidth or Low Bandwidth mode. See BIP 152 for full details.

For compact block relay to work, the receiver must have a mempool containing transactions which are likely to be included in the block. The receiver uses these transactions to reconstruct the block from the short transaction ids included in the cmpctblock message. Compact blocks are therefore only useful for relaying blocks at or near the tip of the block chain. For older blocks, the recipient won't have the transactions in their mempool and so would need to request them using a getblocktxn message. In such cases, just requesting the full block is more efficient.

BIP 152 supports two versions: version 1 (without witnesses) and version 2 (with witnesses). Version 2 is required to reconstruct segwit blocks. Segwit was activated in August 2017, and providing non-witness blocks to peers is no longer useful. Since the witnesses are not included, the peer would not be able to fully validate all the consensus rules on the provided block.

Therefore, stop supporting version 1 compact blocks. Ignore sendcmpct messages with version=1, and don't advertise support by sending sendcmpct with version=1. Only send sendcmpct to peers with NODE_WITNESS. Respond to all requests for compact blocks or blocktxns with witness-serialized blocks and transactions.

@fanquake fanquake added the P2P label Dec 29, 2020
@maflcko
Copy link
Member

maflcko commented Dec 29, 2020

Segwit was activated in August 2017, and providing non-witness blocks to peers is no longer useful

I think there may be some edge-case scenarios where a peer skips the download of witnesses because they are never read (due to an assumevalid setting), but that has nothing to do with compact blocks. So:

Concept ACK on removing code that doesn't serve any use case in practice.

@sipa
Copy link
Member

sipa commented Dec 29, 2020

Concept ACK on removing non-witness cmpctblock support. IIRC its only purpose is serving Bitcoin Core v0.13.0 nodes (0.12.x didn't have compact blocks; 0.13.1 added segwit activation parameters).

The first commit here seems to mix removal of functionality with some refactoring. Is it possible to separate those more cleanly into separate commits?

@jnewbery
Copy link
Contributor Author

The first commit here seems to mix removal of functionality with some refactoring. Is it possible to separate those more cleanly into separate commits?

Yes, I'll see what I can do to split it up a bit more.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 29, 2020

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #24970 (net processing: Move cleanSubVer, fPreferredDownload and nLocalHostNonce to Peer by jnewbery)
  • #24595 (deploymentstatus: move g_versionbitscache global to ChainstateManager by ajtowns)
  • #24062 (refactor: replace RecursiveMutex m_most_recent_block_mutex with Mutex by theStack)
  • #23127 (tests: Use test framework utils where possible by vincenzopalazzo)

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.

@practicalswift
Copy link
Contributor

Concept ACK

Copy link
Member

@ariard ariard left a comment

Choose a reason for hiding this comment

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

Concept ACK, thanks for cleaning a bit compact blocks code.

src/net_processing.cpp Outdated Show resolved Hide resolved
@jonatack
Copy link
Contributor

jonatack commented Jan 2, 2021

Concept ACK, looks like a good simplification. Worth reviewing the diffs with -w in some parts.

@jnewbery jnewbery force-pushed the 2020-12-remove-cmpctblock-v1 branch from b46f099 to f8ff628 Compare January 2, 2021 15:59
@jnewbery
Copy link
Contributor Author

jnewbery commented Jan 2, 2021

Rebased and broken up the first commit.

I've also dropped the last two commits (Clean up PeerManager::BlockChecked() and Clean up MaybeSetPeerAsAnnouncingHeaderAndIDs()). There's already enough happening in this PR.

src/net_processing.cpp Outdated Show resolved Hide resolved
@jnewbery jnewbery force-pushed the 2020-12-remove-cmpctblock-v1 branch from f8ff628 to befb068 Compare January 6, 2021 18:45
@jnewbery jnewbery changed the title net processing: Only support compact blocks with witnesses net processing: Only support version 2 compact blocks Jan 7, 2021
Copy link

@felipsoarez felipsoarez left a comment

Choose a reason for hiding this comment

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

utACK

@fjahr
Copy link
Contributor

fjahr commented Jan 23, 2021

Concept ACK

Copy link
Contributor

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Reviewed first three commits up to 55c9231 then started getting bogged down in the granular ones going over some of the same parts repeatedly and with the renamings; skim-reviewed them for now and will need to return. All of the commits build cleanly rebased to master with p2p_compactblocks.py passing on each.

test/functional/p2p_compactblocks.py Show resolved Hide resolved
src/net_processing.cpp Outdated Show resolved Hide resolved
src/net_processing.cpp Outdated Show resolved Hide resolved
src/net_processing.cpp Outdated Show resolved Hide resolved
Copy link
Member

@ariard ariard left a comment

Choose a reason for hiding this comment

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

I think you should also modify doc/bips.md to mention we don't support BIP 152 version 1 anymore.

test/functional/p2p_compactblocks.py Show resolved Hide resolved
src/net_processing.cpp Outdated Show resolved Hide resolved
src/net_processing.cpp Show resolved Hide resolved
src/net_processing.cpp Outdated Show resolved Hide resolved
src/net_processing.cpp Outdated Show resolved Hide resolved
src/net_processing.cpp Show resolved Hide resolved
src/net_processing.cpp Outdated Show resolved Hide resolved
@jnewbery jnewbery force-pushed the 2020-12-remove-cmpctblock-v1 branch 2 times, most recently from f3c8cf2 to 77cd1a8 Compare February 3, 2021 10:12
@jnewbery
Copy link
Contributor Author

jnewbery commented Feb 3, 2021

Thanks for the review @jonatack @ariard @sipa @MarcoFalke . I think I've addresses all review comments now.

This PR is probably easier to review if rebased after #21009 is merged. That PR always sets NODE_WITNESS in local services, and so removes all the pfrom->GetLocalServices() & NODE_WITNESS calls in net_processing.

@dhruv
Copy link
Contributor

dhruv commented Feb 5, 2021

#21009 was split into #21009 and #21090. #21090 now sets NODE_WITNESS in local services, and so removes all the pfrom->GetLocalServices() & NODE_WITNESS calls in net_processing.

- use better local variable names
- drop unnecessary if statements
fPreferHeaderAndIDs -> m_requested_hb_cmpctblocks
fProvidesHeaderAndIDs -> m_provides_cmpctblocks
…elay if segwit is enabled

This introduces an early exit in PeerManagerImpl::NewPoWValidBlock() if
segwit has not been activated for the block. This means that we won't cache the
block/compact block for fast relay and won't relay the cmpctblock
immediately to peers that have requested hb compact blocks. This is fine
because any block where segwit is not yet activated is buried deep in
the chain, and so compact block relay will not be effective.

It's ok not to cache the block/compact block for fast relay for the same
reason - the block must be very deeply buried in the block chain.

ProcessBlockAvailability() also won't get called for all nodes. This is
also fine, since that function only updates hashLastUnknownBlock
and pindexBestKnownBlock, and is called early in every SendMessages()
call.
@jnewbery jnewbery force-pushed the 2020-12-remove-cmpctblock-v1 branch from 4c6d983 to a50e34c Compare May 15, 2022 20:23
@bitcoin bitcoin deleted a comment May 15, 2022
@jnewbery
Copy link
Contributor Author

Thanks for the reviews @dergoegge and @MarcoFalke. I've addressed all review comments and rebased on latest master.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

re-ACK a50e34c after rebase 👓

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

re-ACK a50e34c367608fcec9697893981bfa294a7c08d after rebase 👓
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgSIwwAx5jdanYqhTgoX2H5SG6pQ9aoBujOCn7R5sg8loLagrlzE9YOMkNxqTHJ
HY3V4lI3HFaa6TGqgowJNY2MbxNGQ3zqfepGsYe18NINnbnNDt6ZHG54uFQ65foV
hv4GRKRAZ4NGZ2mq28LVwLrVJTyQPIepurdlGLRmzSpRPcLnO81maL+48vFgle7T
H6o1sabgMWGffyfk6sUF+DxgYlk7JiKV8qVYcW3THAZhPuU1UBULB/fCZHnNjNEI
in5vTyIjEaraWyCpawc2OED0MjXghU1bwi8VU630hNE9DdnpBYMhq2TXKC52KM/n
SHIokmIIPk4mpif8S6RBZZGwUS5B28PgAoRfteEk5ce0P+CeewWnMppZFl7lMkSk
aHxl6e7UU7jqjtvotOE5TAubGMG0vn4oWnPx0k3PTtMMFRuSRj5gVvyH5D0y0BbL
90+0z3sS709purkQ+5q+zx11l1sMewFHTxcuVOyjMZ6aM2jd3SFi2MDfB/kPeyqd
mNXfG6pu
=E4BX
-----END PGP SIGNATURE-----

@fanquake fanquake requested a review from dergoegge May 16, 2022 09:07
@dergoegge
Copy link
Member

ACK a50e34c - Only changes since my last review were a rebase and some nits.

Reviewed using git range-diff 5d53cf38784df9ad9ed10306bf3fba3002fd9244..4c6d983708c94af10676048d1c1379be225b8f33 b74a6dde8cf50703a8814d402333580e4cdfea59..a50e34c367608fcec9697893981bfa294a7c08d1

@fanquake fanquake merged commit dc0ee57 into bitcoin:master May 16, 2022
@jnewbery jnewbery deleted the 2020-12-remove-cmpctblock-v1 branch May 16, 2022 14:23
jnewbery added a commit to jnewbery/bitcoin that referenced this pull request May 16, 2022
All uses of CBlockHeaderAndShortTxIDs in the product code are
constructed with fUseWTXID=true, so remove the parameter.

There is one use of the CBlockHeaderAndShortTxIDs constructor with
fUseWTXID=false in the unit tests. This is used to construct a
CBlockHeaderAndShortTxIDs for a block with only the coinbase
transaction, so setting fUseWTXID to true or false makes no difference.

Suggested in bitcoin#20799 (review)
jnewbery added a commit to jnewbery/bitcoin that referenced this pull request May 16, 2022
The only place that segwit=True is for a block that contains only the
coinbase transaction. Since the witness commitment is optional if none
of the transactions have a witness, we can leave it out. This doesn't
change the test coverage, which is testing p2p compact block logic.

Suggested in bitcoin#20799 (comment)
@jnewbery
Copy link
Contributor Author

Review suggestions implemented in #25147

jnewbery added a commit to jnewbery/bitcoin that referenced this pull request May 17, 2022
All uses of CBlockHeaderAndShortTxIDs in the product code are
constructed with fUseWTXID=true, so remove the parameter.

There is one use of the CBlockHeaderAndShortTxIDs constructor with
fUseWTXID=false in the unit tests. This is used to construct a
CBlockHeaderAndShortTxIDs for a block with only the coinbase
transaction, so setting fUseWTXID to true or false makes no difference.

Suggested in bitcoin#20799 (review)
jnewbery added a commit to jnewbery/bitcoin that referenced this pull request May 17, 2022
The only place that segwit=True is for a block that contains only the
coinbase transaction. Since the witness commitment is optional if none
of the transactions have a witness, we can leave it out. This doesn't
change the test coverage, which is testing p2p compact block logic.

Suggested in bitcoin#20799 (comment)
jnewbery added a commit to jnewbery/bitcoin that referenced this pull request May 17, 2022
The only place that segwit=True is for a block that contains only the
coinbase transaction. Since the witness commitment is optional if none
of the transactions have a witness, we can leave it out. This doesn't
change the test coverage, which is testing p2p compact block logic.

Suggested in bitcoin#20799 (comment)
jnewbery added a commit to jnewbery/bitcoin that referenced this pull request May 18, 2022
The only place that segwit=True is for a block that contains only the
coinbase transaction. Since the witness commitment is optional if none
of the transactions have a witness, we can leave it out. This doesn't
change the test coverage, which is testing p2p compact block logic.

Suggested in bitcoin#20799 (comment)
fanquake added a commit that referenced this pull request May 19, 2022
…for v1 compact blocks)

bf6526f [test] Remove segwit argument from build_block_on_tip() (John Newbery)
c65bf50 Remove fUseWTXID parameter from CBlockHeaderAndShortTxIDs constructor (John Newbery)

Pull request description:

  This implements two of the suggestions from code reviews of PR 20799:

  - Remove fUseWTXID parameter from CBlockHeaderAndShortTxIDs constructor
  - Remove segwit argument from build_block_on_tip()

ACKs for top commit:
  dergoegge:
    Code review ACK bf6526f
  naumenkogs:
    ACK bf6526f

Tree-SHA512: d553791d1364b9e655183755e829b195c9b47f59c62371dbae49d9c0f8d84fec58cf18f4dde89591672ef5658e18c9cf0206c2efd70606980f87e506bc3bd4e5
naumenkogs pushed a commit to naumenkogs/bitcoin that referenced this pull request May 23, 2022
All uses of CBlockHeaderAndShortTxIDs in the product code are
constructed with fUseWTXID=true, so remove the parameter.

There is one use of the CBlockHeaderAndShortTxIDs constructor with
fUseWTXID=false in the unit tests. This is used to construct a
CBlockHeaderAndShortTxIDs for a block with only the coinbase
transaction, so setting fUseWTXID to true or false makes no difference.

Suggested in bitcoin#20799 (review)
naumenkogs pushed a commit to naumenkogs/bitcoin that referenced this pull request May 23, 2022
The only place that segwit=True is for a block that contains only the
coinbase transaction. Since the witness commitment is optional if none
of the transactions have a witness, we can leave it out. This doesn't
change the test coverage, which is testing p2p compact block logic.

Suggested in bitcoin#20799 (comment)
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 28, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 28, 2022
janus pushed a commit to BitgesellOfficial/bitgesell that referenced this pull request Aug 4, 2022
All uses of CBlockHeaderAndShortTxIDs in the product code are
constructed with fUseWTXID=true, so remove the parameter.

There is one use of the CBlockHeaderAndShortTxIDs constructor with
fUseWTXID=false in the unit tests. This is used to construct a
CBlockHeaderAndShortTxIDs for a block with only the coinbase
transaction, so setting fUseWTXID to true or false makes no difference.

Suggested in bitcoin/bitcoin#20799 (review)
janus pushed a commit to BitgesellOfficial/bitgesell that referenced this pull request Aug 4, 2022
The only place that segwit=True is for a block that contains only the
coinbase transaction. Since the witness commitment is optional if none
of the transactions have a witness, we can leave it out. This doesn't
change the test coverage, which is testing p2p compact block logic.

Suggested in bitcoin/bitcoin#20799 (comment)
@bitcoin bitcoin locked and limited conversation to collaborators Feb 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet