Skip to content

Commit a3046d4

Browse files
authored
Merge pull request #303 from evoskuil/version3
Backport master/v4 commits for version3/v3.1 release.
2 parents 8808472 + c5e0528 commit a3046d4

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/protocols/protocol_block_in.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ void protocol_block_in::handle_fetch_block_locator(const code& ec,
157157
if (stopped(ec))
158158
return;
159159

160-
const auto& last_hash = message->start_hashes().front();
161-
162160
if (ec)
163161
{
164162
LOG_ERROR(LOG_NODE)
@@ -171,14 +169,25 @@ void protocol_block_in::handle_fetch_block_locator(const code& ec,
171169
if (message->start_hashes().empty())
172170
return;
173171

172+
const auto& last_hash = message->start_hashes().front();
173+
174174
// TODO: move get_headers to a derived class protocol_block_in_31800.
175175
const auto use_headers = negotiated_version() >= version::level::headers;
176-
const auto default_size = use_headers ? "2000" : "500";
176+
const auto request_type = (use_headers ? "headers" : "inventory");
177177

178-
LOG_DEBUG(LOG_NODE)
179-
<< "Ask [" << authority() << "] for headers from ["
180-
<< encode_hash(last_hash) << "] through [" <<
181-
(stop_hash == null_hash ? default_size : encode_hash(stop_hash)) << "]";
178+
if (stop_hash == null_hash)
179+
{
180+
LOG_DEBUG(LOG_NODE)
181+
<< "Ask [" << authority() << "] for " << request_type << " after ["
182+
<< encode_hash(last_hash) << "]";
183+
}
184+
else
185+
{
186+
LOG_DEBUG(LOG_NODE)
187+
<< "Ask [" << authority() << "] for " << request_type << " from ["
188+
<< encode_hash(last_hash) << "] through ["
189+
<< encode_hash(stop_hash) << "]";
190+
}
182191

183192
// Save the locator top to prevent a redundant future request.
184193
last_locator_top_.store(last_hash);
@@ -202,6 +211,15 @@ bool protocol_block_in::handle_receive_headers(const code& ec,
202211
if (stopped(ec))
203212
return false;
204213

214+
// We don't want to request a batch of headers out of order.
215+
if (!message->is_sequential())
216+
{
217+
LOG_WARNING(LOG_NODE)
218+
<< "Block headers out of order from [" << authority() << "].";
219+
stop(error::channel_stopped);
220+
return false;
221+
}
222+
205223
// There is no benefit to this use of headers, in fact it is suboptimal.
206224
// In v3 headers will be used to build block tree before getting blocks.
207225
const auto response = std::make_shared<get_data>();

src/protocols/protocol_transaction_in.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ protocol_transaction_in::protocol_transaction_in(full_node& node,
5151
chain_(chain),
5252

5353
// TODO: move relay to a derived class protocol_transaction_in_70001.
54-
relay_from_peer_(node.network_settings().relay_transactions),
54+
// In the mean time, restrict by negotiated protocol level.
55+
// Because of inconsistent implementation by version we must allow relay
56+
// at bip37 version or below. Enforcement starts above bip37 version.
57+
relay_from_peer_(negotiated_version() <= version::level::bip37 ||
58+
node.network_settings().relay_transactions),
5559

5660
// TODO: move memory_pool to a derived class protocol_transaction_in_60002.
5761
refresh_pool_(negotiated_version() >= version::level::bip35 &&

0 commit comments

Comments
 (0)