From 9f98d2a8c9037302e60e3c176153f95f72c79807 Mon Sep 17 00:00:00 2001 From: Lee *!* Clagett Date: Sun, 3 Dec 2023 15:47:04 -0500 Subject: [PATCH] Fix spend tracking bug in db::storage (#89) --- src/db/data.h | 2 +- src/db/storage.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/db/data.h b/src/db/data.h index f3fac0f..ef741cd 100644 --- a/src/db/data.h +++ b/src/db/data.h @@ -217,8 +217,8 @@ namespace db { transaction_link link; //!< Orders and links `spend` to `output`. crypto::key_image image; //!< Unique ID for the spend - // `link` and `image` must in this order for LMDB optimizations output_id source; //!< The output being spent + // `link`, `image`, and `source` must in this order for LMDB optimizations std::uint64_t timestamp; //!< Timestamp of spend std::uint64_t unlock_time;//!< Unlock time of spend std::uint32_t mixin_count;//!< Ring-size of TX output diff --git a/src/db/storage.cpp b/src/db/storage.cpp index 89ba657..d537840 100644 --- a/src/db/storage.cpp +++ b/src/db/storage.cpp @@ -219,7 +219,13 @@ namespace db right_bytes.remove_prefix(sizeof(crypto::hash)); static_assert(sizeof(crypto::key_image) == 32, "bad memcmp below"); - return compare_32bytes(left_bytes, right_bytes); + diff = compare_32bytes(left_bytes, right_bytes); + if (diff) + return diff; + + left_bytes.remove_prefix(sizeof(crypto::key_image)); + right_bytes.remove_prefix(sizeof(crypto::key_image)); + return less(left_bytes, right_bytes); } constexpr const lmdb::basic_table blocks{