Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | void updatedBlockTip() override { | ||||
m_processor->peerData->proof); | m_processor->peerData->proof); | ||||
} | } | ||||
m_processor->peerManager->updatedBlockTip(); | m_processor->peerManager->updatedBlockTip(); | ||||
} | } | ||||
}; | }; | ||||
Processor::Processor(const ArgsManager &argsman, interfaces::Chain &chain, | Processor::Processor(const ArgsManager &argsman, interfaces::Chain &chain, | ||||
CConnman *connmanIn, std::unique_ptr<PeerData> peerDataIn, | CConnman *connmanIn, CScheduler &scheduler, | ||||
CKey sessionKeyIn, uint32_t minQuorumTotalScoreIn, | std::unique_ptr<PeerData> peerDataIn, CKey sessionKeyIn, | ||||
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) | ||||
: connman(connmanIn), | : connman(connmanIn), | ||||
queryTimeoutDuration(argsman.GetArg( | queryTimeoutDuration(argsman.GetArg( | ||||
"-avatimeout", AVALANCHE_DEFAULT_QUERY_TIMEOUT.count())), | "-avatimeout", AVALANCHE_DEFAULT_QUERY_TIMEOUT.count())), | ||||
round(0), peerManager(std::make_unique<PeerManager>()), | round(0), peerManager(std::make_unique<PeerManager>(scheduler)), | ||||
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 = | ||||
chain.handleNotifications(std::make_shared<NotificationsHandler>(this)); | chain.handleNotifications(std::make_shared<NotificationsHandler>(this)); | ||||
} | } | ||||
Processor::~Processor() { | Processor::~Processor() { | ||||
chainNotificationsHandler.reset(); | chainNotificationsHandler.reset(); | ||||
stopEventLoop(); | stopEventLoop(); | ||||
} | } | ||||
std::unique_ptr<Processor> Processor::MakeProcessor(const ArgsManager &argsman, | std::unique_ptr<Processor> Processor::MakeProcessor(const ArgsManager &argsman, | ||||
interfaces::Chain &chain, | interfaces::Chain &chain, | ||||
CConnman *connman, | CConnman *connman, | ||||
CScheduler &scheduler, | |||||
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()) { | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | if (staleVoteFactor > std::numeric_limits<uint32_t>::max()) { | ||||
error = strprintf(_("The avalanche stale vote factor must be less than " | error = strprintf(_("The avalanche stale vote factor must be less than " | ||||
"or equal to %d"), | "or equal to %d"), | ||||
std::numeric_limits<uint32_t>::max()); | std::numeric_limits<uint32_t>::max()); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
// 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( | ||||
argsman, chain, connman, std::move(peerData), std::move(sessionKey), | argsman, chain, connman, scheduler, std::move(peerData), | ||||
Proof::amountToScore(minQuorumStake), minQuorumConnectedStakeRatio, | std::move(sessionKey), Proof::amountToScore(minQuorumStake), | ||||
minAvaproofsNodeCount, staleVoteThreshold, staleVoteFactor)); | minQuorumConnectedStakeRatio, minAvaproofsNodeCount, staleVoteThreshold, | ||||
staleVoteFactor)); | |||||
} | } | ||||
bool Processor::addBlockToReconcile(const CBlockIndex *pindex) { | bool Processor::addBlockToReconcile(const CBlockIndex *pindex) { | ||||
bool isAccepted; | bool isAccepted; | ||||
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 590 Lines • Show Last 20 Lines |