Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/impl/btc/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,21 @@ void NodeImpl::run_think()
<< " verified_heads=" << m_tracker.verified.get_heads().size();
}

// ROOT-2: fire ONE think-independent delayed re-advert when the
// verified chain first becomes non-empty. Covers peers that
// handshook during the empty window and so never see a best-change
// event. The one-shot timer runs on the IO thread, so it still
// fires even if a later think() cycle wedges (composes with the
// #97 think-watchdog). Pure reads; broadcast stays try_to_lock.
if (m_verified_was_empty && m_tracker.verified.size() > 0) {
m_verified_was_empty = false;
if (!m_readvert_timer)
m_readvert_timer = std::make_unique<core::Timer>(m_context, false);
m_readvert_timer->start(10, [this]() { readvertise_best(); });
LOG_INFO << "[readvertise] verified chain populated — scheduled "
"10s re-advert (ROOT-2)";
}

// Drain share batches queued while think() held the mutex
LOG_INFO << "[ASYNC-THINK] IO-phase: draining " << m_pending_adds.size()
<< " pending batches, peers=" << m_peers.size();
Expand Down
5 changes: 5 additions & 0 deletions src/impl/btc/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ class NodeImpl : public pool::BaseNode<btc::Config, btc::ShareChain, btc::Peer>
size_t m_max_peers = 30;
size_t m_target_outbound_peers = DEFAULT_TARGET_OUTBOUND_PEERS;
std::unique_ptr<core::Timer> m_connect_timer;
std::unique_ptr<core::Timer> m_readvert_timer; // one-shot ROOT-2 re-advert
std::set<NetService> m_pending_outbound; // addresses currently being dialed
std::set<NetService> m_outbound_addrs; // successfully connected outbound peers

Expand Down Expand Up @@ -552,6 +553,10 @@ class NodeImpl : public pool::BaseNode<btc::Config, btc::ShareChain, btc::Peer>
// Cached best share hash from the most recent think() cycle
uint256 m_best_share_hash;

// ROOT-2: fire exactly one delayed re-advert when the verified chain
// first transitions from empty to non-empty (peers that handshook
// during the empty window otherwise never see a best-change event).
bool m_verified_was_empty = true;

// Cache of original raw serialized bytes keyed by share hash.
// Used for relay so we send the exact bytes we received, avoiding
Expand Down
Loading