xrpld
Loading...
Searching...
No Matches
NegativeUNLVote.h
1#pragma once
2
3#include <xrpl/basics/UnorderedContainers.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/ledger/Ledger.h>
7#include <xrpl/protocol/Protocol.h>
8#include <xrpl/protocol/PublicKey.h>
9#include <xrpl/protocol/UintTypes.h>
10
11#include <cstddef>
12#include <cstdint>
13#include <memory>
14#include <mutex>
15#include <optional>
16#include <vector>
17
18namespace xrpl {
19
20template <class Adaptor>
21class Validations;
24class SHAMap;
25namespace test {
28} // namespace test
29
33class NegativeUNLVote final
34{
35public:
42 static constexpr size_t kNegativeUnlLowWaterMark = kFlagLedgerInterval * 50 / 100;
47 static constexpr size_t kNegativeUnlHighWaterMark = kFlagLedgerInterval * 80 / 100;
52 static constexpr size_t kNegativeUnlMinLocalValsToVote = kFlagLedgerInterval * 90 / 100;
57 static constexpr size_t kNewValidatorDisableSkip = kFlagLedgerInterval * 2;
61 static constexpr float kNegativeUnlMaxListed = 0.25;
62
67 enum class NegativeUNLModify {
68 ToDisable, // UNLModify Tx is to disable a validator
69 ToReEnable // UNLModify Tx is to re-enable a validator
70 };
71
79 ~NegativeUNLVote() = default;
80
93 void
95 std::shared_ptr<Ledger const> const& prevLedger,
96 hash_set<PublicKey> const& unlKeys,
97 RCLValidations& validations,
98 std::shared_ptr<SHAMap> const& initialSet);
99
107 void
108 newValidators(LedgerIndex seq, hash_set<NodeID> const& nowTrusted);
109
110private:
115
124
133 void
134 addTx(
135 LedgerIndex seq,
136 PublicKey const& vp,
137 NegativeUNLModify modify,
138 std::shared_ptr<SHAMap> const& initialSet);
139
149 static NodeID
150 choose(uint256 const& randomPadData, std::vector<NodeID> const& candidates);
151
168 std::shared_ptr<Ledger const> const& prevLedger,
169 hash_set<NodeID> const& unl,
170 RCLValidations& validations);
171
183 hash_set<NodeID> const& unl,
184 hash_set<NodeID> const& negUnl,
185 hash_map<NodeID, std::uint32_t> const& scoreTable);
186
192 void
194
197};
198
199} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
void newValidators(LedgerIndex seq, hash_set< NodeID > const &nowTrusted)
Notify NegativeUNLVote that new validators are added.
static constexpr size_t kNegativeUnlHighWaterMark
An unreliable validator must have more than negativeUNLHighWaterMark validations in the last flag led...
static constexpr size_t kNegativeUnlMinLocalValsToVote
The minimum number of validations of the local node for it to participate in the voting.
Candidates findAllCandidates(hash_set< NodeID > const &unl, hash_set< NodeID > const &negUnl, hash_map< NodeID, std::uint32_t > const &scoreTable)
Process the score table and find all disabling and re-enabling candidates.
static NodeID choose(uint256 const &randomPadData, std::vector< NodeID > const &candidates)
Pick one candidate from a vector of candidates.
~NegativeUNLVote()=default
static constexpr size_t kNewValidatorDisableSkip
We don't want to disable new validators immediately after adding them.
NegativeUNLVote(NodeID const &myId, beast::Journal j)
Constructor.
void purgeNewValidators(LedgerIndex seq)
Purge validators that are not new anymore.
NegativeUNLModify
A flag indicating whether a UNLModify Tx is to disable or to re-enable a validator.
static constexpr float kNegativeUnlMaxListed
We only want to put 25% of the UNL on the NegativeUNL.
std::optional< hash_map< NodeID, std::uint32_t > > buildScoreTable(std::shared_ptr< Ledger const > const &prevLedger, hash_set< NodeID > const &unl, RCLValidations &validations)
Build a reliability measurement score table of validators' validation messages in the last flag ledge...
static constexpr size_t kNegativeUnlLowWaterMark
A validator is considered unreliable if its validations is less than negativeUNLLowWaterMark in the l...
void doVoting(std::shared_ptr< Ledger const > const &prevLedger, hash_set< PublicKey > const &unlKeys, RCLValidations &validations, std::shared_ptr< SHAMap > const &initialSet)
Cast our local vote on the NegativeUNL candidates.
hash_map< NodeID, LedgerIndex > newValidators_
void addTx(LedgerIndex seq, PublicKey const &vp, NegativeUNLModify modify, std::shared_ptr< SHAMap > const &initialSet)
Add a ttUNL_MODIFY Tx to the transaction set.
A public key.
Definition PublicKey.h:53
Generic validations adaptor class for RCL.
Maintains current and recent ledger validations.
Test the private member functions of NegativeUNLVote.
Rest the build score table function of NegativeUNLVote.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:370
std::unordered_set< Value, Hash, Pred, Allocator > hash_set
Validations< RCLValidationsAdaptor > RCLValidations
Alias for RCL-specific instantiation of generic Validations.
std::unordered_map< Key, Value, Hash, Pred, Allocator > hash_map
BaseUInt< 256 > uint256
Definition base_uint.h:580
BaseUInt< 160, detail::NodeIDTag > NodeID
NodeID is a 160-bit hash representing one node.
Definition UintTypes.h:47
constexpr std::uint32_t kFlagLedgerInterval
Definition Protocol.h:372
std::vector< NodeID > toDisableCandidates
std::vector< NodeID > toReEnableCandidates