xrpld
Loading...
Searching...
No Matches
xrpl::test::csf::Peer Struct Reference

A single peer in the simulation. More...

#include <Peer.h>

Collaboration diagram for xrpl::test::csf::Peer:

Classes

class  Position
 Basic wrapper of a proposed position taken by a peer. More...
struct  ProcessingDelays
 Simulated delays in internal peer processing. More...
class  TestConsensusLogger
class  ValAdaptor
 Generic Validations adaptor that simply ignores recently stale validations. More...
struct  BroadcastMesg
struct  Router

Public Types

using Ledger_t = Ledger
 Type definitions for generic consensus.
using NodeID_t = PeerID
using NodeKey_t = PeerKey
using TxSet_t = TxSet
using PeerPosition_t = Position
using Result = ConsensusResult<Peer>
using NodeKey = Validation::NodeKey

Public Member Functions

 Peer (PeerID i, Scheduler &s, LedgerOracle &o, BasicNetwork< Peer * > &n, TrustGraph< Peer * > &tg, CollectorRefs &c, beast::Journal jIn)
 Constructor.
template<class T>
void schedule (std::chrono::nanoseconds when, T &&what)
 Schedule the provided callback in when duration, but if when is 0, call immediately.
template<class E>
void issue (E const &event)
void trust (Peer &o)
void untrust (Peer &o)
bool trusts (Peer &o)
bool trusts (PeerID const &oId)
bool connect (Peer &o, SimDuration dur)
 Create network connection.
bool disconnect (Peer &o)
 Remove a network connection.
Ledger const * acquireLedger (Ledger::ID const &ledgerID)
TxSet const * acquireTxSet (TxSet::ID const &setId)
bool hasOpenTransactions () const
std::size_t proposersValidated (Ledger::ID const &prevLedger)
std::size_t proposersFinished (Ledger const &prevLedger, Ledger::ID const &prevLedgerID)
Result onClose (Ledger const &prevLedger, NetClock::time_point closeTime, ConsensusMode mode)
void onForceAccept (Result const &result, Ledger const &prevLedger, NetClock::duration const &closeResolution, ConsensusCloseTimes const &rawCloseTimes, ConsensusMode const &mode, json::Value const &consensusJson)
void onAccept (Result const &result, Ledger const &prevLedger, NetClock::duration const &closeResolution, ConsensusCloseTimes const &rawCloseTimes, ConsensusMode const &mode, json::Value const &consensusJson, bool const validating)
Ledger::Seq earliestAllowedSeq () const
Ledger::ID getPrevLedger (Ledger::ID const &ledgerID, Ledger const &ledger, ConsensusMode mode)
void propose (Proposal const &pos)
ConsensusParms const & parms () const
void onModeChange (ConsensusMode, ConsensusMode)
template<class M>
void share (M const &m)
void share (Position const &p)
bool addTrustedValidation (Validation v)
 Add a trusted validation and return true if it is worth forwarding.
void checkFullyValidated (Ledger const &ledger)
 Check if a new ledger can be deemed fully validated.
template<class M>
void send (BroadcastMesg< M > const &bm, PeerID from)
template<class M>
void receive (BroadcastMesg< M > const &bm, PeerID from)
bool handle (Proposal const &p)
bool handle (TxSet const &txs)
bool handle (Tx const &tx)
bool handle (Validation const &v)
bool haveValidated () const
Ledger::Seq getValidLedgerIndex () const
std::pair< std::size_t, hash_set< NodeKey_t > > getQuorumKeys ()
std::size_t laggards (Ledger::Seq const seq, hash_set< NodeKey_t > &trusted)
bool validator () const
void updateOperatingMode (std::size_t const positions) const
void submit (Tx const &tx)
void timerEntry ()
 Heartbeat timer call.
void startRound ()
void start ()
NetClock::time_point now () const
Ledger::ID prevLedgerID () const
TxSet injectTxs (Ledger prevLedger, TxSet const &src)
 Inject non-consensus Tx.

Static Public Member Functions

static bool validating ()

Public Attributes

beast::WrappedSink sink
 Logging support that prefixes messages with the peer ID.
beast::Journal j
Consensus< Peerconsensus
 Generic consensus.
PeerID id
 Our unique ID.
PeerKey key
 Current signing key.
LedgerOracleoracle
 The oracle that manages unique ledgers.
Schedulerscheduler
 Scheduler of events.
BasicNetwork< Peer * > & net
 Handle to network for sending messages.
TrustGraph< Peer * > & trustGraph
 Handle to Trust graph of network.
TxSetType openTxs
 openTxs that haven't been closed in a ledger yet
Ledger lastClosedLedger
 The last ledger closed by this node.
hash_map< Ledger::ID, Ledgerledgers
 Ledgers this node has closed or loaded from the network.
Validations< ValAdaptorvalidations
 Validations from trusted nodes.
Ledger fullyValidatedLedger
 The most recent ledger that has been fully validated by the network from the perspective of this Peer.
bc::flat_map< Ledger::ID, std::vector< Proposal > > peerPositions
 Map from Ledger::ID to vector of Positions with that ledger as the prior ledger.
bc::flat_map< TxSet::ID, TxSettxSets
 TxSet associated with a TxSet::ID.
bc::flat_map< Ledger::ID, SimTimeacquiringLedgers
bc::flat_map< TxSet::ID, SimTimeacquiringTxSets
int completedLedgers = 0
 The number of ledgers this peer has completed.
int targetLedgers = std::numeric_limits<int>::max()
 The number of ledgers this peer should complete before stopping to run.
std::chrono::seconds clockSkew {0}
 Skew of time relative to the common scheduler clock.
ProcessingDelays delays
 Simulated delays to use for internal processing.
bool runAsValidator = true
 Whether to simulate running as validator or a tracking node.
std::size_t prevProposers = 0
std::chrono::milliseconds prevRoundTime {}
std::size_t quorum = 0
hash_set< NodeKey_ttrustedKeys
ConsensusParms consensusParms
CollectorRefscollectors
 The collectors to report events to.
Router router
hash_map< Ledger::Seq, TxtxInjections

Detailed Description

A single peer in the simulation.

This is the main work-horse of the consensus simulation framework and is where many other components are integrated. The peer

  • Implements the Callbacks required by Consensus
  • Manages trust & network connections with other peers
  • Issues events back to the simulation based on its actions for analysis by Collectors
  • Exposes most internal state for forcibly simulating arbitrary scenarios

Definition at line 56 of file tests/libxrpl/csf/Peer.h.

Member Typedef Documentation

◆ Ledger_t

Type definitions for generic consensus.

Definition at line 178 of file tests/libxrpl/csf/Peer.h.

◆ NodeID_t

◆ NodeKey_t

◆ TxSet_t

◆ PeerPosition_t

◆ Result

◆ NodeKey

Constructor & Destructor Documentation

◆ Peer()

xrpl::test::csf::Peer::Peer ( PeerID i,
Scheduler & s,
LedgerOracle & o,
BasicNetwork< Peer * > & n,
TrustGraph< Peer * > & tg,
CollectorRefs & c,
beast::Journal jIn )

Constructor.

Parameters
iUnique PeerID
sSimulation Scheduler
oSimulation Oracle
nSimulation network
tgSimulation trust graph
cSimulation collectors
jInSimulation journal

Definition at line 327 of file tests/libxrpl/csf/Peer.h.

Member Function Documentation

◆ schedule()

template<class T>
void xrpl::test::csf::Peer::schedule ( std::chrono::nanoseconds when,
T && what )

Schedule the provided callback in when duration, but if when is 0, call immediately.

Definition at line 362 of file tests/libxrpl/csf/Peer.h.

◆ issue()

template<class E>
void xrpl::test::csf::Peer::issue ( E const & event)

Definition at line 379 of file tests/libxrpl/csf/Peer.h.

◆ trust()

void xrpl::test::csf::Peer::trust ( Peer & o)

Definition at line 392 of file tests/libxrpl/csf/Peer.h.

◆ untrust()

void xrpl::test::csf::Peer::untrust ( Peer & o)

Definition at line 399 of file tests/libxrpl/csf/Peer.h.

◆ trusts() [1/2]

bool xrpl::test::csf::Peer::trusts ( Peer & o)

Definition at line 406 of file tests/libxrpl/csf/Peer.h.

◆ trusts() [2/2]

bool xrpl::test::csf::Peer::trusts ( PeerID const & oId)

Definition at line 413 of file tests/libxrpl/csf/Peer.h.

◆ connect()

bool xrpl::test::csf::Peer::connect ( Peer & o,
SimDuration dur )

Create network connection.

Creates a new outbound connection to another Peer if none exists

Parameters
oThe peer with the inbound connection
durThe fixed delay for messages between the two Peers
Returns
Whether the connection was created.

Definition at line 430 of file tests/libxrpl/csf/Peer.h.

◆ disconnect()

bool xrpl::test::csf::Peer::disconnect ( Peer & o)

Remove a network connection.

Removes a connection between peers if one exists

Parameters
oThe peer we disconnect from
Returns
Whether the connection was removed

Definition at line 444 of file tests/libxrpl/csf/Peer.h.

◆ acquireLedger()

Ledger const * xrpl::test::csf::Peer::acquireLedger ( Ledger::ID const & ledgerID)

Definition at line 454 of file tests/libxrpl/csf/Peer.h.

◆ acquireTxSet()

TxSet const * xrpl::test::csf::Peer::acquireTxSet ( TxSet::ID const & setId)

Definition at line 499 of file tests/libxrpl/csf/Peer.h.

◆ hasOpenTransactions()

bool xrpl::test::csf::Peer::hasOpenTransactions ( ) const

Definition at line 542 of file tests/libxrpl/csf/Peer.h.

◆ proposersValidated()

std::size_t xrpl::test::csf::Peer::proposersValidated ( Ledger::ID const & prevLedger)

Definition at line 548 of file tests/libxrpl/csf/Peer.h.

◆ proposersFinished()

std::size_t xrpl::test::csf::Peer::proposersFinished ( Ledger const & prevLedger,
Ledger::ID const & prevLedgerID )

Definition at line 554 of file tests/libxrpl/csf/Peer.h.

◆ onClose()

Result xrpl::test::csf::Peer::onClose ( Ledger const & prevLedger,
NetClock::time_point closeTime,
ConsensusMode mode )

Definition at line 560 of file tests/libxrpl/csf/Peer.h.

◆ onForceAccept()

void xrpl::test::csf::Peer::onForceAccept ( Result const & result,
Ledger const & prevLedger,
NetClock::duration const & closeResolution,
ConsensusCloseTimes const & rawCloseTimes,
ConsensusMode const & mode,
json::Value const & consensusJson )

Definition at line 571 of file tests/libxrpl/csf/Peer.h.

◆ onAccept()

void xrpl::test::csf::Peer::onAccept ( Result const & result,
Ledger const & prevLedger,
NetClock::duration const & closeResolution,
ConsensusCloseTimes const & rawCloseTimes,
ConsensusMode const & mode,
json::Value const & consensusJson,
bool const validating )

Definition at line 584 of file tests/libxrpl/csf/Peer.h.

◆ earliestAllowedSeq()

Ledger::Seq xrpl::test::csf::Peer::earliestAllowedSeq ( ) const

Definition at line 646 of file tests/libxrpl/csf/Peer.h.

◆ getPrevLedger()

Ledger::ID xrpl::test::csf::Peer::getPrevLedger ( Ledger::ID const & ledgerID,
Ledger const & ledger,
ConsensusMode mode )

Definition at line 652 of file tests/libxrpl/csf/Peer.h.

◆ propose()

void xrpl::test::csf::Peer::propose ( Proposal const & pos)

Definition at line 670 of file tests/libxrpl/csf/Peer.h.

◆ parms()

ConsensusParms const & xrpl::test::csf::Peer::parms ( ) const

Definition at line 676 of file tests/libxrpl/csf/Peer.h.

◆ onModeChange()

void xrpl::test::csf::Peer::onModeChange ( ConsensusMode ,
ConsensusMode  )

Definition at line 683 of file tests/libxrpl/csf/Peer.h.

◆ share() [1/2]

template<class M>
void xrpl::test::csf::Peer::share ( M const & m)

Definition at line 690 of file tests/libxrpl/csf/Peer.h.

◆ share() [2/2]

void xrpl::test::csf::Peer::share ( Position const & p)

Definition at line 698 of file tests/libxrpl/csf/Peer.h.

◆ addTrustedValidation()

bool xrpl::test::csf::Peer::addTrustedValidation ( Validation v)

Add a trusted validation and return true if it is worth forwarding.

Definition at line 710 of file tests/libxrpl/csf/Peer.h.

◆ checkFullyValidated()

void xrpl::test::csf::Peer::checkFullyValidated ( Ledger const & ledger)

Check if a new ledger can be deemed fully validated.

Definition at line 729 of file tests/libxrpl/csf/Peer.h.

◆ send()

template<class M>
void xrpl::test::csf::Peer::send ( BroadcastMesg< M > const & bm,
PeerID from )

Definition at line 782 of file tests/libxrpl/csf/Peer.h.

◆ receive()

template<class M>
void xrpl::test::csf::Peer::receive ( BroadcastMesg< M > const & bm,
PeerID from )

Definition at line 804 of file tests/libxrpl/csf/Peer.h.

◆ handle() [1/4]

bool xrpl::test::csf::Peer::handle ( Proposal const & p)

Definition at line 820 of file tests/libxrpl/csf/Peer.h.

◆ handle() [2/4]

bool xrpl::test::csf::Peer::handle ( TxSet const & txs)

Definition at line 839 of file tests/libxrpl/csf/Peer.h.

◆ handle() [3/4]

bool xrpl::test::csf::Peer::handle ( Tx const & tx)

Definition at line 849 of file tests/libxrpl/csf/Peer.h.

◆ handle() [4/4]

bool xrpl::test::csf::Peer::handle ( Validation const & v)

Definition at line 861 of file tests/libxrpl/csf/Peer.h.

◆ haveValidated()

bool xrpl::test::csf::Peer::haveValidated ( ) const

Definition at line 872 of file tests/libxrpl/csf/Peer.h.

◆ getValidLedgerIndex()

Ledger::Seq xrpl::test::csf::Peer::getValidLedgerIndex ( ) const

Definition at line 878 of file tests/libxrpl/csf/Peer.h.

◆ getQuorumKeys()

std::pair< std::size_t, hash_set< NodeKey_t > > xrpl::test::csf::Peer::getQuorumKeys ( )

Definition at line 884 of file tests/libxrpl/csf/Peer.h.

◆ laggards()

std::size_t xrpl::test::csf::Peer::laggards ( Ledger::Seq const seq,
hash_set< NodeKey_t > & trusted )

Definition at line 893 of file tests/libxrpl/csf/Peer.h.

◆ validator()

bool xrpl::test::csf::Peer::validator ( ) const

Definition at line 899 of file tests/libxrpl/csf/Peer.h.

◆ updateOperatingMode()

void xrpl::test::csf::Peer::updateOperatingMode ( std::size_t const positions) const

Definition at line 905 of file tests/libxrpl/csf/Peer.h.

◆ validating()

bool xrpl::test::csf::Peer::validating ( )
static

Definition at line 910 of file tests/libxrpl/csf/Peer.h.

◆ submit()

void xrpl::test::csf::Peer::submit ( Tx const & tx)

Definition at line 919 of file tests/libxrpl/csf/Peer.h.

◆ timerEntry()

void xrpl::test::csf::Peer::timerEntry ( )

Heartbeat timer call.

Definition at line 933 of file tests/libxrpl/csf/Peer.h.

◆ startRound()

void xrpl::test::csf::Peer::startRound ( )

Definition at line 943 of file tests/libxrpl/csf/Peer.h.

◆ start()

void xrpl::test::csf::Peer::start ( )

Definition at line 962 of file tests/libxrpl/csf/Peer.h.

◆ now()

NetClock::time_point xrpl::test::csf::Peer::now ( ) const

Definition at line 971 of file tests/libxrpl/csf/Peer.h.

◆ prevLedgerID()

Ledger::ID xrpl::test::csf::Peer::prevLedgerID ( ) const

Definition at line 985 of file tests/libxrpl/csf/Peer.h.

◆ injectTxs()

TxSet xrpl::test::csf::Peer::injectTxs ( Ledger prevLedger,
TxSet const & src )

Inject non-consensus Tx.

Injects a transactionsinto the ledger following prevLedger's sequence number.

Parameters
prevLedgerThe ledger we are building the new ledger on top of
srcThe Consensus TxSet
Returns
Consensus TxSet with inject transactions added if prevLedger.seq matches a previously registered Tx.

Definition at line 1010 of file tests/libxrpl/csf/Peer.h.

Member Data Documentation

◆ sink

beast::WrappedSink xrpl::test::csf::Peer::sink

Logging support that prefixes messages with the peer ID.

Definition at line 189 of file tests/libxrpl/csf/Peer.h.

◆ j

beast::Journal xrpl::test::csf::Peer::j

Definition at line 190 of file tests/libxrpl/csf/Peer.h.

◆ consensus

Consensus<Peer> xrpl::test::csf::Peer::consensus

Generic consensus.

Definition at line 195 of file tests/libxrpl/csf/Peer.h.

◆ id

PeerID xrpl::test::csf::Peer::id

Our unique ID.

Definition at line 200 of file tests/libxrpl/csf/Peer.h.

◆ key

PeerKey xrpl::test::csf::Peer::key

Current signing key.

Definition at line 205 of file tests/libxrpl/csf/Peer.h.

◆ oracle

LedgerOracle& xrpl::test::csf::Peer::oracle

The oracle that manages unique ledgers.

Definition at line 210 of file tests/libxrpl/csf/Peer.h.

◆ scheduler

Scheduler& xrpl::test::csf::Peer::scheduler

Scheduler of events.

Definition at line 215 of file tests/libxrpl/csf/Peer.h.

◆ net

BasicNetwork<Peer*>& xrpl::test::csf::Peer::net

Handle to network for sending messages.

Definition at line 220 of file tests/libxrpl/csf/Peer.h.

◆ trustGraph

TrustGraph<Peer*>& xrpl::test::csf::Peer::trustGraph

Handle to Trust graph of network.

Definition at line 225 of file tests/libxrpl/csf/Peer.h.

◆ openTxs

TxSetType xrpl::test::csf::Peer::openTxs

openTxs that haven't been closed in a ledger yet

Definition at line 230 of file tests/libxrpl/csf/Peer.h.

◆ lastClosedLedger

Ledger xrpl::test::csf::Peer::lastClosedLedger

The last ledger closed by this node.

Definition at line 235 of file tests/libxrpl/csf/Peer.h.

◆ ledgers

hash_map<Ledger::ID, Ledger> xrpl::test::csf::Peer::ledgers

Ledgers this node has closed or loaded from the network.

Definition at line 240 of file tests/libxrpl/csf/Peer.h.

◆ validations

Validations<ValAdaptor> xrpl::test::csf::Peer::validations

Validations from trusted nodes.

Definition at line 245 of file tests/libxrpl/csf/Peer.h.

◆ fullyValidatedLedger

Ledger xrpl::test::csf::Peer::fullyValidatedLedger

The most recent ledger that has been fully validated by the network from the perspective of this Peer.

Definition at line 251 of file tests/libxrpl/csf/Peer.h.

◆ peerPositions

bc::flat_map<Ledger::ID, std::vector<Proposal> > xrpl::test::csf::Peer::peerPositions

Map from Ledger::ID to vector of Positions with that ledger as the prior ledger.

Definition at line 261 of file tests/libxrpl/csf/Peer.h.

◆ txSets

bc::flat_map<TxSet::ID, TxSet> xrpl::test::csf::Peer::txSets

TxSet associated with a TxSet::ID.

Definition at line 265 of file tests/libxrpl/csf/Peer.h.

◆ acquiringLedgers

bc::flat_map<Ledger::ID, SimTime> xrpl::test::csf::Peer::acquiringLedgers

Definition at line 268 of file tests/libxrpl/csf/Peer.h.

◆ acquiringTxSets

bc::flat_map<TxSet::ID, SimTime> xrpl::test::csf::Peer::acquiringTxSets

Definition at line 269 of file tests/libxrpl/csf/Peer.h.

◆ completedLedgers

int xrpl::test::csf::Peer::completedLedgers = 0

The number of ledgers this peer has completed.

Definition at line 274 of file tests/libxrpl/csf/Peer.h.

◆ targetLedgers

int xrpl::test::csf::Peer::targetLedgers = std::numeric_limits<int>::max()

The number of ledgers this peer should complete before stopping to run.

Definition at line 279 of file tests/libxrpl/csf/Peer.h.

◆ clockSkew

std::chrono::seconds xrpl::test::csf::Peer::clockSkew {0}

Skew of time relative to the common scheduler clock.

Definition at line 284 of file tests/libxrpl/csf/Peer.h.

◆ delays

ProcessingDelays xrpl::test::csf::Peer::delays

Simulated delays to use for internal processing.

Definition at line 289 of file tests/libxrpl/csf/Peer.h.

◆ runAsValidator

bool xrpl::test::csf::Peer::runAsValidator = true

Whether to simulate running as validator or a tracking node.

Definition at line 294 of file tests/libxrpl/csf/Peer.h.

◆ prevProposers

std::size_t xrpl::test::csf::Peer::prevProposers = 0

Definition at line 298 of file tests/libxrpl/csf/Peer.h.

◆ prevRoundTime

std::chrono::milliseconds xrpl::test::csf::Peer::prevRoundTime {}

Definition at line 300 of file tests/libxrpl/csf/Peer.h.

◆ quorum

std::size_t xrpl::test::csf::Peer::quorum = 0

Definition at line 304 of file tests/libxrpl/csf/Peer.h.

◆ trustedKeys

hash_set<NodeKey_t> xrpl::test::csf::Peer::trustedKeys

Definition at line 306 of file tests/libxrpl/csf/Peer.h.

◆ consensusParms

ConsensusParms xrpl::test::csf::Peer::consensusParms

Definition at line 309 of file tests/libxrpl/csf/Peer.h.

◆ collectors

CollectorRefs& xrpl::test::csf::Peer::collectors

The collectors to report events to.

Definition at line 314 of file tests/libxrpl/csf/Peer.h.

◆ router

Router xrpl::test::csf::Peer::router

Definition at line 777 of file tests/libxrpl/csf/Peer.h.

◆ txInjections

hash_map<Ledger::Seq, Tx> xrpl::test::csf::Peer::txInjections

Definition at line 996 of file tests/libxrpl/csf/Peer.h.