Skip to content

Commit c10900b

Browse files
authored
Merge pull request #468 from evoskuil/master
Define and use max_locator, add get_headers.start_hash(), style, comments.
2 parents bc77f01 + 3bf1a2c commit c10900b

File tree

14 files changed

+77
-22
lines changed

14 files changed

+77
-22
lines changed

include/bitcoin/network/error.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ enum error_t : uint8_t
7575
peer_disconnect,
7676
peer_unsupported,
7777
peer_insufficient,
78+
peer_timestamp,
7879
protocol_violation,
7980
channel_overflow,
8081
channel_underflow,

include/bitcoin/network/messages/enums/level.hpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,20 @@ namespace messages {
2828
// Minimum current libbitcoin protocol version: 31402
2929
// Minimum current satoshi protocol version: 31800
3030

31+
// * sendaddrv2 is unverioned in BIP155 but requires version 70016 in Sataoshi:
32+
// "BIP155 defines addrv2 and sendaddrv2 for all protocol versions, but some
33+
// implementations reject messages they don't know. As a courtesy, don't send
34+
// it to nodes with a version before 70016, as no software is known to support
35+
// BIP155 that doesn't announce at least that protocol version number."
36+
// ** TODO: these should be based solely on NODE_COMPACT_FILTERS signal, but we
37+
// may associate protocol version at which it was deployed.
38+
3139
// libbitcoin-network
3240
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3341
// version v1
3442
// verack v1
3543
// getaddr v1
44+
// sendaddrv2 v4 70016 BIP155 expanded address types (*)
3645
// addr v1
3746
// ping v1
3847
// ping v2 60001 BIP031 added nonce field
@@ -72,17 +81,12 @@ namespace messages {
7281
// cmpctblock v4 70014 BIP152
7382
// getblocktxn v4 70014 BIP152
7483
// sendcmpct v4 70014 BIP152
75-
76-
// TODO: these should be based solely on NODE_COMPACT_FILTERS signal.
77-
// TODO: but we may associate protocol version at which it was deployed.
78-
// cfilter v4 70015 BIP157 not BIP-associated to p2p version
79-
// getcfilters v4 70015 BIP157 not BIP-associated to p2p version
80-
// cfcheckpt v4 70015 BIP157 not BIP-associated to p2p version
81-
// getcfcheckpt v4 70015 BIP157 not BIP-associated to p2p version
82-
// cfheaders v4 70015 BIP157 not BIP-associated to p2p version
83-
// getcfheaders v4 70015 BIP157 not BIP-associated to p2p version
84-
85-
// sendaddrv2 -- 00000 BIP155 compat break, unversioned, handshake
84+
// cfilter v4 70015 BIP157 not BIP-associated to p2p version (**)
85+
// getcfilters v4 70015 BIP157 not BIP-associated to p2p version (**)
86+
// cfcheckpt v4 70015 BIP157 not BIP-associated to p2p version (**)
87+
// getcfcheckpt v4 70015 BIP157 not BIP-associated to p2p version (**)
88+
// cfheaders v4 70015 BIP157 not BIP-associated to p2p version (**)
89+
// getcfheaders v4 70015 BIP157 not BIP-associated to p2p version (**)
8690
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8791

8892
enum level: uint32_t

include/bitcoin/network/messages/enums/magic_numbers.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ constexpr size_t max_reject_message = max_uint16;
4444
// This is arbitrary, useful as an address pool and block announce guard.
4545
constexpr size_t maximum_advertisement = 10;
4646

47+
/// Limit given 10 and max supported height chain (stop hash excluded).
48+
constexpr size_t max_locator = 10_size + system::floored_log2(max_size_t);
49+
4750
////constexpr size_t max_bloom_filter_hashes = 2'000;
4851
////constexpr size_t max_get_data = 50'000;
4952
////constexpr size_t max_get_client_filter_headers = 1'999;
@@ -52,8 +55,6 @@ constexpr size_t maximum_advertisement = 10;
5255
/////// compact filter checkpoint interval
5356
////constexpr size_t client_filter_checkpoint_interval = 1000;
5457

55-
/////// Effective limit given a 32 bit chain height boundary: 10 + log2(2^32) + 1.
56-
////constexpr size_t max_locator = 43;
5758

5859
} // namespace messages
5960
} // namespace network

include/bitcoin/network/messages/get_headers.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ struct BCT_API get_headers
5454

5555
size_t size(uint32_t version) const NOEXCEPT;
5656

57+
/// First start hash or null_hash if none.
58+
const system::hash_digest& start_hash() const NOEXCEPT;
59+
5760
////uint32_t protocol_version;
5861
system::hashes start_hashes{};
5962
system::hash_digest stop_hash{};

include/bitcoin/network/protocols/protocol_version_31402.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class BCT_API protocol_version_31402
7878
const uint64_t invalid_services_;
7979

8080
private:
81+
static bool is_disallowed_deviation(uint64_t timestamp) NOEXCEPT;
82+
8183
// These are protected by strand.
8284
bool sent_version_{};
8385
bool received_version_{};

src/error.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
5151
{ peer_disconnect, "peer disconnect" },
5252
{ peer_unsupported, "peer unsupported" },
5353
{ peer_insufficient, "peer insufficient" },
54+
{ peer_timestamp, "peer timestamp" },
5455
{ protocol_violation, "protocol violation" },
5556
{ channel_overflow, "channel overflow" },
5657
{ channel_underflow, "channel underflow" },

src/messages/compact_transactions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ compact_transactions compact_transactions::deserialize(uint32_t version,
6060
transaction_ptrs.reserve(size);
6161

6262
for (size_t tx = 0; tx < size; ++tx)
63-
transaction_ptrs.emplace_back(
64-
std::make_shared<const chain::transaction>(source, witness));
63+
transaction_ptrs.push_back(
64+
to_shared<chain::transaction>(source, witness));
6565

6666
return transaction_ptrs;
6767
};

src/messages/get_blocks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ get_blocks get_blocks::deserialize(uint32_t version, reader& source) NOEXCEPT
9090
const auto read_start_hashes = [](reader& source) NOEXCEPT
9191
{
9292
// Count of hashes is redundant with the message size.
93-
const auto count = source.read_size(max_get_blocks);
93+
const auto count = source.read_size(max_locator);
9494

9595
hashes start_hashes;
9696
start_hashes.reserve(count);

src/messages/get_headers.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ get_headers get_headers::deserialize(uint32_t version, reader& source) NOEXCEPT
6767
// Protocol version is stoopid (and unused).
6868
source.skip_bytes(sizeof(uint32_t));
6969

70-
// Count of hashes is redundant with the message size.
71-
const auto count = source.read_size(max_get_headers);
70+
// Count of hashes is unnecessary given message size, also stoopid.
71+
const auto count = source.read_size(max_locator);
7272

7373
get_headers get;
7474
get.start_hashes.reserve(count);
@@ -101,7 +101,7 @@ void get_headers::serialize(uint32_t version, writer& sink) const NOEXCEPT
101101
// Count of hashes is redundant with the message size.
102102
sink.write_variable(start_hashes.size());
103103

104-
for (const auto& start_hash : start_hashes)
104+
for (const auto& start_hash: start_hashes)
105105
sink.write_bytes(start_hash);
106106

107107
sink.write_bytes(stop_hash);
@@ -117,6 +117,12 @@ size_t get_headers::size(uint32_t) const NOEXCEPT
117117
(hash_size * start_hashes.size());
118118
}
119119

120+
// Used to simplify logging message identity.
121+
const hash_digest& get_headers::start_hash() const NOEXCEPT
122+
{
123+
return start_hashes.empty() ? null_hash : start_hashes.front();
124+
}
125+
120126
} // namespace messages
121127
} // namespace network
122128
} // namespace libbitcoin

src/messages/headers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ headers headers::deserialize(uint32_t version, reader& source) NOEXCEPT
7575

7676
for (size_t header = 0; header < size; ++header)
7777
{
78-
header_ptrs.push_back(std::make_shared<const chain::header>(source));
78+
header_ptrs.push_back(to_shared<chain::header>(source));
7979
if (source.read_byte() != trail)
8080
source.invalidate();
8181
}

0 commit comments

Comments
 (0)