Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
| Show First 20 Lines • Show All 832 Lines • ▼ Show 20 Lines | |||||
| /* | /* | ||||
| * 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() { | ||||
| AssertLockNotHeld(cs_main); | AssertLockNotHeld(cs_main); | ||||
| auto setConnmanQuorumEstablished = [&](bool quorum_established) { | |||||
| if (connman != nullptr) { | |||||
| connman->SetQuorumEstablished(quorum_established); | |||||
| } | |||||
| }; | |||||
| { | { | ||||
| LOCK(cs_peerManager); | LOCK(cs_peerManager); | ||||
| if (peerManager->getNodeCount() < 8) { | if (peerManager->getNodeCount() < 8) { | ||||
| setConnmanQuorumEstablished(false); | |||||
| // There is no point polling if we know the vote cannot converge | // There is no point polling if we know the vote cannot converge | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| setConnmanQuorumEstablished(quorumIsEstablished); | |||||
| /* | /* | ||||
| * The following parameters can naturally go temporarly below the threshold | * The following parameters can naturally go temporarly below the threshold | ||||
| * under normal circumstances, like during a proof replacement with a lower | * under normal circumstances, like during a proof replacement with a lower | ||||
| * stake amount, or the discovery of a new proofs for which we don't have a | * stake amount, or the discovery of a new proofs for which we don't have a | ||||
| * node yet. | * node yet. | ||||
| * In order to prevent our node from starting and stopping the polls | * In order to prevent our node from starting and stopping the polls | ||||
| * spuriously on such event, the quorum establishement is latched. The only | * spuriously on such event, the quorum establishement is latched. The only | ||||
| * parameters that should not latched is the minimum node count, as this | * parameters that should not latched is the minimum node count, as this | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | bool Processor::isQuorumEstablished() { | ||||
| // Ensure we have connected score for enough of the overall score | // Ensure we have connected score for enough of the overall score | ||||
| uint32_t minConnectedScore = | uint32_t minConnectedScore = | ||||
| std::round(double(totalPeersScore) * minQuorumConnectedScoreRatio); | std::round(double(totalPeersScore) * minQuorumConnectedScoreRatio); | ||||
| if (connectedPeersScore < minConnectedScore) { | if (connectedPeersScore < minConnectedScore) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| quorumIsEstablished = true; | quorumIsEstablished = true; | ||||
| setConnmanQuorumEstablished(true); | |||||
| // Attempt to compute the staking rewards winner now so we don't have to | // Attempt to compute the staking rewards winner now so we don't have to | ||||
| // wait for a block if we already have all the prerequisites. | // wait for a block if we already have all the prerequisites. | ||||
| const CBlockIndex *pprev = WITH_LOCK(cs_main, return chainman.ActiveTip()); | const CBlockIndex *pprev = WITH_LOCK(cs_main, return chainman.ActiveTip()); | ||||
| bool computedRewards = false; | bool computedRewards = false; | ||||
| if (pprev && IsStakingRewardsActivated(chainman.GetConsensus(), pprev)) { | if (pprev && IsStakingRewardsActivated(chainman.GetConsensus(), pprev)) { | ||||
| computedRewards = computeStakingReward(pprev); | computedRewards = computeStakingReward(pprev); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 635 Lines • Show Last 20 Lines | |||||