Skip to content

Conversation

jnewbery
Copy link
Contributor

@jnewbery jnewbery commented Dec 8, 2020

BIP 130 (sendheaders) and BIP 152 (compact blocks) do not specify at
which stage the sendheaders or sendcmpct messages should be sent.
Therefore we should tolerate them being sent before the version-verack
handshake is complete.

@fanquake fanquake added the P2P label Dec 8, 2020
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.

Concept ACK

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 8, 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:

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 2020-12-tolerate-early-send-messages branch from 2a942d4 to f72a624 Compare December 8, 2020 12:59
@jnewbery jnewbery changed the title [net processing] Tolerate sendheaders and sendcmpct messages before verack net processing: Tolerate sendheaders and sendcmpct messages before verack Dec 8, 2020
@benthecarman
Copy link
Contributor

ACK f72a624

@naumenkogs
Copy link
Member

I'm wondering whether this is a good allocation of review resources?
It makes practically no difference today, and maybe it won't make a difference ever (unless there's a new implementation I assume)?

At the same time, it's not like the review is super-easy. We had this code working for years now, and now we might miss some corner case of an attacker sending us something while on-VERACK structs are not even initialized yet.

Or perhaps if you're planning to rearrange sending signal messages, then I see the point.

@jnewbery jnewbery force-pushed the 2020-12-tolerate-early-send-messages branch from f72a624 to 427f573 Compare December 9, 2020 08:53
@jnewbery
Copy link
Contributor Author

jnewbery commented Dec 9, 2020

we might miss some corner case of an attacker sending us something while on-VERACK structs are not even initialized yet.

We don't initialize any structs in verack processing. verack processing simply sets fSuccessfullyConnected, logs, and sends the send* messages.

I'm wondering whether this is a good allocation of review resources?

How you allocate your time is up to you. If you don't think this is worth reviewing, then please don't feel under any obligation to spend time on it.

@jnewbery
Copy link
Contributor Author

jnewbery commented Dec 9, 2020

rebased

@practicalswift
Copy link
Contributor

practicalswift commented Dec 9, 2020

@jnewbery Just to understand the context of this change: is this purely a "follow the BIP" change, or is there any known scenario in which this change would improve interoperability with any currently existing client?

@jnewbery
Copy link
Contributor Author

jnewbery commented Dec 9, 2020

Is this purely a "follow the BIP" change, or is there any known scenario in which this change would improve interoperability with any currently existing client?

This is purely to follow the BIP. I don't know of any client that sends send* messages before verack. However, future clients may wish to do so (since that's a more rational place to negotiate features).

@jonatack
Copy link
Member

jonatack commented Dec 9, 2020

Concept ACK, IIUC correctly from a quick glance, the point of this PR is move-only of the hunk, from after the following "unsupported message" conditional to before it, confirm?

    if (!pfrom.fSuccessfullyConnected) {
        LogPrint(BCLog::NET, "Unsupported message \"%s\" prior to verack from peer=%d\n", SanitizeString(msg_type), pfrom.GetId());
        return;
    }

Should a proposal be made to update the BIPs on this point, similarly to BIPS 155/339?

@jnewbery
Copy link
Contributor Author

jnewbery commented Dec 9, 2020

the point of this PR is move-only of the hunk, from after the following "unsupported message" conditional to before it, confirm?

Correct, this PR moves the processing of sendheaders and sendcmpct to before the !pfrom.fSuccessfullyConnected conditional. I'm loathe to call it 'move-only' since it's a behaviour change.

Should a proposal be made to update the BIPs on this point, similarly to BIPS 155/339?

No, this change is simply updating our behaviour to be consistent with those BIPs (since neither specify when the message should be sent).

Copy link
Member

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

ACK 427f573

Lightly tested with blockfilterindex and peerbloomfilters enabled.

@jnewbery
Copy link
Contributor Author

jnewbery commented Dec 9, 2020

the point of this PR is move-only of the hunk, from after the following "unsupported message" conditional to before it, confirm?

Correct, this PR moves the processing of sendheaders and sendcmpct to before the !pfrom.fSuccessfullyConnected conditional. I'm loathe to call it 'move-only' since it's a behaviour change.

For a bit more context, I'd like to make the following change at some point:

Introduce a connection_state enum to CNode which can take the values:

  • NEW_CONNECTION (version message not received)
  • VERSION_RECEIVED (version message received, verack not received)
  • FULLY_CONNECTED (version and verack both received)
  • DISCONNECTING (node is being disconnected. I'm not sure if this is necessary/a good addition)

Then ProcessMessage() becomes a table which maps message types to:

  • a ProcessXXXXXMessage() function
  • connection_states where this message type can be processed
  • connection_states where the peer should be disconnected for sending this message type

That makes the state machine much more explicit.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 9, 2020

🕵️ @sipa has been requested to review this pull request as specified in the REVIEWERS file.

@jnewbery
Copy link
Contributor Author

rebased

@jnewbery jnewbery force-pushed the 2020-12-tolerate-early-send-messages branch from 427f573 to 82d0a43 Compare December 10, 2020 10:20
@laanwj
Copy link
Member

laanwj commented Dec 10, 2020

Code review ACK 82d0a43
Checked that this is move-only.

@jonatack
Copy link
Member

Code review re-ACK 82d0a43 per git range-diff da957cd 427f573 82d0a43

@benthecarman
Copy link
Contributor

Code review ACK 82d0a43

…erack

BIP 130 (sendheaders) and BIP 152 (compact blocks) do not specify at
which stage the `sendheaders` or `sendcmpct` messages should be sent.
Therefore we should tolerate them being sent before the version-verack
handshake is complete.
@jnewbery
Copy link
Contributor Author

rebased

@jnewbery jnewbery force-pushed the 2020-12-tolerate-early-send-messages branch from 82d0a43 to b316dcb Compare December 14, 2020 13:23
@maflcko
Copy link
Member

maflcko commented Dec 14, 2020

review ACK b316dcb 📒

Show signature and timestamp

Signature:

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

review ACK b316dcb758e3dbd302fbb5941a1b5b0ef5f1f207 📒
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjFTQv+MjBurQNjNB/sPp5ynOe9ZPZqoLsSdpWQK3Mco7MIGVe0IuCiXO9EEwNK
n6olAJEkeeze+rtrCig8m55yptQLnQy/Us4U5XrAUHCDqTGy+Uja6m1zt7YZJkvK
SLoQa1SJCtqdmN9r4X3Ejeeat/nVDWRFkrKRaUHxj7E4+jq871h31mjX9eNc2CB4
qwJQP/ZDK4oA0vzJuxqoU48Fs7HCXyk4XnXEm8hPLBmRLogJSF5B6V8+wULc++NT
2b5kUKBBQydqvDrzbOUPHs6QvnkoHflYq6b00BeQsdIy85GiT0TMZwi9G925cpf4
xwIwgEDaEL2GhLpjnKS5BlHyjECC6TarPfPdVaLC9rU45hjmY/PktgK3oJiUEO0o
1TfjFNRHJYkiIz7CuUlcQOWbEwurQeXKx4Kmuy0EpFgK5Z5H1HlILKB8Uo/cSIEB
dvGUZW2kODHCLEab2znPbGEhYej73gBgGiAp1o0MIDshYAW7DdYeNVQ5GC4UDph9
SrTxzuXa
=MU7a
-----END PGP SIGNATURE-----

Timestamp of file with hash 4d415a967d56551b5e8c98d1933644ad7c3b68b61fba3333c1eab1b112bdc144 -

@jonatack
Copy link
Member

jonatack commented Dec 14, 2020

Code review re-ACK b316dcb per git range-diff b103fdcb 82d0a43 b316dcb, rebase only

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

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

utACK b316dcb, only code movement from after verack check to before

@maflcko maflcko merged commit fff7d05 into bitcoin:master Dec 14, 2020
@jnewbery jnewbery deleted the 2020-12-tolerate-early-send-messages branch December 14, 2020 17:25
@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.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants