more debugging, getting closer

This commit is contained in:
Richard Holland
2025-03-05 23:08:59 +11:00
parent b2d30104d4
commit 78bd570016
3 changed files with 50 additions and 41 deletions

View File

@@ -112,25 +112,26 @@ private:
auto const& info = ledger->info(); auto const& info = ledger->info();
uint64_t closeTime = info.closeTime.time_since_epoch().count(); uint64_t closeTime =
uint64_t parentCloseTime = 0xCAFED00DCAFEBABEULL; // info.closeTime.time_since_epoch().count();
info.parentCloseTime.time_since_epoch().count(); uint64_t parentCloseTime = 0xDEADBEEFC001D00D;
// info.parentCloseTime.time_since_epoch().count();
uint32_t closeTimeResolution = info.closeTimeResolution.count(); uint32_t closeTimeResolution = info.closeTimeResolution.count();
uint64_t drops = info.drops.drops();
// Write ledger header information // Write ledger header information
if (!writeToFile(&info.seq, sizeof(info.seq)) || if (!writeToFile(&info.seq, sizeof(info.seq)) ||
!writeToFile(&parentCloseTime, sizeof(parentCloseTime)) ||
!writeToFile(info.hash.data(), 32) || !writeToFile(info.hash.data(), 32) ||
!writeToFile(info.txHash.data(), 32) || !writeToFile(info.txHash.data(), 32) ||
!writeToFile(info.accountHash.data(), 32) || !writeToFile(info.accountHash.data(), 32) ||
!writeToFile(info.parentHash.data(), 32) || !writeToFile(info.parentHash.data(), 32) ||
!writeToFile(&info.drops, sizeof(info.drops)) || !writeToFile(&drops, sizeof(drops)) ||
!writeToFile(&info.validated, sizeof(info.validated)) ||
!writeToFile(&info.accepted, sizeof(info.accepted)) ||
!writeToFile(&info.closeFlags, sizeof(info.closeFlags)) || !writeToFile(&info.closeFlags, sizeof(info.closeFlags)) ||
!writeToFile( !writeToFile(
&closeTimeResolution, sizeof(closeTimeResolution)) || &closeTimeResolution, sizeof(closeTimeResolution)) ||
!writeToFile(&closeTime, sizeof(closeTime))) !writeToFile(&closeTime, sizeof(closeTime)) ||
!writeToFile(&parentCloseTime, sizeof(parentCloseTime)))
{ {
return false; return false;
} }
@@ -356,24 +357,16 @@ doCatalogueLoad(RPC::JsonContext& context)
uint64_t closeTime = -1; uint64_t closeTime = -1;
uint64_t parentCloseTime = -1; uint64_t parentCloseTime = -1;
uint32_t closeTimeResolution = -1; uint32_t closeTimeResolution = -1;
uint64_t drops = -1;
if (!infile.read( if (!infile.read(
reinterpret_cast<char*>(&info.seq), sizeof(info.seq)) || reinterpret_cast<char*>(&info.seq), sizeof(info.seq)) ||
!infile.read(
reinterpret_cast<char*>(&parentCloseTime),
sizeof(parentCloseTime)) ||
!infile.read(reinterpret_cast<char*>(info.hash.data()), 32) || !infile.read(reinterpret_cast<char*>(info.hash.data()), 32) ||
!infile.read(reinterpret_cast<char*>(info.txHash.data()), 32) || !infile.read(reinterpret_cast<char*>(info.txHash.data()), 32) ||
!infile.read( !infile.read(
reinterpret_cast<char*>(info.accountHash.data()), 32) || reinterpret_cast<char*>(info.accountHash.data()), 32) ||
!infile.read(reinterpret_cast<char*>(info.parentHash.data()), 32) || !infile.read(reinterpret_cast<char*>(info.parentHash.data()), 32) ||
!infile.read( !infile.read(reinterpret_cast<char*>(&drops), sizeof(drops)) ||
reinterpret_cast<char*>(&info.drops), sizeof(info.drops)) ||
!infile.read(
reinterpret_cast<char*>(&info.validated),
sizeof(info.validated)) ||
!infile.read(
reinterpret_cast<char*>(&info.accepted),
sizeof(info.accepted)) ||
!infile.read( !infile.read(
reinterpret_cast<char*>(&info.closeFlags), reinterpret_cast<char*>(&info.closeFlags),
sizeof(info.closeFlags)) || sizeof(info.closeFlags)) ||
@@ -381,7 +374,10 @@ doCatalogueLoad(RPC::JsonContext& context)
reinterpret_cast<char*>(&closeTimeResolution), reinterpret_cast<char*>(&closeTimeResolution),
sizeof(closeTimeResolution)) || sizeof(closeTimeResolution)) ||
!infile.read( !infile.read(
reinterpret_cast<char*>(&closeTime), sizeof(closeTime))) reinterpret_cast<char*>(&closeTime), sizeof(closeTime)) ||
!infile.read(
reinterpret_cast<char*>(&parentCloseTime),
sizeof(parentCloseTime)))
{ {
JLOG(context.j.warn()) << "Catalogue load expected but could not " JLOG(context.j.warn()) << "Catalogue load expected but could not "
"read the next ledger header."; "read the next ledger header.";
@@ -391,6 +387,8 @@ doCatalogueLoad(RPC::JsonContext& context)
info.parentCloseTime = time_point{duration{parentCloseTime}}; info.parentCloseTime = time_point{duration{parentCloseTime}};
info.closeTimeResolution = duration{closeTimeResolution}; info.closeTimeResolution = duration{closeTimeResolution};
info.drops = drops;
JLOG(context.j.info()) << "Found ledger " << info.seq << "..."; JLOG(context.j.info()) << "Found ledger " << info.seq << "...";
if (info.seq != expected_seq++) if (info.seq != expected_seq++)
@@ -463,14 +461,13 @@ doCatalogueLoad(RPC::JsonContext& context)
ledger->stateMap().flushDirty(hotACCOUNT_NODE); ledger->stateMap().flushDirty(hotACCOUNT_NODE);
ledger->txMap().flushDirty(hotTRANSACTION_NODE); ledger->txMap().flushDirty(hotTRANSACTION_NODE);
// Set the ledger as validated
ledger->setValidated();
ledger->setAccepted( ledger->setAccepted(
info.closeTime, info.closeTime,
info.closeTimeResolution, info.closeTimeResolution,
info.closeFlags & sLCF_NoConsensusTime); info.closeFlags & sLCF_NoConsensusTime);
ledger->setValidated();
// Set the proper close flags // Set the proper close flags
ledger->setCloseFlags(info.closeFlags); ledger->setCloseFlags(info.closeFlags);

View File

@@ -48,6 +48,7 @@ enum SHAMapNodeType : uint8_t {
tnTRANSACTION_NM = 2, // transaction, no metadata tnTRANSACTION_NM = 2, // transaction, no metadata
tnTRANSACTION_MD = 3, // transaction, with metadata tnTRANSACTION_MD = 3, // transaction, with metadata
tnACCOUNT_STATE = 4, 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 tnTERMINAL = 255 // special type to mark the end of a serialization stream
}; };

View File

@@ -1275,15 +1275,13 @@ SHAMap::serializeToStream(
}; };
auto serializeRemovedLeaf = [&stream](uint256 const& key) -> bool { 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<char const*>(&t), 1);
// write the key // write the key
stream.write(reinterpret_cast<char const*>(key.data()), 32); stream.write(reinterpret_cast<char const*>(key.data()), 32);
// write the data size 0
uint32_t size{0};
stream.write(reinterpret_cast<char const*>(&size), 4);
return !stream.fail(); 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<char const*>(&t), 1);
return nodeCount; return nodeCount;
} }
} }
@@ -1439,29 +1441,35 @@ SHAMap::deserializeFromStream(
return false; return false;
} }
s.read(reinterpret_cast<char*>(&size), 4); if (nodeType == SHAMapNodeType::tnREMOVE)
if (size == 0)
{ {
// deletion // deletion
if (!hasItem(key)) if (!hasItem(key))
{ {
std::cout << "item already missing at delete request " std::cout << "item already missing at delete request "
<< to_string(key) << "\n"; << 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; return true;
} }
if (hasItem(key)) s.read(reinterpret_cast<char*>(&size), 4);
{
std::cout << "Removing modified item ahead of replacement " /*
<< to_string(key) << "\n"; if (hasItem(key))
delItem(key); {
} std::cout << "Removing modified item ahead of
replacement "
<< to_string(key) << "\n";
delItem(key);
}
*/
if (s.fail()) if (s.fail())
{ {
@@ -1489,6 +1497,9 @@ SHAMap::deserializeFromStream(
} }
auto item = make_shamapitem(key, makeSlice(data)); auto item = make_shamapitem(key, makeSlice(data));
if (hasItem(key))
return updateGiveItem(nodeType, std::move(item));
return addGiveItem(nodeType, std::move(item)); return addGiveItem(nodeType, std::move(item));
}; };