Skip to content

Instantly share code, notes, and snippets.

@gavinandresen
Last active July 3, 2023 11:24
Show Gist options
  • Save gavinandresen/7079034 to your computer and use it in GitHub Desktop.
Save gavinandresen/7079034 to your computer and use it in GitHub Desktop.
Design sketch: "reject" p2p message

Design sketch: "reject" p2p message

Motivation

Mike Hearn has been lobbying for an "error" message in the Bitcoin p2p protocol for years (at least since the "ban peers if they send us garbage" denial-of-service mitigation code was pull-requested). This came up again with my proposed "smartfee" changes, which would drop low-priority or low-fee transactions.

In short, giving peers feedback about why their blocks or transactions are dropped or why they are being banned should help interoperability between different implementations, and will give SPV (simplified payment verification) clients feedback when their transactions are rejected due to insufficient priority or fees.

error" versus "reject"

I've gone with "reject" as the message, because "error" implies that the peer did something wrong-- and doing something wrong is only one of several possible reasons a connection, transaction, or block may be rejected.

##Specification

reject

One new message type "reject" is introduced. It is sent directly to a peer in response to a "version", "tx" or "block" message.

For example, the message flow between two peers for a relayed transaction that is rejected for some reason would be:

--> "inv"
<-- "getdata"
--> "tx"
<-- "reject"

common payload

Every "reject" message begins with the following fields. Some messages append extra, message-specific data.

Field SizeDescriptionData typeComments
?response-to-msgvar_strMessage that triggered the reject
1reject-codeuint8_t
?reasonvar_strHuman-readable message for debugging

The human-readable string is intended only for debugging purposes; in particular, different implementations may use different strings. The string should not be shown to users or used for anthing besides diagnosing interoperability problems.

The following reject code categories are used; in the descriptions below, "server" is the peer generating the reject message, "client" is the peer that will receive the message.

RangeCategory
0x01-0x0fProtocol syntax errors
0x10-0x1fProtocol semantic errors
0x40-0x4fServer policy rule

rejection codes common to all message types

CodeDescription
0x01Message could not be decoded

reject version codes

Codes generated during the intial connection process in response to a "version" message:

CodeDescription
0x11Client is an obsolete, unsupported version
0x12Duplicate version message received

reject tx payload, codes

Transaction rejection messages extend the basic message with the transaction id:

Field SizeDescriptionData typeComments
32txidchar[32]transaction that is rejected

The following codes are used:

Codedescription
0x10Transaction is invalid for some reason (invalid signature, output value greater than input, etc.)
0x40Not mined/relayed because it is "non-standard" (type or version unknown by the server)
0x41One or more output amounts are below the 'dust' threshold
0x42Transaction does not have enough fee/priority to be relayed or mined

payload, reject block

Block rejection messages extend the basic message with the block header hash:

Field SizeDescriptionData typeComments
32hashchar[32]block (hash of block header) that is rejected

Rejection codes:

codedescription
0x10Block is invalid for some reason (invalid proof-of-work, invalid signature, etc)
0x11Block's version is no longer supported
0x43Inconsistent with a compiled-in checkpoint

Note: blocks that are not part of the server's idea of the current best chain, but are otherwise valid, should not trigger "reject" messages.

Implementation notes

Sending "reject" messages to old nodes does no harm-- unknown commands are ignored for extensibility (in the reference implementation, at least-- other implementations should do the same). So there is no need to bump the protocol version.

Implementors should consider what happens if an attacker either sends them "reject" messages for valid transactions/blocks or sends them random "reject" messages, and should beware of possible denial-of-service attacks (e.g. blindly notifying the user of every "reject" message received would definitely be the wrong thing to do, and even blindly writing every "reject" message to a debug.log could open up a fill-up-disk DoS attack).

@kawalgrover
Copy link

So, with this implementation is it possible now, that if a message is perfectly valid, say the transactions inputs are all good and the fee is included, that there still exists a possibility that the nodes may decide to reject a message.

What if one of the big pools or a few of them got together and decide to reject all the messages that didn't come from one of them?

The motivation for this use case seems to be to avoid spamming (denial of service). I'm curious... has Bitcoin had to worry about DoS in this way in the past. Or are you guys pre-emptively trying to solve for something that has never happened.

PS: https://en.bitcoin.it/wiki/BIP_0061 is blank and I would have added this entire gist to the Wiki but it was locked.

@scalahub
Copy link

scalahub commented Jan 18, 2018

Can someone refer me to examples/test vectors of reject messages. Its a pain to generate them the hard way.

@DevRatnu
Copy link

Still this Protocol Running and work with Virtacoin VTA currency - Protocol 70002 as Sub-version : VirtaCoin:2.9.1
https://github.com/virtacoin/VirtaCoinProject

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment