diff --git a/src/avalanche/peermanager.h b/src/avalanche/peermanager.h --- a/src/avalanche/peermanager.h +++ b/src/avalanche/peermanager.h @@ -148,7 +148,7 @@ /** * Node API. */ - bool addNode(NodeId nodeid, const Delegation &delegation); + bool addNode(NodeId nodeid, const ProofId &proofid); bool removeNode(NodeId nodeid); bool forNode(NodeId nodeid, std::function func) const; diff --git a/src/avalanche/peermanager.cpp b/src/avalanche/peermanager.cpp --- a/src/avalanche/peermanager.cpp +++ b/src/avalanche/peermanager.cpp @@ -19,19 +19,13 @@ state.GetResult() == ProofValidationResult::HEIGHT_MISMATCH; } -bool PeerManager::addNode(NodeId nodeid, const Delegation &delegation) { +bool PeerManager::addNode(NodeId nodeid, const ProofId &proofid) { auto &pview = peers.get(); - auto it = pview.find(delegation.getProofId()); + auto it = pview.find(proofid); if (it == pview.end()) { return false; } - DelegationState state; - CPubKey pubkey; - if (!delegation.verify(state, pubkey)) { - return false; - } - return addOrUpdateNode(peers.project<0>(it), nodeid); } diff --git a/src/avalanche/processor.h b/src/avalanche/processor.h --- a/src/avalanche/processor.h +++ b/src/avalanche/processor.h @@ -281,7 +281,7 @@ bool registerVotes(NodeId nodeid, const Response &response, std::vector &updates); - bool addNode(NodeId nodeid, const Delegation &delegation); + bool addNode(NodeId nodeid, const ProofId &proofid); bool forNode(NodeId nodeid, std::function func) const; CPubKey getSessionPubKey() const; diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -518,9 +518,9 @@ return true; } -bool Processor::addNode(NodeId nodeid, const Delegation &delegation) { +bool Processor::addNode(NodeId nodeid, const ProofId &proofid) { LOCK(cs_peerManager); - return peerManager->addNode(nodeid, delegation); + return peerManager->addNode(nodeid, proofid); } bool Processor::forNode(NodeId nodeid, diff --git a/src/avalanche/test/peermanager_tests.cpp b/src/avalanche/test/peermanager_tests.cpp --- a/src/avalanche/test/peermanager_tests.cpp +++ b/src/avalanche/test/peermanager_tests.cpp @@ -162,8 +162,7 @@ uint32_t score) { auto proof = getRandomProofPtr(score); BOOST_CHECK_NE(pm.getPeerId(proof), NO_PEER); - Delegation dg = DelegationBuilder(*proof).build(); - BOOST_CHECK(pm.addNode(node, dg)); + BOOST_CHECK(pm.addNode(node, proof->getId())); }; BOOST_AUTO_TEST_CASE(peer_probabilities) { @@ -212,8 +211,7 @@ for (int i = 0; i < 4; i++) { auto p = getRandomProofPtr(100); peerids[i] = pm.getPeerId(p); - BOOST_CHECK( - pm.addNode(InsecureRand32(), DelegationBuilder(*p).build())); + BOOST_CHECK(pm.addNode(InsecureRand32(), p->getId())); } BOOST_CHECK_EQUAL(pm.getSlotCount(), 400); @@ -245,8 +243,7 @@ for (int i = 0; i < 4; i++) { auto p = getRandomProofPtr(100); peerids[i + 4] = pm.getPeerId(p); - BOOST_CHECK( - pm.addNode(InsecureRand32(), DelegationBuilder(*p).build())); + BOOST_CHECK(pm.addNode(InsecureRand32(), p->getId())); } BOOST_CHECK_EQUAL(pm.getSlotCount(), 700); @@ -288,8 +285,7 @@ for (int i = 0; i < 4; i++) { auto p = getRandomProofPtr(100); peerids[i] = pm.getPeerId(p); - BOOST_CHECK( - pm.addNode(InsecureRand32(), DelegationBuilder(*p).build())); + BOOST_CHECK(pm.addNode(InsecureRand32(), p->getId())); } // Remove all peers. @@ -316,12 +312,12 @@ // Create one peer. auto proof = getRandomProofPtr(10000000 * MIN_VALID_PROOF_SCORE); BOOST_CHECK_NE(pm.getPeerId(proof), NO_PEER); - Delegation dg = DelegationBuilder(*proof).build(); BOOST_CHECK_EQUAL(pm.selectNode(), NO_NODE); // Add 4 nodes. + const ProofId &proofid = proof->getId(); for (int i = 0; i < 4; i++) { - BOOST_CHECK(pm.addNode(i, dg)); + BOOST_CHECK(pm.addNode(i, proofid)); } for (int i = 0; i < 100; i++) { 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 @@ -128,18 +128,18 @@ bool addNode(NodeId nodeid) { auto proof = GetProof(); BOOST_CHECK(m_processor->addProof(proof)); - return m_processor->addNode(nodeid, DelegationBuilder(*proof).build()); + return m_processor->addNode(nodeid, proof->getId()); } std::array ConnectNodes() { auto proof = GetProof(); BOOST_CHECK(m_processor->addProof(proof)); - Delegation dg = DelegationBuilder(*proof).build(); + const ProofId &proofid = proof->getId(); std::array nodes; for (CNode *&n : nodes) { n = ConnectNode(NODE_AVALANCHE); - BOOST_CHECK(m_processor->addNode(n->GetId(), dg)); + BOOST_CHECK(m_processor->addNode(n->GetId(), proofid)); } return nodes; @@ -739,12 +739,11 @@ // Create enough nodes so that we run into the inflight request limit. auto proof = GetProof(); BOOST_CHECK(m_processor->addProof(proof)); - Delegation dg = DelegationBuilder(*proof).build(); std::array nodes; for (auto &n : nodes) { n = ConnectNode(NODE_AVALANCHE); - BOOST_CHECK(m_processor->addNode(n->GetId(), dg)); + BOOST_CHECK(m_processor->addNode(n->GetId(), proof->getId())); } // Add a block to poll diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -114,8 +114,7 @@ return false; } - if (!g_avalanche->addNode(nodeid, - avalanche::DelegationBuilder(*proof).build())) { + if (!g_avalanche->addNode(nodeid, proofid)) { return false; }