change to serializeforwire

This commit is contained in:
Richard Holland
2025-03-02 12:30:16 +11:00
parent 90c2726cbd
commit 55a94c400e
2 changed files with 177 additions and 118 deletions

View File

@@ -112,7 +112,7 @@ private:
DeltaType deltaType = DeltaType::ADDED)
{
Serializer s;
node.serializeWithPrefix(s);
node.serializeForWire(s);
// Prepare the node header
NodeHeader header;
@@ -167,6 +167,10 @@ private:
using StackEntry = std::pair<SHAMapTreeNode*, SHAMapNodeID>;
std::stack<StackEntry> nodeStack;
// JLOG(journal.info())
std::cout << "Serializing root node with hash: "
<< to_string(map.root_->getHash().as_uint256()) << "\n";
// Start with the root
nodeStack.push({map.root_.get(), SHAMapNodeID()});
@@ -653,6 +657,22 @@ doCatalogueCreate(RPC::JsonContext& context)
outfile.close();
uint64_t size = static_cast<uint64_t>(bytes_written);
{
std::ifstream validateFile(filepath, std::ios::binary);
CATLHeader validateHeader;
validateFile.read(
reinterpret_cast<char*>(&validateHeader), sizeof(CATLHeader));
if (validateFile.fail() || memcmp(validateHeader.magic, "CATL", 4) != 0)
{
std::cout << "Catalogue file appears to be corrupted!\n";
}
else
{
std::cout << "Catalogue file header verified OK\n";
}
validateFile.close();
}
// Return the result
Json::Value jvResult;
jvResult[jss::min_ledger] = min_ledger;
@@ -978,7 +998,21 @@ doCatalogueLoad(RPC::JsonContext& context)
.isGood())
{
JLOG(context.j.error())
<< "Failed to add root node for base ledger " << seq;
<< "Failed to add root node for base ledger " << seq
<< ", root hash: " << to_string(rootIt->second)
<< ", data size: " << rootData.size();
// Try to dump some of the data for debugging
if (rootData.size() > 0)
{
std::stringstream ss;
ss << "Data: ";
for (size_t i = 0;
i < std::min<size_t>(32, rootData.size());
++i)
ss << std::hex << std::setw(2) << std::setfill('0')
<< (int)rootData[i] << " ";
JLOG(context.j.error()) << ss.str();
}
continue;
}

View File

@@ -345,123 +345,148 @@ class Catalogue_test : public beast::unit_test::suite
loadEnv.app().getLedgerMaster().getLedgerByHash(
loadEnv.app().getLedgerMaster().getHashBySeq(3));
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;
std::cout
<< "\n=== Original Ledger3 Information ===\n"
<< "Sequence: " << to_string(ledger3->info().seq) << "\n"
<< "Hash: " << to_string(ledger3->info().hash) << "\n"
<< "Parent Close Time: "
<< to_string(ledger3->info()
.parentCloseTime.time_since_epoch()
.count())
<< "\n"
<< "Transaction Hash: " << to_string(ledger3->info().txHash)
<< "\n"
<< "Account Hash: " << to_string(ledger3->info().accountHash)
<< "\n"
<< "Parent Hash: " << to_string(ledger3->info().parentHash)
<< "\n"
<< "Drops: " << to_string(ledger3->info().drops) << "\n"
<< "Validated: "
<< (ledger3->info().validated ? "true" : "false") << "\n"
<< "Accepted: " << (ledger3->info().accepted ? "true" : "false")
<< "\n"
<< "Close Flags: " << ledger3->info().closeFlags << "\n"
<< "Close Time Resolution: "
<< to_string(ledger3->info().closeTimeResolution.count())
<< "\n"
<< "Close Time: "
<< to_string(
ledger3->info().closeTime.time_since_epoch().count())
<< "\n"
<< "\n=== Loaded Ledger3 Information ===\n"
<< "Sequence: " << to_string(loadedLedger3->info().seq) << "\n"
<< "Hash: " << to_string(loadedLedger3->info().hash) << "\n"
<< "Parent Close Time: "
<< to_string(loadedLedger3->info()
.parentCloseTime.time_since_epoch()
.count())
<< "\n"
<< "Transaction Hash: "
<< to_string(loadedLedger3->info().txHash) << "\n"
<< "Account Hash: "
<< to_string(loadedLedger3->info().accountHash) << "\n"
<< "Parent Hash: "
<< to_string(loadedLedger3->info().parentHash) << "\n"
<< "Drops: " << to_string(loadedLedger3->info().drops) << "\n"
<< "Validated: "
<< (loadedLedger3->info().validated ? "true" : "false") << "\n"
<< "Accepted: "
<< (loadedLedger3->info().accepted ? "true" : "false") << "\n"
<< "Close Flags: " << loadedLedger3->info().closeFlags << "\n"
<< "Close Time Resolution: "
<< to_string(loadedLedger3->info().closeTimeResolution.count())
<< "\n"
<< "Close Time: "
<< to_string(loadedLedger3->info()
.closeTime.time_since_epoch()
.count())
<< "\n"
<< std::endl;
if (!loadedLedger3)
{
BEAST_EXPECT(false); // Test failure
std::cout << "Failed to load ledger 3!\n";
}
else
{
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;
std::cout
<< "\n=== Original Ledger3 Information ===\n"
<< "Sequence: " << to_string(ledger3->info().seq) << "\n"
<< "Hash: " << to_string(ledger3->info().hash) << "\n"
<< "Parent Close Time: "
<< to_string(ledger3->info()
.parentCloseTime.time_since_epoch()
.count())
<< "\n"
<< "Transaction Hash: " << to_string(ledger3->info().txHash)
<< "\n"
<< "Account Hash: "
<< to_string(ledger3->info().accountHash) << "\n"
<< "Parent Hash: " << to_string(ledger3->info().parentHash)
<< "\n"
<< "Drops: " << to_string(ledger3->info().drops) << "\n"
<< "Validated: "
<< (ledger3->info().validated ? "true" : "false") << "\n"
<< "Accepted: "
<< (ledger3->info().accepted ? "true" : "false") << "\n"
<< "Close Flags: " << ledger3->info().closeFlags << "\n"
<< "Close Time Resolution: "
<< to_string(ledger3->info().closeTimeResolution.count())
<< "\n"
<< "Close Time: "
<< to_string(
ledger3->info().closeTime.time_since_epoch().count())
<< "\n"
<< "\n=== Loaded Ledger3 Information ===\n"
<< "Sequence: " << to_string(loadedLedger3->info().seq)
<< "\n"
<< "Hash: " << to_string(loadedLedger3->info().hash) << "\n"
<< "Parent Close Time: "
<< to_string(loadedLedger3->info()
.parentCloseTime.time_since_epoch()
.count())
<< "\n"
<< "Transaction Hash: "
<< to_string(loadedLedger3->info().txHash) << "\n"
<< "Account Hash: "
<< to_string(loadedLedger3->info().accountHash) << "\n"
<< "Parent Hash: "
<< to_string(loadedLedger3->info().parentHash) << "\n"
<< "Drops: " << to_string(loadedLedger3->info().drops)
<< "\n"
<< "Validated: "
<< (loadedLedger3->info().validated ? "true" : "false")
<< "\n"
<< "Accepted: "
<< (loadedLedger3->info().accepted ? "true" : "false")
<< "\n"
<< "Close Flags: " << loadedLedger3->info().closeFlags
<< "\n"
<< "Close Time Resolution: "
<< to_string(
loadedLedger3->info().closeTimeResolution.count())
<< "\n"
<< "Close Time: "
<< to_string(loadedLedger3->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);