mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-31 19:10:25 +00:00
71 lines
1.3 KiB
C++
71 lines
1.3 KiB
C++
#include <csf/Sim.h>
|
|
|
|
#include <csf/PeerGroup.h>
|
|
#include <csf/SimTime.h>
|
|
|
|
#include <algorithm>
|
|
#include <cstddef>
|
|
#include <limits>
|
|
#include <set>
|
|
|
|
namespace xrpl::test::csf {
|
|
|
|
void
|
|
Sim::run(int ledgers)
|
|
{
|
|
for (auto& p : peers_)
|
|
{
|
|
p.targetLedgers = p.completedLedgers + ledgers;
|
|
p.start();
|
|
}
|
|
scheduler.step();
|
|
}
|
|
|
|
void
|
|
Sim::run(SimDuration const& dur)
|
|
{
|
|
for (auto& p : peers_)
|
|
{
|
|
p.targetLedgers = std::numeric_limits<decltype(p.targetLedgers)>::max();
|
|
p.start();
|
|
}
|
|
scheduler.stepFor(dur);
|
|
}
|
|
|
|
bool
|
|
Sim::synchronized() const
|
|
{
|
|
return synchronized(allPeers_);
|
|
}
|
|
|
|
bool
|
|
Sim::synchronized(PeerGroup const& g)
|
|
{
|
|
if (g.size() < 1)
|
|
return true;
|
|
Peer const* ref = g[0];
|
|
return std::ranges::all_of(g, [&ref](Peer const* p) {
|
|
return p->lastClosedLedger.id() == ref->lastClosedLedger.id() &&
|
|
p->fullyValidatedLedger.id() == ref->fullyValidatedLedger.id();
|
|
});
|
|
}
|
|
|
|
std::size_t
|
|
Sim::branches() const
|
|
{
|
|
return branches(allPeers_);
|
|
}
|
|
std::size_t
|
|
Sim::branches(PeerGroup const& g) const
|
|
{
|
|
if (g.size() < 1)
|
|
return 0;
|
|
std::set<Ledger> ledgers;
|
|
for (auto const& peer : g)
|
|
ledgers.insert(peer->fullyValidatedLedger);
|
|
|
|
return oracle.branches(ledgers);
|
|
}
|
|
|
|
} // namespace xrpl::test::csf
|