Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show First 20 Lines • Show All 606 Lines • ▼ Show 20 Lines | bool Processor::registerVotes(NodeId nodeid, const Response &response, | ||||
return true; | return true; | ||||
} | } | ||||
CPubKey Processor::getSessionPubKey() const { | CPubKey Processor::getSessionPubKey() const { | ||||
return sessionKey.GetPubKey(); | return sessionKey.GetPubKey(); | ||||
} | } | ||||
bool Processor::sendHello(CNode *pfrom) const { | bool Processor::sendHello(CNode *pfrom) const { | ||||
if (!peerData) { | Delegation delegation; | ||||
// We do not have a delegation to advertise. | if (peerData) { | ||||
return false; | delegation = peerData->delegation; | ||||
pfrom->AddKnownProof(delegation.getProofId()); | |||||
} | } | ||||
CHashWriter hasher(SER_GETHASH, 0); | |||||
hasher << delegation.getId(); | |||||
hasher << pfrom->GetLocalNonce(); | |||||
hasher << pfrom->nRemoteHostNonce; | |||||
hasher << pfrom->GetLocalExtraEntropy(); | |||||
hasher << pfrom->nRemoteExtraEntropy; | |||||
// Now let's sign! | // Now let's sign! | ||||
SchnorrSig sig; | SchnorrSig sig; | ||||
if (!sessionKey.SignSchnorr(hasher.GetHash(), sig)) { | |||||
{ | |||||
const uint256 hash = buildLocalSighash(pfrom); | |||||
if (!sessionKey.SignSchnorr(hash, sig)) { | |||||
return false; | return false; | ||||
} | } | ||||
} | |||||
connman->PushMessage(pfrom, CNetMsgMaker(pfrom->GetCommonVersion()) | |||||
.Make(NetMsgType::AVAHELLO, | |||||
Hello(peerData->delegation, sig))); | |||||
pfrom->AddKnownProof(peerData->delegation.getProofId()); | connman->PushMessage( | ||||
pfrom, CNetMsgMaker(pfrom->GetCommonVersion()) | |||||
.Make(NetMsgType::AVAHELLO, Hello(delegation, sig))); | |||||
return true; | return true; | ||||
} | } | ||||
ProofRef Processor::getLocalProof() const { | ProofRef Processor::getLocalProof() const { | ||||
return peerData ? peerData->proof : ProofRef(); | return peerData ? peerData->proof : ProofRef(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 267 Lines • ▼ Show 20 Lines | std::vector<CInv> Processor::getInvsForNextPoll(bool forPoll) { | ||||
auto r = blockVoteRecords.getReadView(); | auto r = blockVoteRecords.getReadView(); | ||||
extractVoteRecordsToInvs(reverse_iterate(r), [](const CBlockIndex *pindex) { | extractVoteRecordsToInvs(reverse_iterate(r), [](const CBlockIndex *pindex) { | ||||
return CInv(MSG_BLOCK, pindex->GetBlockHash()); | return CInv(MSG_BLOCK, pindex->GetBlockHash()); | ||||
}); | }); | ||||
return invs; | return invs; | ||||
} | } | ||||
uint256 Processor::buildLocalSighash(CNode *pfrom) const { | |||||
CHashWriter hasher(SER_GETHASH, 0); | |||||
hasher << peerData->delegation.getId(); | |||||
hasher << pfrom->GetLocalNonce(); | |||||
hasher << pfrom->nRemoteHostNonce; | |||||
hasher << pfrom->GetLocalExtraEntropy(); | |||||
hasher << pfrom->nRemoteExtraEntropy; | |||||
return hasher.GetHash(); | |||||
} | |||||
bool Processor::isWorthPolling(const CBlockIndex *pindex) const { | bool Processor::isWorthPolling(const CBlockIndex *pindex) const { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
if (pindex->nStatus.isInvalid()) { | if (pindex->nStatus.isInvalid()) { | ||||
// No point polling invalid blocks. | // No point polling invalid blocks. | ||||
return false; | return false; | ||||
} | } | ||||
Show All 26 Lines |