diff --git a/src/avalanche/peermanager.h b/src/avalanche/peermanager.h --- a/src/avalanche/peermanager.h +++ b/src/avalanche/peermanager.h @@ -87,6 +87,7 @@ uint32_t node_count = 0; ProofRef proof; + bool hasFinalized = false; // The network stack uses timestamp in seconds, so we oblige. std::chrono::seconds registration_time; @@ -279,6 +280,11 @@ bool updateNextPossibleConflictTime(PeerId peerid, const std::chrono::seconds &nextTime); + /** + * Latch on that this peer has a finalized proof. + */ + bool setFinalized(PeerId peerid); + /** * Registration mode * - DEFAULT: Default policy, register only if the proof is unknown and has diff --git a/src/avalanche/peermanager.cpp b/src/avalanche/peermanager.cpp --- a/src/avalanche/peermanager.cpp +++ b/src/avalanche/peermanager.cpp @@ -195,6 +195,18 @@ return it->nextPossibleConflictTime == nextTime; } +bool PeerManager::setFinalized(PeerId peerid) { + auto it = peers.find(peerid); + if (it == peers.end()) { + // No such peer + return false; + } + + peers.modify(it, [&](Peer &p) { p.hasFinalized = true; }); + + return true; +} + template void PeerManager::moveToConflictingPool(const ProofContainer &proofs) { auto &peersView = peers.get(); diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -5156,6 +5156,10 @@ proofid, [&](const avalanche::Peer &peer) { pm.updateNextPossibleConflictTime( peer.peerid, nextCooldownTimePoint); + if (u.getStatus() == + avalanche::VoteStatus::Finalized) { + pm.setFinalized(peer.peerid); + } // Only fail if the peer was not // created return true; diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -670,6 +670,9 @@ {RPCResult::Type::NUM, "connected_proof_count", "The number of avalanche proofs with at least one node " "we are connected to."}, + {RPCResult::Type::NUM, "finalized_proof_count", + "The number of known avalanche proofs that have been " + "finalized by avalanche."}, {RPCResult::Type::NUM, "conflicting_proof_count", "The number of known avalanche proofs that conflict with " "valid proofs."}, @@ -732,6 +735,7 @@ uint64_t proofCount{0}; uint64_t connectedProofCount{0}; + uint64_t finalizedProofCount{0}; Amount totalStakes = Amount::zero(); Amount connectedStakes = Amount::zero(); @@ -748,6 +752,10 @@ ++proofCount; totalStakes += proofStake; + if (peer.hasFinalized) { + ++finalizedProofCount; + } + if (peer.node_count > 0) { ++connectedProofCount; connectedStakes += proofStake; @@ -756,6 +764,7 @@ network.pushKV("proof_count", proofCount); network.pushKV("connected_proof_count", connectedProofCount); + network.pushKV("finalized_proof_count", finalizedProofCount); network.pushKV("conflicting_proof_count", uint64_t(pm.getConflictingProofCount())); network.pushKV("orphan_proof_count", diff --git a/test/functional/abc_rpc_getavalancheinfo.py b/test/functional/abc_rpc_getavalancheinfo.py --- a/test/functional/abc_rpc_getavalancheinfo.py +++ b/test/functional/abc_rpc_getavalancheinfo.py @@ -68,6 +68,7 @@ "network": { "proof_count": 0, "connected_proof_count": 0, + "finalized_proof_count": 0, "conflicting_proof_count": 0, "orphan_proof_count": 0, "total_stake_amount": Decimal('0.00'), @@ -97,6 +98,7 @@ "network": { "proof_count": 0, "connected_proof_count": 0, + "finalized_proof_count": 0, "conflicting_proof_count": 0, "orphan_proof_count": 0, "total_stake_amount": Decimal('0.00'), @@ -122,6 +124,7 @@ "network": { "proof_count": 0, "connected_proof_count": 0, + "finalized_proof_count": 0, "conflicting_proof_count": 0, "orphan_proof_count": 0, "total_stake_amount": Decimal('0.00'), @@ -177,6 +180,7 @@ "network": { "proof_count": N, "connected_proof_count": N, + "finalized_proof_count": 0, "conflicting_proof_count": N, "orphan_proof_count": 1, "total_stake_amount": coinbase_amount * N, @@ -209,6 +213,7 @@ "network": { "proof_count": N, "connected_proof_count": N - D, + "finalized_proof_count": 0, "conflicting_proof_count": N, "orphan_proof_count": 1, "total_stake_amount": coinbase_amount * N, @@ -259,6 +264,7 @@ # Orphan became mature "proof_count": N + 1, "connected_proof_count": N - D, + "finalized_proof_count": 0, "conflicting_proof_count": N, "orphan_proof_count": 0, "total_stake_amount": coinbase_amount * (N + 1), @@ -287,6 +293,7 @@ "network": { "proof_count": N + 1, "connected_proof_count": 0, + "finalized_proof_count": 0, "conflicting_proof_count": N, "orphan_proof_count": 0, "total_stake_amount": coinbase_amount * (N + 1),