1#include <xrpl/consensus/LedgerTrie.h>
3#include <csf/ledgers.h>
4#include <gtest/gtest.h>
12TEST(LedgerTrieTest, insert)
18 LedgerHistoryHelper h;
32 LedgerHistoryHelper h;
56 LedgerHistoryHelper h;
82 LedgerHistoryHelper h;
100 LedgerHistoryHelper h;
121 LedgerHistoryHelper h;
144 LedgerHistoryHelper h;
147 EXPECT_TRUE(!t.
remove(h[
"ab"]));
149 EXPECT_TRUE(!t.
remove(h[
"a"]));
155 LedgerHistoryHelper h;
161 EXPECT_TRUE(!t.
remove(h[
"abc"]));
169 LedgerHistoryHelper h;
173 EXPECT_TRUE(t.
remove(h[
"abc"]));
179 EXPECT_TRUE(t.
remove(h[
"abc"], 2));
185 EXPECT_TRUE(t.
remove(h[
"abc"], 300));
192 LedgerHistoryHelper h;
201 EXPECT_TRUE(t.
remove(h[
"abc"]));
211 LedgerHistoryHelper h;
221 EXPECT_TRUE(t.
remove(h[
"abc"]));
231 LedgerHistoryHelper h;
240 EXPECT_TRUE(t.
remove(h[
"abc"]));
249 LedgerHistoryHelper h;
273 LedgerHistoryHelper h;
274 EXPECT_TRUE(t.
empty());
276 Ledger const genesis = h[
""];
278 EXPECT_TRUE(!t.
empty());
280 EXPECT_TRUE(t.
empty());
283 EXPECT_TRUE(!t.
empty());
285 EXPECT_TRUE(t.
empty());
293 LedgerHistoryHelper h;
334TEST(LedgerTrieTest, get_preferred)
337 using Seq = Ledger::Seq;
347 LedgerHistoryHelper h;
348 Ledger const genesis = h[
""];
353 EXPECT_TRUE(t.
remove(genesis));
355 EXPECT_TRUE(!t.
remove(genesis));
360 LedgerHistoryHelper h;
369 LedgerHistoryHelper h;
382 LedgerHistoryHelper h;
395 LedgerHistoryHelper h;
413 LedgerHistoryHelper h;
431 LedgerHistoryHelper h;
435 EXPECT_TRUE(h[
"abce"].
id() > h[
"abcd"].
id());
441 EXPECT_TRUE(h[
"abce"].
id() > h[
"abcd"].
id());
450 LedgerHistoryHelper h;
455 EXPECT_TRUE(h[
"abce"].
id() > h[
"abcd"].
id());
473 LedgerHistoryHelper h;
488 LedgerHistoryHelper h;
527 LedgerHistoryHelper h;
615TEST(LedgerTrieTest, root_related)
622 LedgerHistoryHelper h;
623 EXPECT_TRUE(!t.
remove(h[
""]));
637 EXPECT_TRUE(t.
remove(h[
"e"]));
647 LedgerHistoryHelper h;
669 char const depth = depthDist(gen);
671 for (
char d = 0; d < depth; ++d)
673 char const a = offset + widthDist(gen);
675 offset = (a + 1) * width;
Ancestry trie of ledgers.
std::uint32_t tipSupport(Ledger const &ledger) const
Return count of tip support for the specific ledger.
bool empty() const
Return whether the trie is tracking any ledgers.
bool checkInvariants() const
Check the compressed trie and support invariants.
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.
Set the sequence number on a JTx.