2#include <test/jtx/Env.h>
4#include <xrpld/app/consensus/RCLValidations.h>
5#include <xrpld/core/Config.h>
7#include <xrpl/basics/base_uint.h>
8#include <xrpl/basics/chrono.h>
9#include <xrpl/beast/unit_test/suite.h>
10#include <xrpl/consensus/LedgerTrie.h>
11#include <xrpl/ledger/Ledger.h>
12#include <xrpl/protocol/Indexes.h>
13#include <xrpl/protocol/KeyType.h>
14#include <xrpl/protocol/PublicKey.h>
15#include <xrpl/protocol/SField.h>
16#include <xrpl/protocol/STValidation.h>
17#include <xrpl/protocol/SecretKey.h>
29 testcase(
"Change validation trusted status");
36 [&](
STValidation& v) { v.setFieldU32(sfLedgerSequence, 123456); });
38 BEAST_EXPECT(v->isTrusted());
40 BEAST_EXPECT(!v->isTrusted());
53 testcase(
"RCLValidatedLedger ancestry");
61 Seq const maxAncestors = 256;
76 env.
app().getNodeFamily());
78 for (
auto i = 0; i < ((2 * maxAncestors) + 1); ++i)
82 next->updateSkipList();
88 Seq const diverge = history.
size() / 2;
92 using namespace std::chrono_literals;
94 prev = altHistory.
back();
95 bool forceHash =
true;
96 while (altHistory.
size() < history.
size())
101 next->updateSkipList();
105 BEAST_EXPECT(next->setImmutable());
118 BEAST_EXPECT(a.
seq() ==
Seq{0});
119 BEAST_EXPECT(a[
Seq{0}] == ID{0});
127 BEAST_EXPECT(a.
seq() == ledger->header().seq);
128 BEAST_EXPECT(a.
minSeq() == a.
seq() - maxAncestors);
130 for (
Seq s = a.
seq(); s > 0; s--)
134 BEAST_EXPECT(a[s] == history[s - 1]->header().hash);
138 BEAST_EXPECT(a[s] == ID{0});
149 for (
auto const& ledger : {history.
back(), history[maxAncestors - 1]})
159 for (
Seq s = a.
seq(); s > 0; s--)
177 for (
Seq s = 1; s < history.
size(); ++s)
182 BEAST_EXPECT(a.
seq() == b.
seq());
185 BEAST_EXPECT(a[a.
seq()] == b[b.
seq()]);
191 BEAST_EXPECT(a[a.
seq()] != b[b.
seq()]);
192 BEAST_EXPECT(
mismatch(a, b) == diverge + 1);
193 BEAST_EXPECT(
mismatch(b, a) == diverge + 1);
201 for (
Seq offset = diverge / 2; offset < 3 * diverge / 2; ++offset)
204 if (offset <= diverge)
210 BEAST_EXPECT(
mismatch(a, b) == diverge + 1);
219 testcase(
"RCLValidatedLedger LedgerTrie");
232 Seq const maxAncestors = 256;
244 env.
app().getNodeFamily());
246 for (
auto i = 0; i < (maxAncestors + 10); ++i)
250 next->updateSkipList();
276 BEAST_EXPECT(trie.
remove(ledg258, 3));
278 [[maybe_unused]]
auto const unused1 = trie.
getPreferred(1);
302 [[maybe_unused]]
auto const unused2 = trie.
getPreferred(1);
TestcaseT testcase
Memberspace for declaring test cases.
std::unordered_set< UInt256, beast::Uhash<> > features
Ancestry trie of ledgers.
std::uint32_t tipSupport(Ledger const &ledger) const
Return count of tip support for the specific ledger.
std::uint32_t branchSupport(Ledger const &ledger) const
Return the count of branch support for the specific ledger.
std::optional< SpanTip< Ledger > > getPreferred(Seq const largestIssued) const
Return the preferred ledger ID.
void insert(Ledger const &ledger, std::uint32_t count=1)
Insert and/or increment the support for the given ledger.
bool remove(Ledger const &ledger, std::uint32_t count=1)
Decrease support for a ledger, removing and compressing if possible.
std::chrono::time_point< NetClock > time_point
Wraps a ledger instance for use in generic Validations LedgerTrie.
Seq seq() const
The sequence (index) of the ledger.
Wrapper over STValidation for generic Validation code.
bool trusted() const
Whether the validation is considered trusted.
Rules controlling protocol behavior.
virtual TimeKeeper & getTimeKeeper()=0
time_point closeTime() const
Returns the predicted close time, in network time.
time_point now() const override
Returns the current time.
void run() override
Runs the suite.
void testLedgerTrieRCLValidatedLedger()
void testRCLValidatedLedger()
A transaction testing environment.
ManualTimeKeeper & timeKeeper()
beast::Journal const journal
Keylet const & feeSettings() noexcept
The (fixed) index of the object containing the ledger fees.
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
CreateGenesisT const kCreateGenesis
NodeID calcNodeID(PublicKey const &)
Calculate the 160-bit node ID from a node public key.
Validations< RCLValidationsAdaptor > RCLValidations
Alias for RCL-specific instantiation of generic Validations.
RCLValidatedLedger::Seq mismatch(RCLValidatedLedger const &a, RCLValidatedLedger const &b)
Fees toFees() const
Convert to a Fees object for use with Ledger construction.
Set the sequence number on a JTx.