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

@@ -1377,6 +1377,33 @@ public:
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 hash = mLedgerHistory.getLedgerHash (index);