From 29a9ae3573fe1da63a2d6494a21266e20bbe22e4 Mon Sep 17 00:00:00 2001 From: PhilWindle <60546371+PhilWindle@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:07:09 +0000 Subject: [PATCH] fix: Fix inclusion path (#10034) This PR fixes an inclusion path on MAC builds --- .../merkle_tree/lmdb_store/callbacks.cpp | 9 ++- .../lmdb_store/lmdb_tree_store.test.cpp | 80 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/lmdb_store/callbacks.cpp b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/lmdb_store/callbacks.cpp index 1f39eaf2fb1..1f073a76371 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/lmdb_store/callbacks.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/lmdb_store/callbacks.cpp @@ -4,10 +4,17 @@ #include #include #include -#include #include #include +#ifdef __APPLE__ +#include +#define htole64(x) OSSwapHostToLittleInt64(x) +#define le64toh(x) OSSwapLittleToHostInt64(x) +#else +#include +#endif + namespace bb::crypto::merkle_tree { void throw_error(const std::string& errorString, int error) { diff --git a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/lmdb_store/lmdb_tree_store.test.cpp b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/lmdb_store/lmdb_tree_store.test.cpp index f04ec2a0f39..68d7f66faf4 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/lmdb_store/lmdb_tree_store.test.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/merkle_tree/lmdb_store/lmdb_tree_store.test.cpp @@ -102,6 +102,86 @@ TEST_F(LMDBTreeStoreTest, can_write_and_read_meta_data) } } +TEST_F(LMDBTreeStoreTest, can_write_and_read_multiple_blocks_with_meta) +{ + LMDBTreeStore store(_directory, "DB1", _mapSize, _maxReaders); + uint64_t start_block = 647810461952355; + uint64_t num_blocks = 1000; + for (size_t i = 0; i < num_blocks; i++) { + BlockPayload blockData; + blockData.blockNumber = i + start_block; + blockData.root = VALUES[i]; + blockData.size = 45 + (i * 97); + LMDBTreeWriteTransaction::Ptr transaction = store.create_write_transaction(); + store.write_block_data(i + start_block, blockData, *transaction); + + TreeMeta meta; + meta.committedSize = blockData.size; + meta.size = blockData.size; + meta.root = blockData.root; + meta.depth = 32; + meta.unfinalisedBlockHeight = i + start_block; + meta.name = "NullifierTree"; + store.write_meta_data(meta, *transaction); + transaction->commit(); + } + + BlockPayload blockData; + for (size_t i = 0; i < num_blocks; i++) { + LMDBTreeReadTransaction::Ptr transaction = store.create_read_transaction(); + BlockPayload readBack; + bool success = store.read_block_data(i + start_block, readBack, *transaction); + EXPECT_TRUE(success); + + blockData.blockNumber = i + start_block; + blockData.root = VALUES[i]; + blockData.size = 45 + (i * 97); + EXPECT_EQ(readBack, blockData); + } + + { + TreeMeta meta; + LMDBTreeReadTransaction::Ptr transaction = store.create_read_transaction(); + store.read_meta_data(meta, *transaction); + + EXPECT_EQ(meta.committedSize, blockData.size); + EXPECT_EQ(meta.size, blockData.size); + EXPECT_EQ(meta.root, blockData.root); + EXPECT_EQ(meta.depth, 32); + EXPECT_EQ(meta.unfinalisedBlockHeight, blockData.blockNumber); + EXPECT_EQ(meta.name, "NullifierTree"); + } +} + +uint64_t serde_value(uint64_t value) +{ + std::vector data = serialise_key(value); + uint64_t return_value = 0; + deserialise_key(data.data(), return_value); + return return_value; +} + +TEST_F(LMDBTreeStoreTest, can_serde_64bit_values) +{ + union mapped { + uint64_t u64; + uint8_t arr[8]; + }; + mapped value1; + mapped value2; + value1.arr[0] = value2.arr[7] = 0x11; + value1.arr[1] = value2.arr[6] = 0x22; + value1.arr[2] = value2.arr[5] = 0x33; + value1.arr[3] = value2.arr[4] = 0x44; + value1.arr[4] = value2.arr[3] = 0x55; + value1.arr[5] = value2.arr[2] = 0x66; + value1.arr[6] = value2.arr[1] = 0x77; + value1.arr[7] = value2.arr[0] = 0x88; + + EXPECT_EQ(value1.u64, serde_value(value1.u64)); + EXPECT_EQ(value2.u64, serde_value(value2.u64)); +} + TEST_F(LMDBTreeStoreTest, can_write_and_read_leaf_indices) { Indices indices;