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,
384 return std::make_shared<STTx const>(sit);
395 result.
first = std::make_shared<STTx const>(s);
419 boost::optional<uint256>
425 if (last && item->key() >= last)
433 if (k.
key == beast::zero)
441 auto sle = std::make_shared<SLE>(
442 SerialIter{item->data(), item->size()}, 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(), std::move(ss))))
537 LogicError(
"Ledger::rawInsert: key already exists");
547 std::make_shared<SHAMapItem const>(sle->key(), std::move(ss))))
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, std::move(s))))
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, std::move(s));
650 auto sle = std::make_shared<SLE>(
651 SerialIter{value->data(), value->size()}, value->key());
665 for (
auto const& n : nUnlData)
683 boost::optional<PublicKey>
698 boost::optional<PublicKey>
723 if (!hasToDisable && !hasToReEnable)
730 for (
auto v : oldNUnl)
732 if (hasToReEnable && v.isFieldPresent(
sfPublicKey) &&
748 if (!newNUnl.
empty())
781 if (!missingNodes1.
empty())
783 if (
auto stream = j.
info())
785 stream << missingNodes1.
size() <<
" missing account node(s)";
786 stream <<
"First: " << missingNodes1[0].what();
798 txMap_->walkMap(missingNodes2, 32);
801 if (!missingNodes2.
empty())
803 if (
auto stream = j.
info())
805 stream << missingNodes2.
size() <<
" missing transaction node(s)";
806 stream <<
"First: " << missingNodes2[0].what();
809 return missingNodes1.
empty() && missingNodes2.
empty();
827 JLOG(ledgerJ.
fatal()) <<
"ledger is not sensible" << j;
845 if ((prevIndex & 0xff) == 0)
854 sle = std::make_shared<SLE>(k);
859 hashes =
static_cast<decltype(hashes)
>(sle->getFieldV256(
sfHashes));
863 assert(hashes.
size() <= 256);
880 sle = std::make_shared<SLE>(k);
885 hashes =
static_cast<decltype(hashes)
>(sle->getFieldV256(
sfHashes));
888 assert(hashes.
size() <= 256);
889 if (hashes.
size() == 256)
923 auto j = app.
journal(
"Ledger");
928 JLOG(j.debug()) <<
"Save aborted";
933 JLOG(j.trace()) <<
"saveValidatedLedger " << (
current ?
"" :
"fromAcquire ")
938 JLOG(j.fatal()) <<
"AH is zero: " <<
getJson({*ledger, {}});
946 JLOG(j.fatal()) <<
"saveAcceptedLedger: seq=" << seq
968 aLedger = std::make_shared<AcceptedLedger>(ledger, app);
975 JLOG(j.warn()) <<
"An accepted ledger was missing nodes";
985 static boost::format deleteLedger(
986 "DELETE FROM Ledgers WHERE LedgerSeq = %u;");
987 static boost::format deleteTrans1(
988 "DELETE FROM Transactions WHERE LedgerSeq = %u;");
989 static boost::format deleteTrans2(
990 "DELETE FROM AccountTransactions WHERE LedgerSeq = %u;");
991 static boost::format deleteAcctTrans(
992 "DELETE FROM AccountTransactions WHERE TransID = '%s';");
996 *db << boost::str(deleteLedger % seq);
1003 soci::transaction tr(*db);
1005 *db << boost::str(deleteTrans1 % seq);
1006 *db << boost::str(deleteTrans2 % seq);
1010 for (
auto const& [_, acceptedLedgerTx] : aLedger->getMap())
1021 auto const& accts = acceptedLedgerTx->getAffected();
1026 "INSERT INTO AccountTransactions "
1027 "(TransID, Account, LedgerSeq, TxnSeq) VALUES ");
1035 for (
auto const& account : accts)
1055 JLOG(j.trace()) <<
"ActTx: " << sql;
1060 JLOG(j.warn()) <<
"Transaction in ledger " << seq
1061 <<
" affects no accounts";
1062 JLOG(j.warn()) << acceptedLedgerTx->getTxn()->getJson(
1068 acceptedLedgerTx->getTxn()->getMetaSQL(
1069 seq, acceptedLedgerTx->getEscMeta()) +
1080 R
"sql(INSERT OR REPLACE INTO Ledgers
1081 (LedgerHash,LedgerSeq,PrevHash,TotalCoins,ClosingTime,PrevClosingTime,
1082 CloseTimeRes,CloseFlags,AccountSetHash,TransSetHash)
1084 (:ledgerHash,:ledgerSeq,:prevHash,:totalCoins,:closingTime,:prevClosingTime,
1085 :closeTimeRes,:closeFlags,:accountSetHash,:transSetHash);)sql");
1089 soci::transaction tr(*db);
1094 auto const closeTime =
1096 auto const parentCloseTime =
1098 auto const closeTimeResolution =
1104 *db << addLedger, soci::use(hash), soci::use(seq),
1105 soci::use(parentHash), soci::use(drops), soci::use(closeTime),
1106 soci::use(parentCloseTime), soci::use(closeTimeResolution),
1107 soci::use(closeFlags), soci::use(accountHash),
1138 JLOG(stream) <<
"Double pend save for " << ledger->
info().
seq;
1153 JLOG(stream) <<
"Pend save with seq in pending saves "
1160 char const*
const jobName{
1161 isCurrent ?
"Ledger::pendSave" :
"Ledger::pendOldSave"};
1164 if (!isSynchronous &&
1167 saveValidatedLedger(app, ledger, isCurrent);
1208 boost::optional<std::string> sLedgerHash, sPrevHash, sAccountHash,
1210 boost::optional<std::uint64_t> totDrops, closingTime, prevClosingTime,
1211 closeResolution, closeFlags, ledgerSeq64;
1215 "LedgerHash, PrevHash, AccountSetHash, TransSetHash, "
1217 "ClosingTime, PrevClosingTime, CloseTimeRes, CloseFlags,"
1218 "LedgerSeq from Ledgers " +
1221 *db << sql, soci::into(sLedgerHash), soci::into(sPrevHash),
1222 soci::into(sAccountHash), soci::into(sTransHash), soci::into(totDrops),
1223 soci::into(closingTime), soci::into(prevClosingTime),
1224 soci::into(closeResolution), soci::into(closeFlags),
1225 soci::into(ledgerSeq64);
1227 if (!db->got_data())
1230 JLOG(stream) <<
"Ledger not found: " << sqlSuffix;
1235 ledgerSeq = rangeCheckedCast<std::uint32_t>(ledgerSeq64.value_or(0));
1237 uint256 prevHash{}, accountHash{}, transHash{};
1239 (void)ledgerHash.
parseHex(*sLedgerHash);
1241 (void)prevHash.parseHex(*sPrevHash);
1243 (void)accountHash.parseHex(*sAccountHash);
1245 (void)transHash.parseHex(*sTransHash);
1254 info.
drops = totDrops.value_or(0);
1255 info.
closeTime = time_point{duration{closingTime.value_or(0)}};
1256 info.
parentCloseTime = time_point{duration{prevClosingTime.value_or(0)}};
1259 info.
seq = ledgerSeq;
1262 auto ledger = std::make_shared<Ledger>(
1279 Config
const& config,
1307 #ifdef RIPPLED_REPORTING
1308 auto log = app.
journal(
"Ledger");
1311 sql <<
"SELECT ledger_hash, prev_hash, account_set_hash, trans_set_hash, "
1312 "total_coins, closing_time, prev_closing_time, close_time_res, "
1313 "close_flags, ledger_seq FROM ledgers ";
1315 uint32_t expNumResults = 1;
1317 if (
auto ledgerSeq = std::get_if<uint32_t>(&whichLedger))
1321 else if (
auto ledgerHash = std::get_if<uint256>(&whichLedger))
1323 sql << (
"WHERE ledger_hash = \'\\x" +
strHex(*ledgerHash) +
"\'");
1329 expNumResults = minAndMax->second - minAndMax->first;
1337 sql << (
"ORDER BY ledger_seq desc LIMIT 1");
1341 JLOG(log.trace()) << __func__ <<
" : sql = " << sql.
str();
1343 auto res = PgQuery(app.getPgPool())(sql.
str().data());
1346 JLOG(log.error()) << __func__ <<
" : Postgres response is null - sql = "
1351 else if (res.status() != PGRES_TUPLES_OK)
1353 JLOG(log.error()) << __func__
1354 <<
" : Postgres response should have been "
1355 "PGRES_TUPLES_OK but instead was "
1356 << res.status() <<
" - msg = " << res.msg()
1357 <<
" - sql = " << sql.
str();
1362 JLOG(log.trace()) << __func__ <<
" Postgres result msg : " << res.msg();
1364 if (res.isNull() || res.ntuples() == 0)
1366 JLOG(log.debug()) << __func__
1367 <<
" : Ledger not found. sql = " << sql.
str();
1370 else if (res.ntuples() > 0)
1372 if (res.nfields() != 10)
1374 JLOG(log.error()) << __func__
1375 <<
" : Wrong number of fields in Postgres "
1376 "response. Expected 10, but got "
1377 << res.nfields() <<
" . sql = " << sql.
str();
1383 for (
size_t i = 0; i < res.ntuples(); ++i)
1385 char const* hash = res.c_str(i, 0);
1386 char const* prevHash = res.c_str(i, 1);
1387 char const* accountHash = res.c_str(i, 2);
1388 char const* txHash = res.c_str(i, 3);
1396 JLOG(log.trace()) << __func__ <<
" - Postgres response = " << hash
1397 <<
" , " << prevHash <<
" , " << accountHash <<
" , "
1398 << txHash <<
" , " << totalCoins <<
", " << closeTime
1399 <<
", " << parentCloseTime <<
", " << closeTimeRes
1400 <<
", " << closeFlags <<
", " << ledgerSeq
1401 <<
" - sql = " << sql.
str();
1402 JLOG(log.debug()) << __func__
1403 <<
" - Successfully fetched ledger with sequence = "
1404 << ledgerSeq <<
" from Postgres";
1416 info.
drops = totalCoins;
1417 info.
closeTime = time_point{duration{closeTime}};
1421 info.
seq = ledgerSeq;
1444 [&infos, &app](
auto&& arg) {
1448 assert(infos.
size() <= 1);
1453 auto ledger = std::make_shared<Ledger>(
1470 if (app.config().reporting())
1484 std::tie(ledger, std::ignore, std::ignore) =
1498 std::tie(ledger, std::ignore, std::ignore) =
1503 assert(!ledger || ledger->
info().
hash == ledgerHash);
1518 assert(infos.size() <= 1);
1520 return infos[0].hash;
1538 assert(infos.size() <= 1);
1541 ledgerHash = infos[0].hash;
1542 parentHash = infos[0].parentHash;
1562 for (
auto& info : infos)
1572 if (app.config().reporting())
1577 s <<
"WHERE LedgerSeq = " << ledgerIndex;
1578 std::tie(ledger, std::ignore, std::ignore) =
1589 if (app.config().reporting())
1594 s <<
"WHERE LedgerHash = '" << ledgerHash <<
"'";
1595 std::tie(ledger, std::ignore, std::ignore) =
1601 assert(!ledger || ledger->
info().
hash == ledgerHash);
1609 if (app.config().reporting())
1614 "SELECT LedgerHash FROM Ledgers INDEXED BY SeqLedger WHERE LedgerSeq='";
1620 auto db = app.getLedgerDB().checkoutDb();
1622 boost::optional<std::string> lh;
1623 *db << sql, soci::into(lh);
1625 if (!db->got_data() || !lh)
1633 (void)ret.parseHex(hash);
1644 if (app.config().reporting())
1646 ledgerIndex, ledgerHash, parentHash, app);
1647 auto db = app.getLedgerDB().checkoutDb();
1649 boost::optional<std::string> lhO, phO;
1651 *db <<
"SELECT LedgerHash,PrevHash FROM Ledgers "
1652 "INDEXED BY SeqLedger Where LedgerSeq = :ls;",
1653 soci::into(lhO), soci::into(phO), soci::use(ledgerIndex);
1657 auto stream = app.journal(
"Ledger").trace();
1658 JLOG(stream) <<
"Don't have ledger " << ledgerIndex;
1662 return ledgerHash.parseHex(*lhO) && parentHash.parseHex(*phO);
1668 if (app.config().reporting())
1673 "SELECT LedgerSeq,LedgerHash,PrevHash FROM Ledgers WHERE LedgerSeq >= ";
1675 sql.
append(
" AND LedgerSeq <= ");
1679 auto db = app.getLedgerDB().checkoutDb();
1683 boost::optional<std::string> ph;
1684 soci::statement st =
1685 (db->prepare << sql, soci::into(ls), soci::into(lh), soci::into(ph));
1691 ret[rangeCheckedCast<std::uint32_t>(ls)];
1692 (void)hashes.
first.parseHex(lh);
1694 (void)hashes.
second.parseHex(*ph);
1699 auto stream = app.journal(
"Ledger").warn();
1700 JLOG(stream) <<
"Null prev hash for ledger seq: " << ls;
1711 if (!app.config().reporting())
1714 Throw<std::runtime_error>(
1715 "flatFetchTransactions: not running in reporting mode");
1723 dynamic_cast<NodeStore::DatabaseNodeImp*
>(&(app.getNodeStore()));
1727 Throw<std::runtime_error>(
1728 "Called flatFetchTransactions but database is not DatabaseNodeImp");
1730 auto objs = nodeDb->fetchBatch(nodestoreHashes);
1733 JLOG(app.journal(
"Ledger").debug())
1734 <<
" Flat fetch time : " << ((
end - start).
count() / 1000000000.0)
1735 <<
" number of transactions " << nodestoreHashes.
size();
1736 assert(objs.size() == nodestoreHashes.
size());
1737 for (
size_t i = 0; i < objs.size(); ++i)
1739 uint256& nodestoreHash = nodestoreHashes[i];
1740 auto& obj = objs[i];
1744 makeSlice(obj->getData()), SHAMapHash{nodestoreHash});
1748 Throw<std::runtime_error>(
1749 "flatFetchTransactions : Error making SHAMap node");
1751 auto item = (
static_cast<SHAMapLeafNode*
>(node.get()))->peekItem();
1755 Throw<std::runtime_error>(
1756 "flatFetchTransactions : Error reading SHAMap node");
1759 if (!txnPlusMeta.first || !txnPlusMeta.second)
1762 Throw<std::runtime_error>(
1763 "flatFetchTransactions : Error deserializing SHAMap node");
1765 txns.push_back(std::move(txnPlusMeta));
1770 Throw<std::runtime_error>(
1771 "flatFetchTransactions : Containing SHAMap node not found");
1780 if (!app.config().reporting())
1786 #ifdef RIPPLED_REPORTING
1788 auto log = app.journal(
"Ledger");
1791 "SELECT nodestore_hash"
1792 " FROM transactions "
1793 " WHERE ledger_seq = " +
1795 auto res = PgQuery(app.getPgPool())(query.
c_str());
1799 JLOG(
log.error()) << __func__
1800 <<
" : Postgres response is null - query = " << query;
1804 else if (res.status() != PGRES_TUPLES_OK)
1806 JLOG(
log.error()) << __func__
1807 <<
" : Postgres response should have been "
1808 "PGRES_TUPLES_OK but instead was "
1809 << res.status() <<
" - msg = " << res.msg()
1810 <<
" - query = " << query;
1815 JLOG(
log.trace()) << __func__ <<
" Postgres result msg : " << res.msg();
1817 if (res.isNull() || res.ntuples() == 0)
1819 JLOG(
log.debug()) << __func__
1820 <<
" : Ledger not found. query = " << query;
1823 else if (res.ntuples() > 0)
1825 if (res.nfields() != 1)
1827 JLOG(
log.error()) << __func__
1828 <<
" : Wrong number of fields in Postgres "
1829 "response. Expected 1, but got "
1830 << res.nfields() <<
" . query = " << query;
1836 JLOG(
log.trace()) << __func__ <<
" : result = " << res.c_str()
1837 <<
" : query = " << query;
1838 for (
size_t i = 0; i < res.ntuples(); ++i)
1840 char const* nodestoreHash = res.
c_str(i, 0);
1842 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.
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.
boost::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
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.
std::string to_string(ListDisposition disposition)
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::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
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)
boost::optional< PublicKey > validatorToReEnable() const
get the to be re-enabled validator's master public key if any
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
boost::optional< PublicKey > validatorToDisable() const
get the to be disabled validator's master public key if any
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
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)
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 parseHex(std::string_view sv)
Parse a hex string into a base_uint.
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.
boost::optional< uint256 > succ(uint256 const &key, boost::optional< uint256 > const &last=boost::none) const override
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.
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
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
boost::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