aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp16
-rw-r--r--src/net.cpp5
-rw-r--r--src/net.h10
-rw-r--r--src/rpc/blockchain.cpp7
-rw-r--r--src/validation.cpp4
-rw-r--r--src/validation.h2
6 files changed, 34 insertions, 10 deletions
diff --git a/src/init.cpp b/src/init.cpp
index faaf3353d0..2572f9d78c 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1558,7 +1558,12 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
// This is defined and set here instead of inline in validation.h to avoid a hard
// dependency between validation and index/base, since the latter is not in
// libbitcoinkernel.
- chainman.restart_indexes = [&node]() {
+ chainman.snapshot_download_completed = [&node]() {
+ if (!node.chainman->m_blockman.IsPruneMode()) {
+ LogPrintf("[snapshot] re-enabling NODE_NETWORK services\n");
+ node.connman->AddLocalServices(NODE_NETWORK);
+ }
+
LogPrintf("[snapshot] restarting indexes\n");
// Drain the validation interface queue to ensure that the old indexes
@@ -1695,8 +1700,13 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
}
}
} else {
- LogPrintf("Setting NODE_NETWORK on non-prune mode\n");
- nLocalServices = ServiceFlags(nLocalServices | NODE_NETWORK);
+ // Prior to setting NODE_NETWORK, check if we can provide historical blocks.
+ if (!WITH_LOCK(chainman.GetMutex(), return chainman.BackgroundSyncInProgress())) {
+ LogPrintf("Setting NODE_NETWORK on non-prune mode\n");
+ nLocalServices = ServiceFlags(nLocalServices | NODE_NETWORK);
+ } else {
+ LogPrintf("Running node in NODE_NETWORK_LIMITED mode until snapshot background sync completes\n");
+ }
}
// ********************************************************* Step 11: import blocks
diff --git a/src/net.cpp b/src/net.cpp
index e1206745a4..05b98d1029 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1789,7 +1789,8 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
const bool inbound_onion = std::find(m_onion_binds.begin(), m_onion_binds.end(), addr_bind) != m_onion_binds.end();
// The V2Transport transparently falls back to V1 behavior when an incoming V1 connection is
// detected, so use it whenever we signal NODE_P2P_V2.
- const bool use_v2transport(nLocalServices & NODE_P2P_V2);
+ ServiceFlags local_services = GetLocalServices();
+ const bool use_v2transport(local_services & NODE_P2P_V2);
CNode* pnode = new CNode(id,
std::move(sock),
@@ -1807,7 +1808,7 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
.use_v2transport = use_v2transport,
});
pnode->AddRef();
- m_msgproc->InitializeNode(*pnode, nLocalServices);
+ m_msgproc->InitializeNode(*pnode, local_services);
{
LOCK(m_nodes_mutex);
m_nodes.push_back(pnode);
diff --git a/src/net.h b/src/net.h
index beec58c389..b04b73e696 100644
--- a/src/net.h
+++ b/src/net.h
@@ -1221,6 +1221,11 @@ public:
//! that peer during `net_processing.cpp:PushNodeVersion()`.
ServiceFlags GetLocalServices() const;
+ //! Updates the local services that this node advertises to other peers
+ //! during connection handshake.
+ void AddLocalServices(ServiceFlags services) { nLocalServices = ServiceFlags(nLocalServices | services); };
+ void RemoveLocalServices(ServiceFlags services) { nLocalServices = ServiceFlags(nLocalServices & ~services); }
+
uint64_t GetMaxOutboundTarget() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
std::chrono::seconds GetMaxOutboundTimeframe() const;
@@ -1460,11 +1465,12 @@ private:
* This data is replicated in each Peer instance we create.
*
* This data is not marked const, but after being set it should not
- * change.
+ * change. Unless AssumeUTXO is started, in which case, the peer
+ * will be limited until the background chain sync finishes.
*
* \sa Peer::our_services
*/
- ServiceFlags nLocalServices;
+ std::atomic<ServiceFlags> nLocalServices;
std::unique_ptr<CSemaphore> semOutbound;
std::unique_ptr<CSemaphore> semAddnode;
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index b449444aff..8b8576ab88 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -2866,6 +2866,13 @@ static RPCHelpMan loadtxoutset()
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Unable to load UTXO snapshot: %s. (%s)", util::ErrorString(activation_result).original, path.utf8string()));
}
+ // Because we can't provide historical blocks during tip or background sync.
+ // Update local services to reflect we are a limited peer until we are fully sync.
+ node.connman->RemoveLocalServices(NODE_NETWORK);
+ // Setting the limited state is usually redundant because the node can always
+ // provide the last 288 blocks, but it doesn't hurt to set it.
+ node.connman->AddLocalServices(NODE_NETWORK_LIMITED);
+
CBlockIndex& snapshot_index{*CHECK_NONFATAL(*activation_result)};
UniValue result(UniValue::VOBJ);
diff --git a/src/validation.cpp b/src/validation.cpp
index 8f75b2e30a..a6b7f3d361 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -3574,8 +3574,8 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
//
// This cannot be done while holding cs_main (within
// MaybeCompleteSnapshotValidation) or a cs_main deadlock will occur.
- if (m_chainman.restart_indexes) {
- m_chainman.restart_indexes();
+ if (m_chainman.snapshot_download_completed) {
+ m_chainman.snapshot_download_completed();
}
break;
}
diff --git a/src/validation.h b/src/validation.h
index f905d6e624..bc9bacf7ce 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -976,7 +976,7 @@ public:
//! Function to restart active indexes; set dynamically to avoid a circular
//! dependency on `base/index.cpp`.
- std::function<void()> restart_indexes = std::function<void()>();
+ std::function<void()> snapshot_download_completed = std::function<void()>();
const CChainParams& GetParams() const { return m_options.chainparams; }
const Consensus::Params& GetConsensus() const { return m_options.chainparams.GetConsensus(); }