Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
CassandraBackendFamily.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "data/DBHelpers.hpp"
5#include "data/LedgerCacheInterface.hpp"
6#include "data/LedgerHeaderCache.hpp"
7#include "data/Types.hpp"
8#include "data/cassandra/Concepts.hpp"
9#include "data/cassandra/Handle.hpp"
10#include "data/cassandra/Types.hpp"
11#include "data/cassandra/impl/ExecutionStrategy.hpp"
12#include "util/Assert.hpp"
13#include "util/LedgerUtils.hpp"
14#include "util/Profiler.hpp"
15#include "util/log/Logger.hpp"
16
17#include <boost/asio/spawn.hpp>
18#include <boost/json/object.hpp>
19#include <boost/uuid/string_generator.hpp>
20#include <boost/uuid/uuid.hpp>
21#include <cassandra.h>
22#include <fmt/format.h>
23#include <xrpl/basics/Blob.h>
24#include <xrpl/basics/base_uint.h>
25#include <xrpl/basics/strHex.h>
26#include <xrpl/protocol/AccountID.h>
27#include <xrpl/protocol/Indexes.h>
28#include <xrpl/protocol/LedgerHeader.h>
29#include <xrpl/protocol/nft.h>
30
31#include <algorithm>
32#include <atomic>
33#include <chrono>
34#include <cstddef>
35#include <cstdint>
36#include <iterator>
37#include <limits>
38#include <optional>
39#include <stdexcept>
40#include <string>
41#include <tuple>
42#include <utility>
43#include <vector>
44
48class CacheBackendCassandraTest;
49
50namespace data::cassandra {
51
62template <
63 SomeSettingsProvider SettingsProviderType,
64 SomeExecutionStrategy ExecutionStrategyType,
65 typename SchemaType,
66 typename FetchLedgerCacheType = FetchLedgerCache>
68protected:
69 util::Logger log_{"Backend"};
70
71 SettingsProviderType settingsProvider_;
72 SchemaType schema_;
73 std::atomic_uint32_t ledgerSequence_ = 0u;
74 friend class ::CacheBackendCassandraTest;
75
76 Handle handle_;
77
78 // have to be mutable because BackendInterface constness :(
79 mutable ExecutionStrategyType executor_;
80 // TODO: move to interface level
81 mutable FetchLedgerCacheType ledgerCache_{};
82
83 static constexpr std::size_t kTransactionCursorBindIndex = 1;
84 static constexpr std::size_t kTransactionLimitBindIndex = 2;
85 static constexpr std::size_t kMPTokenIssuanceTxCursorBindIndex = 1;
86 static constexpr std::size_t kMPTokenIssuanceTxLimitBindIndex = 2;
87 static constexpr std::size_t kAccountMPTokenIssuanceTxCursorBindIndex = 2;
88 static constexpr std::size_t kAccountMPTokenIssuanceTxLimitBindIndex = 3;
89
90public:
99 SettingsProviderType settingsProvider,
101 bool readOnly
102 )
104 , settingsProvider_{std::move(settingsProvider)}
105 , schema_{settingsProvider_}
106 , handle_{settingsProvider_.getSettings()}
107 , executor_{settingsProvider_.getSettings(), handle_}
108 {
109 if (auto const res = handle_.connect(); not res.has_value())
110 throw std::runtime_error("Could not connect to database: " + res.error());
111
112 if (not readOnly) {
113 if (auto const res = handle_.execute(schema_.createKeyspace); not res.has_value()) {
114 // on datastax, creation of keyspaces can be configured to only be done thru the
115 // admin interface. this does not mean that the keyspace does not already exist tho.
116 if (res.error().code() != CASS_ERROR_SERVER_UNAUTHORIZED)
117 throw std::runtime_error("Could not create keyspace: " + res.error());
118 }
119
120 if (auto const res = handle_.executeEach(schema_.createSchema); not res.has_value())
121 throw std::runtime_error("Could not create schema: " + res.error());
122 }
123
124 try {
125 schema_.prepareStatements(handle_);
126 } catch (std::runtime_error const& ex) {
127 auto const error = fmt::format(
128 "Failed to prepare the statements: {}; readOnly: {}. ReadOnly should be turned off "
129 "or another Clio "
130 "node with write access to DB should be started first.",
131 ex.what(),
132 readOnly
133 );
134 LOG(log_.error()) << error;
135 throw std::runtime_error(error);
136 }
137 LOG(log_.info()) << "Created (revamped) CassandraBackend";
138 }
139
144
148 [[nodiscard]] std::chrono::milliseconds
149 initialRetryDelay() const override
150 {
151 return settingsProvider_.getInitialRetryDelay();
152 }
153
157 [[nodiscard]] std::chrono::milliseconds
158 maxRetryDelay() const override
159 {
160 return settingsProvider_.getMaxRetryDelay();
161 }
162
175 xrpl::AccountID const& account,
176 std::uint32_t const limit,
177 bool forward,
178 std::optional<TransactionsCursor> const& txnCursor,
179 boost::asio::yield_context yield
180 ) const override
181 {
182 auto rng = fetchLedgerRange();
183 if (!rng)
184 return {.txns = {}, .cursor = {}};
185
186 Statement const statement = [this, forward, &account] {
187 if (forward)
188 return schema_->selectAccountTxForward.bind(account);
189
190 return schema_->selectAccountTx.bind(account);
191 }();
192
193 auto cursor = txnCursor;
194 if (cursor) {
195 statement.bindAt(kTransactionCursorBindIndex, cursor->asTuple());
196 LOG(log_.debug()) << "account = " << xrpl::strHex(account)
197 << " tuple = " << cursor->ledgerSequence << cursor->transactionIndex;
198 } else {
199 auto const seq = forward ? rng->minSequence : rng->maxSequence;
200 auto const placeHolder = forward ? 0u : std::numeric_limits<std::uint32_t>::max();
201
202 statement.bindAt(
203 kTransactionCursorBindIndex, std::make_tuple(placeHolder, placeHolder)
204 );
205 LOG(log_.debug()) << "account = " << xrpl::strHex(account) << " idx = " << seq
206 << " tuple = " << placeHolder;
207 }
208
209 // FIXME: Limit is a hack to support uint32_t properly for the time
210 // being. Should be removed later and schema updated to use proper
211 // types.
212 statement.bindAt(kTransactionLimitBindIndex, Limit{limit});
213 auto const res = executor_.read(yield, statement);
214 auto const& results = res.value();
215 if (not results.hasRows()) {
216 LOG(log_.debug()) << "No rows returned";
217 return {};
218 }
219
220 std::vector<xrpl::uint256> hashes = {};
221 auto numRows = results.numRows();
222 LOG(log_.info()) << "num_rows = " << numRows;
223
224 for (auto [hash, data] : extract<xrpl::uint256, std::tuple<uint32_t, uint32_t>>(results)) {
225 hashes.push_back(hash);
226 if (--numRows == 0) {
227 LOG(log_.debug()) << "Setting cursor";
228 cursor = data;
229 }
230 }
231
232 auto const txns = fetchTransactions(hashes, yield);
233 LOG(log_.debug()) << "Txns = " << txns.size();
234
235 if (txns.size() == limit) {
236 LOG(log_.debug()) << "Returning cursor";
237 return {txns, cursor};
238 }
239
240 return {txns, {}};
241 }
242
246 void
248 {
249 executor_.sync();
250 }
251
259 void
260 writeLedger(xrpl::LedgerHeader const& ledgerHeader, std::string&& blob) override
261 {
262 executor_.write(schema_->insertLedgerHeader, ledgerHeader.seq, std::move(blob));
263
264 executor_.write(schema_->insertLedgerHash, ledgerHeader.hash, ledgerHeader.seq);
265
266 ledgerSequence_ = ledgerHeader.seq;
267 }
268
275 std::optional<std::uint32_t>
276 fetchLatestLedgerSequence(boost::asio::yield_context yield) const override
277 {
278 if (auto const res = executor_.read(yield, schema_->selectLatestLedger); res.has_value()) {
279 if (auto const& rows = *res; rows) {
280 if (auto const maybeRow = rows.template get<uint32_t>(); maybeRow.has_value())
281 return maybeRow;
282
283 LOG(log_.error()) << "Could not fetch latest ledger - no rows";
284 return std::nullopt;
285 }
286
287 LOG(log_.error()) << "Could not fetch latest ledger - no result";
288 } else {
289 LOG(log_.error()) << "Could not fetch latest ledger: " << res.error();
290 }
291
292 return std::nullopt;
293 }
294
302 std::optional<xrpl::LedgerHeader>
304 std::uint32_t const sequence,
305 boost::asio::yield_context yield
306 ) const override
307 {
308 if (auto const lock = ledgerCache_.get(); lock.has_value() && lock->seq == sequence)
309 return lock->ledger;
310
311 auto const res = executor_.read(yield, schema_->selectLedgerBySeq, sequence);
312 if (res) {
313 if (auto const& result = res.value(); result) {
314 if (auto const maybeValue = result.template get<std::vector<unsigned char>>();
315 maybeValue) {
316 auto const header = util::deserializeHeader(xrpl::makeSlice(*maybeValue));
317 ledgerCache_.put(FetchLedgerCache::CacheEntry{header, sequence});
318 return header;
319 }
320
321 LOG(log_.error()) << "Could not fetch ledger by sequence - no rows";
322 return std::nullopt;
323 }
324
325 LOG(log_.error()) << "Could not fetch ledger by sequence - no result";
326 } else {
327 LOG(log_.error()) << "Could not fetch ledger by sequence: " << res.error();
328 }
329
330 return std::nullopt;
331 }
332
340 std::optional<xrpl::LedgerHeader>
341 fetchLedgerByHash(xrpl::uint256 const& hash, boost::asio::yield_context yield) const override
342 {
343 if (auto const res = executor_.read(yield, schema_->selectLedgerByHash, hash); res) {
344 if (auto const& result = res.value(); result) {
345 if (auto const maybeValue = result.template get<uint32_t>(); maybeValue)
346 return fetchLedgerBySequence(*maybeValue, yield);
347
348 LOG(log_.error()) << "Could not fetch ledger by hash - no rows";
349 return std::nullopt;
350 }
351
352 LOG(log_.error()) << "Could not fetch ledger by hash - no result";
353 } else {
354 LOG(log_.error()) << "Could not fetch ledger by hash: " << res.error();
355 }
356
357 return std::nullopt;
358 }
359
366 std::optional<LedgerRange>
367 hardFetchLedgerRange(boost::asio::yield_context yield) const override
368 {
369 auto const res = executor_.read(yield, schema_->selectLedgerRange);
370 if (res) {
371 auto const& results = res.value();
372 if (not results.hasRows()) {
373 LOG(log_.debug()) << "Could not fetch ledger range - no rows";
374 return std::nullopt;
375 }
376
377 // TODO: this is probably a good place to use user type in
378 // cassandra instead of having two rows with bool flag. or maybe at
379 // least use tuple<int, int>?
380 LedgerRange range;
381 std::size_t idx = 0;
382 for (auto [seq] : extract<uint32_t>(results)) {
383 if (idx == 0) {
384 range.maxSequence = range.minSequence = seq;
385 } else if (idx == 1) {
386 range.maxSequence = seq;
387 }
388
389 ++idx;
390 }
391
392 if (range.minSequence > range.maxSequence)
393 std::swap(range.minSequence, range.maxSequence);
394
395 LOG(log_.debug()) << "After hardFetchLedgerRange range is " << range.minSequence << ":"
396 << range.maxSequence;
397 return range;
398 }
399 LOG(log_.error()) << "Could not fetch ledger range: " << res.error();
400
401 return std::nullopt;
402 }
403
411 std::vector<TransactionAndMetadata>
413 std::uint32_t const ledgerSequence,
414 boost::asio::yield_context yield
415 ) const override
416 {
417 auto const hashes = fetchAllTransactionHashesInLedger(ledgerSequence, yield);
418 return fetchTransactions(hashes, yield);
419 }
420
428 std::vector<xrpl::uint256>
430 std::uint32_t const ledgerSequence,
431 boost::asio::yield_context yield
432 ) const override
433 {
434 auto const start = std::chrono::system_clock::now();
435 auto const res =
436 executor_.read(yield, schema_->selectAllTransactionHashesInLedger, ledgerSequence);
437
438 if (not res) {
439 LOG(log_.error()) << "Could not fetch all transaction hashes: " << res.error();
440 return {};
441 }
442
443 auto const& result = res.value();
444 if (not result.hasRows()) {
445 LOG(log_.warn()) << "Could not fetch all transaction hashes - no rows; ledger = "
446 << std::to_string(ledgerSequence);
447 return {};
448 }
449
450 std::vector<xrpl::uint256> hashes;
451 for (auto [hash] : extract<xrpl::uint256>(result))
452 hashes.push_back(std::move(hash));
453
454 auto const end = std::chrono::system_clock::now();
455 LOG(
456 log_.debug()
457 ) << "Fetched "
458 << hashes.size() << " transaction hashes from database in "
459 << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
460 << " milliseconds";
461
462 return hashes;
463 }
464
473 std::optional<NFT>
475 xrpl::uint256 const& tokenID,
476 std::uint32_t const ledgerSequence,
477 boost::asio::yield_context yield
478 ) const override
479 {
480 auto const res = executor_.read(yield, schema_->selectNFT, tokenID, ledgerSequence);
481 if (not res)
482 return std::nullopt;
483
484 if (auto const maybeRow = res->template get<uint32_t, xrpl::AccountID, bool>(); maybeRow) {
485 auto [seq, owner, isBurned] = *maybeRow;
486 auto result = std::make_optional<NFT>(tokenID, seq, owner, isBurned);
487
488 // now fetch URI. Usually we will have the URI even for burned NFTs,
489 // but if the first ledger on this clio included NFTokenBurn
490 // transactions we will not have the URIs for any of those tokens.
491 // In any other case not having the URI indicates something went
492 // wrong with our data.
493 //
494 // TODO - in the future would be great for any handlers that use
495 // this could inject a warning in this case (the case of not having
496 // a URI because it was burned in the first ledger) to indicate that
497 // even though we are returning a blank URI, the NFT might have had
498 // one.
499 auto uriRes = executor_.read(yield, schema_->selectNFTURI, tokenID, ledgerSequence);
500 if (uriRes) {
501 if (auto const maybeUri = uriRes->template get<xrpl::Blob>(); maybeUri)
502 result->uri = *maybeUri;
503 }
504
505 return result;
506 }
507
508 LOG(log_.error()) << "Could not fetch NFT - no rows";
509 return std::nullopt;
510 }
511
524 xrpl::uint256 const& tokenID,
525 std::uint32_t const limit,
526 bool const forward,
527 std::optional<TransactionsCursor> const& cursorIn,
528 boost::asio::yield_context yield
529 ) const override
530 {
531 auto rng = fetchLedgerRange();
532 if (!rng)
533 return {.txns = {}, .cursor = {}};
534
535 Statement const statement = [this, forward, &tokenID] {
536 if (forward)
537 return schema_->selectNFTTxForward.bind(tokenID);
538
539 return schema_->selectNFTTx.bind(tokenID);
540 }();
541
542 auto cursor = cursorIn;
543 if (cursor) {
544 statement.bindAt(kTransactionCursorBindIndex, cursor->asTuple());
545 LOG(log_.debug()) << "token_id = " << xrpl::strHex(tokenID)
546 << " tuple = " << cursor->ledgerSequence << cursor->transactionIndex;
547 } else {
548 auto const seq = forward ? rng->minSequence : rng->maxSequence;
549 auto const placeHolder = forward ? 0 : std::numeric_limits<std::uint32_t>::max();
550
551 statement.bindAt(
552 kTransactionCursorBindIndex, std::make_tuple(placeHolder, placeHolder)
553 );
554 LOG(log_.debug()) << "token_id = " << xrpl::strHex(tokenID) << " idx = " << seq
555 << " tuple = " << placeHolder;
556 }
557
558 statement.bindAt(kTransactionLimitBindIndex, Limit{limit});
559
560 auto const res = executor_.read(yield, statement);
561 auto const& results = res.value();
562 if (not results.hasRows()) {
563 LOG(log_.debug()) << "No rows returned";
564 return {};
565 }
566
567 std::vector<xrpl::uint256> hashes = {};
568 auto numRows = results.numRows();
569 LOG(log_.info()) << "num_rows = " << numRows;
570
571 for (auto [hash, data] : extract<xrpl::uint256, std::tuple<uint32_t, uint32_t>>(results)) {
572 hashes.push_back(hash);
573 if (--numRows == 0) {
574 LOG(log_.debug()) << "Setting cursor";
575 cursor = data;
576
577 // forward queries by ledger/tx sequence `>=`
578 // so we have to advance the index by one
579 if (forward)
580 ++cursor->transactionIndex;
581 }
582 }
583
584 auto const txns = fetchTransactions(hashes, yield);
585 LOG(log_.debug()) << "NFT Txns = " << txns.size();
586
587 if (txns.size() == limit) {
588 LOG(log_.debug()) << "Returning cursor";
589 return {txns, cursor};
590 }
591
592 return {txns, {}};
593 }
594
607 xrpl::uint192 const& mptIssuanceID,
608 std::uint32_t const limit,
609 bool const forward,
610 std::optional<TransactionsCursor> const& cursorIn,
611 boost::asio::yield_context yield
612 ) const override
613 {
614 auto const statement = [this, forward, &mptIssuanceID] {
615 if (forward)
616 return schema_->selectMPTokenIssuanceTxForward.bind(mptIssuanceID);
617
618 return schema_->selectMPTokenIssuanceTx.bind(mptIssuanceID);
619 }();
621 statement,
622 kMPTokenIssuanceTxCursorBindIndex,
623 kMPTokenIssuanceTxLimitBindIndex,
624 limit,
625 forward,
626 cursorIn,
627 yield
628 );
629 }
630
645 xrpl::uint192 const& mptIssuanceID,
646 xrpl::AccountID const& account,
647 std::uint32_t const limit,
648 bool const forward,
649 std::optional<TransactionsCursor> const& cursorIn,
650 boost::asio::yield_context yield
651 ) const override
652 {
653 auto const statement = [this, forward, &mptIssuanceID, &account] {
654 if (forward)
655 return schema_->selectAccountMPTokenIssuanceTxForward.bind(mptIssuanceID, account);
656
657 return schema_->selectAccountMPTokenIssuanceTx.bind(mptIssuanceID, account);
658 }();
660 statement,
661 kAccountMPTokenIssuanceTxCursorBindIndex,
662 kAccountMPTokenIssuanceTxLimitBindIndex,
663 limit,
664 forward,
665 cursorIn,
666 yield
667 );
668 }
669
683 xrpl::uint192 const& mptID,
684 std::uint32_t const limit,
685 std::optional<xrpl::AccountID> const& cursorIn,
686 std::uint32_t const ledgerSequence,
687 boost::asio::yield_context yield
688 ) const override
689 {
690 auto const holderEntries = executor_.read(
691 yield,
692 schema_->selectMPTHolders,
693 mptID,
694 cursorIn.value_or(xrpl::AccountID(0)),
695 Limit{limit}
696 );
697
698 auto const& holderResults = holderEntries.value();
699 if (not holderResults.hasRows()) {
700 LOG(log_.debug()) << "No rows returned";
701 return {};
702 }
703
704 std::vector<xrpl::uint256> mptKeys;
705 std::optional<xrpl::AccountID> cursor;
706 for (auto const [holder] : extract<xrpl::AccountID>(holderResults)) {
707 mptKeys.push_back(xrpl::keylet::mptoken(mptID, holder).key);
708 cursor = holder;
709 }
710
711 auto mptObjects = doFetchLedgerObjects(mptKeys, ledgerSequence, yield);
712
713 auto const it = std::remove_if(mptObjects.begin(), mptObjects.end(), [](Blob const& mpt) {
714 return mpt.empty();
715 });
716
717 mptObjects.erase(it, mptObjects.end());
718
719 ASSERT(mptKeys.size() <= limit, "Number of keys can't exceed the limit");
720 if (mptKeys.size() == limit)
721 return {mptObjects, cursor};
722
723 return {mptObjects, {}};
724 }
725
734 std::optional<Blob>
736 xrpl::uint256 const& key,
737 std::uint32_t const sequence,
738 boost::asio::yield_context yield
739 ) const override
740 {
741 LOG(log_.debug()) << "Fetching ledger object for seq " << sequence
742 << ", key = " << xrpl::to_string(key);
743 if (auto const res = executor_.read(yield, schema_->selectObject, key, sequence); res) {
744 if (auto const result = res->template get<Blob>(); result) {
745 if (result->size())
746 return result;
747 } else {
748 LOG(log_.debug()) << "Could not fetch ledger object - no rows";
749 }
750 } else {
751 LOG(log_.error()) << "Could not fetch ledger object: " << res.error();
752 }
753
754 return std::nullopt;
755 }
756
766 std::optional<std::uint32_t>
768 xrpl::uint256 const& key,
769 std::uint32_t const sequence,
770 boost::asio::yield_context yield
771 ) const override
772 {
773 LOG(log_.debug()) << "Fetching ledger object for seq " << sequence
774 << ", key = " << xrpl::to_string(key);
775 if (auto const res = executor_.read(yield, schema_->selectObject, key, sequence); res) {
776 if (auto const result = res->template get<Blob, std::uint32_t>(); result) {
777 auto [_, seq] = *result;
778 return seq;
779 }
780 LOG(log_.debug()) << "Could not fetch ledger object sequence - no rows";
781 } else {
782 LOG(log_.error()) << "Could not fetch ledger object sequence: " << res.error();
783 }
784
785 return std::nullopt;
786 }
787
795 std::optional<TransactionAndMetadata>
796 fetchTransaction(xrpl::uint256 const& hash, boost::asio::yield_context yield) const override
797 {
798 if (auto const res = executor_.read(yield, schema_->selectTransaction, hash); res) {
799 if (auto const maybeValue = res->template get<Blob, Blob, uint32_t, uint32_t>();
800 maybeValue) {
801 auto [transaction, meta, seq, date] = *maybeValue;
802 return std::make_optional<TransactionAndMetadata>(transaction, meta, seq, date);
803 }
804
805 LOG(log_.debug()) << "Could not fetch transaction - no rows";
806 } else {
807 LOG(log_.error()) << "Could not fetch transaction: " << res.error();
808 }
809
810 return std::nullopt;
811 }
812
821 std::optional<xrpl::uint256>
823 xrpl::uint256 key,
824 std::uint32_t const ledgerSequence,
825 boost::asio::yield_context yield
826 ) const override
827 {
828 if (auto const res = executor_.read(yield, schema_->selectSuccessor, key, ledgerSequence);
829 res) {
830 if (auto const result = res->template get<xrpl::uint256>(); result) {
831 if (*result == kLastKey)
832 return std::nullopt;
833 return result;
834 }
835
836 LOG(log_.debug()) << "Could not fetch successor - no rows";
837 } else {
838 LOG(log_.error()) << "Could not fetch successor: " << res.error();
839 }
840
841 return std::nullopt;
842 }
843
851 std::vector<TransactionAndMetadata>
853 std::vector<xrpl::uint256> const& hashes,
854 boost::asio::yield_context yield
855 ) const override
856 {
857 if (hashes.empty())
858 return {};
859
860 auto const numHashes = hashes.size();
861 std::vector<TransactionAndMetadata> results;
862 results.reserve(numHashes);
863
864 std::vector<Statement> statements;
865 statements.reserve(numHashes);
866
867 auto const timeDiff = util::timed([this, yield, &results, &hashes, &statements] {
868 // TODO: seems like a job for "hash IN (list of hashes)" instead?
869 std::transform(
870 std::cbegin(hashes),
871 std::cend(hashes),
872 std::back_inserter(statements),
873 [this](auto const& hash) { return schema_->selectTransaction.bind(hash); }
874 );
875
876 auto const entries = executor_.readEach(yield, statements);
877 std::transform(
878 std::cbegin(entries),
879 std::cend(entries),
880 std::back_inserter(results),
881 [](auto const& res) -> TransactionAndMetadata {
882 if (auto const maybeRow = res.template get<Blob, Blob, uint32_t, uint32_t>();
883 maybeRow)
884 return *maybeRow;
885
886 return {};
887 }
888 );
889 });
890
891 ASSERT(numHashes == results.size(), "Number of hashes and results must match");
892 LOG(log_.debug()) << "Fetched " << numHashes << " transactions from database in "
893 << timeDiff << " milliseconds";
894 return results;
895 }
896
905 std::vector<Blob>
907 std::vector<xrpl::uint256> const& keys,
908 std::uint32_t const sequence,
909 boost::asio::yield_context yield
910 ) const override
911 {
912 if (keys.empty())
913 return {};
914
915 auto const numKeys = keys.size();
916 LOG(log_.trace()) << "Fetching " << numKeys << " objects";
917
918 std::vector<Blob> results;
919 results.reserve(numKeys);
920
921 std::vector<Statement> statements;
922 statements.reserve(numKeys);
923
924 // TODO: seems like a job for "key IN (list of keys)" instead?
925 std::transform(
926 std::cbegin(keys),
927 std::cend(keys),
928 std::back_inserter(statements),
929 [this, &sequence](auto const& key) { return schema_->selectObject.bind(key, sequence); }
930 );
931
932 auto const entries = executor_.readEach(yield, statements);
933 std::transform(
934 std::cbegin(entries),
935 std::cend(entries),
936 std::back_inserter(results),
937 [](auto const& res) -> Blob {
938 if (auto const maybeValue = res.template get<Blob>(); maybeValue)
939 return *maybeValue;
940
941 return {};
942 }
943 );
944
945 LOG(log_.trace()) << "Fetched " << numKeys << " objects";
946 return results;
947 }
948
956 std::vector<LedgerObject>
958 std::uint32_t const ledgerSequence,
959 boost::asio::yield_context yield
960 ) const override
961 {
962 auto const [keys, timeDiff] =
963 util::timed([this, &ledgerSequence, yield] -> std::vector<xrpl::uint256> {
964 auto const res = executor_.read(yield, schema_->selectDiff, ledgerSequence);
965 if (not res) {
966 LOG(log_.error()) << "Could not fetch ledger diff: " << res.error()
967 << "; ledger = " << ledgerSequence;
968 return {};
969 }
970
971 auto const& results = res.value();
972 if (not results) {
973 LOG(log_.error())
974 << "Could not fetch ledger diff - no rows; ledger = " << ledgerSequence;
975 return {};
976 }
977
978 std::vector<xrpl::uint256> resultKeys;
979 for (auto [key] : extract<xrpl::uint256>(results))
980 resultKeys.push_back(key);
981
982 return resultKeys;
983 });
984
985 // one of the above errors must have happened
986 if (keys.empty())
987 return {};
988
989 LOG(log_.debug()) << "Fetched " << keys.size() << " diff hashes from database in "
990 << timeDiff << " milliseconds";
991
992 auto const objs = fetchLedgerObjects(keys, ledgerSequence, yield);
993 std::vector<LedgerObject> results;
994 results.reserve(keys.size());
995
996 std::transform(
997 std::cbegin(keys),
998 std::cend(keys),
999 std::cbegin(objs),
1000 std::back_inserter(results),
1001 [](auto const& key, auto const& obj) { return LedgerObject{key, obj}; }
1002 );
1003
1004 return results;
1005 }
1006
1014 std::optional<std::string>
1016 std::string const& migratorName,
1017 boost::asio::yield_context yield
1018 ) const override
1019 {
1020 auto const res = executor_.read(yield, schema_->selectMigratorStatus, Text(migratorName));
1021 if (not res) {
1022 LOG(log_.error()) << "Could not fetch migrator status: " << res.error();
1023 return {};
1024 }
1025
1026 auto const& results = res.value();
1027 if (not results) {
1028 return {};
1029 }
1030
1031 for (auto [statusString] : extract<std::string>(results))
1032 return statusString;
1033
1034 return {};
1035 }
1036
1043 std::expected<std::vector<std::pair<boost::uuids::uuid, std::string>>, std::string>
1044 fetchClioNodesData(boost::asio::yield_context yield) const override
1045 {
1046 auto const readResult = executor_.read(yield, schema_->selectClioNodesData);
1047 if (not readResult)
1048 return std::unexpected{readResult.error().message()};
1049
1050 std::vector<std::pair<boost::uuids::uuid, std::string>> result;
1051
1052 for (auto [uuid, message] : extract<boost::uuids::uuid, std::string>(*readResult)) {
1053 result.emplace_back(uuid, std::move(message));
1054 }
1055
1056 return result;
1057 }
1058
1067 void
1068 doWriteLedgerObject(std::string&& key, std::uint32_t const seq, std::string&& blob) override
1069 {
1070 LOG(log_.trace()) << " Writing ledger object " << key.size() << ":" << seq << " ["
1071 << blob.size() << " bytes]";
1072
1073 if (range_)
1074 executor_.write(schema_->insertDiff, seq, key);
1075
1076 executor_.write(schema_->insertObject, std::move(key), seq, std::move(blob));
1077 }
1078
1086 void
1087 writeSuccessor(std::string&& key, std::uint32_t const seq, std::string&& successor) override
1088 {
1089 LOG(log_.trace()) << "Writing successor. key = " << key.size() << " bytes. "
1090 << " seq = " << std::to_string(seq) << " successor = " << successor.size()
1091 << " bytes.";
1092 ASSERT(!key.empty(), "Key must not be empty");
1093 ASSERT(!successor.empty(), "Successor must not be empty");
1094
1095 executor_.write(schema_->insertSuccessor, std::move(key), seq, std::move(successor));
1096 }
1097
1103 void
1104 writeAccountTransactions(std::vector<AccountTransactionsData> data) override
1105 {
1106 std::vector<Statement> statements;
1107 statements.reserve(data.size() * 10); // assume 10 transactions avg
1108
1109 for (auto& record : data) {
1110 std::ranges::transform(
1111 record.accounts, std::back_inserter(statements), [this, &record](auto&& account) {
1112 return schema_->insertAccountTx.bind(
1113 std::forward<decltype(account)>(account),
1114 std::make_tuple(record.ledgerSequence, record.transactionIndex),
1115 record.txHash
1116 );
1117 }
1118 );
1119 }
1120
1121 executor_.write(std::move(statements));
1122 }
1123
1129 void
1131 {
1132 std::vector<Statement> statements;
1133 statements.reserve(record.accounts.size());
1134
1135 std::ranges::transform(
1136 record.accounts, std::back_inserter(statements), [this, &record](auto&& account) {
1137 return schema_->insertAccountTx.bind(
1138 std::forward<decltype(account)>(account),
1139 std::make_tuple(record.ledgerSequence, record.transactionIndex),
1140 record.txHash
1141 );
1142 }
1143 );
1144
1145 executor_.write(std::move(statements));
1146 }
1147
1153 void
1154 writeNFTTransactions(std::vector<NFTTransactionsData> const& data) override
1155 {
1156 std::vector<Statement> statements;
1157 statements.reserve(data.size());
1158
1159 std::ranges::transform(data, std::back_inserter(statements), [this](auto const& record) {
1160 return schema_->insertNFTTx.bind(
1161 record.tokenID,
1162 std::make_tuple(record.ledgerSequence, record.transactionIndex),
1163 record.txHash
1164 );
1165 });
1166
1167 executor_.write(std::move(statements));
1168 }
1169
1176 void
1178 std::vector<MPTokenIssuanceTransactionsData> const& data
1179 ) override
1180 {
1181 std::vector<Statement> statements;
1182 statements.reserve(data.size());
1183
1184 std::ranges::transform(data, std::back_inserter(statements), [this](auto const& record) {
1185 return schema_->insertMPTokenIssuanceTx.bind(
1186 record.mptIssuanceID,
1187 std::make_tuple(record.ledgerSequence, record.transactionIndex),
1188 record.txHash
1189 );
1190 });
1191
1192 executor_.write(std::move(statements));
1193 }
1194
1203 void
1205 std::vector<MPTokenIssuanceTransactionsData> const& data
1206 ) override
1207 {
1208 std::size_t numStatements = 0u;
1209 for (auto const& record : data)
1210 numStatements += record.accounts.size();
1211
1212 std::vector<Statement> statements;
1213 statements.reserve(numStatements);
1214
1215 for (auto const& record : data) {
1216 std::ranges::transform(
1217 record.accounts,
1218 std::back_inserter(statements),
1219 [this, &record](auto const& account) {
1220 return schema_->insertAccountMPTokenIssuanceTx.bind(
1221 record.mptIssuanceID,
1222 account,
1223 std::make_tuple(record.ledgerSequence, record.transactionIndex),
1224 record.txHash
1225 );
1226 }
1227 );
1228 }
1229
1230 executor_.write(std::move(statements));
1231 }
1232
1242 void
1244 std::string&& hash,
1245 std::uint32_t const seq,
1246 std::uint32_t const date,
1247 std::string&& transaction,
1248 std::string&& metadata
1249 ) override
1250 {
1251 LOG(log_.trace()) << "Writing txn to database";
1252
1253 executor_.write(schema_->insertLedgerTransaction, seq, hash);
1254 executor_.write(
1255 schema_->insertTransaction,
1256 std::move(hash),
1257 seq,
1258 date,
1259 std::move(transaction),
1260 std::move(metadata)
1261 );
1262 }
1263
1269 void
1270 writeNFTs(std::vector<NFTsData> const& data) override
1271 {
1272 std::vector<Statement> statements;
1273 statements.reserve(data.size() * 3);
1274
1275 for (NFTsData const& record : data) {
1276 if (!record.onlyUriChanged) {
1277 statements.push_back(schema_->insertNFT.bind(
1278 record.tokenID, record.ledgerSequence, record.owner, record.isBurned
1279 ));
1280
1281 // If `uri` is set (and it can be set to an empty uri), we know this
1282 // is a net-new NFT. That is, this NFT has not been seen before by
1283 // us _OR_ it is in the extreme edge case of a re-minted NFT ID with
1284 // the same NFT ID as an already-burned token. In this case, we need
1285 // to record the URI and link to the issuer_nf_tokens table.
1286 if (record.uri) {
1287 statements.push_back(schema_->insertIssuerNFT.bind(
1288 xrpl::nft::getIssuer(record.tokenID),
1289 static_cast<uint32_t>(xrpl::nft::getTaxon(record.tokenID)),
1290 record.tokenID
1291 ));
1292 statements.push_back(schema_->insertNFTURI.bind(
1293 record.tokenID, record.ledgerSequence, *record.uri
1294 ));
1295 }
1296 } else {
1297 // only uri changed, we update the uri table only
1298 statements.push_back(
1299 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
1300 schema_->insertNFTURI.bind(record.tokenID, record.ledgerSequence, *record.uri)
1301 );
1302 }
1303 }
1304
1305 executor_.writeEach(std::move(statements));
1306 }
1307
1313 void
1314 writeMPTHolders(std::vector<MPTHolderData> const& data) override
1315 {
1316 std::vector<Statement> statements;
1317 statements.reserve(data.size());
1318 for (auto [mptId, holder] : data)
1319 statements.push_back(schema_->insertMPTHolder.bind(mptId, holder));
1320
1321 executor_.write(std::move(statements));
1322 }
1323
1327 void
1328 startWrites() const override
1329 {
1330 // Note: no-op in original implementation too.
1331 // probably was used in PG to start a transaction or smth.
1332 }
1333
1340 void
1341 writeMigratorStatus(std::string const& migratorName, std::string const& status) override
1342 {
1343 executor_.writeSync(
1344 schema_->insertMigratorStatus,
1345 data::cassandra::Text{migratorName},
1346 data::cassandra::Text(status)
1347 );
1348 }
1349
1356 void
1357 writeNodeMessage(boost::uuids::uuid const& uuid, std::string message) override
1358 {
1359 executor_.writeSync(
1360 schema_->updateClioNodeMessage, data::cassandra::Text{std::move(message)}, uuid
1361 );
1362 }
1363
1369 bool
1370 isTooBusy() const override
1371 {
1372 return executor_.isTooBusy();
1373 }
1374
1380 boost::json::object
1381 stats() const override
1382 {
1383 return executor_.stats();
1384 }
1385
1386protected:
1393 bool
1395 {
1396 auto const res = executor_.writeSync(statement);
1397 auto maybeSuccess = res->template get<bool>();
1398 if (not maybeSuccess) {
1399 LOG(log_.error()) << "executeSyncUpdate - error getting result - no row";
1400 return false;
1401 }
1402
1403 if (not *maybeSuccess) {
1404 LOG(log_.warn()) << "Update failed. Checking if DB state is what we expect";
1405
1406 // error may indicate that another writer wrote something.
1407 // in this case let's just compare the current state of things
1408 // against what we were trying to write in the first place and
1409 // use that as the source of truth for the result.
1410 auto rng = hardFetchLedgerRangeNoThrow();
1411 return rng && rng->maxSequence == ledgerSequence_;
1412 }
1413
1414 return true;
1415 }
1416
1435 Statement const& statement,
1436 std::size_t const cursorIdx,
1437 std::size_t const limitIdx,
1438 std::uint32_t const limit,
1439 bool const forward,
1440 std::optional<TransactionsCursor> const& cursorIn,
1441 boost::asio::yield_context yield
1442 ) const
1443 {
1444 auto rng = fetchLedgerRange();
1445 if (!rng)
1446 return {.txns = {}, .cursor = {}};
1447
1448 auto cursor = cursorIn;
1449 if (cursor.has_value()) {
1450 statement.bindAt(cursorIdx, cursor->asTuple());
1451 } else {
1452 // Forward uses the nft_history-style inclusive lower bound; reverse starts just past
1453 // the latest validated ledger so its exclusive `<` query includes that ledger's rows.
1454 auto const ledgerSequence = forward ? rng->minSequence : rng->maxSequence;
1455 auto const transactionIndex = forward ? 0u : std::numeric_limits<std::uint32_t>::max();
1456 statement.bindAt(cursorIdx, std::make_tuple(ledgerSequence, transactionIndex));
1457 }
1458
1459 statement.bindAt(limitIdx, Limit{limit});
1460
1461 auto const res = executor_.read(yield, statement);
1462 auto const& results = res.value();
1463 if (not results.hasRows()) {
1464 LOG(log_.debug()) << "No rows returned";
1465 return {};
1466 }
1467
1468 std::vector<xrpl::uint256> hashes = {};
1469 auto numRows = results.numRows();
1470
1471 for (auto const& [hash, data] :
1472 extract<xrpl::uint256, std::tuple<uint32_t, uint32_t>>(results)) {
1473 hashes.push_back(hash);
1474
1475 if (--numRows == 0) {
1476 LOG(log_.debug()) << "Setting cursor";
1477 cursor = data;
1478
1479 // forward queries by ledger/tx sequence `>=`
1480 // so we have to advance the index by one
1481 if (forward)
1482 ++cursor->transactionIndex;
1483 }
1484 }
1485
1486 auto txns = fetchTransactions(hashes, yield);
1487 LOG(log_.debug()) << "MPTokenIssuance Txns = " << txns.size();
1488
1489 if (txns.size() == limit) {
1490 LOG(log_.debug()) << "Returning cursor";
1491 return {std::move(txns), cursor};
1492 }
1493
1494 return {std::move(txns), {}};
1495 }
1496};
1497
1498} // namespace data::cassandra
BackendInterface(LedgerCacheInterface &cache)
Construct a new backend interface instance.
Definition BackendInterface.hpp:225
std::optional< LedgerRange > hardFetchLedgerRangeNoThrow() const
Fetches the ledger range from DB retrying until no DatabaseError is thrown.
Definition BackendInterface.cpp:53
std::optional< LedgerRange > fetchLedgerRange() const
Fetch the current ledger range.
Definition BackendInterface.cpp:251
std::vector< Blob > fetchLedgerObjects(std::vector< xrpl::uint256 > const &keys, std::uint32_t sequence, boost::asio::yield_context yield) const
Fetches all ledger objects by their keys.
Definition BackendInterface.cpp:95
LedgerCacheInterface const & cache() const
Definition BackendInterface.hpp:256
A simple cache holding one xrpl::LedgerHeader to reduce DB lookups.
Definition LedgerHeaderCache.hpp:22
Cache for an entire ledger.
Definition LedgerCacheInterface.hpp:21
void writeMigratorStatus(std::string const &migratorName, std::string const &status) override
Write the migration status of a migrator to the database.
Definition CassandraBackendFamily.hpp:1341
std::optional< LedgerRange > hardFetchLedgerRange(boost::asio::yield_context yield) const override
Fetches the ledger range from DB.
Definition CassandraBackendFamily.hpp:367
std::optional< xrpl::LedgerHeader > fetchLedgerBySequence(std::uint32_t const sequence, boost::asio::yield_context yield) const override
Fetches a specific ledger by sequence number, using the ledger header cache first.
Definition CassandraBackendFamily.hpp:303
TransactionsAndCursor fetchAccountMPTokenIssuanceTransactions(xrpl::uint192 const &mptIssuanceID, xrpl::AccountID const &account, std::uint32_t const limit, bool const forward, std::optional< TransactionsCursor > const &cursorIn, boost::asio::yield_context yield) const override
Fetches transactions for a particular MPTokenIssuance ID involving a particular account.
Definition CassandraBackendFamily.hpp:644
std::optional< NFT > fetchNFT(xrpl::uint256 const &tokenID, std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Fetches a specific NFT.
Definition CassandraBackendFamily.hpp:474
void startWrites() const override
Starts a write transaction with the DB. No-op for Cassandra.
Definition CassandraBackendFamily.hpp:1328
void doWriteLedgerObject(std::string &&key, std::uint32_t const seq, std::string &&blob) override
Write a ledger object version to objects and, once the ledger range is known, record its key in diff.
Definition CassandraBackendFamily.hpp:1068
std::chrono::milliseconds initialRetryDelay() const override
Definition CassandraBackendFamily.hpp:149
std::optional< std::uint32_t > doFetchLedgerObjectSeq(xrpl::uint256 const &key, std::uint32_t const sequence, boost::asio::yield_context yield) const override
The database-specific implementation for fetching a ledger object sequence.
Definition CassandraBackendFamily.hpp:767
std::optional< xrpl::LedgerHeader > fetchLedgerByHash(xrpl::uint256 const &hash, boost::asio::yield_context yield) const override
Fetches a specific ledger by hash.
Definition CassandraBackendFamily.hpp:341
TransactionsAndCursor fetchAccountTransactions(xrpl::AccountID const &account, std::uint32_t const limit, bool forward, std::optional< TransactionsCursor > const &txnCursor, boost::asio::yield_context yield) const override
Fetches all transactions for a specific account.
Definition CassandraBackendFamily.hpp:174
std::optional< Blob > doFetchLedgerObject(xrpl::uint256 const &key, std::uint32_t const sequence, boost::asio::yield_context yield) const override
The database-specific implementation for fetching a ledger object.
Definition CassandraBackendFamily.hpp:735
void writeNFTs(std::vector< NFTsData > const &data) override
Writes NFTs to the database.
Definition CassandraBackendFamily.hpp:1270
void writeNFTTransactions(std::vector< NFTTransactionsData > const &data) override
Write NFTs transactions.
Definition CassandraBackendFamily.hpp:1154
void writeNodeMessage(boost::uuids::uuid const &uuid, std::string message) override
Write a node message. Used by ClusterCommunicationService.
Definition CassandraBackendFamily.hpp:1357
std::optional< std::uint32_t > fetchLatestLedgerSequence(boost::asio::yield_context yield) const override
Fetches the latest ledger sequence.
Definition CassandraBackendFamily.hpp:276
CassandraBackendFamily(SettingsProviderType settingsProvider, data::LedgerCacheInterface &cache, bool readOnly)
Create a new cassandra/scylla backend instance.
Definition CassandraBackendFamily.hpp:98
void writeAccountMPTokenIssuanceTransactions(std::vector< MPTokenIssuanceTransactionsData > const &data) override
Write MPTokenIssuance transaction index rows to the account_mptoken_issuance_transactions table.
Definition CassandraBackendFamily.hpp:1204
MPTHoldersAndCursor fetchMPTHolders(xrpl::uint192 const &mptID, std::uint32_t const limit, std::optional< xrpl::AccountID > const &cursorIn, std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Fetches a page of MPToken objects held for an MPTokenIssuance ID.
Definition CassandraBackendFamily.hpp:682
std::optional< xrpl::uint256 > doFetchSuccessorKey(xrpl::uint256 key, std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Database-specific implementation of fetching the successor key.
Definition CassandraBackendFamily.hpp:822
TransactionsAndCursor fetchNFTTransactions(xrpl::uint256 const &tokenID, std::uint32_t const limit, bool const forward, std::optional< TransactionsCursor > const &cursorIn, boost::asio::yield_context yield) const override
Fetches all transactions for a specific NFT.
Definition CassandraBackendFamily.hpp:523
bool isTooBusy() const override
Check whether the database is overwhelmed with requests.
Definition CassandraBackendFamily.hpp:1370
void writeMPTHolders(std::vector< MPTHolderData > const &data) override
Write accounts that started holding onto a MPT.
Definition CassandraBackendFamily.hpp:1314
void writeAccountTransaction(AccountTransactionsData record) override
Write a new account transaction.
Definition CassandraBackendFamily.hpp:1130
void writeSuccessor(std::string &&key, std::uint32_t const seq, std::string &&successor) override
Write a new successor.
Definition CassandraBackendFamily.hpp:1087
void waitForWritesToFinish() override
Wait for all pending writes to finish.
Definition CassandraBackendFamily.hpp:247
TransactionsAndCursor fetchMPTokenIssuanceTransactions(xrpl::uint192 const &mptIssuanceID, std::uint32_t const limit, bool const forward, std::optional< TransactionsCursor > const &cursorIn, boost::asio::yield_context yield) const override
Fetches transactions for a particular MPTokenIssuance ID.
Definition CassandraBackendFamily.hpp:606
void writeLedger(xrpl::LedgerHeader const &ledgerHeader, std::string &&blob) override
Write a ledger header and its hash-to-sequence mapping, and set the ledger that doFinishWrites() will...
Definition CassandraBackendFamily.hpp:260
std::optional< TransactionAndMetadata > fetchTransaction(xrpl::uint256 const &hash, boost::asio::yield_context yield) const override
Fetches a specific transaction.
Definition CassandraBackendFamily.hpp:796
TransactionsAndCursor fetchMPTokenIssuanceTransactionsImpl(Statement const &statement, std::size_t const cursorIdx, std::size_t const limitIdx, std::uint32_t const limit, bool const forward, std::optional< TransactionsCursor > const &cursorIn, boost::asio::yield_context yield) const
Shared implementation of the two MPTokenIssuance transaction-index fetchers.
Definition CassandraBackendFamily.hpp:1434
boost::json::object stats() const override
Get backend usage statistics collected by the execution strategy.
Definition CassandraBackendFamily.hpp:1381
std::optional< std::string > fetchMigratorStatus(std::string const &migratorName, boost::asio::yield_context yield) const override
Fetches the status of migrator by name.
Definition CassandraBackendFamily.hpp:1015
std::chrono::milliseconds maxRetryDelay() const override
Definition CassandraBackendFamily.hpp:158
std::expected< std::vector< std::pair< boost::uuids::uuid, std::string > >, std::string > fetchClioNodesData(boost::asio::yield_context yield) const override
Fetches the data of all nodes in the cluster.
Definition CassandraBackendFamily.hpp:1044
void writeAccountTransactions(std::vector< AccountTransactionsData > data) override
Write a new set of account transactions.
Definition CassandraBackendFamily.hpp:1104
std::vector< Blob > doFetchLedgerObjects(std::vector< xrpl::uint256 > const &keys, std::uint32_t const sequence, boost::asio::yield_context yield) const override
The database-specific implementation for fetching ledger objects.
Definition CassandraBackendFamily.hpp:906
CassandraBackendFamily(CassandraBackendFamily &&)=delete
Move constructor is deleted because handle_ is shared by reference with executor.
bool executeSyncUpdate(Statement statement)
Executes statements and tries to write to DB.
Definition CassandraBackendFamily.hpp:1394
void writeMPTokenIssuanceTransactions(std::vector< MPTokenIssuanceTransactionsData > const &data) override
Write MPTokenIssuance transaction index rows to the mptoken_issuance_transactions table.
Definition CassandraBackendFamily.hpp:1177
void writeTransaction(std::string &&hash, std::uint32_t const seq, std::uint32_t const date, std::string &&transaction, std::string &&metadata) override
Writes a new transaction.
Definition CassandraBackendFamily.hpp:1243
std::vector< xrpl::uint256 > fetchAllTransactionHashesInLedger(std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Fetches all transaction hashes from a specific ledger.
Definition CassandraBackendFamily.hpp:429
std::vector< TransactionAndMetadata > fetchTransactions(std::vector< xrpl::uint256 > const &hashes, boost::asio::yield_context yield) const override
Fetches multiple transactions.
Definition CassandraBackendFamily.hpp:852
std::vector< LedgerObject > fetchLedgerDiff(std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Fetch the objects changed in the given ledger.
Definition CassandraBackendFamily.hpp:957
std::vector< TransactionAndMetadata > fetchAllTransactionsInLedger(std::uint32_t const ledgerSequence, boost::asio::yield_context yield) const override
Fetches all transactions from a specific ledger.
Definition CassandraBackendFamily.hpp:412
Represents a handle to the cassandra database cluster.
Definition Handle.hpp:27
void bindAt(std::size_t const idx, Type &&value) const
Binds an argument to a specific index.
Definition Statement.hpp:76
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
The requirements of an execution strategy.
Definition Concepts.hpp:39
The requirements of a settings provider.
Definition Concepts.hpp:26
This namespace implements a wrapper for the Cassandra C++ driver.
Definition CassandraBackendFamily.hpp:50
impl::ResultExtractor< Types... > extract(Handle::ResultType const &result)
Extracts the results into series of std::tuple<Types...> by creating a simple wrapper with an STL inp...
Definition Handle.hpp:318
impl::Statement Statement
A simple or bound statement.
Definition Types.hpp:27
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:56
constexpr xrpl::uint256 kLastKey
The largest possible ledger object key; used as the end of the key space.
Definition Types.hpp:339
std::vector< unsigned char > Blob
Raw serialized data, e.g. a ledger object, transaction or metadata.
Definition Types.hpp:20
xrpl::LedgerHeader deserializeHeader(xrpl::Slice data)
Deserializes a xrpl::LedgerHeader from xrpl::Slice of data.
Definition LedgerUtils.hpp:76
auto timed(FnType &&func)
Profiler function to measure the time a function execution consumes.
Definition Profiler.hpp:21
Struct used to keep track of what to write to account_transactions/account_tx tables.
Definition DBHelpers.hpp:26
boost::container::flat_set< xrpl::AccountID > accounts
Accounts affected by the transaction.
Definition DBHelpers.hpp:27
Represents an NFT state at a particular ledger.
Definition DBHelpers.hpp:93
Struct to store ledger header cache entry and the sequence it belongs to.
Definition LedgerHeaderCache.hpp:29
Represents an object in the ledger.
Definition Types.hpp:25
Stores a range of sequences as a min and max pair.
Definition Types.hpp:246
std::uint32_t minSequence
Lowest ledger sequence in the range (inclusive).
Definition Types.hpp:247
std::uint32_t maxSequence
Highest ledger sequence in the range (inclusive).
Definition Types.hpp:248
Represents an array of MPTokens.
Definition Types.hpp:238
Represents a transaction and its metadata bundled together.
Definition Types.hpp:52
Represests a bundle of transactions with metadata and a cursor to the next page.
Definition Types.hpp:156
A strong type wrapper for int32_t.
Definition Types.hpp:38
A strong type wrapper for string.
Definition Types.hpp:49