From 21d164b23b0ef09ed2a7dd0f2eba7f0e00577473 Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Mon, 24 Feb 2025 18:54:16 +1100 Subject: [PATCH] fix close flags (hacky) and more debug --- src/ripple/app/ledger/Ledger.cpp | 6 ++++ src/ripple/app/ledger/Ledger.h | 5 ++++ src/ripple/rpc/handlers/Catalogue.cpp | 41 +++++++++++++++++++++---- src/test/rpc/Catalogue_test.cpp | 43 ++++++++++++++++++++++----- 4 files changed, 82 insertions(+), 13 deletions(-) diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index 081ed9c8f..e451cb4f5 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -385,6 +385,12 @@ Ledger::setImmutable(bool rehash) setup(); } +void +Ledger::setCloseFlags(int closeFlags) +{ + info_.closeFlags = closeFlags; +} + void Ledger::setAccepted( NetClock::time_point closeTime, diff --git a/src/ripple/app/ledger/Ledger.h b/src/ripple/app/ledger/Ledger.h index 051b322e2..3a37a717a 100644 --- a/src/ripple/app/ledger/Ledger.h +++ b/src/ripple/app/ledger/Ledger.h @@ -275,6 +275,9 @@ public: void setImmutable(bool rehash = true); + void + setCloseFlags(int closeFlags); + bool isImmutable() const { @@ -306,6 +309,8 @@ public: info_.drops = totDrops; } + + SHAMap const& stateMap() const { diff --git a/src/ripple/rpc/handlers/Catalogue.cpp b/src/ripple/rpc/handlers/Catalogue.cpp index daf2768f9..a1885beb2 100644 --- a/src/ripple/rpc/handlers/Catalogue.cpp +++ b/src/ripple/rpc/handlers/Catalogue.cpp @@ -724,10 +724,18 @@ doCatalogueLoad(RPC::JsonContext& context) infile.read( reinterpret_cast(&info.parentCloseTime), sizeof(info.parentCloseTime)); - infile.read(info.hash.cdata(), 32); - infile.read(info.txHash.cdata(), 32); - infile.read(info.accountHash.cdata(), 32); + + char orig_hash[32], orig_ah[32], orig_th[32]; + + + infile.read(&orig_hash[0], 32); info.hash = beast::zero; + infile.read(&orig_th[0], 32); info.txHash = beast::zero; + infile.read(&orig_ah[0], 32); info.accountHash = beast::zero; +// infile.read(info.hash.cdata(), 32); +// infile.read(info.txHash.cdata(), 32); +// infile.read(info.accountHash.cdata(), 32); infile.read(info.parentHash.cdata(), 32); + infile.read(reinterpret_cast(&info.drops), sizeof(info.drops)); infile.read( reinterpret_cast(&info.validated), sizeof(info.validated)); @@ -867,7 +875,7 @@ doCatalogueLoad(RPC::JsonContext& context) std::cout << "Read state data at pos " << it->filePos << " size " << it->size - << " hex: " << strHex(makeSlice(data)) + //<< " hex: " << strHex(makeSlice(data)) << std::endl; // Verify data read was successful @@ -897,16 +905,39 @@ doCatalogueLoad(RPC::JsonContext& context) std::cout << "Applied " << stateChangeCount << " state changes" << std::endl; - currentLedger->stateMap().flushDirty(hotACCOUNT_NODE); currentLedger->updateSkipList(); + currentLedger->stateMap().flushDirty(hotACCOUNT_NODE); + currentLedger->txMap().flushDirty(hotTRANSACTION_NODE); + + currentLedger->unshare(); //? + + auto const ah = currentLedger->stateMap().getHash().as_uint256(); + auto const th = currentLedger->txMap().getHash().as_uint256(); + + std::cout << "ah: " << to_string(ah) << " orig: " << to_string(uint256::fromVoid(orig_ah)) << "\n"; + std::cout << "th: " << to_string(th) << " orig: " << to_string(uint256::fromVoid(orig_th)) << "\n"; + + memcpy(info.accountHash.cdata(), ah.data(), 32); + memcpy(info.txHash.cdata(), th.data(), 32); + + currentLedger->setLedgerInfo(info); + +// infile.read(info.txHash.cdata(), 32); +// infile.read(info.accountHash.cdata(), 32); // Finalize and store the ledger currentLedger->setValidated(); + + auto cf = currentLedger->info().closeFlags; currentLedger->setAccepted( currentLedger->info().closeTime, currentLedger->info().closeTimeResolution, currentLedger->info().closeFlags & sLCF_NoConsensusTime); + // hacky + currentLedger->setCloseFlags(cf); + + // Set the ledger as immutable after all mutations are complete currentLedger->setImmutable(true); diff --git a/src/test/rpc/Catalogue_test.cpp b/src/test/rpc/Catalogue_test.cpp index 1b7d74dcd..89f8df61d 100644 --- a/src/test/rpc/Catalogue_test.cpp +++ b/src/test/rpc/Catalogue_test.cpp @@ -326,19 +326,46 @@ class Catalogue_test : public beast::unit_test::suite auto const loadedLedger = loadEnv.closed(); // After loading each ledger - std::cout << "Original ledger hash: " - << to_string(sourceLedger->info().hash) - << "\nLoaded ledger hash: " - << to_string(loadedLedger->info().hash) - << "Original ledger seq: " - << to_string(sourceLedger->info().seq) - << "\nLoaded ledger seq: " - << to_string(loadedLedger->info().seq) << std::endl; + // +// After loading each ledger +std::cout << "\n=== Original Ledger Information ===\n" + << "Sequence: " << to_string(sourceLedger->info().seq) << "\n" + << "Hash: " << to_string(sourceLedger->info().hash) << "\n" + << "Parent Close Time: " << to_string(sourceLedger->info().parentCloseTime.time_since_epoch().count()) << "\n" + << "Transaction Hash: " << to_string(sourceLedger->info().txHash) << "\n" + << "Account Hash: " << to_string(sourceLedger->info().accountHash) << "\n" + << "Parent Hash: " << to_string(sourceLedger->info().parentHash) << "\n" + << "Drops: " << to_string(sourceLedger->info().drops) << "\n" + << "Validated: " << (sourceLedger->info().validated ? "true" : "false") << "\n" + << "Accepted: " << (sourceLedger->info().accepted ? "true" : "false") << "\n" + << "Close Flags: " << sourceLedger->info().closeFlags << "\n" + << "Close Time Resolution: " << to_string(sourceLedger->info().closeTimeResolution.count()) << "\n" + << "Close Time: " << to_string(sourceLedger->info().closeTime.time_since_epoch().count()) << "\n" + << "\n=== Loaded Ledger Information ===\n" + << "Sequence: " << to_string(loadedLedger->info().seq) << "\n" + << "Hash: " << to_string(loadedLedger->info().hash) << "\n" + << "Parent Close Time: " << to_string(loadedLedger->info().parentCloseTime.time_since_epoch().count()) << "\n" + << "Transaction Hash: " << to_string(loadedLedger->info().txHash) << "\n" + << "Account Hash: " << to_string(loadedLedger->info().accountHash) << "\n" + << "Parent Hash: " << to_string(loadedLedger->info().parentHash) << "\n" + << "Drops: " << to_string(loadedLedger->info().drops) << "\n" + << "Validated: " << (loadedLedger->info().validated ? "true" : "false") << "\n" + << "Accepted: " << (loadedLedger->info().accepted ? "true" : "false") << "\n" + << "Close Flags: " << loadedLedger->info().closeFlags << "\n" + << "Close Time Resolution: " << to_string(loadedLedger->info().closeTimeResolution.count()) << "\n" + << "Close Time: " << to_string(loadedLedger->info().closeTime.time_since_epoch().count()) << "\n" + << std::endl; auto const loadedBobAcct = loadedLedger->read(bobKeylet); auto const loadedCharlieAcct = loadedLedger->read(charlieKeylet); auto const loadedEurTrust = loadedLedger->read(eurTrustKeylet); + auto const& ll = *loadedLedger; + + std::cout << "bob exists: " << (ll.exists(bobKeylet) ? "t" : "f") << "\n"; + std::cout << "chl exists: " << (ll.exists(charlieKeylet) ? "t" : "f") << "\n"; + std::cout << "eur exists: " << (ll.exists(eurTrustKeylet) ? "t" : "f") << "\n"; + BEAST_EXPECT(!!loadedBobAcct); BEAST_EXPECT(!!loadedCharlieAcct); BEAST_EXPECT(!!loadedEurTrust);