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

Outbound peers disconnect - implement #2283 #2459

Open
wants to merge 2 commits into
base: 1.15.0-dev
Choose a base branch
from

Conversation

ReverseControl
Copy link
Collaborator

#2283 Suggested fix. However, it will disconnect outbound connection even if the invalid header comes from a compact block, which under BIP 152 there are scenarios where that is allowed.

We need a test for this. I would write it, but don't know how to. If someone can take care of that, or teach me how to do it, that would be great.

@rnicoll @patricklodder @michilumin

…logically equivalent to the old version but for when called as needed wuth first_invalid.
…ders even if from compact blocks (See BIP 152).
@patricklodder
Copy link
Member

I think that the BIP-152 text referred to is:

As high-bandwidth mode permits relaying of CMPCTBLOCK messages prior to full validation (requiring only that the block header is valid before relay), nodes SHOULD NOT ban a peer for announcing a new block with a CMPCTBLOCK message that is invalid, but has a valid header. For avoidance of doubt, nodes SHOULD bump their peer-to-peer protocol version to 70015 or higher to signal that they will not ban or punish a peer for announcing compact blocks prior to full validation, and nodes SHOULD NOT announce a CMPCTBLOCK to a peer with a version number below 70015 before fully validating the block.

Since we do run protocol version 70015 since 1.14.0, and Dogecoin currently has 2.5x higher bandwidth and 10x lower latency requirements than Bitcoin for blocks, this at first glance looks very relevant, because a non-malicious peer will craft and broadcast CMPCTBLOCK messages received from a malicious peer of its own if the header was valid: meaning the following code SHOULD NOT cause a disconnect if this and the preceding HEADER message were combined into a single CMPCTBLOCK message rather than a BLOCK message:

test_node.send_message(msg_block(block_1443))
# At this point we've sent an obviously-bogus block,
# and we must get disconnected
assert_equal(test_node.wait_for_disconnect(), True)
print("Successfully got disconnected after sending an invalid block")

However, this (CMPCTBLOCK-only announcement) will never happen on mainnet by 1.14.x nodes because CMPCTBLOCK will only be triggered if NODE_WITNESS is set:

uint64_t nCMPCTBLOCKVersion = (pfrom->GetLocalServices() & NODE_WITNESS) ? 2 : 1;

and that will only be set if the following condition is true:

if (chainparams.GetConsensus(0).vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0) {

and this condition is always false for all 1.14.x clients because of this:

consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 0; // Disabled

So because the relevance right now is low, I propose to postpone this one until the next minor release, with the note that:

  • 1.14/rpc tests #1431 disabled all CMPCTBLOCK tests even though the protocol is supported (and defaulted to in src/version.h !!!) - re-enabling that test (p2p-compactblocks.py) is a prerequisite for merging this PR.
  • This fix is likely to be a MUST HAVE before any v1.21 soft forks come into play and adds pressure to 1.21: bring back compatibility tests #2435, will probably impact 1.21 timelines.

@ReverseControl
Copy link
Collaborator Author

@patricklodder I agree. Let's move it to the next minor release.

@patricklodder patricklodder added this to In progress in 1.14.5 via automation Aug 18, 2021
@patricklodder patricklodder changed the title 1.14.4 outbound peers disconnect implement #2283 Outbound peers disconnect - implement #2283 Aug 19, 2021
@patricklodder patricklodder changed the base branch from 1.14.4-dev to 1.14.5-dev August 20, 2021 21:26
@patricklodder patricklodder added this to the 1.14.5 milestone Aug 20, 2021
@patricklodder
Copy link
Member

As mentioned above, this is blocked by not having p2p-compactblocks.py enabled. Adding do-not-merge as the test needs to work before changes from this PR, so that has to be raised separately.

@ReverseControl ReverseControl mentioned this pull request Sep 11, 2021
@rnicoll rnicoll modified the milestones: 1.14.5, 1.14.6 Sep 25, 2021
@patricklodder patricklodder removed this from In progress in 1.14.5 Nov 1, 2021
@patricklodder patricklodder added this to In progress in Next minor - 1.14.6 via automation Nov 1, 2021
ajarhserus
ajarhserus previously approved these changes Nov 6, 2021
@patricklodder patricklodder changed the base branch from 1.14.5-dev to 1.14.6-dev November 8, 2021 14:33
@patricklodder patricklodder dismissed ajarhserus’s stale review November 8, 2021 14:33

The base branch was changed.

@ReverseControl
Copy link
Collaborator Author

@patricklodder What is the status of this?

@patricklodder
Copy link
Member

This is still blocked because we still have no working p2p-compactblocks.py - I'll work on it.

@patricklodder patricklodder added this to 🚀 needs review in Review & merge board Mar 25, 2022
@patricklodder patricklodder moved this from 🚀 needs review to 🔨needs rework in Review & merge board Mar 25, 2022
@patricklodder patricklodder moved this from 🔨needs rework to 🛑 blocked in Review & merge board Mar 25, 2022
@xanimo
Copy link
Member

xanimo commented Jul 4, 2022

hey my apologies, i've been oblivious this was blocked on account of the non-functional test. perhaps i was in the know but forgot. :(

in any case i had been working on this 12/2021 and gutted most of the segwit code as modeled off an iteration of bitcoin-cash which i unfortunately can't find atm but seeing is how they didn't implement segwit and supported compact blocks i thought it a good reference. omitted the bch ref as it wasn't relevant.

the test passes, however i'm not certain it's what we need considering changing the test to make the code pass vs vice versa...anyway if anyone wants to use as a starting point, i've pushed a rebased version here for cherry-picking or whatever if worthy and if not i'll try to find some time to fix it up:
xanimo@aa2d05f

@patricklodder patricklodder removed this from In progress in Next minor - 1.14.6 Jul 9, 2022
@patricklodder patricklodder removed this from the 1.14.6 milestone Jul 9, 2022
@patricklodder patricklodder added this to the 1.14.7 milestone Jul 9, 2022
@patricklodder patricklodder changed the base branch from 1.14.6-dev to 1.14.7-dev July 21, 2022 05:01
@@ -247,9 +247,10 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons
* @param[in] block The block headers themselves
* @param[out] state This may be set to an Error state if any error occurred processing them
* @param[in] chainparams The params for the chain we want to connect to
* @param[out] store the invalid block here if there is one.

Choose a reason for hiding this comment

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

The new parameter was added to the end of the method, but this line makes it seem like it is located where the 'ppindex' is. I suggest swapping line 250 with line 251.

@patricklodder patricklodder mentioned this pull request Feb 8, 2024
43 tasks
@patricklodder patricklodder removed this from the 1.14.7 milestone Feb 16, 2024
@patricklodder patricklodder changed the base branch from 1.14.7-dev to 1.15.0-dev February 28, 2024 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

[vulnerability] Disconnect outbound peers on the invalid chain
8 participants