Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 4,135 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::BLOCK) { | ||||
} else { | } else { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
mapBlockSource.erase(hash); | mapBlockSource.erase(hash); | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
if (msg_type == NetMsgType::AVAHELLO) { | if (msg_type == NetMsgType::AVAHELLO) { | ||||
if (!pfrom.m_avalanche_state) { | |||||
pfrom.m_avalanche_state = std::make_unique<CNode::AvalancheState>(); | |||||
} | |||||
CHashVerifier<CDataStream> verifier(&vRecv); | CHashVerifier<CDataStream> verifier(&vRecv); | ||||
avalanche::Delegation delegation; | avalanche::Delegation delegation; | ||||
verifier >> delegation; | verifier >> delegation; | ||||
avalanche::DelegationState state; | |||||
CPubKey &pubkey = pfrom.m_avalanche_state->pubkey; | |||||
if (!delegation.verify(state, pubkey)) { | |||||
Misbehaving(pfrom, 100, "invalid-delegation"); | |||||
return; | |||||
} | |||||
CHashWriter sighasher(SER_GETHASH, 0); | CHashWriter sighasher(SER_GETHASH, 0); | ||||
sighasher << delegation.getId(); | sighasher << delegation.getId(); | ||||
sighasher << pfrom.nRemoteHostNonce; | sighasher << pfrom.nRemoteHostNonce; | ||||
sighasher << pfrom.GetLocalNonce(); | sighasher << pfrom.GetLocalNonce(); | ||||
sighasher << pfrom.nRemoteExtraEntropy; | sighasher << pfrom.nRemoteExtraEntropy; | ||||
sighasher << pfrom.GetLocalExtraEntropy(); | sighasher << pfrom.GetLocalExtraEntropy(); | ||||
SchnorrSig sig; | SchnorrSig sig; | ||||
verifier >> sig; | verifier >> sig; | ||||
{ | |||||
LOCK(pfrom.cs_avalanche_state); | |||||
if (!pfrom.m_avalanche_state) { | |||||
pfrom.m_avalanche_state = | |||||
std::make_unique<CNode::AvalancheState>(); | |||||
} | |||||
avalanche::DelegationState state; | |||||
CPubKey &pubkey = pfrom.m_avalanche_state->pubkey; | |||||
if (!delegation.verify(state, pubkey)) { | |||||
Misbehaving(pfrom, 100, "invalid-delegation"); | |||||
return; | |||||
} | |||||
if (!pubkey.VerifySchnorr(sighasher.GetHash(), sig)) { | if (!pubkey.VerifySchnorr(sighasher.GetHash(), sig)) { | ||||
Misbehaving(pfrom, 100, "invalid-avahello-signature"); | Misbehaving(pfrom, 100, "invalid-avahello-signature"); | ||||
return; | return; | ||||
} | } | ||||
} | |||||
// If we don't know this proof already, add it to the tracker so it can | // If we don't know this proof already, add it to the tracker so it can | ||||
// be requested. | // be requested. | ||||
const avalanche::ProofId proofid(delegation.getProofId()); | const avalanche::ProofId proofid(delegation.getProofId()); | ||||
if (!AlreadyHaveProof(proofid)) { | if (!AlreadyHaveProof(proofid)) { | ||||
const bool preferred = isPreferredDownloadPeer(pfrom); | const bool preferred = isPreferredDownloadPeer(pfrom); | ||||
LOCK(cs_proofrequest); | LOCK(cs_proofrequest); | ||||
AddProofAnnouncement(pfrom, proofid, | AddProofAnnouncement(pfrom, proofid, | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::AVARESPONSE) { | ||||
// verify response's signatures in order to avoid any manipulation of | // verify response's signatures in order to avoid any manipulation of | ||||
// messages at the transport level. | // messages at the transport level. | ||||
CHashVerifier<CDataStream> verifier(&vRecv); | CHashVerifier<CDataStream> verifier(&vRecv); | ||||
avalanche::Response response; | avalanche::Response response; | ||||
verifier >> response; | verifier >> response; | ||||
SchnorrSig sig; | SchnorrSig sig; | ||||
vRecv >> sig; | vRecv >> sig; | ||||
{ | |||||
LOCK(pfrom.cs_avalanche_state); | |||||
if (!pfrom.m_avalanche_state || | if (!pfrom.m_avalanche_state || | ||||
!pfrom.m_avalanche_state->pubkey.VerifySchnorr(verifier.GetHash(), | !pfrom.m_avalanche_state->pubkey.VerifySchnorr( | ||||
sig)) { | verifier.GetHash(), sig)) { | ||||
Misbehaving(pfrom, 100, "invalid-ava-response-signature"); | Misbehaving(pfrom, 100, "invalid-ava-response-signature"); | ||||
return; | return; | ||||
} | } | ||||
} | |||||
std::vector<avalanche::BlockUpdate> updates; | std::vector<avalanche::BlockUpdate> updates; | ||||
if (!g_avalanche->registerVotes(pfrom.GetId(), response, updates)) { | if (!g_avalanche->registerVotes(pfrom.GetId(), response, updates)) { | ||||
return; | return; | ||||
} | } | ||||
if (updates.size()) { | if (updates.size()) { | ||||
for (avalanche::BlockUpdate &u : updates) { | for (avalanche::BlockUpdate &u : updates) { | ||||
▲ Show 20 Lines • Show All 1,551 Lines • Show Last 20 Lines |