20 #include <ripple/app/ledger/AcceptedLedger.h>
21 #include <ripple/app/ledger/InboundLedgers.h>
22 #include <ripple/app/ledger/Ledger.h>
23 #include <ripple/app/ledger/LedgerMaster.h>
24 #include <ripple/app/ledger/LedgerToJson.h>
25 #include <ripple/app/ledger/OrderBookDB.h>
26 #include <ripple/app/ledger/PendingSaves.h>
27 #include <ripple/app/ledger/TransactionMaster.h>
28 #include <ripple/app/main/Application.h>
29 #include <ripple/app/misc/HashRouter.h>
30 #include <ripple/app/misc/LoadFeeTrack.h>
31 #include <ripple/app/misc/NetworkOPs.h>
32 #include <ripple/app/reporting/DBHelpers.h>
33 #include <ripple/basics/Log.h>
34 #include <ripple/basics/StringUtilities.h>
35 #include <ripple/basics/contract.h>
36 #include <ripple/beast/core/LexicalCast.h>
37 #include <ripple/consensus/LedgerTiming.h>
38 #include <ripple/core/Config.h>
39 #include <ripple/core/DatabaseCon.h>
40 #include <ripple/core/JobQueue.h>
41 #include <ripple/core/Pg.h>
42 #include <ripple/core/SociDB.h>
43 #include <ripple/json/to_string.h>
44 #include <ripple/nodestore/Database.h>
45 #include <ripple/protocol/Feature.h>
46 #include <ripple/protocol/HashPrefix.h>
47 #include <ripple/protocol/Indexes.h>
48 #include <ripple/protocol/PublicKey.h>
49 #include <ripple/protocol/SecretKey.h>
50 #include <ripple/protocol/UintTypes.h>
51 #include <ripple/protocol/digest.h>
52 #include <ripple/protocol/jss.h>
53 #include <boost/optional.hpp>
58 #include <ripple/nodestore/impl/DatabaseNodeImp.h>
102 return std::make_unique<sles_iter_impl>(*
this);
106 equal(base_type
const& impl)
const override
109 return iter_ == p->iter_;
122 auto const item = *
iter_;
124 return std::make_shared<SLE const>(sit, item.key());
151 return std::make_unique<txs_iter_impl>(*
this);
155 equal(base_type
const& impl)
const override
157 if (
auto const p =
dynamic_cast<txs_iter_impl const*
>(&impl))
158 return iter_ == p->iter_;
171 auto const item = *
iter_;
201 sle->setFieldAmount(
sfBalance, info_.drops);
205 if (!amendments.empty())
208 sle->setFieldV256(
sfAmendments, STVector256{amendments});
213 setImmutable(config);
230 , rules_(config.features)
241 Throw<std::runtime_error>(
"Missing tx map root for ledger");
244 JLOG(j.
warn()) <<
"Don't have transaction root for ledger" <<
info_.
seq;
253 Throw<std::runtime_error>(
"Missing state map root for ledger");
256 JLOG(j.
warn()) <<
"Don't have state data root for ledger" <<
info_.
seq;
278 prevLedger.stateMap_->family()))
279 , stateMap_(prevLedger.stateMap_->snapShot(true))
280 , fees_(prevLedger.fees_)
281 , rules_(prevLedger.rules_)
329 info_.seq = ledgerSeq;
330 info_.closeTime = closeTime;
359 bool correctCloseTime,
385 return std::make_shared<STTx const>(sit);
396 result.
first = std::make_shared<STTx const>(s);
426 if (last && item->key() >= last)
434 if (k.
key == beast::zero)
442 auto sle = std::make_shared<SLE>(
SerialIter{item->slice()}, item->key());
453 return std::make_unique<sles_iter_impl>(
stateMap_->begin());
459 return std::make_unique<sles_iter_impl>(
stateMap_->end());
466 return std::make_unique<sles_iter_impl>(stateMap_->upper_bound(key));
472 return std::make_unique<txs_iter_impl>(!
open(),
txMap_->begin());
478 return std::make_unique<txs_iter_impl>(!
open(),
txMap_->end());
484 return txMap_->hasItem(key);
491 auto const& item = txMap_->peekItem(key);
497 return {std::move(result.first), std::move(result.second)};
508 if (!stateMap_->peekItem(key,
digest))
510 return digest.as_uint256();
519 LogicError(
"Ledger::rawErase: key not found");
526 LogicError(
"Ledger::rawErase: key not found");
536 std::make_shared<SHAMapItem const>(sle->key(), ss.
slice())))
537 LogicError(
"Ledger::rawInsert: key already exists");
547 std::make_shared<SHAMapItem const>(sle->key(), ss.
slice())))
548 LogicError(
"Ledger::rawReplace: key not found");
560 Serializer s(txn->getDataLength() + metaData->getDataLength() + 16);
561 s.
addVL(txn->peekData());
562 s.
addVL(metaData->peekData());
563 if (!
txMap().addGiveItem(
565 std::make_shared<SHAMapItem const>(key, s.
slice())))
578 Serializer s(txn->getDataLength() + metaData->getDataLength() + 16);
579 s.
addVL(txn->peekData());
580 s.
addVL(metaData->peekData());
581 auto item = std::make_shared<SHAMapItem const>(key, s.
slice());
649 auto sle = std::make_shared<SLE>(
SerialIter{value->slice()}, value->key());
663 for (
auto const& n : nUnlData)
721 if (!hasToDisable && !hasToReEnable)
728 for (
auto v : oldNUnl)
730 if (hasToReEnable && v.isFieldPresent(
sfPublicKey) &&
746 if (!newNUnl.
empty())
779 if (!missingNodes1.
empty())
781 if (
auto stream = j.
info())
783 stream << missingNodes1.
size() <<
" missing account node(s)";
784 stream <<
"First: " << missingNodes1[0].what();
796 txMap_->walkMap(missingNodes2, 32);
799 if (!missingNodes2.
empty())
801 if (
auto stream = j.
info())
803 stream << missingNodes2.
size() <<
" missing transaction node(s)";
804 stream <<
"First: " << missingNodes2[0].what();
807 return missingNodes1.
empty() && missingNodes2.
empty();
825 JLOG(ledgerJ.
fatal()) <<
"ledger is not sensible" << j;
843 if ((prevIndex & 0xff) == 0)
852 sle = std::make_shared<SLE>(k);
857 hashes =
static_cast<decltype(hashes)
>(sle->getFieldV256(
sfHashes));
861 assert(hashes.
size() <= 256);
878 sle = std::make_shared<SLE>(k);
883 hashes =
static_cast<decltype(hashes)
>(sle->getFieldV256(
sfHashes));
886 assert(hashes.
size() <= 256);
887 if (hashes.
size() == 256)
921 auto j = app.
journal(
"Ledger");
926 JLOG(j.debug()) <<
"Save aborted";
931 JLOG(j.trace()) <<
"saveValidatedLedger " << (
current ?
"" :
"fromAcquire ")
936 JLOG(j.fatal()) <<
"AH is zero: " <<
getJson({*ledger, {}});
944 JLOG(j.fatal()) <<
"saveAcceptedLedger: seq=" << seq
966 aLedger = std::make_shared<AcceptedLedger>(ledger, app);
973 JLOG(j.warn()) <<
"An accepted ledger was missing nodes";
983 static boost::format deleteLedger(
984 "DELETE FROM Ledgers WHERE LedgerSeq = %u;");
985 static boost::format deleteTrans1(
986 "DELETE FROM Transactions WHERE LedgerSeq = %u;");
987 static boost::format deleteTrans2(
988 "DELETE FROM AccountTransactions WHERE LedgerSeq = %u;");
989 static boost::format deleteAcctTrans(
990 "DELETE FROM AccountTransactions WHERE TransID = '%s';");
994 *db << boost::str(deleteLedger % seq);
1001 soci::transaction tr(*db);
1003 *db << boost::str(deleteTrans1 % seq);
1004 *db << boost::str(deleteTrans2 % seq);
1008 for (
auto const& [_, acceptedLedgerTx] : aLedger->getMap())
1019 auto const& accts = acceptedLedgerTx->getAffected();
1024 "INSERT INTO AccountTransactions "
1025 "(TransID, Account, LedgerSeq, TxnSeq) VALUES ");
1033 for (
auto const& account : accts)
1053 JLOG(j.trace()) <<
"ActTx: " << sql;
1058 JLOG(j.warn()) <<
"Transaction in ledger " << seq
1059 <<
" affects no accounts";
1060 JLOG(j.warn()) << acceptedLedgerTx->getTxn()->getJson(
1066 acceptedLedgerTx->getTxn()->getMetaSQL(
1067 seq, acceptedLedgerTx->getEscMeta()) +
1078 R
"sql(INSERT OR REPLACE INTO Ledgers
1079 (LedgerHash,LedgerSeq,PrevHash,TotalCoins,ClosingTime,PrevClosingTime,
1080 CloseTimeRes,CloseFlags,AccountSetHash,TransSetHash)
1082 (:ledgerHash,:ledgerSeq,:prevHash,:totalCoins,:closingTime,:prevClosingTime,
1083 :closeTimeRes,:closeFlags,:accountSetHash,:transSetHash);)sql");
1087 soci::transaction tr(*db);
1092 auto const closeTime =
1094 auto const parentCloseTime =
1096 auto const closeTimeResolution =
1102 *db << addLedger, soci::use(hash), soci::use(seq),
1103 soci::use(parentHash), soci::use(drops), soci::use(closeTime),
1104 soci::use(parentCloseTime), soci::use(closeTimeResolution),
1105 soci::use(closeFlags), soci::use(accountHash),
1136 JLOG(stream) <<
"Double pend save for " << ledger->
info().
seq;
1151 JLOG(stream) <<
"Pend save with seq in pending saves "
1158 char const*
const jobName{
1159 isCurrent ?
"Ledger::pendSave" :
"Ledger::pendOldSave"};
1162 if (!isSynchronous &&
1165 saveValidatedLedger(app, ledger, isCurrent);
1207 boost::optional<std::string> sLedgerHash, sPrevHash, sAccountHash,
1209 boost::optional<std::uint64_t> totDrops, closingTime, prevClosingTime,
1210 closeResolution, closeFlags, ledgerSeq64;
1214 "LedgerHash, PrevHash, AccountSetHash, TransSetHash, "
1216 "ClosingTime, PrevClosingTime, CloseTimeRes, CloseFlags,"
1217 "LedgerSeq from Ledgers " +
1220 *db << sql, soci::into(sLedgerHash), soci::into(sPrevHash),
1221 soci::into(sAccountHash), soci::into(sTransHash), soci::into(totDrops),
1222 soci::into(closingTime), soci::into(prevClosingTime),
1223 soci::into(closeResolution), soci::into(closeFlags),
1224 soci::into(ledgerSeq64);
1226 if (!db->got_data())
1229 JLOG(stream) <<
"Ledger not found: " << sqlSuffix;
1234 ledgerSeq = rangeCheckedCast<std::uint32_t>(ledgerSeq64.value_or(0));
1236 uint256 prevHash{}, accountHash{}, transHash{};
1238 (void)ledgerHash.
parseHex(*sLedgerHash);
1240 (void)prevHash.parseHex(*sPrevHash);
1242 (void)accountHash.parseHex(*sAccountHash);
1244 (void)transHash.parseHex(*sTransHash);
1253 info.
drops = totDrops.value_or(0);
1254 info.
closeTime = time_point{duration{closingTime.value_or(0)}};
1255 info.
parentCloseTime = time_point{duration{prevClosingTime.value_or(0)}};
1258 info.
seq = ledgerSeq;
1261 auto ledger = std::make_shared<Ledger>(
1278 Config
const& config,
1306 #ifdef RIPPLED_REPORTING
1307 auto log = app.
journal(
"Ledger");
1310 sql <<
"SELECT ledger_hash, prev_hash, account_set_hash, trans_set_hash, "
1311 "total_coins, closing_time, prev_closing_time, close_time_res, "
1312 "close_flags, ledger_seq FROM ledgers ";
1314 uint32_t expNumResults = 1;
1316 if (
auto ledgerSeq = std::get_if<uint32_t>(&whichLedger))
1320 else if (
auto ledgerHash = std::get_if<uint256>(&whichLedger))
1322 sql << (
"WHERE ledger_hash = \'\\x" +
strHex(*ledgerHash) +
"\'");
1328 expNumResults = minAndMax->second - minAndMax->first;
1336 sql << (
"ORDER BY ledger_seq desc LIMIT 1");
1340 JLOG(log.trace()) << __func__ <<
" : sql = " << sql.
str();
1342 auto res = PgQuery(app.getPgPool())(sql.
str().data());
1345 JLOG(log.error()) << __func__ <<
" : Postgres response is null - sql = "
1350 else if (res.status() != PGRES_TUPLES_OK)
1352 JLOG(log.error()) << __func__
1353 <<
" : Postgres response should have been "
1354 "PGRES_TUPLES_OK but instead was "
1355 << res.status() <<
" - msg = " << res.msg()
1356 <<
" - sql = " << sql.
str();
1361 JLOG(log.trace()) << __func__ <<
" Postgres result msg : " << res.msg();
1363 if (res.isNull() || res.ntuples() == 0)
1365 JLOG(log.debug()) << __func__
1366 <<
" : Ledger not found. sql = " << sql.
str();
1369 else if (res.ntuples() > 0)
1371 if (res.nfields() != 10)
1373 JLOG(log.error()) << __func__
1374 <<
" : Wrong number of fields in Postgres "
1375 "response. Expected 10, but got "
1376 << res.nfields() <<
" . sql = " << sql.
str();
1382 for (
size_t i = 0; i < res.ntuples(); ++i)
1384 char const* hash = res.c_str(i, 0);
1385 char const* prevHash = res.c_str(i, 1);
1386 char const* accountHash = res.c_str(i, 2);
1387 char const* txHash = res.c_str(i, 3);
1395 JLOG(log.trace()) << __func__ <<
" - Postgres response = " << hash
1396 <<
" , " << prevHash <<
" , " << accountHash <<
" , "
1397 << txHash <<
" , " << totalCoins <<
", " << closeTime
1398 <<
", " << parentCloseTime <<
", " << closeTimeRes
1399 <<
", " << closeFlags <<
", " << ledgerSeq
1400 <<
" - sql = " << sql.
str();
1401 JLOG(log.debug()) << __func__
1402 <<
" - Successfully fetched ledger with sequence = "
1403 << ledgerSeq <<
" from Postgres";
1415 info.
drops = totalCoins;
1416 info.
closeTime = time_point{duration{closeTime}};
1420 info.
seq = ledgerSeq;
1443 [&infos, &app](
auto&& arg) {
1447 assert(infos.
size() <= 1);
1452 auto ledger = std::make_shared<Ledger>(
1469 if (app.config().reporting())
1483 std::tie(ledger, std::ignore, std::ignore) =
1497 std::tie(ledger, std::ignore, std::ignore) =
1502 assert(!ledger || ledger->
info().
hash == ledgerHash);
1515 assert(infos.size() <= 1);
1517 return infos[0].hash;
1535 assert(infos.size() <= 1);
1538 ledgerHash = infos[0].hash;
1539 parentHash = infos[0].parentHash;
1559 for (
auto& info : infos)
1569 if (app.config().reporting())
1574 s <<
"WHERE LedgerSeq = " << ledgerIndex;
1575 std::tie(ledger, std::ignore, std::ignore) =
1586 if (app.config().reporting())
1591 s <<
"WHERE LedgerHash = '" << ledgerHash <<
"'";
1592 std::tie(ledger, std::ignore, std::ignore) =
1598 assert(!ledger || ledger->
info().
hash == ledgerHash);
1606 if (app.config().reporting())
1611 "SELECT LedgerHash FROM Ledgers INDEXED BY SeqLedger WHERE LedgerSeq='";
1617 auto db = app.getLedgerDB().checkoutDb();
1620 boost::optional<std::string> lh;
1621 *db << sql, soci::into(lh);
1623 if (!db->got_data() || !lh)
1631 (void)ret.parseHex(hash);
1642 if (app.config().reporting())
1644 ledgerIndex, ledgerHash, parentHash, app);
1645 auto db = app.getLedgerDB().checkoutDb();
1648 boost::optional<std::string> lhO, phO;
1650 *db <<
"SELECT LedgerHash,PrevHash FROM Ledgers "
1651 "INDEXED BY SeqLedger Where LedgerSeq = :ls;",
1652 soci::into(lhO), soci::into(phO), soci::use(ledgerIndex);
1656 auto stream = app.journal(
"Ledger").trace();
1657 JLOG(stream) <<
"Don't have ledger " << ledgerIndex;
1661 return ledgerHash.parseHex(*lhO) && parentHash.parseHex(*phO);
1667 if (app.config().reporting())
1672 "SELECT LedgerSeq,LedgerHash,PrevHash FROM Ledgers WHERE LedgerSeq >= ";
1674 sql.
append(
" AND LedgerSeq <= ");
1678 auto db = app.getLedgerDB().checkoutDb();
1684 boost::optional<std::string> ph;
1685 soci::statement st =
1686 (db->prepare << sql, soci::into(ls), soci::into(lh), soci::into(ph));
1692 ret[rangeCheckedCast<std::uint32_t>(ls)];
1693 (void)hashes.
first.parseHex(lh);
1695 (void)hashes.
second.parseHex(*ph);
1700 auto stream = app.journal(
"Ledger").warn();
1701 JLOG(stream) <<
"Null prev hash for ledger seq: " << ls;
1712 if (!app.config().reporting())
1715 Throw<std::runtime_error>(
1716 "flatFetchTransactions: not running in reporting mode");
1724 dynamic_cast<NodeStore::DatabaseNodeImp*
>(&(app.getNodeStore()));
1728 Throw<std::runtime_error>(
1729 "Called flatFetchTransactions but database is not DatabaseNodeImp");
1731 auto objs = nodeDb->fetchBatch(nodestoreHashes);
1734 JLOG(app.journal(
"Ledger").debug())
1735 <<
" Flat fetch time : " << ((
end - start).
count() / 1000000000.0)
1736 <<
" number of transactions " << nodestoreHashes.
size();
1737 assert(objs.size() == nodestoreHashes.
size());
1738 for (
size_t i = 0; i < objs.size(); ++i)
1740 uint256& nodestoreHash = nodestoreHashes[i];
1741 auto& obj = objs[i];
1745 makeSlice(obj->getData()), SHAMapHash{nodestoreHash});
1749 Throw<std::runtime_error>(
1750 "flatFetchTransactions : Error making SHAMap node");
1752 auto item = (
static_cast<SHAMapLeafNode*
>(node.get()))->peekItem();
1756 Throw<std::runtime_error>(
1757 "flatFetchTransactions : Error reading SHAMap node");
1760 if (!txnPlusMeta.first || !txnPlusMeta.second)
1763 Throw<std::runtime_error>(
1764 "flatFetchTransactions : Error deserializing SHAMap node");
1766 txns.push_back(std::move(txnPlusMeta));
1771 Throw<std::runtime_error>(
1772 "flatFetchTransactions : Containing SHAMap node not found");
1781 if (!app.config().reporting())
1787 #ifdef RIPPLED_REPORTING
1789 auto log = app.journal(
"Ledger");
1792 "SELECT nodestore_hash"
1793 " FROM transactions "
1794 " WHERE ledger_seq = " +
1796 auto res = PgQuery(app.getPgPool())(query.
c_str());
1800 JLOG(
log.error()) << __func__
1801 <<
" : Postgres response is null - query = " << query;
1805 else if (res.status() != PGRES_TUPLES_OK)
1807 JLOG(
log.error()) << __func__
1808 <<
" : Postgres response should have been "
1809 "PGRES_TUPLES_OK but instead was "
1810 << res.status() <<
" - msg = " << res.msg()
1811 <<
" - query = " << query;
1816 JLOG(
log.trace()) << __func__ <<
" Postgres result msg : " << res.msg();
1818 if (res.isNull() || res.ntuples() == 0)
1820 JLOG(
log.debug()) << __func__
1821 <<
" : Ledger not found. query = " << query;
1824 else if (res.ntuples() > 0)
1826 if (res.nfields() != 1)
1828 JLOG(
log.error()) << __func__
1829 <<
" : Wrong number of fields in Postgres "
1830 "response. Expected 1, but got "
1831 << res.nfields() <<
" . query = " << query;
1837 JLOG(
log.trace()) << __func__ <<
" : result = " << res.c_str()
1838 <<
" : query = " << query;
1839 for (
size_t i = 0; i < res.ntuples(); ++i)
1841 char const* nodestoreHash = res.
c_str(i, 0);
1843 if (!hash.parseHex(nodestoreHash + 2))
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
std::tuple< std::shared_ptr< Ledger >, std::uint32_t, uint256 > loadLedgerHelper(std::string const &sqlSuffix, Application &app, bool acquire)
sles_iter_impl(SHAMap::const_iterator iter)
std::unique_ptr< sles_type::iter_base > slesBegin() const override
virtual Family & getNodeFamily()=0
bool addSLE(SLE const &sle)
bool isFlagLedger(LedgerIndex seq)
Returns true if the given ledgerIndex is a flag ledgerIndex.
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
@ ledgerMaster
ledger master data for signing
std::shared_ptr< SHAMap > txMap_
static std::shared_ptr< Ledger > loadByHashPostgres(uint256 const &ledgerHash, Application &app)
void setImmutable(Config const &config, bool rehash=true)
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
const SF_UINT32 sfReserveBase
A pair of SHAMap key and LedgerEntryType.
virtual TaggedCache< uint256, AcceptedLedger > & getAcceptedLedgerCache()=0
bool isVotingLedger() const
Returns true if the ledger directly precedes a flag ledger.
std::optional< uint256 > succ(uint256 const &key, std::optional< uint256 > const &last=std::nullopt) const override
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Keylet const & amendments() noexcept
The index of the amendment table.
SHAMapHash getHash() const
std::shared_ptr< Ledger > loadByIndex(std::uint32_t ledgerIndex, Application &app, bool acquire)
@ txNode
transaction plus metadata
Stream trace() const
Severity stream access functions.
std::unique_ptr< sles_type::iter_base > slesEnd() const override
const SF_UINT32 sfFirstLedgerSequence
bool pending(LedgerIndex seq)
Return true if a ledger is in the progress of being saved.
constexpr value_type drops() const
Returns the number of drops.
const SF_UINT32 sfSequence
void addRaw(LedgerInfo const &info, Serializer &s, bool includeHash)
sles_type::value_type dereference() const override
Keylet const & skip() noexcept
The index of the "short" skip list.
std::tuple< std::shared_ptr< Ledger >, std::uint32_t, uint256 > getLatestLedger(Application &app)
constexpr std::uint32_t FLAG_LEDGER_INTERVAL
Serializer getSerializer() const
bool exists(Keylet const &k) const override
Determine if a state item exists.
bool equal(base_type const &impl) const override
void push_back(STObject const &object)
std::shared_ptr< SLE > peek(Keylet const &k) const
std::chrono::time_point< Clock, Duration > roundCloseTime(std::chrono::time_point< Clock, Duration > closeTime, std::chrono::duration< Rep, Period > closeResolution)
Calculates the close time for a ledger, given a close time resolution.
txs_iter_impl & operator=(txs_iter_impl const &)=delete
bool walkLedger(beast::Journal j) const
static std::string const & getMetaSQLInsertReplaceHeader()
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
virtual void store(NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t ledgerSeq)=0
Store the object.
void rawTxInsert(uint256 const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData) override
void setFieldVL(SField const &field, Blob const &)
bool startWork(LedgerIndex seq)
Start working on a ledger.
txs_iter_impl(bool metadata, SHAMap::const_iterator iter)
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
void updateNegativeUNL()
update the Negative UNL ledger component.
virtual void missingNode(std::uint32_t refNum)=0
static void finishLoadByIndexOrHash(std::shared_ptr< Ledger > const &ledger, Config const &config, beast::Journal j)
static std::tuple< std::shared_ptr< Ledger >, std::uint32_t, uint256 > loadLedgerHelperPostgres(std::variant< std::monostate, uint256, uint32_t > const &whichLedger, Application &app)
std::shared_ptr< STTx const > deserializeTx(SHAMapItem const &item)
Deserialize a SHAMapItem containing a single STTx.
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
virtual AccountIDCache const & accountIDCache() const =0
constexpr XRPAmount INITIAL_XRP
Configure the native currency.
uint256 getHashByIndex(std::uint32_t ledgerIndex, Application &app)
std::shared_ptr< SLE const > value_type
std::optional< PublicKey > validatorToDisable() const
get the to be disabled validator's master public key if any
std::unique_ptr< txs_type::iter_base > txsEnd() const override
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
NetClock::time_point closeTime
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
uint256 const & key() const
Returns the 'key' (or 'index') of this item.
static std::shared_ptr< Ledger > loadByIndexPostgres(std::uint32_t ledgerIndex, Application &app)
LedgerInfo const & info() const override
Returns information about the ledger.
T time_since_epoch(T... args)
bool txExists(uint256 const &key) const override
static bool saveValidatedLedger(Application &app, std::shared_ptr< Ledger const > const &ledger, bool current)
std::shared_ptr< Ledger > loadByHash(uint256 const &ledgerHash, Application &app, bool acquire)
LockedSociSession checkoutDb()
void setAccepted(NetClock::time_point closeTime, NetClock::duration closeResolution, bool correctCloseTime, Config const &config)
void failedSave(std::uint32_t seq, uint256 const &hash)
virtual LedgerMaster & getLedgerMaster()=0
Keylet account(AccountID const &id) noexcept
AccountID root.
virtual PendingSaves & pendingSaves()=0
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > deserializeTxPlusMeta(SHAMapItem const &item)
Deserialize a SHAMapItem containing STTx + STObject metadata.
uint256 calculateLedgerHash(LedgerInfo const &info)
static constexpr FeeUnit32 TRANSACTION_FEE_BASE
std::unique_ptr< base_type > copy() const override
void Rethrow()
Rethrow the exception currently being handled.
const SF_UINT32 sfReserveIncrement
virtual Config & config()=0
bool isCurrent(ValidationParms const &p, NetClock::time_point now, NetClock::time_point signTime, NetClock::time_point seenTime)
Whether a validation is still current.
SHAMap::const_iterator iter_
SHAMap const & stateMap() const
XRPAmount FEE_OWNER_RESERVE
AccountID calcAccountID(PublicKey const &pk)
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
SHAMap::const_iterator iter_
bool isFlagLedger() const
Returns true if the ledger is a flag ledger.
bool equal(base_type const &impl) const override
sles_iter_impl & operator=(sles_iter_impl const &)=delete
virtual JobQueue & getJobQueue()=0
const SF_VL sfValidatorToDisable
XRPAmount FEE_ACCOUNT_RESERVE
Slice slice() const noexcept
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
bool assertSensible(beast::Journal ledgerJ) const
@ current
This was a new validation and was added.
static std::vector< LedgerInfo > loadLedgerInfosPostgres(std::variant< std::monostate, uint256, uint32_t, std::pair< uint32_t, uint32_t >> const &whichLedger, Application &app)
void finishWork(LedgerIndex seq)
Finish working on a ledger.
@ transactionID
transaction plus signature to give transaction ID
A generic endpoint for log messages.
virtual DatabaseCon & getLedgerDB()=0
static uint256 getHashByIndexPostgres(std::uint32_t ledgerIndex, Application &app)
std::optional< PublicKey > validatorToReEnable() const
get the to be re-enabled validator's master public key if any
bool shouldWork(LedgerIndex seq, bool isSynchronous)
Check if a ledger should be dispatched.
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
static std::shared_ptr< SHAMapTreeNode > makeFromPrefix(Slice rawNode, SHAMapHash const &hash)
SHAMap const & txMap() const
const SF_UINT64 sfBaseFee
bool getCloseAgree(LedgerInfo const &info)
const SF_VECTOR256 sfHashes
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
std::unique_ptr< txs_type::iter_base > txsBegin() const override
bool inLedger(uint256 const &hash, std::uint32_t ledger)
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::unordered_set< uint256, beast::uhash<> > features
virtual NodeStore::Database & getNodeStore()=0
virtual beast::Journal journal(std::string const &name)=0
bool setup(Config const &config)
void emplace_back(Args &&... args)
LedgerIndex seq() const
Returns the sequence number of the base ledger.
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
NetClock::duration closeTimeResolution
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
const create_genesis_t create_genesis
std::shared_ptr< SHAMap > stateMap_
const SField sfDisabledValidator
bool open() const override
Returns true if this reflects an open ledger.
const SF_AMOUNT sfBalance
const SF_UINT32 sfReferenceFeeUnits
int addVL(Blob const &vector)
hash_set< PublicKey > negativeUNL() const
get Negative UNL validators' master public keys
Rules controlling protocol behavior.
Keylet const & fees() noexcept
The (fixed) index of the object containing the ledger fees.
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
bool getHashesByIndex(std::uint32_t ledgerIndex, uint256 &ledgerHash, uint256 &parentHash, Application &app)
constexpr auto ledgerGenesisTimeResolution
Close time resolution in genesis ledger.
bool check(STLedgerEntry const &) const
Returns true if the SLE matches the type.
const SF_ACCOUNT sfAccount
int add32(std::uint32_t i)
Information about the notional ledger backing the view.
std::string strHex(FwdIt begin, FwdIt end)
std::chrono::duration< rep, period > duration
static bool getHashesByIndexPostgres(std::uint32_t ledgerIndex, uint256 &ledgerHash, uint256 &parentHash, Application &app)
uint256 const & as_uint256() const
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
std::chrono::duration< Rep, Period > getNextLedgerTimeResolution(std::chrono::duration< Rep, Period > previousResolution, bool previousAgree, Seq ledgerSeq)
Calculates the close time resolution for the specified ledger.
uint256 rawTxInsertWithHash(uint256 const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData)
const SF_UINT32 sfLastLedgerSequence
constexpr auto ledgerDefaultTimeResolution
Initial resolution of ledger close time.
Keylet const & negativeUNL() noexcept
The (fixed) index of the object containing the ledger negativeUNL.
txs_type::value_type dereference() const override
bool pendSaveValidated(Application &app, std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
Save, or arrange to save, a fully-validated ledger Returns false on error.
Ledger(Ledger const &)=delete
std::optional< digest_type > digest(key_type const &key) const override
Return the digest associated with the key.
void increment() override
std::chrono::time_point< NetClock > time_point
void setFieldU32(SField const &field, std::uint32_t)
std::unique_ptr< base_type > copy() const override
const SField sfDisabledValidators
virtual HashRouter & getHashRouter()=0
void increment() override
bool setFlags(uint256 const &key, int flags)
Set the flags on a hash.
Slice getSlice(std::size_t bytes)
const SF_VECTOR256 sfAmendments
static const std::uint32_t sLCF_NoConsensusTime
virtual DatabaseCon & getTxnDB()=0
void open(soci::session &s, BasicConfig const &config, std::string const &dbName)
Open a soci session.
const SF_VL sfValidatorToReEnable
std::string toBase58(AccountID const &) const
Return ripple::toBase58 for the AccountID.
NetClock::time_point parentCloseTime
std::vector< std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > > flatFetchTransactions(Application &app, std::vector< uint256 > &nodestoreHashes)
virtual TransactionMaster & getMasterTransaction()=0