rippled
Loading...
Searching...
No Matches
NegativeUNLVote.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2020 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_MISC_NEGATIVEUNLVOTE_H_INCLUDED
21#define RIPPLE_APP_MISC_NEGATIVEUNLVOTE_H_INCLUDED
22
23#include <xrpld/app/ledger/Ledger.h>
24
25#include <xrpl/beast/utility/Journal.h>
26#include <xrpl/protocol/Protocol.h>
27#include <xrpl/protocol/PublicKey.h>
28#include <xrpl/protocol/UintTypes.h>
29
30#include <optional>
31
32namespace ripple {
33
34template <class Adaptor>
35class Validations;
36class RCLValidationsAdaptor;
37using RCLValidations = Validations<RCLValidationsAdaptor>;
38class SHAMap;
39namespace test {
40class NegativeUNLVoteInternal_test;
41class NegativeUNLVoteScoreTable_test;
42} // namespace test
43
47class NegativeUNLVote final
48{
49public:
56 static constexpr size_t negativeUNLLowWaterMark =
57 FLAG_LEDGER_INTERVAL * 50 / 100;
62 static constexpr size_t negativeUNLHighWaterMark =
63 FLAG_LEDGER_INTERVAL * 80 / 100;
68 static constexpr size_t negativeUNLMinLocalValsToVote =
69 FLAG_LEDGER_INTERVAL * 90 / 100;
74 static constexpr size_t newValidatorDisableSkip = FLAG_LEDGER_INTERVAL * 2;
78 static constexpr float negativeUNLMaxListed = 0.25;
79
85 ToDisable, // UNLModify Tx is to disable a validator
86 ToReEnable // UNLModify Tx is to re-enable a validator
87 };
88
96 ~NegativeUNLVote() = default;
97
110 void
111 doVoting(
112 std::shared_ptr<Ledger const> const& prevLedger,
113 hash_set<PublicKey> const& unlKeys,
114 RCLValidations& validations,
115 std::shared_ptr<SHAMap> const& initialSet);
116
124 void
125 newValidators(LedgerIndex seq, hash_set<NodeID> const& nowTrusted);
126
127private:
132
141
150 void
151 addTx(
152 LedgerIndex seq,
153 PublicKey const& vp,
154 NegativeUNLModify modify,
155 std::shared_ptr<SHAMap> const& initialSet);
156
166 NodeID
167 choose(uint256 const& randomPadData, std::vector<NodeID> const& candidates);
168
185 std::shared_ptr<Ledger const> const& prevLedger,
186 hash_set<NodeID> const& unl,
187 RCLValidations& validations);
188
198 Candidates const
200 hash_set<NodeID> const& unl,
201 hash_set<NodeID> const& negUnl,
202 hash_map<NodeID, std::uint32_t> const& scoreTable);
203
209 void
211
214};
215
216} // namespace ripple
217
218#endif
A generic endpoint for log messages.
Definition Journal.h:60
Manager to create NegativeUNL votes.
static constexpr size_t negativeUNLHighWaterMark
An unreliable validator must have more than negativeUNLHighWaterMark validations in the last flag led...
NodeID choose(uint256 const &randomPadData, std::vector< NodeID > const &candidates)
Pick one candidate from a vector of candidates.
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...
NegativeUNLModify
A flag indicating whether a UNLModify Tx is to disable or to re-enable a validator.
void purgeNewValidators(LedgerIndex seq)
Purge validators that are not new anymore.
Candidates const 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 constexpr size_t newValidatorDisableSkip
We don't want to disable new validators immediately after adding them.
static constexpr size_t negativeUNLLowWaterMark
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 newValidators(LedgerIndex seq, hash_set< NodeID > const &nowTrusted)
Notify NegativeUNLVote that new validators are added.
static constexpr float negativeUNLMaxListed
We only want to put 25% of the UNL on the NegativeUNL.
void addTx(LedgerIndex seq, PublicKey const &vp, NegativeUNLModify modify, std::shared_ptr< SHAMap > const &initialSet)
Add a ttUNL_MODIFY Tx to the transaction set.
static constexpr size_t negativeUNLMinLocalValsToVote
The minimum number of validations of the local node for it to participate in the voting.
A public key.
Definition PublicKey.h:61
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:25
std::uint32_t constexpr FLAG_LEDGER_INTERVAL
Definition Ledger.h:426
Validations< RCLValidationsAdaptor > RCLValidations
Alias for RCL-specific instantiation of generic Validations.
std::vector< NodeID > toReEnableCandidates
std::vector< NodeID > toDisableCandidates