rippled
Loading...
Searching...
No Matches
ConsensusTypes.h
1#pragma once
2
3#include <xrpld/consensus/ConsensusProposal.h>
4#include <xrpld/consensus/DisputedTx.h>
5
6#include <xrpl/basics/chrono.h>
7
8#include <chrono>
9#include <map>
10
11namespace xrpl {
12
50
51inline std::string
53{
54 switch (m)
55 {
57 return "proposing";
59 return "observing";
61 return "wrongLedger";
63 return "switchedLedger";
64 default:
65 return "unknown";
66 }
67}
68
85enum class ConsensusPhase {
87 open,
88
91
96};
97
98inline std::string
100{
101 switch (p)
102 {
104 return "open";
106 return "establish";
108 return "accepted";
109 default:
110 return "unknown";
111 }
112}
113
117{
118 using time_point = std::chrono::steady_clock::time_point;
121
122public:
124 read() const
125 {
126 return dur_;
127 }
128
129 void
134
135 void
137 {
138 start_ = tp;
140 }
141
142 void
144 {
145 using namespace std::chrono;
146 dur_ = duration_cast<milliseconds>(tp - start_);
147 }
148};
149
166
168enum class ConsensusState {
169 No,
170 MovedOn,
171 Expired,
172 Yes
173};
174
183template <class Traits>
185{
186 using Ledger_t = typename Traits::Ledger_t;
187 using TxSet_t = typename Traits::TxSet_t;
188 using NodeID_t = typename Traits::NodeID_t;
189
190 using Tx_t = typename TxSet_t::Tx;
193
194 ConsensusResult(TxSet_t&& s, Proposal_t&& p) : txns{std::move(s)}, position{std::move(p)}
195 {
196 XRPL_ASSERT(txns.id() == position.position(), "xrpl::ConsensusResult : valid inputs");
197 }
198
201
204
207
208 // Set of TxSet ids we have already compared/created disputes
210
211 // Measures the duration of the establish phase for this consensus round
213
214 // Indicates state in which consensus ended. Once in the accept phase
215 // will be either Yes or MovedOn or Expired
217
218 // The number of peers proposing during the round
220};
221} // namespace xrpl
Position_t const & position() const
Get the proposed position.
Measures the duration of phases of consensus.
std::chrono::milliseconds dur_
void reset(time_point tp)
void tick(std::chrono::milliseconds fixed)
std::chrono::steady_clock::time_point time_point
std::chrono::milliseconds read() const
void tick(time_point tp)
A transaction discovered to be in dispute during consensus.
Definition DisputedTx.h:29
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
ConsensusMode
Represents how a node currently participates in Consensus.
@ wrongLedger
We have the wrong ledger and are attempting to acquire it.
@ proposing
We are normal participant in consensus and propose our position.
@ switchedLedger
We switched ledgers since we started this consensus round but are now running on what we believe is t...
@ observing
We are observing peer positions, but not proposing our position.
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:597
static FunctionType fixed(Keylet const &keylet)
ConsensusState
Whether we have or don't have a consensus.
@ Expired
Consensus time limit has hard-expired.
@ MovedOn
The network has consensus without us.
@ No
We do not have consensus.
ConsensusPhase
Phases of consensus for a single ledger round.
@ accepted
We have accepted a new last closed ledger and are waiting on a call to startRound to begin the next c...
@ open
We haven't closed our ledger yet, but others might have.
@ establish
Establishing consensus by exchanging proposals with our peers.
@ accepted
Manifest is valid.
Stores the set of initial close times.
NetClock::time_point self
Our close time estimate.
std::map< NetClock::time_point, int > peers
Close time estimates, keep ordered for predictable traverse.
Encapsulates the result of consensus.
typename Traits::Ledger_t Ledger_t
TxSet_t txns
The set of transactions consensus agrees go in the ledger.
ConsensusResult(TxSet_t &&s, Proposal_t &&p)
hash_map< typename Tx_t::ID, Dispute_t > disputes
Transactions which are under dispute with our peers.
ConsensusTimer roundTime
typename TxSet_t::Tx Tx_t
typename Traits::TxSet_t TxSet_t
Proposal_t position
Our proposed position on transactions/close time.
typename Traits::NodeID_t NodeID_t
hash_set< typename TxSet_t::ID > compares