mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
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:
committed by
Nik Bougalis
parent
3a039fff66
commit
d9905ec719
@@ -137,6 +137,12 @@ public:
|
||||
virtual uint256 getLedgerHash(
|
||||
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 fixMismatch (Ledger::ref ledger) = 0;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -161,10 +161,10 @@ Json::Value Transaction::getJson (int options, bool binary) const
|
||||
|
||||
if (options == 1)
|
||||
{
|
||||
auto ledger = mApp.getLedgerMaster ().
|
||||
getLedgerBySeq (mInLedger);
|
||||
if (ledger)
|
||||
ret[jss::date] = ledger->info().closeTime;
|
||||
auto ct = mApp.getLedgerMaster().
|
||||
getCloseTimeBySeq (mInLedger);
|
||||
if (ct)
|
||||
ret[jss::date] = *ct;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user