diff --git a/src/avalanche/processor.h b/src/avalanche/processor.h --- a/src/avalanche/processor.h +++ b/src/avalanche/processor.h @@ -289,7 +289,7 @@ bool registerVotes(NodeId nodeid, const Response &response, std::vector &updates); - bool addNode(NodeId nodeid, const Proof &proof, + bool addNode(NodeId nodeid, std::shared_ptr proof, const Delegation &delegation); bool forNode(NodeId nodeid, std::function func) const; diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -138,7 +138,7 @@ } struct Processor::PeerData { - Proof proof; + std::shared_ptr proof; Delegation delegation; }; @@ -154,8 +154,7 @@ if (m_processor->mustRegisterProof && !::ChainstateActive().IsInitialBlockDownload()) { - m_processor->peerManager->getPeerId( - std::make_shared(m_processor->peerData->proof)); + m_processor->peerManager->getPeerId(m_processor->peerData->proof); m_processor->mustRegisterProof = false; } @@ -216,14 +215,14 @@ } peerData = std::make_unique(); - if (!Proof::FromHex(peerData->proof, argsman.GetArg("-avaproof", ""), - error)) { + Proof proof; + if (!Proof::FromHex(proof, argsman.GetArg("-avaproof", ""), error)) { // error is set by FromHex return nullptr; } ProofValidationState proof_state; - if (!peerData->proof.verify(proof_state)) { + if (!proof.verify(proof_state)) { switch (proof_state.GetResult()) { case ProofValidationResult::NO_STAKE: error = _("the avalanche proof has no stake"); @@ -250,10 +249,12 @@ } // Generate the delegation to the session key. - DelegationBuilder dgb(peerData->proof); - if (sessionKey.GetPubKey() != peerData->proof.getMaster()) { + DelegationBuilder dgb(proof); + if (sessionKey.GetPubKey() != proof.getMaster()) { dgb.addLevel(masterKey, sessionKey.GetPubKey()); } + + peerData->proof = std::make_shared(std::move(proof)); peerData->delegation = dgb.build(); } @@ -442,11 +443,10 @@ return true; } -bool Processor::addNode(NodeId nodeid, const Proof &proof, +bool Processor::addNode(NodeId nodeid, std::shared_ptr proof, const Delegation &delegation) { LOCK(cs_peerManager); - return peerManager->addNode(nodeid, std::make_shared(proof), - delegation); + return peerManager->addNode(nodeid, std::move(proof), delegation); } bool Processor::forNode(NodeId nodeid, diff --git a/src/avalanche/test/processor_tests.cpp b/src/avalanche/test/processor_tests.cpp --- a/src/avalanche/test/processor_tests.cpp +++ b/src/avalanche/test/processor_tests.cpp @@ -129,8 +129,9 @@ bool addNode(NodeId nodeid) { Proof proof = GetProof(); - return m_processor->addNode(nodeid, proof, - DelegationBuilder(proof).build()); + const Delegation &dg = DelegationBuilder(proof).build(); + return m_processor->addNode( + nodeid, std::make_shared(std::move(proof)), dg); } std::array ConnectNodes() { diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -91,8 +91,10 @@ return false; } - return g_avalanche->addNode(nodeid, proof, - avalanche::DelegationBuilder(proof).build()); + const avalanche::Delegation &dg = + avalanche::DelegationBuilder(proof).build(); + return g_avalanche->addNode( + nodeid, std::make_shared(std::move(proof)), dg); } static UniValue buildavalancheproof(const Config &config,