diff --git a/src/avalanche/peermanager.h b/src/avalanche/peermanager.h --- a/src/avalanche/peermanager.h +++ b/src/avalanche/peermanager.h @@ -257,7 +257,7 @@ private: void moveToOrphan(const ProofRef &proof); - bool createPeer(const ProofRef &proof); + bool createPeer(const ProofRef &proof, std::chrono::seconds cooldown); bool addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid); bool addNodeToPeer(const PeerSet::iterator &it); bool removeNodeFromPeer(const PeerSet::iterator &it, uint32_t count = 1); diff --git a/src/avalanche/peermanager.cpp b/src/avalanche/peermanager.cpp --- a/src/avalanche/peermanager.cpp +++ b/src/avalanche/peermanager.cpp @@ -149,7 +149,12 @@ return false; } - return createPeer(proof); + // Set a cooldown time to limit the proof replacement rate + std::chrono::seconds cooldown{ + gArgs.GetArg("-avalancheproofreplacementcooldown", + AVALANCHE_DEFAULT_PROOF_REPLACEMENT_COOLDOWN)}; + + return createPeer(proof, cooldown); } NodeId PeerManager::selectNode() { @@ -175,6 +180,11 @@ return NO_NODE; } +static bool isOrphanState(const ProofValidationState &state) { + return state.GetResult() == ProofValidationResult::MISSING_UTXO || + state.GetResult() == ProofValidationResult::HEIGHT_MISMATCH; +} + void PeerManager::updatedBlockTip() { std::vector invalidPeers; std::vector newOrphans; @@ -242,12 +252,8 @@ orphanProofPool.addProofIfPreferred(proof); } -static bool isOrphanState(const ProofValidationState &state) { - return state.GetResult() == ProofValidationResult::MISSING_UTXO || - state.GetResult() == ProofValidationResult::HEIGHT_MISMATCH; -} - -bool PeerManager::createPeer(const ProofRef &proof) { +bool PeerManager::createPeer(const ProofRef &proof, + std::chrono::seconds cooldown) { assert(proof); // Check the proof's validity. @@ -266,10 +272,6 @@ } ProofPool::ConflictingProofSet conflictingProofs; - // Set a cooldown time to limit the proof replacement rate - std::chrono::seconds cooldown{ - gArgs.GetArg("-avalancheproofreplacementcooldown", - AVALANCHE_DEFAULT_PROOF_REPLACEMENT_COOLDOWN)}; auto added = gArgs.GetBoolArg("-enableavalancheproofreplacement", AVALANCHE_DEFAULT_PROOF_REPLACEMENT_ENABLED)