aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.h
AgeCommit message (Collapse)Author
2021-12-30scripted-diff: Bump copyright headersHennadii Stepanov
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT- Commits of previous years: * 2020: fa0074e2d82928016a43ca408717154a1c70a4db * 2019: aaaaad6ac95b402fe18d019d67897ced6b316ee0
2021-08-23doc: Remove incorrect INIT_PROTO_VERSION from nTime commentMarcoFalke
2021-08-21refactor: move CAddress-without-nTime logic to net_processingPieter Wuille
Historically, the VERSION message contains an "addrMe" and an "addrYou". As these are sent before version negotiation is complete, the protocol version is INIT_PROTO_VERSION (209), and in that protocol, CAddress is serialized without nTime. This is in fact the only situation left where a CAddress is (de)serialized without nTime. As it's such a simple structure (CService for ip/port + uint64_t for nServices), just inline that structure in the few places where it occurs, and remove the logic for dealing with missing nTime from CAddress.
2021-05-24Add roundtrip fuzz tests for CAddress serializationPieter Wuille
2021-05-24Introduce well-defined CAddress disk serializationPieter Wuille
Before this commit, CAddress disk serialization was messy. It stored CLIENT_VERSION in the first 4 bytes, optionally OR'ed with ADDRV2_FORMAT. - All bits except ADDRV2_FORMAT were ignored, making it hard to use for actual future format changes. - ADDRV2_FORMAT determines whether or not nServices is serialized in LE64 format or in CompactSize format. - Whether or not the embedded CService is serialized in V1 or V2 format is determined by the stream's version having ADDRV2_FORMAT (as opposed to the nServices encoding, which is determined by the disk version). To improve the situation, this commit introduces the following disk serialization format, compatible with earlier versions, but better defined for future changes: - The first 4 bytes store a format version number. Its low 19 bits are ignored (as it historically stored the CLIENT_VERSION), but its high 13 bits specify the serialization exactly: - 0x00000000: LE64 encoding for nServices, V1 encoding for CService - 0x20000000: CompactSize encoding for nServices, V2 encoding for CService - Any other value triggers an unsupported format error on deserialization, and can be used for future format changes. - The ADDRV2_FORMAT flag in the stream's version does not impact the actual serialization format; it only determines whether V2 encoding is permitted; whether it's actually enabled depends solely on the disk version number. Operationally the changes to the deserializer are: - Failure when the stored format version number is unexpected. - The embedded CService's format is determined by the stored format version number rather than the stream's version number. These do no introduce incompatibilities, as no code versions exist that write any value other than 0 or 0x20000000 in the top 13 bits, and no code paths where the stream's version differs from the stored version.
2021-05-13refactor: Replace memset calls with array initializationJoĆ£o Barbosa
2021-05-11net: initialize nMessageSize to max uint32_t instead of -1eugene
nMessageSize is uint32_t and is set to -1. This will warn with -fsanitize=implicit-integer-sign-change.
2020-12-31scripted-diff: Bump copyright headersMarcoFalke
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT-
2020-12-08Remove unused bits from service flags enumMarcoFalke
2020-10-09net: advertise support for ADDRv2 via new messageVasil Dimov
Introduce a new message `sendaddrv2` to signal support for ADDRv2. Send the new message immediately after sending the `VERACK` message. Add support for receiving and parsing ADDRv2 messages. Send ADDRv2 messages (instead of ADDR) to a peer if he has advertised support for it. Co-authored-by: Carl Dong <contact@carldong.me>
2020-10-09net: CAddress & CAddrMan: (un)serialize as ADDRv2Vasil Dimov
Change the serialization of `CAddrMan` to serialize its addresses in ADDRv2/BIP155 format by default. Introduce a new `CAddrMan` format version (3). Add support for ADDRv2 format in `CAddress` (un)serialization. Co-authored-by: Carl Dong <contact@carldong.me>
2020-09-22Remove header checks out of net_processingTroy Giorshev
This moves header size and netmagic checking out of net_processing and into net. This check now runs in ReadHeader, so that net can exit early out of receiving bytes from the peer. IsValid is now slimmed down, so it no longer needs a MessageStartChars& parameter. Additionally this removes the rest of the m_valid_* members from CNetMessage.
2020-09-22Change CMessageHeader ConstructorTroy Giorshev
This commit removes the single-parameter contructor of CMessageHeader and replaces it with a default constructor. The single parameter contructor isn't used anywhere except for tests. There is no reason to initialize a CMessageHeader with a particular messagestart. This messagestart should always be replaced when deserializing an actual message header so that we can run checks on it. The default constructor initializes it to zero, just like the command and checksum. This also removes a parameter of a V1TransportDeserializer constructor, as it was only used for this purpose.
2020-09-03Merge #19818: p2p: change `CInv::type` from `int` to `uint32_t`, fix UBSan ā†µWladimir J. van der Laan
warning 7984c39be11ca04460883365e1ae2a496aaa6c0e test framework: serialize/deserialize inv type as unsigned int (Jon Atack) 407175e0c2bc797599ebd9c0a1f2ec89ad7af136 p2p: change CInv::type from int to uint32_t (Jon Atack) Pull request description: Fixes UBSan implicit-integer-sign-change issue per https://github.com/bitcoin/bitcoin/pull/19610#issuecomment-680686460. Credit to Crypt-iQ for finding and reporting the issue and to vasild for the original review suggestion in https://github.com/bitcoin/bitcoin/pull/19590#pullrequestreview-455788826. Closes #19678. ACKs for top commit: laanwj: ACK 7984c39be11ca04460883365e1ae2a496aaa6c0e MarcoFalke: ACK 7984c39be11ca04460883365e1ae2a496aaa6c0e šŸŒ» vasild: ACK 7984c39be Tree-SHA512: 59f3a75f40ce066ca6f0bb1927197254238302b4073af1574bdbfe6ed580876437be804be4e47d51467d604f0d9e3a5875159f7f2edbb2351fdb2bb9465100b5
2020-08-27p2p: change CInv::type from int to uint32_tJon Atack
fixes issue #19678 UBSan implicit-integer-sign-change Credit to Eugene (Crypt-iQ) for finding and reporting the issue and to Vasil Dimov (vasild) for the original suggestion
2020-08-26p2p: add CInv block message helper methodsJon Atack
2020-08-18Merge #19721: p2p: comment out unused MSG_FILTERED_WITNESS_BLOCKfanquake
4792cad88c5c3c93e639a051df779230ee817396 doc: comment out and add annotation to unused MSG_FILTERED_WITNESS_BLOCK (Adam Jonas) Pull request description: Commenting out and adding a note to unused `MSG_FILTERED_WITNESS_BLOCK` [defined in BIP144](https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki#relay). There was an attempt to make use of this in https://github.com/bitcoin/bitcoin/pull/10350, but it was closed due to lack of support. (h/t sdaftuar for pointing to the PR and jnewbery for the idea) ACKs for top commit: jnewbery: Obvious ACK 4792cad88c5c3c93e639a051df779230ee817396 theStack: ACK https://github.com/bitcoin/bitcoin/pull/19721/commits/4792cad88c5c3c93e639a051df779230ee817396 šŸ“œ MarcoFalke: cr ACK 4792cad88c5c3c93e639a051df779230ee817396 good to keep it around in a comment to avoid accidental future re-assignment practicalswift: ACK 4792cad88c5c3c93e639a051df779230ee817396 Tree-SHA512: 22327ddded643ae50fdb529e4529a9b464f74e90620d0d2079a11070eaa8afe8363f6e14cca52f3bec2c9f87ee13e318edc6c5193761c94b8ae77be353a8da1f
2020-08-16Merge #19705: Shrink CAddress from 48 to 40 bytes on x64Wladimir J. van der Laan
767073fb9645f5cb0976a14288c03fe71912b569 Shrink CAddress from 48 to 40 bytes on x64 (Vasil Dimov) Pull request description: `CAddress` inherits `CService` which is 28 bytes (on 64 bit machines). `CAddress` then adds two member variables - one that requires 4 byte alignment (`nTime`) and one that requires 8 byte alignment (`nServices`). Declare the smaller one first so that it fits in bytes 29..32. On 32 bit machines this change has no effect and `CAddress` remains 40 bytes. ACKs for top commit: laanwj: ACK 767073fb9645f5cb0976a14288c03fe71912b569 theStack: ACK https://github.com/bitcoin/bitcoin/commit/767073fb9645f5cb0976a14288c03fe71912b569 Tree-SHA512: 73d6a4fcfa2687b4076950801871252e369510ecf09f820576dbeca9ee3ee94d14672e7d5596cb45fedd9e4b973dd0716a2ea3f13fc3058b4b697d036a7c9db0
2020-08-14doc: comment out and add annotation to unused MSG_FILTERED_WITNESS_BLOCKAdam Jonas
2020-08-13Merge #19070: p2p: Signal support for compact block filters with ā†µWladimir J. van der Laan
NODE_COMPACT_FILTERS f5c003d3ead182335252558c5c6c9b9ca8968065 [test] Add test for NODE_COMPACT_FILTER. (Jim Posen) 132b30d9c84f2a8053714a438f227b583a89a9ea [net] Signal NODE_COMPACT_FILTERS if we're serving compact filters. (Jim Posen) b3fbc94d4f2937bb682f2766cc9a8d4fde328a3f Apply cfilters review fixups (John Newbery) Pull request description: If -peerblockfilters is configured, signal the `NODE_COMPACT_FILTERS` service bit to indicate that we are able to serve compact block filters, headers and checkpoints. ACKs for top commit: MarcoFalke: re-review and Concept ACK f5c003d3ead182335252558c5c6c9b9ca8968065 fjahr: Code review ACK f5c003d3ead182335252558c5c6c9b9ca8968065 clarkmoody: Concept ACK f5c003d3ead182335252558c5c6c9b9ca8968065 ariard: Concept and Code Review ACK f5c003d jonatack: ACK f5c003d3e Tree-SHA512: 34d1c153530a0e55d09046fe548c9dc37344b5d6d50e00af1b4e1de1e7b49de770fca8471346a17c151de9fe164776296bb3dd5af331977f0c3ef1e6fc906f85
2020-08-12Shrink CAddress from 48 to 40 bytes on x64Vasil Dimov
`CAddress` inherits `CService` which is 28 bytes (on 64 bit machines). `CAddress` then adds two member variables - one that requires 4 byte alignment (`nTime`) and one that requires 8 byte alignment (`nServices`). Declare the smaller one first so that it fits in bytes 29..32. On 32 bit machines this change has no effect and `CAddress` remains 40 bytes.
2020-08-01scripted-diff: Remove Reference LinksRobert
-BEGIN VERIFY SCRIPT- sed -i '/https:\/\/bitcoin.org\/en\/developer-reference/d' ./src/protocol.h -END VERIFY SCRIPT-
2020-07-30refactor: add GenTxid (=txid or wtxid) type and use it for tx request logicPieter Wuille
2020-07-27p2p: add CInv transaction message helper methodsJon Atack
2020-07-19Add p2p message "wtxidrelay"Suhas Daftuar
When sent to and received from a given peer, enables using wtxid's for announcing and fetching transactions with that peer.
2020-07-19Add support for tx-relay via wtxidSuhas Daftuar
This adds a field to CNodeState that tracks whether to relay transactions with that peer via wtxid, instead of txid. As of this commit the field will always be false, but in a later commit we will add a way to negotiate turning this on via p2p messages exchanged with the peer.
2020-07-10[protocol] Remove unused CADDR_TIME_VERSIONJohn Newbery
Add comments to CAddress serialization code explaining why it's no longer needed.
2020-05-31[net] Signal NODE_COMPACT_FILTERS if we're serving compact filters.Jim Posen
If -peerblockfilters is configured, signal the NODE_COMPACT_FILTERS service bit to indicate that we are able to serve compact block filters, headers and checkpoints.
2020-05-31Merge #19044: net processing: Add support for getcfiltersMarcoFalke
9e36067d8cd02830c7e5a88a391dff6ac3adbe0c [test] Add test for cfilters. (Jim Posen) 11106a4722558765a44ae45c7892724a73ce514c [net processing] Message handling for getcfilters. (Jim Posen) e535670726952e43483763dfca6fc6ec2f4b0691 [indexes] Fix default [de]serialization of BlockFilter. (Jim Posen) bb911ae7f5cbe4974ec61266d2334b95067fa49d [refactor] Pass CNode and CConnman by reference (John Newbery) Pull request description: Support `getcfilters` requests when `-peerblockfilters` is set. Does not advertise compact filter support in version messages. ACKs for top commit: Empact: re-Code Review ACK https://github.com/bitcoin/bitcoin/pull/19044/commits/9e36067d8cd02830c7e5a88a391dff6ac3adbe0c MarcoFalke: re-ACK 9e36067d8c , only change is adding commit "[refactor] Pass CNode and CConnman by reference" šŸ„‘ jkczyz: ACK 9e36067d8cd02830c7e5a88a391dff6ac3adbe0c fjahr: Code review ACK 9e36067d8cd02830c7e5a88a391dff6ac3adbe0c Tree-SHA512: b45b42a25905ef0bd9e195029185300c86856c87f78cbe17921f4a25e159ae0f6f003e61714fa43779017eb97cd89d3568419be88e47d19dc8095562939e7887
2020-05-29util: dedup code in callers of serviceFlagToStr()Vasil Dimov
Introduce `serviceFlagsToStr()` which hides the internals of the bitmask and simplifies callers of `serviceFlagToStr()`.
2020-05-29util: simplify the interface of serviceFlagToStr()Vasil Dimov
Don't take two redundant arguments in `serviceFlagToStr()`. As a side effect this fixes an issue introduced in https://github.com/bitcoin/bitcoin/pull/18165 due to which the GUI could print something like `UNKNOWN[1033] & UNKNOWN[1033] & UNKNOWN[2^10]` instead of `NETWORK & WITNESS`.
2020-05-29Merge #18165: Consolidate service flag bit-to-name conversion to a shared ā†µJonas Schnelli
serviceFlagToStr function c31bc5bcfddf440e9a1713f7ba2ca2bf9cfa8e2e Consolidate service flag bit-to-name conversion to a shared serviceFlagToStr function (Luke Dashjr) cea91a1e40e12029140ebfba969ce3ef2965029c Bugfix: GUI: Use unsigned long long type to avoid implicit conversion of MSB check (Luke Dashjr) Pull request description: Side effect: this results in the RPC showing unknown service bits as "UNKNOWN[n]" like the GUI. Note that there is no common mask-to-`vector<string>` function because both GUI and RPC would need to iterate through it to convert to their desired target formats. ACKs for top commit: jonasschnelli: utACK ~~cea91a1e40e12029140ebfba969ce3ef2965029c~~ c31bc5bcfddf440e9a1713f7ba2ca2bf9cfa8e2e Tree-SHA512: 32c7ba8ac7ef2d4087f4f317447ae93a328ec9fb9ad81301df2fbaeeb21a3db7a503187a369552b05a9414251b7cf8e15bcde74c1ea2ef36591ea7ffb6721f60
2020-05-26[net processing] Message handling for getcfilters.Jim Posen
Handle getcfilters request if -peercfilter is configured.
2020-05-22[net processing] Message handling for getcfheaders.Jim Posen
if -peerblockfilters is configured, handle requests for cfheaders.
2020-05-20net: Use C++11 member initialization in protocolMarcoFalke
2020-05-20Merge #18317: Serialization improvements step 6 (all except wallet/gui)MarcoFalke
f9ee0f37c28f604bc82dab502ce229c66ef5b3b9 Add comments to CustomUintFormatter (Pieter Wuille) 4eb5643e3538863c9d2ff261f49a9a1b248de243 Convert everything except wallet/qt to new serialization (Pieter Wuille) 2b1f85e8c52c8bc5a17eae4c809eaf61d724af98 Convert blockencodings_tests to new serialization (Pieter Wuille) 73747afbbeb013669faf4c4d2c0903cec4526fb0 Convert merkleblock to new serialization (Pieter Wuille) d06fedd1bc26bf5bf2b203d4445aeaebccca780e Add SER_READ and SER_WRITE for read/write-dependent statements (Russell Yanofsky) 6f9a1e5ad0a270d3b5a715f3e3ea0911193bf244 Extend CustomUintFormatter to support enums (Russell Yanofsky) 769ee5fa0011ae658770586442715452a656559d Merge BigEndian functionality into CustomUintFormatter (Pieter Wuille) Pull request description: The next step of changes from #10785. This: * Adds support for enum serialization to `CustomUintFormatter`, used in `CAddress` for service flags. * Merges `BigEndian` into `CustomUintFormatter`, used in `CNetAddr` for port numbers. * Converts everything (except wallet and gui) to use the new serialization framework. ACKs for top commit: MarcoFalke: re-ACK f9ee0f37c2, only change is new documentation commit for CustomUintFormatter šŸ“‚ ryanofsky: Code review ACK f9ee0f37c28f604bc82dab502ce229c66ef5b3b9. Just new commit adding comment since last review jonatack: Code review re-ACK f9ee0f37c28f604bc82dab502ce229c6 only change since last review is an additional commit adding Doxygen documentation for `CustomUintFormatter`. Tree-SHA512: e7a0a36afae592d5a4ff8c81ae04d858ac409388e361f2bc197d9a78abca45134218497ab2dfd6d031e0cce0ca586cf857077b7c6ce17fccf67e2d367c1b6cd4
2020-05-17net: Run clang-format on protocol.hMarcoFalke
Can be reviewed with the git diff flags -U0 --ignore-all-space --word-diff-regex=.
2020-05-17net: Remove un-actionable TODOMarcoFalke
2020-05-08[net processing] Message handling for getcfcheckpt.Jim Posen
If -peerblockfilters is configured, handle requests for cfcheckpt.
2020-03-30Convert everything except wallet/qt to new serializationPieter Wuille
2020-02-21Consolidate service flag bit-to-name conversion to a shared serviceFlagToStr ā†µLuke Dashjr
function Side effect: this results in the RPC showing unknown service bits as "UNKNOWN[n]" like the GUI. Note that there is no common mask-to-vector<string> function because both GUI and RPC would need to iterate through it to convert to their desired target formats.
2020-02-06net: Fail instead of truncate command name in CMessageHeaderWladimir J. van der Laan
Replace the memset/strncpy dance in `CMessageHeader::CMessageHeader` with explicit code that copies then name and asserts the length. This removes a warning in g++ 9.1.1 and IMO makes the code more readable by not relying on strncpy padding and silent truncation behavior.
2019-12-11Merge #17474: Bugfix: GUI: Recognise NETWORK_LIMITED in formatServicesStrMarcoFalke
4341bffb6ef10909f3721329db27c5dc9bc720dd GUI: Refactor formatServicesStr to warn when a ServicesFlag is missing (Luke Dashjr) df77de8c2157fbb4c0898586dacb2215286745c8 Bugfix: GUI: Recognise NETWORK_LIMITED in formatServicesStr (Luke Dashjr) Pull request description: Currently, only the bottom 8 service bits are shown in the GUI peer details view. `NODE_NETWORK_LIMITED` is the 11th bit (2^10). The first commit expands the range to cover the full 64 bits, and properly label `"NETWORK_LIMITED"`. The second commit refactors the code so that any future omitted service bits will trigger a compile warning. ACKs for top commit: jonasschnelli: utACK 4341bffb6ef10909f3721329db27c5dc9bc720dd jonasschnelli: Tested ACK 4341bffb6ef10909f3721329db27c5dc9bc720dd hebasto: Concept ACK 4341bffb6ef10909f3721329db27c5dc9bc720dd Tree-SHA512: 8338737d03fbcd92024159aabd7e632d46e13c72436d935b504d2bf7ee92b7d124e89a5917bf64d51c87f12a64de703270c2d7b4c6711fa8ed08ea7887d817c7
2019-11-14GUI: Refactor formatServicesStr to warn when a ServicesFlag is missingLuke Dashjr
2019-10-15Remove unused includespracticalswift
2019-10-02p2p: Remove BIP61 reject messagesMarcoFalke
2019-07-12Remove unused bits from the service flags enumMarcoFalke
2019-01-05Use C++11 default member initializersMarcoFalke
2018-07-27Update copyright headers to 2018DrahtBot
2018-04-10Merge #12731: Support serialization as another type without castingWladimir J. van der Laan
818dc74 Support serialization as another type without casting (Pieter Wuille) Pull request description: This adds a `READWRITEAS(type, obj)` macro which serializes `obj` as if it were converted to `const type&` when `const`, and to `type&` when non-`const`. No actual cast is involved, so this only works when this conversion can be done automatically. This makes it usable in serialization code that uses a single implementation for both serialization and deserializing, which doesn't know the constness of the object involved. This is a redo of #12712, using a slightly different interface. Tree-SHA512: 262f0257284ff99b5ffaec9b997c194e221522ba35c3ac8eaa9bb344449d7ea0a314de254dc77449fa7aaa600f8cd9a24da65aade8c1ec6aa80c6e9a7bba5ca7