Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show All 29 Lines | |||||
*/ | */ | ||||
static constexpr std::chrono::milliseconds AVALANCHE_TIME_STEP{10}; | static constexpr std::chrono::milliseconds AVALANCHE_TIME_STEP{10}; | ||||
// Unfortunately, the bitcoind codebase is full of global and we are kinda | // Unfortunately, the bitcoind codebase is full of global and we are kinda | ||||
// forced into it here. | // forced into it here. | ||||
std::unique_ptr<avalanche::Processor> g_avalanche; | std::unique_ptr<avalanche::Processor> g_avalanche; | ||||
namespace avalanche { | namespace avalanche { | ||||
static bool VerifyProof(const Proof &proof, bilingual_str &error) { | static bool VerifyProof(const ProofParams &proofParams, const Proof &proof, | ||||
bilingual_str &error) { | |||||
ProofValidationState proof_state; | ProofValidationState proof_state; | ||||
if (!proof.verify(proof_state)) { | if (!proof.verify(proofParams, 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 false; | return false; | ||||
case ProofValidationResult::DUST_THRESHOLD: | case ProofValidationResult::DUST_THRESHOLD: | ||||
error = _("The avalanche proof stake is too low."); | error = _("The avalanche proof stake is too low."); | ||||
return false; | return false; | ||||
case ProofValidationResult::DUPLICATE_STAKE: | case ProofValidationResult::DUPLICATE_STAKE: | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | void updatedBlockTip() override { | ||||
auto registeredProofs = registerProofs(); | auto registeredProofs = registerProofs(); | ||||
for (const auto &proof : registeredProofs) { | for (const auto &proof : registeredProofs) { | ||||
m_processor->addProofToReconcile(proof); | m_processor->addProofToReconcile(proof); | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
Processor::Processor(Config avaconfigIn, interfaces::Chain &chain, | Processor::Processor(Config avaconfigIn, ProofParams proofParamsIn, | ||||
CConnman *connmanIn, ChainstateManager &chainmanIn, | interfaces::Chain &chain, CConnman *connmanIn, | ||||
CScheduler &scheduler, | ChainstateManager &chainmanIn, CScheduler &scheduler, | ||||
std::unique_ptr<PeerData> peerDataIn, CKey sessionKeyIn, | std::unique_ptr<PeerData> peerDataIn, CKey sessionKeyIn, | ||||
uint32_t minQuorumTotalScoreIn, | uint32_t minQuorumTotalScoreIn, | ||||
double minQuorumConnectedScoreRatioIn, | double minQuorumConnectedScoreRatioIn, | ||||
int64_t minAvaproofsNodeCountIn, | int64_t minAvaproofsNodeCountIn, | ||||
uint32_t staleVoteThresholdIn, uint32_t staleVoteFactorIn) | uint32_t staleVoteThresholdIn, uint32_t staleVoteFactorIn) | ||||
: avaconfig(std::move(avaconfigIn)), connman(connmanIn), | : avaconfig(std::move(avaconfigIn)), proofParams(std::move(proofParamsIn)), | ||||
chainman(chainmanIn), round(0), | connman(connmanIn), chainman(chainmanIn), round(0), | ||||
peerManager(std::make_unique<PeerManager>(chainman)), | peerManager(std::make_unique<PeerManager>(chainman, proofParams)), | ||||
peerData(std::move(peerDataIn)), sessionKey(std::move(sessionKeyIn)), | peerData(std::move(peerDataIn)), sessionKey(std::move(sessionKeyIn)), | ||||
minQuorumScore(minQuorumTotalScoreIn), | minQuorumScore(minQuorumTotalScoreIn), | ||||
minQuorumConnectedScoreRatio(minQuorumConnectedScoreRatioIn), | minQuorumConnectedScoreRatio(minQuorumConnectedScoreRatioIn), | ||||
minAvaproofsNodeCount(minAvaproofsNodeCountIn), | minAvaproofsNodeCount(minAvaproofsNodeCountIn), | ||||
staleVoteThreshold(staleVoteThresholdIn), | staleVoteThreshold(staleVoteThresholdIn), | ||||
staleVoteFactor(staleVoteFactorIn) { | staleVoteFactor(staleVoteFactorIn) { | ||||
// Make sure we get notified of chain state changes. | // Make sure we get notified of chain state changes. | ||||
chainNotificationsHandler = | chainNotificationsHandler = | ||||
Show All 17 Lines | |||||
std::unique_ptr<Processor> | std::unique_ptr<Processor> | ||||
Processor::MakeProcessor(const ArgsManager &argsman, interfaces::Chain &chain, | Processor::MakeProcessor(const ArgsManager &argsman, interfaces::Chain &chain, | ||||
CConnman *connman, ChainstateManager &chainman, | CConnman *connman, ChainstateManager &chainman, | ||||
CScheduler &scheduler, bilingual_str &error) { | CScheduler &scheduler, bilingual_str &error) { | ||||
std::unique_ptr<PeerData> peerData; | std::unique_ptr<PeerData> peerData; | ||||
CKey masterKey; | CKey masterKey; | ||||
CKey sessionKey; | CKey sessionKey; | ||||
ProofParams proofParams; | |||||
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. | ||||
Show All 16 Lines | if (argsman.IsArgSet("-avaproof")) { | ||||
auto proof = RCUPtr<Proof>::make(); | auto proof = RCUPtr<Proof>::make(); | ||||
if (!Proof::FromHex(*proof, argsman.GetArg("-avaproof", ""), error)) { | if (!Proof::FromHex(*proof, argsman.GetArg("-avaproof", ""), error)) { | ||||
// error is set by FromHex | // error is set by FromHex | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
peerData = std::make_unique<PeerData>(); | peerData = std::make_unique<PeerData>(); | ||||
peerData->proof = std::move(proof); | peerData->proof = std::move(proof); | ||||
if (!VerifyProof(*peerData->proof, error)) { | if (!VerifyProof(proofParams, *peerData->proof, error)) { | ||||
// error is set by VerifyProof | // error is set by VerifyProof | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
std::unique_ptr<DelegationBuilder> dgb; | std::unique_ptr<DelegationBuilder> dgb; | ||||
const CPubKey &masterPubKey = masterKey.GetPubKey(); | const CPubKey &masterPubKey = masterKey.GetPubKey(); | ||||
if (argsman.IsArgSet("-avadelegation")) { | if (argsman.IsArgSet("-avadelegation")) { | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | if (staleVoteFactor > std::numeric_limits<uint32_t>::max()) { | ||||
std::numeric_limits<uint32_t>::max()); | std::numeric_limits<uint32_t>::max()); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
Config avaconfig(queryTimeoutDuration); | Config avaconfig(queryTimeoutDuration); | ||||
// We can't use std::make_unique with a private constructor | // We can't use std::make_unique with a private constructor | ||||
return std::unique_ptr<Processor>(new Processor( | return std::unique_ptr<Processor>(new Processor( | ||||
std::move(avaconfig), chain, connman, chainman, scheduler, | std::move(avaconfig), std::move(proofParams), chain, connman, chainman, | ||||
std::move(peerData), std::move(sessionKey), | scheduler, std::move(peerData), std::move(sessionKey), | ||||
Proof::amountToScore(minQuorumStake), minQuorumConnectedStakeRatio, | Proof::amountToScore(minQuorumStake), minQuorumConnectedStakeRatio, | ||||
minAvaproofsNodeCount, staleVoteThreshold, staleVoteFactor)); | minAvaproofsNodeCount, staleVoteThreshold, staleVoteFactor)); | ||||
} | } | ||||
bool Processor::addBlockToReconcile(const CBlockIndex *pindex) { | bool Processor::addBlockToReconcile(const CBlockIndex *pindex) { | ||||
if (!pindex) { | if (!pindex) { | ||||
// isWorthPolling expects this to be non-null, so bail early. | // isWorthPolling expects this to be non-null, so bail early. | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 636 Lines • Show Last 20 Lines |