From 78bd570016d0eedc60d41de4a9479914f2047e4a Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Wed, 5 Mar 2025 23:08:59 +1100 Subject: [PATCH] more debugging, getting closer --- src/ripple/rpc/handlers/Catalogue.cpp | 43 ++++++++++++------------ src/ripple/shamap/SHAMapTreeNode.h | 1 + src/ripple/shamap/impl/SHAMap.cpp | 47 +++++++++++++++++---------- 3 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/ripple/rpc/handlers/Catalogue.cpp b/src/ripple/rpc/handlers/Catalogue.cpp index ce0ce721e..4566c81fb 100644 --- a/src/ripple/rpc/handlers/Catalogue.cpp +++ b/src/ripple/rpc/handlers/Catalogue.cpp @@ -112,25 +112,26 @@ private: auto const& info = ledger->info(); - uint64_t closeTime = info.closeTime.time_since_epoch().count(); - uint64_t parentCloseTime = - info.parentCloseTime.time_since_epoch().count(); + uint64_t closeTime = + 0xCAFED00DCAFEBABEULL; // info.closeTime.time_since_epoch().count(); + uint64_t parentCloseTime = 0xDEADBEEFC001D00D; + // info.parentCloseTime.time_since_epoch().count(); uint32_t closeTimeResolution = info.closeTimeResolution.count(); + uint64_t drops = info.drops.drops(); + // Write ledger header information if (!writeToFile(&info.seq, sizeof(info.seq)) || - !writeToFile(&parentCloseTime, sizeof(parentCloseTime)) || !writeToFile(info.hash.data(), 32) || !writeToFile(info.txHash.data(), 32) || !writeToFile(info.accountHash.data(), 32) || !writeToFile(info.parentHash.data(), 32) || - !writeToFile(&info.drops, sizeof(info.drops)) || - !writeToFile(&info.validated, sizeof(info.validated)) || - !writeToFile(&info.accepted, sizeof(info.accepted)) || + !writeToFile(&drops, sizeof(drops)) || !writeToFile(&info.closeFlags, sizeof(info.closeFlags)) || !writeToFile( &closeTimeResolution, sizeof(closeTimeResolution)) || - !writeToFile(&closeTime, sizeof(closeTime))) + !writeToFile(&closeTime, sizeof(closeTime)) || + !writeToFile(&parentCloseTime, sizeof(parentCloseTime))) { return false; } @@ -356,24 +357,16 @@ doCatalogueLoad(RPC::JsonContext& context) uint64_t closeTime = -1; uint64_t parentCloseTime = -1; uint32_t closeTimeResolution = -1; + uint64_t drops = -1; + if (!infile.read( reinterpret_cast(&info.seq), sizeof(info.seq)) || - !infile.read( - reinterpret_cast(&parentCloseTime), - sizeof(parentCloseTime)) || !infile.read(reinterpret_cast(info.hash.data()), 32) || !infile.read(reinterpret_cast(info.txHash.data()), 32) || !infile.read( reinterpret_cast(info.accountHash.data()), 32) || !infile.read(reinterpret_cast(info.parentHash.data()), 32) || - !infile.read( - reinterpret_cast(&info.drops), sizeof(info.drops)) || - !infile.read( - reinterpret_cast(&info.validated), - sizeof(info.validated)) || - !infile.read( - reinterpret_cast(&info.accepted), - sizeof(info.accepted)) || + !infile.read(reinterpret_cast(&drops), sizeof(drops)) || !infile.read( reinterpret_cast(&info.closeFlags), sizeof(info.closeFlags)) || @@ -381,7 +374,10 @@ doCatalogueLoad(RPC::JsonContext& context) reinterpret_cast(&closeTimeResolution), sizeof(closeTimeResolution)) || !infile.read( - reinterpret_cast(&closeTime), sizeof(closeTime))) + reinterpret_cast(&closeTime), sizeof(closeTime)) || + !infile.read( + reinterpret_cast(&parentCloseTime), + sizeof(parentCloseTime))) { JLOG(context.j.warn()) << "Catalogue load expected but could not " "read the next ledger header."; @@ -391,6 +387,8 @@ doCatalogueLoad(RPC::JsonContext& context) info.parentCloseTime = time_point{duration{parentCloseTime}}; info.closeTimeResolution = duration{closeTimeResolution}; + info.drops = drops; + JLOG(context.j.info()) << "Found ledger " << info.seq << "..."; if (info.seq != expected_seq++) @@ -463,14 +461,13 @@ doCatalogueLoad(RPC::JsonContext& context) ledger->stateMap().flushDirty(hotACCOUNT_NODE); ledger->txMap().flushDirty(hotTRANSACTION_NODE); - // Set the ledger as validated - ledger->setValidated(); - ledger->setAccepted( info.closeTime, info.closeTimeResolution, info.closeFlags & sLCF_NoConsensusTime); + ledger->setValidated(); + // Set the proper close flags ledger->setCloseFlags(info.closeFlags); diff --git a/src/ripple/shamap/SHAMapTreeNode.h b/src/ripple/shamap/SHAMapTreeNode.h index 7728e8201..d8df3e8c0 100644 --- a/src/ripple/shamap/SHAMapTreeNode.h +++ b/src/ripple/shamap/SHAMapTreeNode.h @@ -48,6 +48,7 @@ enum SHAMapNodeType : uint8_t { tnTRANSACTION_NM = 2, // transaction, no metadata tnTRANSACTION_MD = 3, // transaction, with metadata tnACCOUNT_STATE = 4, + tnREMOVE = 254, // special type to mark deleted nodes in serialization tnTERMINAL = 255 // special type to mark the end of a serialization stream }; diff --git a/src/ripple/shamap/impl/SHAMap.cpp b/src/ripple/shamap/impl/SHAMap.cpp index ca77fd15b..8f0a5f4cc 100644 --- a/src/ripple/shamap/impl/SHAMap.cpp +++ b/src/ripple/shamap/impl/SHAMap.cpp @@ -1275,15 +1275,13 @@ SHAMap::serializeToStream( }; auto serializeRemovedLeaf = [&stream](uint256 const& key) -> bool { - // to indicate a node is removed it is written with size 0 + // to indicate a node is removed it is written with a removal type + auto t = SHAMapNodeType::tnREMOVE; + stream.write(reinterpret_cast(&t), 1); // write the key stream.write(reinterpret_cast(key.data()), 32); - // write the data size 0 - uint32_t size{0}; - stream.write(reinterpret_cast(&size), 4); - return !stream.fail(); }; @@ -1329,6 +1327,10 @@ SHAMap::serializeToStream( } } + // write a terminal symbol to indicate the map stream has ended + auto t = SHAMapNodeType::tnTERMINAL; + stream.write(reinterpret_cast(&t), 1); + return nodeCount; } } @@ -1439,29 +1441,35 @@ SHAMap::deserializeFromStream( return false; } - s.read(reinterpret_cast(&size), 4); - - if (size == 0) + if (nodeType == SHAMapNodeType::tnREMOVE) { // deletion if (!hasItem(key)) { std::cout << "item already missing at delete request " << to_string(key) << "\n"; - return false; + // return false; + } + else + { + std::cout << "Successfully deleted " << to_string(key) + << "\n"; + delItem(key); } - - std::cout << "Successfully deleted " << to_string(key) << "\n"; - delItem(key); return true; } - if (hasItem(key)) - { - std::cout << "Removing modified item ahead of replacement " - << to_string(key) << "\n"; - delItem(key); - } + s.read(reinterpret_cast(&size), 4); + + /* + if (hasItem(key)) + { + std::cout << "Removing modified item ahead of + replacement " + << to_string(key) << "\n"; + delItem(key); + } + */ if (s.fail()) { @@ -1489,6 +1497,9 @@ SHAMap::deserializeFromStream( } auto item = make_shamapitem(key, makeSlice(data)); + if (hasItem(key)) + return updateGiveItem(nodeType, std::move(item)); + return addGiveItem(nodeType, std::move(item)); };