Skip to content

Commit 8089ef1

Browse files
committed
Handle null/empty sentinel pointers in tx/block subscribers.
1 parent bca3627 commit 8089ef1

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/full_node.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,15 @@ bool full_node::handle_reorganized(code ec, size_t fork_height,
197197
return false;
198198
}
199199

200+
// Nothing to do here.
201+
if (!incoming || incoming->empty())
202+
return true;
203+
200204
for (const auto block: *outgoing)
201205
LOG_DEBUG(LOG_NODE)
202206
<< "Reorganization moved block to orphan pool ["
203207
<< encode_hash(block->header().hash()) << "]";
204208

205-
BITCOIN_ASSERT(!incoming->empty());
206209
const auto height = safe_add(fork_height, incoming->size());
207210

208211
set_top_block({ incoming->back()->hash(), height });
@@ -305,7 +308,7 @@ safe_chain& full_node::chain()
305308

306309
void full_node::subscribe_blockchain(reorganize_handler&& handler)
307310
{
308-
chain().subscribe_reorganize(std::move(handler));
311+
chain().subscribe_blockchain(std::move(handler));
309312
}
310313

311314
void full_node::subscribe_transaction(transaction_handler&& handler)

src/protocols/protocol_block_out.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void protocol_block_out::start()
8585
SUBSCRIBE2(get_data, handle_receive_get_data, _1, _2);
8686

8787
// Subscribe to block acceptance notifications (the block-out heartbeat).
88-
chain_.subscribe_reorganize(BIND4(handle_reorganized, _1, _2, _3, _4));
88+
chain_.subscribe_blockchain(BIND4(handle_reorganized, _1, _2, _3, _4));
8989
}
9090

9191
// Receive send_headers and send_compact.
@@ -437,6 +437,10 @@ bool protocol_block_out::handle_reorganized(code ec, size_t fork_height,
437437
return false;
438438
}
439439

440+
// Nothing to do here.
441+
if (!incoming)
442+
return true;
443+
440444
// TODO: consider always sending the last block as compact if enabled.
441445
if (false && compact_to_peer_ && incoming->size() == 1)
442446
{
@@ -499,6 +503,8 @@ bool protocol_block_out::handle_reorganized(code ec, size_t fork_height,
499503

500504
void protocol_block_out::handle_stop(const code&)
501505
{
506+
chain_.unsubscribe();
507+
502508
LOG_DEBUG(LOG_NETWORK)
503509
<< "Stopped block_out protocol for [" << authority() << "].";
504510
}

src/protocols/protocol_transaction_out.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ bool protocol_transaction_out::handle_notification(const code& ec,
240240
return false;
241241
}
242242

243+
// TODO: make this a collection and send empty in this case.
244+
// Nothing to do, a channel is stopping but it's not this one.
245+
if (!message)
246+
return true;
247+
243248
if (message->validation.originator == nonce())
244249
return true;
245250

@@ -259,6 +264,8 @@ bool protocol_transaction_out::handle_notification(const code& ec,
259264

260265
void protocol_transaction_out::handle_stop(const code&)
261266
{
267+
chain_.unsubscribe();
268+
262269
LOG_DEBUG(LOG_NETWORK)
263270
<< "Stopped transaction_out protocol for [" << authority() << "].";
264271
}

0 commit comments

Comments
 (0)