Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 3,624 Lines • ▼ Show 20 Lines | if (strCommand == NetMsgType::AVARESPONSE && !fImporting && !fReindex && | ||||
gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | ||||
// As long as QUIC is not implemented, we need to sign response and | // As long as QUIC is not implemented, we need to sign response and | ||||
// 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); | ||||
AvalancheResponse response; | AvalancheResponse response; | ||||
verifier >> response; | verifier >> response; | ||||
if (!g_avalanche->forNode(pfrom->GetId(), [&](const AvalancheNode &n) { | if (!g_avalanche->forNode( | ||||
pfrom->GetId(), [&](const avalanche::Node &n) { | |||||
std::array<uint8_t, 64> sig; | std::array<uint8_t, 64> sig; | ||||
vRecv >> sig; | vRecv >> sig; | ||||
// Unfortunately, the verify API require a vector. | // Unfortunately, the verify API require a vector. | ||||
std::vector<uint8_t> vchSig{sig.begin(), sig.end()}; | std::vector<uint8_t> vchSig{sig.begin(), sig.end()}; | ||||
return n.pubkey.VerifySchnorr(verifier.GetHash(), vchSig); | return n.pubkey.VerifySchnorr(verifier.GetHash(), vchSig); | ||||
})) { | })) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
Misbehaving(pfrom, 100, "invalid-ava-response-signature"); | Misbehaving(pfrom, 100, "invalid-ava-response-signature"); | ||||
return true; | return true; | ||||
} | } | ||||
std::vector<AvalancheBlockUpdate> updates; | std::vector<avalanche::BlockUpdate> updates; | ||||
if (!g_avalanche->registerVotes(pfrom->GetId(), response, updates)) { | if (!g_avalanche->registerVotes(pfrom->GetId(), response, updates)) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
Misbehaving(pfrom, 100, "invalid-ava-response-content"); | Misbehaving(pfrom, 100, "invalid-ava-response-content"); | ||||
return true; | return true; | ||||
} | } | ||||
if (updates.size()) { | if (updates.size()) { | ||||
for (AvalancheBlockUpdate &u : updates) { | for (avalanche::BlockUpdate &u : updates) { | ||||
CBlockIndex *pindex = u.getBlockIndex(); | CBlockIndex *pindex = u.getBlockIndex(); | ||||
switch (u.getStatus()) { | switch (u.getStatus()) { | ||||
case AvalancheBlockUpdate::Status::Invalid: | case avalanche::BlockUpdate::Status::Invalid: | ||||
case AvalancheBlockUpdate::Status::Rejected: { | case avalanche::BlockUpdate::Status::Rejected: { | ||||
CValidationState state; | CValidationState state; | ||||
ParkBlock(config, state, pindex); | ParkBlock(config, state, pindex); | ||||
if (!state.IsValid()) { | if (!state.IsValid()) { | ||||
return error("Database error: %s", | return error("Database error: %s", | ||||
state.GetRejectReason()); | state.GetRejectReason()); | ||||
} | } | ||||
} break; | } break; | ||||
case AvalancheBlockUpdate::Status::Accepted: | case avalanche::BlockUpdate::Status::Accepted: | ||||
case AvalancheBlockUpdate::Status::Finalized: { | case avalanche::BlockUpdate::Status::Finalized: { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
UnparkBlock(pindex); | UnparkBlock(pindex); | ||||
} break; | } break; | ||||
} | } | ||||
} | } | ||||
CValidationState state; | CValidationState state; | ||||
if (!ActivateBestChain(config, state)) { | if (!ActivateBestChain(config, state)) { | ||||
▲ Show 20 Lines • Show All 1,410 Lines • Show Last 20 Lines |