diff --git a/src/avalanche/processor.h b/src/avalanche/processor.h --- a/src/avalanche/processor.h +++ b/src/avalanche/processor.h @@ -296,10 +296,9 @@ /** * Get the local proof used by this node. * - * @returns Proof for this node. - * @throws a std::runtime_error if there is no proof set for this node + * @returns Pointer to proof for this node, nullptr if there isn't one. */ - const Proof getProof() const; + const Proof *getLocalProof() const; std::vector getPeers() const; std::vector getNodeIdsForPeer(PeerId peerId) const; diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -444,11 +444,11 @@ return true; } -const Proof Processor::getProof() const { +const Proof *Processor::getLocalProof() const { if (!peerData) { - throw std::runtime_error("proof not set"); + return nullptr; } - return peerData->proof; + return &peerData->proof; } bool Processor::startEventLoop(CScheduler &scheduler) { diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -2440,12 +2440,11 @@ // If avalanche is enabled and a proof is supplied, make sure it does // not contain garbage. At this point the validity of the utxos cannot // be checked, so only basic verification is performed. - try { - avalanche::Proof proof; - proof = g_avalanche->getProof(); + const avalanche::Proof *proof = g_avalanche->getLocalProof(); + if (proof) { avalanche::ProofValidationState proof_state; - if (!proof.verify(proof_state)) { + if (!proof->verify(proof_state)) { switch (proof_state.GetResult()) { case avalanche::ProofValidationResult::NO_STAKE: InitError(_("the avalanche proof has no stake")); @@ -2471,7 +2470,7 @@ return false; } } - } catch (const std::runtime_error &e) { + } else { LogPrintf("Avalanche is enabled but no proof supplied, the node " "will not be able to vote\n"); }