mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 14:35:52 +00:00
Refactor computation of Ledger hash
This commit is contained in:
@@ -200,8 +200,7 @@ Ledger::Ledger (Ledger const& ledger,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a new open ledger that follows this one
|
// Create a new open ledger that follows this one
|
||||||
Ledger::Ledger (bool /* dummy */,
|
Ledger::Ledger (open_ledger_t, Ledger const& prevLedger)
|
||||||
Ledger& prevLedger)
|
|
||||||
: mImmutable (false)
|
: mImmutable (false)
|
||||||
, txMap_ (std::make_shared <SHAMap> (SHAMapType::TRANSACTION,
|
, txMap_ (std::make_shared <SHAMap> (SHAMapType::TRANSACTION,
|
||||||
getApp().family(), deprecatedLogs().journal("SHAMap")))
|
getApp().family(), deprecatedLogs().journal("SHAMap")))
|
||||||
@@ -216,28 +215,17 @@ Ledger::Ledger (bool /* dummy */,
|
|||||||
info_.hash = prevLedger.info().hash + uint256(1);
|
info_.hash = prevLedger.info().hash + uint256(1);
|
||||||
info_.drops = prevLedger.info().drops;
|
info_.drops = prevLedger.info().drops;
|
||||||
info_.closeTimeResolution = prevLedger.info_.closeTimeResolution;
|
info_.closeTimeResolution = prevLedger.info_.closeTimeResolution;
|
||||||
|
|
||||||
prevLedger.updateHash ();
|
|
||||||
|
|
||||||
// VFALCO TODO Require callers to update the hash
|
|
||||||
info_.parentHash = prevLedger.getHash ();
|
info_.parentHash = prevLedger.getHash ();
|
||||||
|
|
||||||
assert (info_.parentHash.isNonZero ());
|
|
||||||
|
|
||||||
info_.closeTimeResolution = getNextLedgerTimeResolution (
|
info_.closeTimeResolution = getNextLedgerTimeResolution (
|
||||||
prevLedger.info_.closeTimeResolution,
|
prevLedger.info_.closeTimeResolution,
|
||||||
getCloseAgree(prevLedger.info()), info_.seq);
|
getCloseAgree(prevLedger.info()), info_.seq);
|
||||||
|
// VFALCO Remove this call to getApp
|
||||||
if (prevLedger.info_.closeTime == 0)
|
if (prevLedger.info_.closeTime == 0)
|
||||||
{
|
|
||||||
info_.closeTime = roundCloseTime (
|
info_.closeTime = roundCloseTime (
|
||||||
getApp().getOPs ().getCloseTimeNC (), info_.closeTimeResolution);
|
getApp().getOPs ().getCloseTimeNC (), info_.closeTimeResolution);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
info_.closeTime =
|
info_.closeTime =
|
||||||
prevLedger.info_.closeTime + info_.closeTimeResolution;
|
prevLedger.info_.closeTime + info_.closeTimeResolution;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ledger::Ledger (void const* data,
|
Ledger::Ledger (void const* data,
|
||||||
@@ -381,14 +369,6 @@ bool Ledger::addSLE (SLE const& sle)
|
|||||||
return stateMap_->addItem(item, false, false);
|
return stateMap_->addItem(item, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 const&
|
|
||||||
Ledger::getHash()
|
|
||||||
{
|
|
||||||
if (! mValidHash)
|
|
||||||
updateHash();
|
|
||||||
return info_.hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Ledger::saveValidatedLedger (bool current)
|
bool Ledger::saveValidatedLedger (bool current)
|
||||||
{
|
{
|
||||||
// TODO(tom): Fix this hard-coded SQL!
|
// TODO(tom): Fix this hard-coded SQL!
|
||||||
@@ -1010,9 +990,6 @@ Ledger::rawTxInsert (uint256 const& key,
|
|||||||
std::move(item), true, false))
|
std::move(item), true, false))
|
||||||
LogicError("duplicate_tx: " + to_string(key));
|
LogicError("duplicate_tx: " + to_string(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// VFALCO TODO We could touch only the txMap
|
|
||||||
touch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<SLE>
|
std::shared_ptr<SLE>
|
||||||
|
|||||||
@@ -110,9 +110,13 @@ public:
|
|||||||
Ledger (void const* data,
|
Ledger (void const* data,
|
||||||
std::size_t size, bool hasPrefix);
|
std::size_t size, bool hasPrefix);
|
||||||
|
|
||||||
// Create a new ledger that follows this one
|
/** Create a new open ledger
|
||||||
// VFALCO `previous` should be const
|
|
||||||
Ledger (bool dummy, Ledger& previous);
|
The ledger will have the sequence number that
|
||||||
|
follows previous, and have
|
||||||
|
parentCloseTime == previous.closeTime.
|
||||||
|
*/
|
||||||
|
Ledger (open_ledger_t, Ledger const& previous);
|
||||||
|
|
||||||
// Create a new ledger that's a snapshot of this one
|
// Create a new ledger that's a snapshot of this one
|
||||||
Ledger (Ledger const& target, bool isMutable);
|
Ledger (Ledger const& target, bool isMutable);
|
||||||
@@ -198,18 +202,6 @@ public:
|
|||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
/** Hint that the contents have changed.
|
|
||||||
Thread Safety:
|
|
||||||
Not thread safe
|
|
||||||
Effects:
|
|
||||||
The next call to getHash will return updated hashes
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
touch()
|
|
||||||
{
|
|
||||||
mValidHash = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setClosed()
|
void setClosed()
|
||||||
{
|
{
|
||||||
info_.open = false;
|
info_.open = false;
|
||||||
@@ -245,11 +237,13 @@ public:
|
|||||||
void addRaw (Serializer& s) const;
|
void addRaw (Serializer& s) const;
|
||||||
void setRaw (SerialIter& sit, bool hasPrefix);
|
void setRaw (SerialIter& sit, bool hasPrefix);
|
||||||
|
|
||||||
/** Return the hash of the ledger.
|
// DEPRECATED
|
||||||
This will recalculate the hash if necessary.
|
// Remove contract.h include
|
||||||
*/
|
|
||||||
uint256 const&
|
uint256 const&
|
||||||
getHash();
|
getHash() const
|
||||||
|
{
|
||||||
|
return info_.hash;
|
||||||
|
}
|
||||||
|
|
||||||
void setTotalDrops (std::uint64_t totDrops)
|
void setTotalDrops (std::uint64_t totDrops)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -979,7 +979,8 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
|
|||||||
CanonicalTXSet retriableTransactions (set->getHash ());
|
CanonicalTXSet retriableTransactions (set->getHash ());
|
||||||
|
|
||||||
// Build the new last closed ledger
|
// Build the new last closed ledger
|
||||||
auto newLCL = std::make_shared<Ledger> (false, *mPreviousLedger);
|
auto newLCL = std::make_shared<Ledger>(
|
||||||
|
open_ledger, *mPreviousLedger);
|
||||||
newLCL->setClosed (); // so applyTransactions sees a closed ledger
|
newLCL->setClosed (); // so applyTransactions sees a closed ledger
|
||||||
|
|
||||||
// Set up to write SHAMap changes to our database,
|
// Set up to write SHAMap changes to our database,
|
||||||
@@ -1075,7 +1076,8 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
|
|||||||
ledgerMaster_.consensusBuilt (newLCL);
|
ledgerMaster_.consensusBuilt (newLCL);
|
||||||
|
|
||||||
// Build new open ledger
|
// Build new open ledger
|
||||||
auto newOL = std::make_shared<Ledger> (true, *newLCL);
|
auto newOL = std::make_shared<Ledger>(
|
||||||
|
open_ledger, *newLCL);
|
||||||
OpenView accum(&*newOL);
|
OpenView accum(&*newOL);
|
||||||
assert(accum.open());
|
assert(accum.open());
|
||||||
|
|
||||||
|
|||||||
@@ -1045,17 +1045,18 @@ private:
|
|||||||
|
|
||||||
void ApplicationImp::startGenesisLedger ()
|
void ApplicationImp::startGenesisLedger ()
|
||||||
{
|
{
|
||||||
auto const genesis = std::make_shared<Ledger>(
|
std::shared_ptr<Ledger const> const genesis =
|
||||||
|
std::make_shared<Ledger>(
|
||||||
create_genesis, getConfig());
|
create_genesis, getConfig());
|
||||||
auto const next =
|
auto const next = std::make_shared<Ledger>(
|
||||||
std::make_shared<Ledger>(true, *genesis);
|
open_ledger, *genesis);
|
||||||
next->setClosed ();
|
next->setClosed ();
|
||||||
next->setAccepted ();
|
next->setAccepted ();
|
||||||
m_networkOPs->setLastCloseTime (next->info().closeTime);
|
m_networkOPs->setLastCloseTime (next->info().closeTime);
|
||||||
openLedger_.emplace(next, getConfig(),
|
openLedger_.emplace(next, getConfig(),
|
||||||
cachedSLEs_, deprecatedLogs().journal("OpenLedger"));
|
cachedSLEs_, deprecatedLogs().journal("OpenLedger"));
|
||||||
m_ledgerMaster->pushLedger (next,
|
m_ledgerMaster->pushLedger (next,
|
||||||
std::make_shared<Ledger>(true, *next));
|
std::make_shared<Ledger>(open_ledger, *next));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ledger::pointer
|
Ledger::pointer
|
||||||
@@ -1301,7 +1302,8 @@ bool ApplicationImp::loadOldLedger (
|
|||||||
|
|
||||||
m_ledgerMaster->setLedgerRangePresent (loadLedger->info().seq, loadLedger->info().seq);
|
m_ledgerMaster->setLedgerRangePresent (loadLedger->info().seq, loadLedger->info().seq);
|
||||||
|
|
||||||
Ledger::pointer openLedger = std::make_shared<Ledger> (false, std::ref (*loadLedger));
|
auto const openLedger =
|
||||||
|
std::make_shared<Ledger>(open_ledger, *loadLedger);
|
||||||
m_ledgerMaster->switchLedgers (loadLedger, openLedger);
|
m_ledgerMaster->switchLedgers (loadLedger, openLedger);
|
||||||
m_ledgerMaster->forceValid(loadLedger);
|
m_ledgerMaster->forceValid(loadLedger);
|
||||||
m_networkOPs->setLastCloseTime (loadLedger->info().closeTime);
|
m_networkOPs->setLastCloseTime (loadLedger->info().closeTime);
|
||||||
|
|||||||
@@ -1365,7 +1365,7 @@ void NetworkOPsImp::switchLastClosedLedger (
|
|||||||
clearNeedNetworkLedger ();
|
clearNeedNetworkLedger ();
|
||||||
newLCL->setClosed ();
|
newLCL->setClosed ();
|
||||||
auto const newOL = std::make_shared<
|
auto const newOL = std::make_shared<
|
||||||
Ledger>(false, std::ref (*newLCL));
|
Ledger>(open_ledger, std::ref (*newLCL));
|
||||||
// Caller must own master lock
|
// Caller must own master lock
|
||||||
{
|
{
|
||||||
auto const oldOL =
|
auto const oldOL =
|
||||||
|
|||||||
@@ -148,9 +148,12 @@ class View_test
|
|||||||
{
|
{
|
||||||
Config const config;
|
Config const config;
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
auto const ledger =
|
std::shared_ptr<Ledger const> const genesis =
|
||||||
std::make_shared<Ledger>(
|
std::make_shared<Ledger>(
|
||||||
create_genesis, config);
|
create_genesis, config);
|
||||||
|
auto const ledger =
|
||||||
|
std::make_shared<Ledger>(
|
||||||
|
open_ledger, *genesis);
|
||||||
wipe(*ledger);
|
wipe(*ledger);
|
||||||
ReadView& v = *ledger;
|
ReadView& v = *ledger;
|
||||||
succ(v, 0, boost::none);
|
succ(v, 0, boost::none);
|
||||||
@@ -392,9 +395,12 @@ class View_test
|
|||||||
// erase the item, apply.
|
// erase the item, apply.
|
||||||
{
|
{
|
||||||
Config const config;
|
Config const config;
|
||||||
auto const ledger =
|
std::shared_ptr<Ledger const> const genesis =
|
||||||
std::make_shared<Ledger>(
|
std::make_shared<Ledger>(
|
||||||
create_genesis, config);
|
create_genesis, config);
|
||||||
|
auto const ledger =
|
||||||
|
std::make_shared<Ledger>(
|
||||||
|
open_ledger, *genesis);
|
||||||
wipe(*ledger);
|
wipe(*ledger);
|
||||||
ledger->rawInsert(sle(1));
|
ledger->rawInsert(sle(1));
|
||||||
ReadView& v0 = *ledger;
|
ReadView& v0 = *ledger;
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ Env::close(
|
|||||||
clock.set(closeTime);
|
clock.set(closeTime);
|
||||||
// VFALCO TODO Fix the Ledger constructor
|
// VFALCO TODO Fix the Ledger constructor
|
||||||
auto next = std::make_shared<Ledger>(
|
auto next = std::make_shared<Ledger>(
|
||||||
false, const_cast<Ledger&>(*closed_));
|
open_ledger, *closed_);
|
||||||
next->setClosed();
|
next->setClosed();
|
||||||
#if 0
|
#if 0
|
||||||
// Build a SHAMap, put all the transactions
|
// Build a SHAMap, put all the transactions
|
||||||
|
|||||||
Reference in New Issue
Block a user