1#ifndef XRPL_APP_CONSENSUS_RCLCONSENSUS_H_INCLUDED
2#define XRPL_APP_CONSENSUS_RCLCONSENSUS_H_INCLUDED
4#include <xrpld/app/consensus/RCLCensorshipDetector.h>
5#include <xrpld/app/consensus/RCLCxLedger.h>
6#include <xrpld/app/consensus/RCLCxPeerPos.h>
7#include <xrpld/app/consensus/RCLCxTx.h>
8#include <xrpld/app/misc/FeeVote.h>
9#include <xrpld/app/misc/NegativeUNLVote.h>
10#include <xrpld/consensus/Consensus.h>
12#include <xrpl/beast/utility/Journal.h>
13#include <xrpl/core/JobQueue.h>
14#include <xrpl/protocol/RippleLedgerHash.h>
15#include <xrpl/shamap/SHAMap.h>
26class InboundTransactions;
336 protocol::NodeEvent ne,
338 bool haveCorrectLCL);
379 bool closeTimeCorrect,
536 std::chrono::steady_clock::time_point
start_;
A generic endpoint for log messages.
Holds transactions which were deferred to the next pass of consensus.
Generic implementation of consensus algorithm.
Manages the acquisition and lifetime of transaction sets.
Manager to create NegativeUNL votes.
std::chrono::time_point< NetClock > time_point
InboundTransactions & inboundTransactions_
NegativeUNLVote nUnlVote_
Result onClose(RCLCxLedger const &ledger, NetClock::time_point const &closeTime, ConsensusMode mode)
Close the open ledger and return initial consensus position.
bool preStartRound(RCLCxLedger const &prevLedger, hash_set< NodeID > const &nowTrusted)
Called before kicking off a new consensus round.
bool validator() const
Whether I am a validator.
LedgerIndex getValidLedgerIndex() const
void updateOperatingMode(std::size_t const positions) const
Update operating mode based on current peer positions.
std::size_t proposersFinished(RCLCxLedger const &ledger, LedgerHash const &h) const
Number of proposers that have validated a ledger descended from requested ledger.
void validate(RCLCxLedger const &ledger, RCLTxSet const &txns, bool proposing)
Validate the given ledger and share with peers as necessary.
std::size_t prevProposers() const
ConsensusParms const & parms() const
Consensus simulation parameters.
std::unique_ptr< FeeVote > feeVote_
LedgerHash acquiringLedger_
std::atomic< bool > validating_
void doAccept(Result const &result, RCLCxLedger const &prevLedger, NetClock::duration closeResolution, ConsensusCloseTimes const &rawCloseTimes, ConsensusMode const &mode, Json::Value &&consensusJson)
Accept a new ledger based on the given transactions.
void propose(RCLCxPeerPos::Proposal const &proposal)
Propose the given position to my peers.
RCLCxLedger buildLCL(RCLCxLedger const &previousLedger, CanonicalTXSet &retriableTxs, NetClock::time_point closeTime, bool closeTimeCorrect, NetClock::duration closeResolution, std::chrono::milliseconds roundTime, std::set< TxID > &failedTxs)
Build the new last closed ledger.
ConsensusMode mode() const
NetClock::time_point lastValidationTime_
std::size_t proposersValidated(LedgerHash const &h) const
Number of proposers that have validated the given ledger.
void notify(protocol::NodeEvent ne, RCLCxLedger const &ledger, bool haveCorrectLCL)
Notify peers of a consensus state change.
void onAccept(Result const &result, RCLCxLedger const &prevLedger, NetClock::duration const &closeResolution, ConsensusCloseTimes const &rawCloseTimes, ConsensusMode const &mode, Json::Value &&consensusJson, bool const validating)
Process the accepted ledger.
std::atomic< ConsensusMode > mode_
std::pair< std::size_t, hash_set< NodeKey_t > > getQuorumKeys() const
std::optional< RCLTxSet > acquireTxSet(RCLTxSet::ID const &setId)
Acquire the transaction set associated with a proposal.
ValidatorKeys const & validatorKeys_
uint256 getPrevLedger(uint256 ledgerID, RCLCxLedger const &ledger, ConsensusMode mode)
Get the ID of the previous ledger/last closed ledger(LCL) on the network.
LedgerMaster & ledgerMaster_
std::atomic< std::chrono::milliseconds > prevRoundTime_
std::size_t laggards(Ledger_t::Seq const seq, hash_set< NodeKey_t > &trustedKeys) const
void onForceAccept(Result const &result, RCLCxLedger const &prevLedger, NetClock::duration const &closeResolution, ConsensusCloseTimes const &rawCloseTimes, ConsensusMode const &mode, Json::Value &&consensusJson)
Process the accepted ledger that was a result of simulation/force accept.
std::optional< RCLCxLedger > acquireLedger(LedgerHash const &hash)
Attempt to acquire a specific ledger.
std::chrono::milliseconds prevRoundTime() const
bool hasOpenTransactions() const
Whether the open ledger has any transactions.
RCLCensorshipDetector< TxID, LedgerIndex > censorshipDetector_
std::atomic< std::size_t > prevProposers_
bool haveValidated() const
void onModeChange(ConsensusMode before, ConsensusMode after)
Notified of change in consensus mode.
std::uint64_t const valCookie_
void share(RCLCxPeerPos const &peerPos)
Share the given proposal with all peers.
Manages the generic consensus algorithm for use by the RCL.
Consensus< Adaptor > consensus_
void timerEntry(NetClock::time_point const &now, std::unique_ptr< std::stringstream > const &clog={})
void startRound(NetClock::time_point const &now, RCLCxLedger::ID const &prevLgrId, RCLCxLedger const &prevLgr, hash_set< NodeID > const &nowUntrusted, hash_set< NodeID > const &nowTrusted, std::unique_ptr< std::stringstream > const &clog)
Adjust the set of trusted validators and kick-off the next round of consensus.
bool validating() const
Whether we are validating consensus ledgers.
std::size_t prevProposers() const
Get the number of proposing peers that participated in the previous round.
RCLConsensus(RCLConsensus const &)=delete
bool peerProposal(NetClock::time_point const &now, RCLCxPeerPos const &newProposal)
void simulate(NetClock::time_point const &now, std::optional< std::chrono::milliseconds > consensusDelay)
ConsensusParms const & parms() const
RCLConsensus & operator=(RCLConsensus const &)=delete
Json::Value getJson(bool full) const
std::chrono::milliseconds prevRoundTime() const
Get duration of the previous round.
std::recursive_mutex mutex_
static constexpr unsigned int censorshipWarnInternal
Warn for transactions that haven't been included every so many ledgers.
ConsensusMode mode() const
void gotTxSet(NetClock::time_point const &now, RCLTxSet const &txSet)
RCLCxLedger::ID prevLedgerID() const
ConsensusPhase phase() const
Represents a ledger in RCLConsensus.
LedgerHash ID
Unique identifier of a ledger.
LedgerIndex Seq
Sequence number of a ledger.
A peer's signed, proposed position for use in RCLConsensus.
Represents a transaction in RCLConsensus.
Represents a set of transactions in RCLConsensus.
Collects logging information.
std::unique_ptr< std::stringstream > const & ss()
std::chrono::steady_clock::time_point start_
std::unique_ptr< std::stringstream > ss_
Validator keys and manifest as set in configuration file.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
base_uint< 160, detail::NodeIDTag > NodeID
NodeID is a 160-bit hash representing one node.
ConsensusMode
Represents how a node currently participates in Consensus.
@ proposing
We are normal participant in consensus and propose our position.
@ observing
We are observing peer positions, but not proposing our position.
ConsensusPhase
Phases of consensus for a single ledger round.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
@ ledgerMaster
ledger master data for signing
@ proposal
proposal for signing
boost::outcome_v2::result< T, std::error_code > Result
Stores the set of initial close times.
Consensus algorithm parameters.
Encapsulates the result of consensus.