From b277c353a80af23fe2a259094431452d4b2a0113 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Sat, 7 Jan 2023 15:29:35 -0800 Subject: [PATCH] Eliminate dead bytes from nodestore encoding: The legacy nodestore encoding for blobs had an 8 byte prefix. Originally the first 4 bytes stored the sequence number of the ledger to which the encoded object belogned; the next 4 bytes were never specified rigidly and some versions stored a redundant copy of the ledger sequence while others simply set the bytes to 0. Eventually that scheme was abandoned, and the first 8 bytes were just set to 0 and ignored when reloading a blob. This commit removes the unusued 8 byte legacy prefix. The change is makes it impossible to load old databases with this code and for old versions to load databases created with this code. --- src/ripple/nodestore/impl/DecodedBlob.cpp | 18 +++++++----------- src/ripple/nodestore/impl/EncodedBlob.cpp | 9 +++------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/ripple/nodestore/impl/DecodedBlob.cpp b/src/ripple/nodestore/impl/DecodedBlob.cpp index 0c5a5de20..9321ae0b2 100644 --- a/src/ripple/nodestore/impl/DecodedBlob.cpp +++ b/src/ripple/nodestore/impl/DecodedBlob.cpp @@ -30,10 +30,8 @@ DecodedBlob::DecodedBlob(void const* key, void const* value, int valueBytes) /* Data format: Bytes - - 0...7 Unused - 8 char One of NodeObjectType - 9...end The body of the object data + 0 uint8 One of NodeObjectType + 1...end The body of the object data */ m_success = false; @@ -41,19 +39,17 @@ DecodedBlob::DecodedBlob(void const* key, void const* value, int valueBytes) // VFALCO NOTE Ledger indexes should have started at 1 m_objectType = hotUNKNOWN; m_objectData = nullptr; - m_dataBytes = std::max(0, valueBytes - 9); + m_dataBytes = std::max(0, valueBytes - 1); - // VFALCO NOTE What about bytes 4 through 7 inclusive? - - if (valueBytes > 8) + if (valueBytes != 0) { unsigned char const* byte = static_cast(value); - m_objectType = safe_cast(byte[8]); + m_objectType = safe_cast(byte[0]); } - if (valueBytes > 9) + if (valueBytes > 1) { - m_objectData = static_cast(value) + 9; + m_objectData = static_cast(value) + 1; switch (m_objectType) { diff --git a/src/ripple/nodestore/impl/EncodedBlob.cpp b/src/ripple/nodestore/impl/EncodedBlob.cpp index 4ec15b102..3b33c8be4 100644 --- a/src/ripple/nodestore/impl/EncodedBlob.cpp +++ b/src/ripple/nodestore/impl/EncodedBlob.cpp @@ -28,14 +28,11 @@ EncodedBlob::prepare(std::shared_ptr const& object) { m_key = object->getHash().begin(); - auto ret = m_data.alloc(object->getData().size() + 9); + auto ret = m_data.alloc(object->getData().size() + 1); - // the first 8 bytes are unused - std::memset(ret, 0, 8); + ret[0] = static_cast(object->getType()); - ret[8] = static_cast(object->getType()); - - std::memcpy(ret + 9, object->getData().data(), object->getData().size()); + std::memcpy(ret + 1, object->getData().data(), object->getData().size()); } } // namespace NodeStore