rippled
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ripple::RCLConsensus::Adaptor Class Reference
Collaboration diagram for ripple::RCLConsensus::Adaptor:
Collaboration graph
[legend]

Public Types

using Ledger_t = RCLCxLedger
 
using NodeID_t = NodeID
 
using NodeKey_t = PublicKey
 
using TxSet_t = RCLTxSet
 
using PeerPosition_t = RCLCxPeerPos
 
using Result = ConsensusResult< Adaptor >
 

Public Member Functions

 Adaptor (Application &app, std::unique_ptr< FeeVote > &&feeVote, LedgerMaster &ledgerMaster, LocalTxs &localTxs, InboundTransactions &inboundTransactions, ValidatorKeys const &validatorKeys, beast::Journal journal)
 
bool validating () const
 
std::size_t prevProposers () const
 
std::chrono::milliseconds prevRoundTime () const
 
ConsensusMode mode () const
 
bool preStartRound (RCLCxLedger const &prevLedger, hash_set< NodeID > const &nowTrusted)
 Called before kicking off a new consensus round. More...
 
bool haveValidated () const
 
LedgerIndex getValidLedgerIndex () const
 
std::pair< std::size_t, hash_set< NodeKey_t > > getQuorumKeys () const
 
std::size_t laggards (Ledger_t::Seq const seq, hash_set< NodeKey_t > &trustedKeys) const
 
bool validator () const
 Whether I am a validator. More...
 
void updateOperatingMode (std::size_t const positions) const
 Update operating mode based on current peer positions. More...
 
ConsensusParms const & parms () const
 Consensus simulation parameters. More...
 

Private Member Functions

std::optional< RCLCxLedgeracquireLedger (LedgerHash const &hash)
 Attempt to acquire a specific ledger. More...
 
void share (RCLCxPeerPos const &peerPos)
 Share the given proposal with all peers. More...
 
void share (RCLCxTx const &tx)
 Share disputed transaction to peers. More...
 
std::optional< RCLTxSetacquireTxSet (RCLTxSet::ID const &setId)
 Acquire the transaction set associated with a proposal. More...
 
bool hasOpenTransactions () const
 Whether the open ledger has any transactions. More...
 
std::size_t proposersValidated (LedgerHash const &h) const
 Number of proposers that have validated the given ledger. More...
 
std::size_t proposersFinished (RCLCxLedger const &ledger, LedgerHash const &h) const
 Number of proposers that have validated a ledger descended from requested ledger. More...
 
void propose (RCLCxPeerPos::Proposal const &proposal)
 Propose the given position to my peers. More...
 
void share (RCLTxSet const &txns)
 Share the given tx set to peers. More...
 
uint256 getPrevLedger (uint256 ledgerID, RCLCxLedger const &ledger, ConsensusMode mode)
 Get the ID of the previous ledger/last closed ledger(LCL) on the network. More...
 
void onModeChange (ConsensusMode before, ConsensusMode after)
 Notified of change in consensus mode. More...
 
Result onClose (RCLCxLedger const &ledger, NetClock::time_point const &closeTime, ConsensusMode mode)
 Close the open ledger and return initial consensus position. More...
 
void onAccept (Result const &result, RCLCxLedger const &prevLedger, NetClock::duration const &closeResolution, ConsensusCloseTimes const &rawCloseTimes, ConsensusMode const &mode, Json::Value &&consensusJson)
 Process the accepted ledger. More...
 
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. More...
 
void notify (protocol::NodeEvent ne, RCLCxLedger const &ledger, bool haveCorrectLCL)
 Notify peers of a consensus state change. More...
 
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. More...
 
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. More...
 
void validate (RCLCxLedger const &ledger, RCLTxSet const &txns, bool proposing)
 Validate the given ledger and share with peers as necessary. More...
 

Private Attributes

Applicationapp_
 
std::unique_ptr< FeeVotefeeVote_
 
LedgerMasterledgerMaster_
 
LocalTxslocalTxs_
 
InboundTransactionsinboundTransactions_
 
const beast::Journal j_
 
ValidatorKeys const & validatorKeys_
 
const std::uint64_t valCookie_
 
LedgerHash acquiringLedger_
 
ConsensusParms parms_
 
NetClock::time_point lastValidationTime_
 
std::atomic< bool > validating_ {false}
 
std::atomic< std::size_tprevProposers_ {0}
 
std::atomic< std::chrono::millisecondsprevRoundTime_
 
std::atomic< ConsensusModemode_ {ConsensusMode::observing}
 
RCLCensorshipDetector< TxID, LedgerIndexcensorshipDetector_
 
NegativeUNLVote nUnlVote_
 

Friends

class Consensus< Adaptor >
 

Detailed Description

Definition at line 57 of file RCLConsensus.h.

Member Typedef Documentation

◆ Ledger_t

Definition at line 91 of file RCLConsensus.h.

◆ NodeID_t

Definition at line 92 of file RCLConsensus.h.

◆ NodeKey_t

Definition at line 93 of file RCLConsensus.h.

◆ TxSet_t

Definition at line 94 of file RCLConsensus.h.

◆ PeerPosition_t

Definition at line 95 of file RCLConsensus.h.

◆ Result

Definition at line 97 of file RCLConsensus.h.

Constructor & Destructor Documentation

◆ Adaptor()

ripple::RCLConsensus::Adaptor::Adaptor ( Application app,
std::unique_ptr< FeeVote > &&  feeVote,
LedgerMaster ledgerMaster,
LocalTxs localTxs,
InboundTransactions inboundTransactions,
ValidatorKeys const &  validatorKeys,
beast::Journal  journal 
)

Definition at line 74 of file RCLConsensus.cpp.

Member Function Documentation

◆ validating()

bool ripple::RCLConsensus::Adaptor::validating ( ) const

Definition at line 109 of file RCLConsensus.h.

◆ prevProposers()

std::size_t ripple::RCLConsensus::Adaptor::prevProposers ( ) const

Definition at line 115 of file RCLConsensus.h.

◆ prevRoundTime()

std::chrono::milliseconds ripple::RCLConsensus::Adaptor::prevRoundTime ( ) const

Definition at line 121 of file RCLConsensus.h.

◆ mode()

ConsensusMode ripple::RCLConsensus::Adaptor::mode ( ) const

Definition at line 127 of file RCLConsensus.h.

◆ preStartRound()

bool ripple::RCLConsensus::Adaptor::preStartRound ( RCLCxLedger const &  prevLedger,
hash_set< NodeID > const &  nowTrusted 
)

Called before kicking off a new consensus round.

Parameters
prevLedgerLedger that will be prior ledger for next round
nowTrustedthe new validators
Returns
Whether we enter the round proposing

Definition at line 957 of file RCLConsensus.cpp.

◆ haveValidated()

bool ripple::RCLConsensus::Adaptor::haveValidated ( ) const

Definition at line 1008 of file RCLConsensus.cpp.

◆ getValidLedgerIndex()

LedgerIndex ripple::RCLConsensus::Adaptor::getValidLedgerIndex ( ) const

Definition at line 1014 of file RCLConsensus.cpp.

◆ getQuorumKeys()

std::pair< std::size_t, hash_set< RCLConsensus::Adaptor::NodeKey_t > > ripple::RCLConsensus::Adaptor::getQuorumKeys ( ) const

Definition at line 1020 of file RCLConsensus.cpp.

◆ laggards()

std::size_t ripple::RCLConsensus::Adaptor::laggards ( Ledger_t::Seq const  seq,
hash_set< NodeKey_t > &  trustedKeys 
) const

Definition at line 1026 of file RCLConsensus.cpp.

◆ validator()

bool ripple::RCLConsensus::Adaptor::validator ( ) const

Whether I am a validator.

Returns
whether I am a validator.

Definition at line 1034 of file RCLConsensus.cpp.

◆ updateOperatingMode()

void ripple::RCLConsensus::Adaptor::updateOperatingMode ( std::size_t const  positions) const

Update operating mode based on current peer positions.

If our current ledger has no agreement from the network, then we cannot be in the omFULL mode.

Parameters
positionsNumber of current peer positions.

Definition at line 1040 of file RCLConsensus.cpp.

◆ parms()

ConsensusParms const& ripple::RCLConsensus::Adaptor::parms ( ) const

Consensus simulation parameters.

Definition at line 176 of file RCLConsensus.h.

◆ acquireLedger()

std::optional< RCLCxLedger > ripple::RCLConsensus::Adaptor::acquireLedger ( LedgerHash const &  hash)
private

Attempt to acquire a specific ledger.

If not available, asynchronously acquires from the network.

Parameters
hashThe ID/hash of the ledger acquire
Returns
Optional ledger, will be seated if we locally had the ledger

Definition at line 121 of file RCLConsensus.cpp.

◆ share() [1/3]

void ripple::RCLConsensus::Adaptor::share ( RCLCxPeerPos const &  peerPos)
private

Share the given proposal with all peers.

Parameters
peerPosThe peer position to share.

Definition at line 154 of file RCLConsensus.cpp.

◆ share() [2/3]

void ripple::RCLConsensus::Adaptor::share ( RCLCxTx const &  tx)
private

Share disputed transaction to peers.

Only share if the provided transaction hasn't been shared recently.

Parameters
txThe disputed transaction to share.

Definition at line 178 of file RCLConsensus.cpp.

◆ acquireTxSet()

std::optional< RCLTxSet > ripple::RCLConsensus::Adaptor::acquireTxSet ( RCLTxSet::ID const &  setId)
private

Acquire the transaction set associated with a proposal.

If the transaction set is not available locally, will attempt acquire it from the network.

Parameters
setIdThe transaction set ID associated with the proposal
Returns
Optional set of transactions, seated if available.

Definition at line 243 of file RCLConsensus.cpp.

◆ hasOpenTransactions()

bool ripple::RCLConsensus::Adaptor::hasOpenTransactions ( ) const
private

Whether the open ledger has any transactions.

Definition at line 253 of file RCLConsensus.cpp.

◆ proposersValidated()

std::size_t ripple::RCLConsensus::Adaptor::proposersValidated ( LedgerHash const &  h) const
private

Number of proposers that have validated the given ledger.

Parameters
hThe hash of the ledger of interest
Returns
the number of proposers that validated a ledger

Definition at line 259 of file RCLConsensus.cpp.

◆ proposersFinished()

std::size_t ripple::RCLConsensus::Adaptor::proposersFinished ( RCLCxLedger const &  ledger,
LedgerHash const &  h 
) const
private

Number of proposers that have validated a ledger descended from requested ledger.

Parameters
ledgerThe current working ledger
hThe hash of the preferred working ledger
Returns
The number of validating peers that have validated a ledger descended from the preferred working ledger.

Definition at line 265 of file RCLConsensus.cpp.

◆ propose()

void ripple::RCLConsensus::Adaptor::propose ( RCLCxPeerPos::Proposal const &  proposal)
private

Propose the given position to my peers.

Parameters
proposalOur proposed position

Definition at line 199 of file RCLConsensus.cpp.

◆ share() [3/3]

void ripple::RCLConsensus::Adaptor::share ( RCLTxSet const &  txns)
private

Share the given tx set to peers.

Parameters
txnsThe TxSet to share.

Definition at line 237 of file RCLConsensus.cpp.

◆ getPrevLedger()

uint256 ripple::RCLConsensus::Adaptor::getPrevLedger ( uint256  ledgerID,
RCLCxLedger const &  ledger,
ConsensusMode  mode 
)
private

Get the ID of the previous ledger/last closed ledger(LCL) on the network.

Parameters
ledgerIDID of previous ledger used by consensus
ledgerPrevious ledger consensus has available
modeCurrent consensus mode
Returns
The id of the last closed network
Note
ledgerID may not match ledger.id() if we haven't acquired the ledger matching ledgerID from the network

Definition at line 275 of file RCLConsensus.cpp.

◆ onModeChange()

void ripple::RCLConsensus::Adaptor::onModeChange ( ConsensusMode  before,
ConsensusMode  after 
)
private

Notified of change in consensus mode.

Parameters
beforeThe prior consensus mode
afterThe new consensus mode

Definition at line 877 of file RCLConsensus.cpp.

◆ onClose()

auto ripple::RCLConsensus::Adaptor::onClose ( RCLCxLedger const &  ledger,
NetClock::time_point const &  closeTime,
ConsensusMode  mode 
)
private

Close the open ledger and return initial consensus position.

Parameters
ledgerthe ledger we are changing to
closeTimeWhen consensus closed the ledger
modeCurrent consensus mode
Returns
Tentative consensus result

Definition at line 297 of file RCLConsensus.cpp.

◆ onAccept()

void ripple::RCLConsensus::Adaptor::onAccept ( Result const &  result,
RCLCxLedger const &  prevLedger,
NetClock::duration const &  closeResolution,
ConsensusCloseTimes const &  rawCloseTimes,
ConsensusMode const &  mode,
Json::Value &&  consensusJson 
)
private

Process the accepted ledger.

Parameters
resultThe result of consensus
prevLedgerThe closed ledger consensus worked from
closeResolutionThe resolution used in agreeing on an effective closeTime
rawCloseTimesThe unrounded closetimes of ourself and our peers
modeOur participating mode at the time consensus was declared
consensusJsonJson representation of consensus state

Definition at line 413 of file RCLConsensus.cpp.

◆ onForceAccept()

void ripple::RCLConsensus::Adaptor::onForceAccept ( Result const &  result,
RCLCxLedger const &  prevLedger,
NetClock::duration const &  closeResolution,
ConsensusCloseTimes const &  rawCloseTimes,
ConsensusMode const &  mode,
Json::Value &&  consensusJson 
)
private

Process the accepted ledger that was a result of simulation/force accept.

onAccept

Definition at line 395 of file RCLConsensus.cpp.

◆ notify()

void ripple::RCLConsensus::Adaptor::notify ( protocol::NodeEvent  ne,
RCLCxLedger const &  ledger,
bool  haveCorrectLCL 
)
private

Notify peers of a consensus state change.

Parameters
neEvent type for notification
ledgerThe ledger at the time of the state change
haveCorrectLCLWhether we believe we have the correct LCL.

Definition at line 710 of file RCLConsensus.cpp.

◆ doAccept()

void ripple::RCLConsensus::Adaptor::doAccept ( Result const &  result,
RCLCxLedger const &  prevLedger,
NetClock::duration  closeResolution,
ConsensusCloseTimes const &  rawCloseTimes,
ConsensusMode const &  mode,
Json::Value &&  consensusJson 
)
private

Accept a new ledger based on the given transactions.

onAccept

Definition at line 442 of file RCLConsensus.cpp.

◆ buildLCL()

RCLCxLedger ripple::RCLConsensus::Adaptor::buildLCL ( RCLCxLedger const &  previousLedger,
CanonicalTXSet retriableTxs,
NetClock::time_point  closeTime,
bool  closeTimeCorrect,
NetClock::duration  closeResolution,
std::chrono::milliseconds  roundTime,
std::set< TxID > &  failedTxs 
)
private

Build the new last closed ledger.

Accept the given the provided set of consensus transactions and build the last closed ledger. Since consensus just agrees on which transactions to apply, but not whether they make it into the closed ledger, this function also populates retriableTxs with those that can be retried in the next round.

Parameters
previousLedgerPrior ledger building upon
retriableTxsOn entry, the set of transactions to apply to the ledger; on return, the set of transactions to retry in the next round.
closeTimeThe time the ledger closed
closeTimeCorrectWhether consensus agreed on close time
closeResolutionResolution used to determine consensus close time
roundTimeDuration of this consensus round
failedTxsPopulate with transactions that we could not successfully apply.
Returns
The newly built ledger

Definition at line 749 of file RCLConsensus.cpp.

◆ validate()

void ripple::RCLConsensus::Adaptor::validate ( RCLCxLedger const &  ledger,
RCLTxSet const &  txns,
bool  proposing 
)
private

Validate the given ledger and share with peers as necessary.

Parameters
ledgerThe ledger to validate
txnsThe consensus transaction set
proposingWhether we were proposing transactions while generating this ledger. If we are not proposing, a validation can still be sent to inform peers that we know we aren't fully participating in consensus but are still around and trying to catch up.

Definition at line 790 of file RCLConsensus.cpp.

Friends And Related Function Documentation

◆ Consensus< Adaptor >

friend class Consensus< Adaptor >
friend

Definition at line 193 of file RCLConsensus.h.

Member Data Documentation

◆ app_

Application& ripple::RCLConsensus::Adaptor::app_
private

Definition at line 59 of file RCLConsensus.h.

◆ feeVote_

std::unique_ptr<FeeVote> ripple::RCLConsensus::Adaptor::feeVote_
private

Definition at line 60 of file RCLConsensus.h.

◆ ledgerMaster_

LedgerMaster& ripple::RCLConsensus::Adaptor::ledgerMaster_
private

Definition at line 61 of file RCLConsensus.h.

◆ localTxs_

LocalTxs& ripple::RCLConsensus::Adaptor::localTxs_
private

Definition at line 62 of file RCLConsensus.h.

◆ inboundTransactions_

InboundTransactions& ripple::RCLConsensus::Adaptor::inboundTransactions_
private

Definition at line 63 of file RCLConsensus.h.

◆ j_

const beast::Journal ripple::RCLConsensus::Adaptor::j_
private

Definition at line 64 of file RCLConsensus.h.

◆ validatorKeys_

ValidatorKeys const& ripple::RCLConsensus::Adaptor::validatorKeys_
private

Definition at line 67 of file RCLConsensus.h.

◆ valCookie_

const std::uint64_t ripple::RCLConsensus::Adaptor::valCookie_
private

Definition at line 70 of file RCLConsensus.h.

◆ acquiringLedger_

LedgerHash ripple::RCLConsensus::Adaptor::acquiringLedger_
private

Definition at line 73 of file RCLConsensus.h.

◆ parms_

ConsensusParms ripple::RCLConsensus::Adaptor::parms_
private

Definition at line 74 of file RCLConsensus.h.

◆ lastValidationTime_

NetClock::time_point ripple::RCLConsensus::Adaptor::lastValidationTime_
private

Definition at line 77 of file RCLConsensus.h.

◆ validating_

std::atomic<bool> ripple::RCLConsensus::Adaptor::validating_ {false}
private

Definition at line 81 of file RCLConsensus.h.

◆ prevProposers_

std::atomic<std::size_t> ripple::RCLConsensus::Adaptor::prevProposers_ {0}
private

Definition at line 82 of file RCLConsensus.h.

◆ prevRoundTime_

std::atomic<std::chrono::milliseconds> ripple::RCLConsensus::Adaptor::prevRoundTime_
private
Initial value:

Definition at line 83 of file RCLConsensus.h.

◆ mode_

std::atomic<ConsensusMode> ripple::RCLConsensus::Adaptor::mode_ {ConsensusMode::observing}
private

Definition at line 85 of file RCLConsensus.h.

◆ censorshipDetector_

RCLCensorshipDetector<TxID, LedgerIndex> ripple::RCLConsensus::Adaptor::censorshipDetector_
private

Definition at line 87 of file RCLConsensus.h.

◆ nUnlVote_

NegativeUNLVote ripple::RCLConsensus::Adaptor::nUnlVote_
private

Definition at line 88 of file RCLConsensus.h.

std::chrono::milliseconds