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

Do not send (potentially) invalid headers in response to getheaders #11580

Merged
merged 2 commits into from Nov 9, 2017

Conversation

TheBlueMatt
Copy link
Contributor

Nowhere else in the protocol do we send headers which are for
blocks we have not fully validated except in response to getheaders
messages with a null locator. On my public node I have not seen any
such request (whether for an invalid block or not) in at least two
years of debug.log output, indicating that this should have minimal
impact.

@fanquake fanquake added the P2P label Oct 30, 2017
@@ -1986,8 +1982,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
return true;
pindex = (*mi).second;

if (!chainActive.Contains(pindex) &&
!StaleBlockRequestAllowed(pindex, chainparams.GetConsensus())) {
if (!StaleBlockRequestAllowed(pindex, chainparams.GetConsensus())) {
Copy link
Member

Choose a reason for hiding this comment

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

So it was missing IsValid(BLOCK_VALID_SCRIPTS) here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Missing" is a strong word given there isn't exactly a spec for the P2P protocol, but, yes, I'd say it should be there.

Copy link
Member

Choose a reason for hiding this comment

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

Should be tagged backport then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Meh, dont think it matters too much.

Copy link
Contributor

@jimpo jimpo 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

@@ -759,7 +759,8 @@ void Misbehaving(NodeId pnode, int howmuch)
static bool StaleBlockRequestAllowed(const CBlockIndex* pindex, const Consensus::Params& consensusParams)
{
AssertLockHeld(cs_main);
return (pindexBestHeader != nullptr) &&
if (chainActive.Contains(pindex)) return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that this function is expected to accept main chain blocks, maybe change the function name to BlockRequestAllowed?

@@ -759,7 +759,8 @@ void Misbehaving(NodeId pnode, int howmuch)
static bool StaleBlockRequestAllowed(const CBlockIndex* pindex, const Consensus::Params& consensusParams)
{
AssertLockHeld(cs_main);
return (pindexBestHeader != nullptr) &&
if (chainActive.Contains(pindex)) return true;
return pindex->IsValid(BLOCK_VALID_SCRIPTS) && (pindexBestHeader != nullptr) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the function comment to describe this condition.

Nowhere else in the protocol do we send headers which are for
blocks we have not fully validated except in response to getheaders
messages with a null locator. On my public node I have not seen any
such request (whether for an invalid block or not) in at least two
years of debug.log output, indicating that this should have minimal
impact.
@TheBlueMatt TheBlueMatt force-pushed the 2017-10-getheaders-valid-only branch 2 times, most recently from 7344795 to 3788a84 Compare October 30, 2017 22:59
@TheBlueMatt
Copy link
Contributor Author

Addressed @jimpo's comments.

@gmaxwell
Copy link
Contributor

gmaxwell commented Nov 1, 2017

utACK

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

I wrote a test for this change which you could include here: e79a9c9.

ACK 3788a84

@TheBlueMatt
Copy link
Contributor Author

TheBlueMatt commented Nov 2, 2017

Thanks @ryanofsky!

@laanwj
Copy link
Member

laanwj commented Nov 9, 2017

utACK 725b79a, thanks for adding the test @ryanofsky

@laanwj laanwj merged commit 725b79a into bitcoin:master Nov 9, 2017
laanwj added a commit that referenced this pull request Nov 9, 2017
…o getheaders

725b79a [test] Verify node doesn't send headers that haven't been fully validated (Russell Yanofsky)
3788a84 Do not send (potentially) invalid headers in response to getheaders (Matt Corallo)

Pull request description:

  Nowhere else in the protocol do we send headers which are for
  blocks we have not fully validated except in response to getheaders
  messages with a null locator. On my public node I have not seen any
  such request (whether for an invalid block or not) in at least two
  years of debug.log output, indicating that this should have minimal
  impact.

Tree-SHA512: c1f6e0cdcdfb78ea577d555f9b3ceb1b4b60eff4f6cf313bfd8b576c9562d797bea73abc23f7011f249ae36dd539c715f3d20487ac03ace60e84e1b77c0c1e1a
laanwj added a commit that referenced this pull request Dec 11, 2017
…g entries

be9f38c Do not make it trivial for inbound peers to generate log entries (Matt Corallo)

Pull request description:

  Based on #11580 because I'm lazy.

  We should generally avoid writing to debug.log unconditionally for
  inbound peers which misbehave (the peer being about to be banned
  being an exception, since they cannot do this twice).

Tree-SHA512: 8e59c8d08d00b1527951b30f4842d010a4c2fc440503ade112baa2c1b9afd0e0d1c5c2df83dde25183a242af45089cf9b9f873b71796771232ffb6c5fc6cc0cc
codablock pushed a commit to codablock/dash that referenced this pull request Mar 12, 2019
…ponse to getheaders

725b79a [test] Verify node doesn't send headers that haven't been fully validated (Russell Yanofsky)
3788a84 Do not send (potentially) invalid headers in response to getheaders (Matt Corallo)

Pull request description:

  Nowhere else in the protocol do we send headers which are for
  blocks we have not fully validated except in response to getheaders
  messages with a null locator. On my public node I have not seen any
  such request (whether for an invalid block or not) in at least two
  years of debug.log output, indicating that this should have minimal
  impact.

Tree-SHA512: c1f6e0cdcdfb78ea577d555f9b3ceb1b4b60eff4f6cf313bfd8b576c9562d797bea73abc23f7011f249ae36dd539c715f3d20487ac03ace60e84e1b77c0c1e1a
codablock pushed a commit to codablock/dash that referenced this pull request Mar 12, 2019
…ponse to getheaders

725b79a [test] Verify node doesn't send headers that haven't been fully validated (Russell Yanofsky)
3788a84 Do not send (potentially) invalid headers in response to getheaders (Matt Corallo)

Pull request description:

  Nowhere else in the protocol do we send headers which are for
  blocks we have not fully validated except in response to getheaders
  messages with a null locator. On my public node I have not seen any
  such request (whether for an invalid block or not) in at least two
  years of debug.log output, indicating that this should have minimal
  impact.

Tree-SHA512: c1f6e0cdcdfb78ea577d555f9b3ceb1b4b60eff4f6cf313bfd8b576c9562d797bea73abc23f7011f249ae36dd539c715f3d20487ac03ace60e84e1b77c0c1e1a
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 26, 2020
…rate log entries

be9f38c Do not make it trivial for inbound peers to generate log entries (Matt Corallo)

Pull request description:

  Based on bitcoin#11580 because I'm lazy.

  We should generally avoid writing to debug.log unconditionally for
  inbound peers which misbehave (the peer being about to be banned
  being an exception, since they cannot do this twice).

Tree-SHA512: 8e59c8d08d00b1527951b30f4842d010a4c2fc440503ade112baa2c1b9afd0e0d1c5c2df83dde25183a242af45089cf9b9f873b71796771232ffb6c5fc6cc0cc
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Jun 30, 2021
…rate log entries

be9f38c Do not make it trivial for inbound peers to generate log entries (Matt Corallo)

Pull request description:

  Based on bitcoin#11580 because I'm lazy.

  We should generally avoid writing to debug.log unconditionally for
  inbound peers which misbehave (the peer being about to be banned
  being an exception, since they cannot do this twice).

Tree-SHA512: 8e59c8d08d00b1527951b30f4842d010a4c2fc440503ade112baa2c1b9afd0e0d1c5c2df83dde25183a242af45089cf9b9f873b71796771232ffb6c5fc6cc0cc
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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

7 participants