Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 3,973 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::BLOCK) { | ||||
return; | return; | ||||
} | } | ||||
if (msg_type == NetMsgType::AVAHELLO) { | if (msg_type == NetMsgType::AVAHELLO) { | ||||
if (!pfrom.m_avalanche_state) { | if (!pfrom.m_avalanche_state) { | ||||
pfrom.m_avalanche_state = std::make_unique<CNode::AvalancheState>(); | pfrom.m_avalanche_state = std::make_unique<CNode::AvalancheState>(); | ||||
} | } | ||||
// Store the delegation and signature for later verification. | |||||
CHashVerifier<CDataStream> verifier(&vRecv); | CHashVerifier<CDataStream> verifier(&vRecv); | ||||
avalanche::Delegation &delegation = pfrom.m_avalanche_state->delegation; | verifier >> pfrom.m_avalanche_state->delegation; | ||||
verifier >> delegation; | |||||
SchnorrSig &sig = pfrom.m_avalanche_state->sig; | |||||
verifier >> sig; | |||||
return; | |||||
} | |||||
if (msg_type == NetMsgType::AVAPROOF) { | |||||
if (!pfrom.m_avalanche_state) { | |||||
// We don't support the case of a AVAPROOF received before | |||||
// the AVAHELLO for now. Ideally we should store all the data | |||||
// received, and process it after both messages were received, | |||||
// no matter which order they reach us. | |||||
PiRK: This todo can be addressed only after we do the proof storage. | |||||
return; | |||||
} | |||||
// Read the proof. | |||||
avalanche::Proof proof; | avalanche::Proof proof; | ||||
vRecv >> proof; | |||||
// Verify the delegation | |||||
const avalanche::Delegation &delegation = | |||||
pfrom.m_avalanche_state->delegation; | |||||
avalanche::DelegationState state; | avalanche::DelegationState state; | ||||
CPubKey pubkey; | CPubKey pubkey; | ||||
if (!delegation.verify(state, proof, pubkey)) { | if (!delegation.verify(state, proof, pubkey)) { | ||||
Misbehaving(pfrom, 100, "invalid-delegation"); | Misbehaving(pfrom, 100, "invalid-delegation"); | ||||
return; | return; | ||||
} | } | ||||
SchnorrSig sig; | // Use the delegated pubkey to verify the signature received | ||||
verifier >> sig; | // in the avahello message. | ||||
const uint256 hash = g_avalanche->buildRemoteSighash(&pfrom); | |||||
if (!pubkey.VerifySchnorr(hash, pfrom.m_avalanche_state->sig)) { | |||||
Misbehaving(pfrom, 100, "invalid-avalanche-handshake"); | |||||
return; | |||||
} | |||||
// TODO: | |||||
// - store the proof in a proofpool | |||||
// - if IBD is finished, add the node | |||||
// - if IBD, add the node later, when we can check its proof | |||||
return; | |||||
} | } | ||||
if (msg_type == NetMsgType::AVAPOLL) { | if (msg_type == NetMsgType::AVAPOLL) { | ||||
auto now = std::chrono::steady_clock::now(); | auto now = std::chrono::steady_clock::now(); | ||||
int64_t cooldown = | int64_t cooldown = | ||||
gArgs.GetArg("-avacooldown", AVALANCHE_DEFAULT_COOLDOWN); | gArgs.GetArg("-avacooldown", AVALANCHE_DEFAULT_COOLDOWN); | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,586 Lines • Show Last 20 Lines |
This todo can be addressed only after we do the proof storage.