Skip to content

Commit 62c5270

Browse files
committed
Comments on block protocol handling of staleness.
1 parent 3e16422 commit 62c5270

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/protocols/protocol_block_in.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ void protocol_block_in::handle_fetch_block_locator(const code& ec,
150150
//-----------------------------------------------------------------------------
151151

152152
// TODO: move headers to a derived class protocol_block_in_31800.
153-
// This originates from send_header->annoucements and get_headers requests.
153+
// This originates from send_header->annoucements and get_headers requests, or
154+
// from an unsolicited announcement. There is no way to distinguish.
154155
bool protocol_block_in::handle_receive_headers(const code& ec,
155156
headers_const_ptr message)
156157
{
@@ -176,7 +177,8 @@ bool protocol_block_in::handle_receive_headers(const code& ec,
176177
return true;
177178
}
178179

179-
// This originates from default annoucements and get_blocks requests.
180+
// This originates from default annoucements and get_blocks requests, or from
181+
// an unsolicited announcement. There is no way to distinguish.
180182
bool protocol_block_in::handle_receive_inventory(const code& ec,
181183
inventory_const_ptr message)
182184
{
@@ -293,7 +295,8 @@ bool protocol_block_in::handle_receive_block(const code& ec,
293295
mutex.unlock();
294296
///////////////////////////////////////////////////////////////////////////
295297

296-
// It is common for block announcements to cause block requests to be sent
298+
// If a peer sends a block unannounced we drop the peer - always. However
299+
// it is common for block announcements to cause block requests to be sent
297300
// out of backlog order due to interleaving of threads. This results in
298301
// channel drops during initial block download but not after sync. The
299302
// resolution to this issue is use of headers-first sync, but short of that

src/protocols/protocol_block_out.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ void protocol_block_out::handle_fetch_locator_headers(const code& ec,
170170
if (message->elements().empty())
171171
return;
172172

173+
174+
// Allow a peer to sync despite our being stale.
175+
////if (chain_.is_stale())
176+
//// return;
177+
173178
// Respond to get_headers with headers.
174179
SEND2(*message, handle_send, _1, message->command);
175180

@@ -205,6 +210,10 @@ bool protocol_block_out::handle_receive_get_blocks(const code& ec,
205210
return true;
206211
}
207212

213+
// Allow a peer to sync despite our being stale.
214+
////if (chain_.is_stale())
215+
//// return true;
216+
208217
const auto threshold = last_locator_top_.load();
209218

210219
chain_.fetch_locator_block_hashes(message, threshold, max_get_blocks,
@@ -230,6 +239,10 @@ void protocol_block_out::handle_fetch_locator_hashes(const code& ec,
230239
if (message->inventories().empty())
231240
return;
232241

242+
// Allow a peer to sync despite our being stale.
243+
////if (chain_.is_stale())
244+
//// return;
245+
233246
// Respond to get_blocks with inventory.
234247
SEND2(*message, handle_send, _1, message->command);
235248

@@ -248,6 +261,7 @@ bool protocol_block_out::handle_receive_get_data(const code& ec,
248261
if (stopped(ec))
249262
return false;
250263

264+
// TODO: consider rejecting the message for duplicated entries.
251265
if (message->inventories().size() > max_get_data)
252266
{
253267
LOG_WARNING(LOG_NODE)
@@ -257,6 +271,10 @@ bool protocol_block_out::handle_receive_get_data(const code& ec,
257271
return false;
258272
}
259273

274+
// Allow a peer to sync despite our being stale.
275+
////if (chain_.is_stale())
276+
//// return true;
277+
260278
// Create a copy because message is const because it is shared.
261279
const auto& inventories = message->inventories();
262280
const auto response = std::make_shared<inventory>();

0 commit comments

Comments
 (0)