mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Refactor Ledger and support classes:
This performs a deep refactor on the Ledger class and its supporting classes, in preparation for the move to shared_ptr<SLE const> in places where the SLE is immutable and we are currently using shared_ptr<SLE>. Member functions are converted to free functions, the SLECache is an explicit parameter, one line convenience functions are removed to streamline the interface. Some callers are changed to use <SLE const> instead of <SLE> SLECache: * Moved to its own header file RippleState: * Remove unused functions * Store the SLE as const * Simplify callers AccountState: * Remove unused members * Simplify existing members Ledger: * Replace writeBack with insert and update * Remove unused functions * Remove LedgerStateParams * Move getLastFullLedger to Application * add entryCacheI, exists, fetch, erase * Use boost::optional where it makes sense * Make member functions free functions Free functions: * fetch: cache-aware SLE retrieval * forEachItem, forEachItemAfter * (various)
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include <ripple/app/ledger/AcceptedLedger.h>
|
||||
#include <ripple/app/ledger/InboundLedgers.h>
|
||||
#include <ripple/app/ledger/LedgerMaster.h>
|
||||
#include <ripple/app/ledger/LedgerToJson.h>
|
||||
#include <ripple/app/ledger/OrderBookDB.h>
|
||||
#include <ripple/app/ledger/PendingSaves.h>
|
||||
#include <ripple/app/main/CollectorManager.h>
|
||||
@@ -57,6 +58,7 @@
|
||||
#include <ripple/nodestore/DummyScheduler.h>
|
||||
#include <ripple/nodestore/Manager.h>
|
||||
#include <ripple/overlay/make_Overlay.h>
|
||||
#include <ripple/protocol/Indexes.h>
|
||||
#include <ripple/protocol/STParsedJSON.h>
|
||||
#include <ripple/rpc/Manager.h>
|
||||
#include <ripple/server/make_ServerHandler.h>
|
||||
@@ -1041,6 +1043,7 @@ public:
|
||||
private:
|
||||
void updateTables ();
|
||||
void startNewLedger ();
|
||||
Ledger::pointer getLastFullLedger();
|
||||
bool loadOldLedger (
|
||||
std::string const& ledgerID, bool replay, bool isFilename);
|
||||
|
||||
@@ -1062,10 +1065,10 @@ void ApplicationImp::startNewLedger ()
|
||||
|
||||
{
|
||||
Ledger::pointer firstLedger = std::make_shared<Ledger> (rootAddress, SYSTEM_CURRENCY_START);
|
||||
assert (firstLedger->getAccountState (rootAddress));
|
||||
assert (firstLedger->exists(getAccountRootIndex(rootAddress.getAccountID())));
|
||||
// TODO(david): Add any default amendments
|
||||
// TODO(david): Set default fee/reserve
|
||||
firstLedger->updateHash ();
|
||||
firstLedger->getHash(); // updates the hash
|
||||
firstLedger->setClosed ();
|
||||
firstLedger->setAccepted ();
|
||||
m_ledgerMaster->pushLedger (firstLedger);
|
||||
@@ -1074,11 +1077,58 @@ void ApplicationImp::startNewLedger ()
|
||||
secondLedger->setClosed ();
|
||||
secondLedger->setAccepted ();
|
||||
m_ledgerMaster->pushLedger (secondLedger, std::make_shared<Ledger> (true, std::ref (*secondLedger)));
|
||||
assert (secondLedger->getAccountState (rootAddress));
|
||||
assert (secondLedger->exists(getAccountRootIndex(rootAddress.getAccountID())));
|
||||
m_networkOPs->setLastCloseTime (secondLedger->getCloseTimeNC ());
|
||||
}
|
||||
}
|
||||
|
||||
Ledger::pointer
|
||||
ApplicationImp::getLastFullLedger()
|
||||
{
|
||||
try
|
||||
{
|
||||
Ledger::pointer ledger;
|
||||
std::uint32_t ledgerSeq;
|
||||
uint256 ledgerHash;
|
||||
std::tie (ledger, ledgerSeq, ledgerHash) =
|
||||
loadLedgerHelper ("order by LedgerSeq desc limit 1");
|
||||
|
||||
if (!ledger)
|
||||
return ledger;
|
||||
|
||||
ledger->setClosed ();
|
||||
|
||||
if (getApp().getOPs ().haveLedger (ledgerSeq))
|
||||
{
|
||||
ledger->setAccepted ();
|
||||
ledger->setValidated ();
|
||||
}
|
||||
|
||||
if (ledger->getHash () != ledgerHash)
|
||||
{
|
||||
if (ShouldLog (lsERROR, Ledger))
|
||||
{
|
||||
WriteLog (lsERROR, Ledger) << "Failed on ledger";
|
||||
Json::Value p;
|
||||
addJson (p, {*ledger, LedgerFill::full});
|
||||
WriteLog (lsERROR, Ledger) << p;
|
||||
}
|
||||
|
||||
assert (false);
|
||||
return Ledger::pointer ();
|
||||
}
|
||||
|
||||
WriteLog (lsTRACE, Ledger) << "Loaded ledger: " << ledgerHash;
|
||||
return ledger;
|
||||
}
|
||||
catch (SHAMapMissingNode& sn)
|
||||
{
|
||||
WriteLog (lsWARNING, Ledger)
|
||||
<< "Database contains ledger with missing nodes: " << sn;
|
||||
return Ledger::pointer ();
|
||||
}
|
||||
}
|
||||
|
||||
bool ApplicationImp::loadOldLedger (
|
||||
std::string const& ledgerID, bool replay, bool isFileName)
|
||||
{
|
||||
@@ -1185,7 +1235,9 @@ bool ApplicationImp::loadOldLedger (
|
||||
}
|
||||
}
|
||||
else if (ledgerID.empty () || (ledgerID == "latest"))
|
||||
loadLedger = Ledger::getLastFullLedger ();
|
||||
{
|
||||
loadLedger = getLastFullLedger ();
|
||||
}
|
||||
else if (ledgerID.length () == 64)
|
||||
{
|
||||
// by hash
|
||||
|
||||
Reference in New Issue
Block a user