Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | Processor::MakeProcessor(const ArgsManager &argsman, interfaces::Chain &chain, | ||||
bilingual_str &error) { | bilingual_str &error) { | ||||
std::unique_ptr<PeerData> peerData; | std::unique_ptr<PeerData> peerData; | ||||
CKey masterKey; | CKey masterKey; | ||||
CKey sessionKey; | CKey sessionKey; | ||||
if (argsman.IsArgSet("-avasessionkey")) { | if (argsman.IsArgSet("-avasessionkey")) { | ||||
sessionKey = DecodeSecret(argsman.GetArg("-avasessionkey", "")); | sessionKey = DecodeSecret(argsman.GetArg("-avasessionkey", "")); | ||||
if (!sessionKey.IsValid()) { | if (!sessionKey.IsValid()) { | ||||
error = _("the avalanche session key is invalid"); | error = _("The avalanche session key is invalid."); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
} else { | } else { | ||||
// Pick a random key for the session. | // Pick a random key for the session. | ||||
sessionKey.MakeNewKey(true); | sessionKey.MakeNewKey(true); | ||||
} | } | ||||
if (argsman.IsArgSet("-avaproof")) { | if (argsman.IsArgSet("-avaproof")) { | ||||
if (!argsman.IsArgSet("-avamasterkey")) { | if (!argsman.IsArgSet("-avamasterkey")) { | ||||
error = _( | error = _( | ||||
"the avalanche master key is missing for the avalanche proof"); | "The avalanche master key is missing for the avalanche proof."); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
masterKey = DecodeSecret(argsman.GetArg("-avamasterkey", "")); | masterKey = DecodeSecret(argsman.GetArg("-avamasterkey", "")); | ||||
if (!masterKey.IsValid()) { | if (!masterKey.IsValid()) { | ||||
error = _("the avalanche master key is invalid"); | error = _("The avalanche master key is invalid."); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
peerData = std::make_unique<PeerData>(); | peerData = std::make_unique<PeerData>(); | ||||
peerData->proof = std::make_shared<Proof>(); | peerData->proof = std::make_shared<Proof>(); | ||||
if (!Proof::FromHex(*peerData->proof, argsman.GetArg("-avaproof", ""), | if (!Proof::FromHex(*peerData->proof, argsman.GetArg("-avaproof", ""), | ||||
error)) { | error)) { | ||||
// error is set by FromHex | // error is set by FromHex | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
ProofValidationState proof_state; | ProofValidationState proof_state; | ||||
if (!peerData->proof->verify(proof_state)) { | if (!peerData->proof->verify(proof_state)) { | ||||
switch (proof_state.GetResult()) { | switch (proof_state.GetResult()) { | ||||
case ProofValidationResult::NO_STAKE: | case ProofValidationResult::NO_STAKE: | ||||
error = _("the avalanche proof has no stake"); | error = _("The avalanche proof has no stake."); | ||||
return nullptr; | return nullptr; | ||||
case ProofValidationResult::DUST_THRESOLD: | case ProofValidationResult::DUST_THRESOLD: | ||||
error = _("the avalanche proof stake is too low"); | error = _("The avalanche proof stake is too low."); | ||||
return nullptr; | return nullptr; | ||||
case ProofValidationResult::DUPLICATE_STAKE: | case ProofValidationResult::DUPLICATE_STAKE: | ||||
error = _("the avalanche proof has duplicated stake"); | error = _("The avalanche proof has duplicated stake."); | ||||
return nullptr; | return nullptr; | ||||
case ProofValidationResult::INVALID_SIGNATURE: | case ProofValidationResult::INVALID_SIGNATURE: | ||||
error = | error = | ||||
_("the avalanche proof has invalid stake signatures"); | _("The avalanche proof has invalid stake signatures."); | ||||
return nullptr; | return nullptr; | ||||
case ProofValidationResult::TOO_MANY_UTXOS: | case ProofValidationResult::TOO_MANY_UTXOS: | ||||
error = strprintf( | error = strprintf( | ||||
_("the avalanche proof has too many utxos (max: %u)"), | _("The avalanche proof has too many utxos (max: %u)."), | ||||
AVALANCHE_MAX_PROOF_STAKES); | AVALANCHE_MAX_PROOF_STAKES); | ||||
return nullptr; | return nullptr; | ||||
default: | default: | ||||
error = _("the avalanche proof is invalid"); | error = _("The avalanche proof is invalid."); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
} | } | ||||
// Generate the delegation to the session key. | // Generate the delegation to the session key. | ||||
DelegationBuilder dgb(*peerData->proof); | DelegationBuilder dgb(*peerData->proof); | ||||
if (sessionKey.GetPubKey() != peerData->proof->getMaster()) { | if (sessionKey.GetPubKey() != peerData->proof->getMaster()) { | ||||
dgb.addLevel(masterKey, sessionKey.GetPubKey()); | dgb.addLevel(masterKey, sessionKey.GetPubKey()); | ||||
▲ Show 20 Lines • Show All 452 Lines • Show Last 20 Lines |