rippled
Loading...
Searching...
No Matches
ConsensusTypes.h
1#ifndef XRPL_CONSENSUS_CONSENSUS_TYPES_H_INCLUDED
2#define XRPL_CONSENSUS_CONSENSUS_TYPES_H_INCLUDED
3
4#include <xrpld/consensus/ConsensusProposal.h>
5#include <xrpld/consensus/DisputedTx.h>
6
7#include <xrpl/basics/chrono.h>
8
9#include <chrono>
10#include <map>
11
12namespace ripple {
13
51
52inline std::string
54{
55 switch (m)
56 {
58 return "proposing";
60 return "observing";
62 return "wrongLedger";
64 return "switchedLedger";
65 default:
66 return "unknown";
67 }
68}
69
86enum class ConsensusPhase {
88 open,
89
92
97};
98
99inline std::string
101{
102 switch (p)
103 {
105 return "open";
107 return "establish";
109 return "accepted";
110 default:
111 return "unknown";
112 }
113}
114
118{
119 using time_point = std::chrono::steady_clock::time_point;
122
123public:
125 read() const
126 {
127 return dur_;
128 }
129
130 void
132 {
133 dur_ += fixed;
134 }
135
136 void
138 {
139 start_ = tp;
141 }
142
143 void
145 {
146 using namespace std::chrono;
147 dur_ = duration_cast<milliseconds>(tp - start_);
148 }
149};
150
167
169enum class ConsensusState {
170 No,
171 MovedOn,
172 Expired,
173 Yes
174};
175
184template <class Traits>
186{
187 using Ledger_t = typename Traits::Ledger_t;
188 using TxSet_t = typename Traits::TxSet_t;
189 using NodeID_t = typename Traits::NodeID_t;
190
191 using Tx_t = typename TxSet_t::Tx;
193 NodeID_t,
194 typename Ledger_t::ID,
195 typename TxSet_t::ID>;
197
199 : txns{std::move(s)}, position{std::move(p)}
200 {
201 XRPL_ASSERT(
202 txns.id() == position.position(),
203 "ripple::ConsensusResult : valid inputs");
204 }
205
208
211
214
215 // Set of TxSet ids we have already compared/created disputes
217
218 // Measures the duration of the establish phase for this consensus round
220
221 // Indicates state in which consensus ended. Once in the accept phase
222 // will be either Yes or MovedOn or Expired
224
225 // The number of peers proposing during the round
227};
228} // namespace ripple
229
230#endif
Position_t const & position() const
Get the proposed position.
Measures the duration of phases of consensus.
std::chrono::milliseconds read() const
void reset(time_point tp)
std::chrono::milliseconds dur_
std::chrono::steady_clock::time_point time_point
void tick(std::chrono::milliseconds fixed)
void tick(time_point tp)
A transaction discovered to be in dispute during consensus.
Definition DisputedTx.h:30
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
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.
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.
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.
@ accepted
Manifest is valid.
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:611
STL namespace.
Stores the set of initial close times.
std::map< NetClock::time_point, int > peers
Close time estimates, keep ordered for predictable traverse.
NetClock::time_point self
Our close time estimate.
Encapsulates the result of consensus.
typename Traits::Ledger_t Ledger_t
ConsensusResult(TxSet_t &&s, Proposal_t &&p)
typename TxSet_t::Tx Tx_t
hash_map< typename Tx_t::ID, Dispute_t > disputes
Transactions which are under dispute with our peers.
hash_set< typename TxSet_t::ID > compares
typename Traits::NodeID_t NodeID_t
TxSet_t txns
The set of transactions consensus agrees go in the ledger.
typename Traits::TxSet_t TxSet_t
Proposal_t position
Our proposed position on transactions/close time.