20 #ifndef RIPPLE_APP_CONSENSUS_RCLCONSENSUS_H_INCLUDED
21 #define RIPPLE_APP_CONSENSUS_RCLCONSENSUS_H_INCLUDED
23 #include <ripple/app/consensus/RCLCensorshipDetector.h>
24 #include <ripple/app/consensus/RCLCxLedger.h>
25 #include <ripple/app/consensus/RCLCxPeerPos.h>
26 #include <ripple/app/consensus/RCLCxTx.h>
27 #include <ripple/app/misc/FeeVote.h>
28 #include <ripple/app/misc/NegativeUNLVote.h>
29 #include <ripple/basics/CountedObject.h>
30 #include <ripple/basics/Log.h>
31 #include <ripple/basics/chrono.h>
32 #include <ripple/beast/utility/Journal.h>
33 #include <ripple/consensus/Consensus.h>
34 #include <ripple/core/JobQueue.h>
35 #include <ripple/overlay/Message.h>
36 #include <ripple/protocol/RippleLedgerHash.h>
37 #include <ripple/protocol/STValidation.h>
38 #include <ripple/shamap/SHAMap.h>
47 class InboundTransactions;
456 protocol::NodeEvent ne,
458 bool haveCorrectLCL);
521 bool closeTimeCorrect,
RCLCxLedger::ID prevLedgerID() const
ConsensusPhase phase() const
std::atomic< std::chrono::milliseconds > prevRoundTime_
void setTimerDelay(std::optional< std::chrono::milliseconds > td=std::nullopt)
A peer's signed, proposed position for use in RCLConsensus.
const std::uint64_t valCookie_
LedgerIndex Seq
Sequence number of a ledger.
std::chrono::milliseconds prevRoundTime() const
Json::Value getJson(bool full) const
std::atomic< ConsensusMode > mode_
std::unique_ptr< FeeVote > feeVote_
void startRound(NetClock::time_point const &now, RCLCxLedger::ID const &prevLgrId, RCLCxLedger const &prevLgr, hash_set< NodeID > const &nowUntrusted, hash_set< NodeID > const &nowTrusted)
Adjust the set of trusted validators and kick-off the next round of consensus.
base_uint< 160, detail::NodeIDTag > NodeID
NodeID is a 160-bit hash representing one node.
std::recursive_mutex mutex_
std::optional< RCLCxLedger > acquireLedger(LedgerHash const &hash)
Attempt to acquire a specific ledger.
Consensus< Adaptor > consensus_
std::optional< std::chrono::milliseconds > getValidationDelay() const
Amount of time delayed waiting to confirm validation.
void setValidationDelay(std::optional< std::chrono::milliseconds > vd=std::nullopt)
Set amount of time that has been delayed waiting for validation.
bool preStartRound(RCLCxLedger const &prevLedger, hash_set< NodeID > const &nowTrusted)
Called before kicking off a new consensus round.
bool hasOpenTransactions() const
Whether the open ledger has any transactions.
RCLConsensus(Application &app, std::unique_ptr< FeeVote > &&feeVote, LedgerMaster &ledgerMaster, LocalTxs &localTxs, InboundTransactions &inboundTransactions, Consensus< Adaptor >::clock_type &clock, ValidatorKeys const &validatorKeys, beast::Journal journal)
Constructor.
Generic implementation of consensus algorithm.
void gotTxSet(NetClock::time_point const &now, RCLTxSet const &txSet)
uint256 getPrevLedger(uint256 ledgerID, RCLCxLedger const &ledger, ConsensusMode mode)
Get the ID of the previous ledger/last closed ledger(LCL) on the network.
void onAccept(Result const &result, ConsensusCloseTimes const &rawCloseTimes, ConsensusMode const &mode, Json::Value &&consensusJson, std::pair< CanonicalTxSet_t, Ledger_t > &&txsBuilt)
Process the accepted ledger.
void timerEntry(NetClock::time_point const &now)
NegativeUNLVote nUnlVote_
std::optional< std::chrono::milliseconds > validationDelay_
Encapsulates the result of consensus.
ConsensusParms const & parms() const
Consensus simulation parameters.
Validator keys and manifest as set in configuration file.
std::size_t quorum() const
Holds transactions which were deferred to the next pass of consensus.
void simulate(NetClock::time_point const &now, std::optional< std::chrono::milliseconds > consensusDelay)
@ observing
We are observing peer positions, but not proposing our position.
std::optional< std::chrono::milliseconds > getTimerDelay() const
void updateOperatingMode(std::size_t const positions) const
Update operating mode based on current peer positions.
Manages the generic consensus algorithm for use by the RCL.
std::optional< std::chrono::milliseconds > timerDelay_
bool haveValidated() const
std::size_t prevProposers() const
std::size_t laggards(Ledger_t::Seq const seq, hash_set< NodeKey_t > &trustedKeys) const
void share(RCLCxPeerPos const &peerPos)
Share the given proposal with all peers.
Result onClose(RCLCxLedger const &ledger, NetClock::time_point const &closeTime, ConsensusMode mode, clock_type &clock)
Close the open ledger and return initial consensus position.
std::pair< CanonicalTxSet_t, Ledger_t > buildAndValidate(Result const &result, Ledger_t const &prevLedger, NetClock::duration const &closeResolution, ConsensusMode const &mode, Json::Value &&consensusJson)
Build and attempt to validate a new ledger.
bool peerProposal(NetClock::time_point const &now, RCLCxPeerPos const &newProposal)
Represents a set of transactions in RCLConsensus.
void validate(RCLCxLedger const &ledger, RCLTxSet const &txns, bool proposing)
Validate the given ledger and share with peers as necessary.
ConsensusMode mode() const
LedgerMaster & getLedgerMaster() const
ConsensusPhase
Phases of consensus for a single ledger round.
Adaptor(Application &app, std::unique_ptr< FeeVote > &&feeVote, LedgerMaster &ledgerMaster, LocalTxs &localTxs, InboundTransactions &inboundTransactions, ValidatorKeys const &validatorKeys, beast::Journal journal)
ConsensusMode mode() const
A generic endpoint for log messages.
RCLCensorshipDetector< TxID, LedgerIndex > censorshipDetector_
void notify(protocol::NodeEvent ne, RCLCxLedger const &ledger, bool haveCorrectLCL)
Notify peers of a consensus state change.
bool validator() const
Whether I am a validator.
ConsensusParms const & parms() const
std::optional< RCLTxSet > acquireTxSet(RCLTxSet::ID const &setId)
Acquire the transaction set associated with a proposal.
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.
constexpr static unsigned int censorshipWarnInternal
Warn for transactions that haven't been included every so many ledgers.
void onModeChange(ConsensusMode before, ConsensusMode after)
Notified of change in consensus mode.
Represents a ledger in RCLConsensus.
RCLConsensus & operator=(RCLConsensus const &)=delete
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::chrono::milliseconds prevRoundTime() const
Get duration of the previous round.
ConsensusMode
Represents how a node currently participates in Consensus.
LedgerIndex getValidLedgerIndex() const
Consensus algorithm parameters.
std::recursive_mutex & peekMutex() const
LedgerHash acquiringLedger_
bool retryAccept(Ledger_t const &newLedger, std::optional< std::chrono::time_point< std::chrono::steady_clock >> &start) const
Whether to try building another ledger to validate.
std::atomic< bool > validating_
std::size_t prevProposers() const
Get the number of proposing peers that participated in the previous round.
LedgerMaster & ledgerMaster_
std::size_t proposersValidated(LedgerHash const &h) const
Number of proposers that have validated the given ledger.
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
void prepareOpenLedger(std::pair< CanonicalTxSet_t, Ledger_t > &&txsBuilt, Result const &result, ConsensusCloseTimes const &rawCloseTimes, ConsensusMode const &mode)
Prepare the next open ledger.
Manager to create NegativeUNL votes.
InboundTransactions & inboundTransactions_
bool validating() const
Whether we are validating consensus ledgers.
std::optional< std::chrono::milliseconds > getTimerDelay() const
Amount of time to wait for heartbeat.
Represents a transaction in RCLConsensus.
void setTimerDelay(std::optional< std::chrono::milliseconds > td=std::nullopt)
Set amount of time to wait for next heartbeat.
void propose(RCLCxPeerPos::Proposal const &proposal)
Propose the given position to my peers.
NetClock::time_point lastValidationTime_
std::size_t proposersFinished(RCLCxLedger const &ledger, LedgerHash const &h) const
Number of proposers that have validated a ledger descended from requested ledger.
beast::abstract_clock< std::chrono::steady_clock > Stopwatch
A clock for measuring elapsed time.
std::atomic< std::size_t > prevProposers_
ValidatorKeys const & validatorKeys_
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::pair< std::size_t, hash_set< NodeKey_t > > getQuorumKeys() const
Stores the set of initial close times.
Manages the acquisition and lifetime of transaction sets.