rippled
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 <ripple/app/ledger/Ledger.h>
24 #include <ripple/beast/utility/Journal.h>
25 #include <ripple/protocol/Protocol.h>
26 #include <ripple/protocol/PublicKey.h>
27 #include <ripple/protocol/UintTypes.h>
28 
29 #include <optional>
30 
31 namespace ripple {
32 
33 template <class Adaptor>
34 class Validations;
35 class RCLValidationsAdaptor;
36 using RCLValidations = Validations<RCLValidationsAdaptor>;
37 class SHAMap;
38 namespace test {
39 class NegativeUNLVoteInternal_test;
40 class NegativeUNLVoteScoreTable_test;
41 } // namespace test
42 
46 class NegativeUNLVote final
47 {
48 public:
55  static constexpr size_t negativeUNLLowWaterMark =
56  FLAG_LEDGER_INTERVAL * 50 / 100;
61  static constexpr size_t negativeUNLHighWaterMark =
62  FLAG_LEDGER_INTERVAL * 80 / 100;
67  static constexpr size_t negativeUNLMinLocalValsToVote =
68  FLAG_LEDGER_INTERVAL * 90 / 100;
73  static constexpr size_t newValidatorDisableSkip = FLAG_LEDGER_INTERVAL * 2;
77  static constexpr float negativeUNLMaxListed = 0.25;
78 
84  ToDisable, // UNLModify Tx is to disable a validator
85  ToReEnable // UNLModify Tx is to re-enable a validator
86  };
87 
94  NegativeUNLVote(NodeID const& myId, beast::Journal j);
95  ~NegativeUNLVote() = default;
96 
109  void
110  doVoting(
111  std::shared_ptr<Ledger const> const& prevLedger,
112  hash_set<PublicKey> const& unlKeys,
113  RCLValidations& validations,
114  std::shared_ptr<SHAMap> const& initialSet);
115 
123  void
124  newValidators(LedgerIndex seq, hash_set<NodeID> const& nowTrusted);
125 
126 private:
127  NodeID const myId_;
131 
135  struct Candidates
136  {
139  };
140 
149  void
150  addTx(
151  LedgerIndex seq,
152  PublicKey const& vp,
153  NegativeUNLModify modify,
154  std::shared_ptr<SHAMap> const& initialSet);
155 
165  NodeID
166  choose(uint256 const& randomPadData, std::vector<NodeID> const& candidates);
167 
184  std::shared_ptr<Ledger const> const& prevLedger,
185  hash_set<NodeID> const& unl,
186  RCLValidations& validations);
187 
197  Candidates const
199  hash_set<NodeID> const& unl,
200  hash_set<NodeID> const& negUnl,
201  hash_map<NodeID, std::uint32_t> const& scoreTable);
202 
208  void
210 
213 };
214 
215 } // namespace ripple
216 
217 #endif
ripple::RCLValidations
Validations< RCLValidationsAdaptor > RCLValidations
Alias for RCL-specific instantiation of generic Validations.
Definition: RCLValidations.h:236
ripple::NegativeUNLVote::doVoting
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.
Definition: NegativeUNLVote.cpp:33
std::shared_ptr
STL class.
std::unordered_set
STL class.
ripple::NegativeUNLVote::j_
beast::Journal j_
Definition: NegativeUNLVote.h:128
std::vector
STL class.
ripple::NegativeUNLVote::~NegativeUNLVote
~NegativeUNLVote()=default
ripple::FLAG_LEDGER_INTERVAL
constexpr std::uint32_t FLAG_LEDGER_INTERVAL
Definition: Ledger.h:426
ripple::NegativeUNLVote::ToReEnable
@ ToReEnable
Definition: NegativeUNLVote.h:85
ripple::NegativeUNLVote::negativeUNLHighWaterMark
static constexpr size_t negativeUNLHighWaterMark
An unreliable validator must have more than negativeUNLHighWaterMark validations in the last flag led...
Definition: NegativeUNLVote.h:61
ripple::NegativeUNLVote::newValidators_
hash_map< NodeID, LedgerIndex > newValidators_
Definition: NegativeUNLVote.h:130
ripple::NegativeUNLVote::Candidates::toDisableCandidates
std::vector< NodeID > toDisableCandidates
Definition: NegativeUNLVote.h:137
ripple::base_uint< 160, detail::NodeIDTag >
ripple::NegativeUNLVote::Candidates::toReEnableCandidates
std::vector< NodeID > toReEnableCandidates
Definition: NegativeUNLVote.h:138
ripple::NegativeUNLVote::ToDisable
@ ToDisable
Definition: NegativeUNLVote.h:84
ripple::NegativeUNLVote::findAllCandidates
const 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.
Definition: NegativeUNLVote.cpp:242
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::NegativeUNLVote::negativeUNLMaxListed
static constexpr float negativeUNLMaxListed
We only want to put 25% of the UNL on the NegativeUNL.
Definition: NegativeUNLVote.h:77
ripple::NegativeUNLVote::negativeUNLMinLocalValsToVote
static constexpr size_t negativeUNLMinLocalValsToVote
The minimum number of validations of the local node for it to participate in the voting.
Definition: NegativeUNLVote.h:67
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::NegativeUNLVote::buildScoreTable
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...
Definition: NegativeUNLVote.cpp:158
ripple::NegativeUNLVote::Candidates
UNLModify Tx candidates.
Definition: NegativeUNLVote.h:135
ripple::NegativeUNLVote::addTx
void addTx(LedgerIndex seq, PublicKey const &vp, NegativeUNLModify modify, std::shared_ptr< SHAMap > const &initialSet)
Add a ttUNL_MODIFY Tx to the transaction set.
Definition: NegativeUNLVote.cpp:107
ripple::NegativeUNLVote::newValidatorDisableSkip
static constexpr size_t newValidatorDisableSkip
We don't want to disable new validators immediately after adding them.
Definition: NegativeUNLVote.h:73
ripple::test::NegativeUNLVoteScoreTable_test
Rest the build score table function of NegativeUNLVote.
Definition: NegativeUNL_test.cpp:1410
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NegativeUNLVote::myId_
const NodeID myId_
Definition: NegativeUNLVote.h:127
ripple::NegativeUNLVote::NegativeUNLModify
NegativeUNLModify
A flag indicating whether a UNLModify Tx is to disable or to re-enable a validator.
Definition: NegativeUNLVote.h:83
ripple::NegativeUNLVote::negativeUNLLowWaterMark
static constexpr size_t negativeUNLLowWaterMark
A validator is considered unreliable if its validations is less than negativeUNLLowWaterMark in the l...
Definition: NegativeUNLVote.h:55
ripple::test::NegativeUNLVoteInternal_test
Test the private member functions of NegativeUNLVote.
Definition: NegativeUNL_test.cpp:767
ripple::Validations< RCLValidationsAdaptor >
optional
std::mutex
STL class.
ripple::NegativeUNLVote::purgeNewValidators
void purgeNewValidators(LedgerIndex seq)
Purge validators that are not new anymore.
Definition: NegativeUNLVote.cpp:334
ripple::NegativeUNLVote
Manager to create NegativeUNL votes.
Definition: NegativeUNLVote.h:46
ripple::NegativeUNLVote::choose
NodeID choose(uint256 const &randomPadData, std::vector< NodeID > const &candidates)
Pick one candidate from a vector of candidates.
Definition: NegativeUNLVote.cpp:139
std::unordered_map
STL class.
ripple::NegativeUNLVote::mutex_
std::mutex mutex_
Definition: NegativeUNLVote.h:129
ripple::NegativeUNLVote::NegativeUNLVote
NegativeUNLVote(NodeID const &myId, beast::Journal j)
Constructor.
Definition: NegativeUNLVote.cpp:27
ripple::NegativeUNLVote::newValidators
void newValidators(LedgerIndex seq, hash_set< NodeID > const &nowTrusted)
Notify NegativeUNLVote that new validators are added.
Definition: NegativeUNLVote.cpp:317