Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | void updatedBlockTip() override { | ||||
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, std::unique_ptr<PeerData> peerDataIn, | ||||
CKey sessionKeyIn, uint32_t minQuorumTotalScoreIn, | CKey sessionKeyIn, uint32_t minQuorumTotalScoreIn, | ||||
double minQuorumConnectedScoreRatioIn, | double minQuorumConnectedScoreRatioIn, | ||||
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>()), | ||||
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), | |||||
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() { | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | std::unique_ptr<Processor> Processor::MakeProcessor(const ArgsManager &argsman, | ||||
} | } | ||||
if (minQuorumConnectedStakeRatio < 0 || minQuorumConnectedStakeRatio > 1) { | if (minQuorumConnectedStakeRatio < 0 || minQuorumConnectedStakeRatio > 1) { | ||||
error = _( | error = _( | ||||
"The avalanche min quorum connected stake ratio is out of range."); | "The avalanche min quorum connected stake ratio is out of range."); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
int64_t minAvaproofsNodeCount = | |||||
argsman.GetArg("-avaminavaproofsnodecount", | |||||
AVALANCHE_DEFAULT_MIN_AVAPROOFS_NODE_COUNT); | |||||
if (minAvaproofsNodeCount < 0) { | |||||
error = _("The minimum number of node that sent avaproofs message " | |||||
"should be non-negative"); | |||||
return nullptr; | |||||
} | |||||
// Determine voting parameters | // Determine voting parameters | ||||
int64_t staleVoteThreshold = argsman.GetArg("-avastalevotethreshold", | int64_t staleVoteThreshold = argsman.GetArg("-avastalevotethreshold", | ||||
AVALANCHE_VOTE_STALE_THRESHOLD); | AVALANCHE_VOTE_STALE_THRESHOLD); | ||||
if (staleVoteThreshold < AVALANCHE_VOTE_STALE_MIN_THRESHOLD) { | if (staleVoteThreshold < AVALANCHE_VOTE_STALE_MIN_THRESHOLD) { | ||||
error = strprintf(_("The avalanche stale vote threshold must be " | error = strprintf(_("The avalanche stale vote threshold must be " | ||||
"greater than or equal to %d"), | "greater than or equal to %d"), | ||||
AVALANCHE_VOTE_STALE_MIN_THRESHOLD); | AVALANCHE_VOTE_STALE_MIN_THRESHOLD); | ||||
return nullptr; | return nullptr; | ||||
Show All 17 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; | ||||
} | } | ||||
// 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, std::move(peerData), std::move(sessionKey), | ||||
Proof::amountToScore(minQuorumStake), minQuorumConnectedStakeRatio, | Proof::amountToScore(minQuorumStake), minQuorumConnectedStakeRatio, | ||||
staleVoteThreshold, staleVoteFactor)); | 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 496 Lines • ▼ Show 20 Lines | do { | ||||
peerManager->removeNode(nodeid); | peerManager->removeNode(nodeid); | ||||
} | } | ||||
// Get next suitable node to try again | // Get next suitable node to try again | ||||
nodeid = getSuitableNodeToQuery(); | nodeid = getSuitableNodeToQuery(); | ||||
} while (nodeid != NO_NODE); | } while (nodeid != NO_NODE); | ||||
} | } | ||||
void Processor::avaproofsSent(NodeId nodeid) { | |||||
if (::ChainstateActive().IsInitialBlockDownload()) { | |||||
// Before IBD is complete there is no way to make sure a proof is valid | |||||
// or not, e.g. it can be spent in a block we don't know yet. In order | |||||
// to increase confidence that our proof set is similar to other nodes | |||||
// on the network, the messages received during IBD are not accounted. | |||||
return; | |||||
} | |||||
LOCK(cs_peerManager); | |||||
if (peerManager->latchAvaproofsSent(nodeid)) { | |||||
avaproofsNodeCounter++; | |||||
} | |||||
} | |||||
/* | /* | ||||
* Returns a bool indicating whether we have a usable Avalanche quorum enabling | * Returns a bool indicating whether we have a usable Avalanche quorum enabling | ||||
* us to take decisions based on polls. | * us to take decisions based on polls. | ||||
*/ | */ | ||||
bool Processor::isQuorumEstablished() { | bool Processor::isQuorumEstablished() { | ||||
if (quorumIsEstablished) { | if (quorumIsEstablished) { | ||||
return true; | return true; | ||||
} | } | ||||
if (avaproofsNodeCounter < minAvaproofsNodeCount) { | |||||
return false; | |||||
} | |||||
auto localProof = getLocalProof(); | auto localProof = getLocalProof(); | ||||
// Get the registered proof score and registered score we have nodes for | // Get the registered proof score and registered score we have nodes for | ||||
uint32_t totalPeersScore; | uint32_t totalPeersScore; | ||||
uint32_t connectedPeersScore; | uint32_t connectedPeersScore; | ||||
{ | { | ||||
LOCK(cs_peerManager); | LOCK(cs_peerManager); | ||||
totalPeersScore = peerManager->getTotalPeersScore(); | totalPeersScore = peerManager->getTotalPeersScore(); | ||||
Show All 34 Lines |