Ledger close time optimizations (RIPD-998, RIPD-791):

Add a LedgerMaster function to get a ledger's
close time from either its hash or sequence number.
Use this function when adding the 'date' fields to
transaction JSON. This avoids constructing large numbers
of ledgers.
This commit is contained in:
David Schwartz
2015-11-09 14:52:10 -08:00
committed by Nik Bougalis
parent 3a039fff66
commit d9905ec719
3 changed files with 37 additions and 4 deletions

View File

@@ -137,6 +137,12 @@ public:
virtual uint256 getLedgerHash( virtual uint256 getLedgerHash(
std::uint32_t desiredSeq, Ledger::ref knownGoodLedger) = 0; std::uint32_t desiredSeq, Ledger::ref knownGoodLedger) = 0;
virtual boost::optional <uint32_t> getCloseTimeBySeq (
LedgerIndex ledgerIndex) = 0;
virtual boost::optional <uint32_t> getCloseTimeByHash (
LedgerHash const& ledgerHash) = 0;
virtual void addHeldTransaction (std::shared_ptr<Transaction> const& trans) = 0; virtual void addHeldTransaction (std::shared_ptr<Transaction> const& trans) = 0;
virtual void fixMismatch (Ledger::ref ledger) = 0; virtual void fixMismatch (Ledger::ref ledger) = 0;

View File

@@ -1377,6 +1377,33 @@ public:
return mCompleteLedgers.toString (); return mCompleteLedgers.toString ();
} }
boost::optional <uint32_t>
getCloseTimeBySeq (LedgerIndex ledgerIndex) override
{
uint256 hash = getHashBySeq (ledgerIndex);
return hash.isNonZero() ? getCloseTimeByHash (hash) : boost::none;
}
boost::optional <uint32_t>
getCloseTimeByHash (LedgerHash const& ledgerHash) override
{
auto node = app_.getNodeStore().fetch (ledgerHash);
if (node &&
(node->getData().size() >= 120))
{
SerialIter it (node->getData().data(), node->getData().size());
if (it.get32() == HashPrefix::ledgerMaster)
{
it.skip (
4+8+32+ // seq drops parentHash
32+32+4); // txHash acctHash parentClose
return it.get32();
}
}
return boost::none;
}
uint256 getHashBySeq (std::uint32_t index) override uint256 getHashBySeq (std::uint32_t index) override
{ {
uint256 hash = mLedgerHistory.getLedgerHash (index); uint256 hash = mLedgerHistory.getLedgerHash (index);

View File

@@ -161,10 +161,10 @@ Json::Value Transaction::getJson (int options, bool binary) const
if (options == 1) if (options == 1)
{ {
auto ledger = mApp.getLedgerMaster (). auto ct = mApp.getLedgerMaster().
getLedgerBySeq (mInLedger); getCloseTimeBySeq (mInLedger);
if (ledger) if (ct)
ret[jss::date] = ledger->info().closeTime; ret[jss::date] = *ct;
} }
} }