Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Clean up data configuration #9973

Merged
merged 43 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
aed5bce
WIP
PhilWindle Oct 29, 2024
0894c13
Updated logging
PhilWindle Oct 29, 2024
36f53d4
Merge branch 'master' into pw/world-state-cleanup
PhilWindle Oct 29, 2024
68f2c25
Removed erroneous code
PhilWindle Oct 29, 2024
f91d91e
Merge branch 'master' into pw/world-state-cleanup
ludamad Oct 30, 2024
4962d96
Detect if trees are out of sync
PhilWindle Oct 30, 2024
8d46f2c
Merge branch 'pw/world-state-cleanup' of github.com:AztecProtocol/azt…
PhilWindle Oct 31, 2024
6511d8a
WIP
PhilWindle Oct 31, 2024
e536a59
WIP
PhilWindle Nov 11, 2024
5019a35
WIP
PhilWindle Nov 11, 2024
22e1a14
Merge remote-tracking branch 'origin/master' into pw/world-state-cleanup
PhilWindle Nov 11, 2024
478296e
Merge remote-tracking branch 'origin/master' into pw/world-state-cleanup
PhilWindle Nov 11, 2024
0c62a94
Merge branch 'master' into pw/world-state-cleanup
PhilWindle Nov 11, 2024
70ec05a
Merge remote-tracking branch 'origin/master' into pw/world-state-cleanup
PhilWindle Nov 12, 2024
eb72f4f
WIP
PhilWindle Nov 12, 2024
c24b940
WIP
PhilWindle Nov 13, 2024
75e8472
WIP
PhilWindle Nov 13, 2024
14fa37b
WIP
PhilWindle Nov 13, 2024
21a5a1c
WIP
PhilWindle Nov 13, 2024
0ad1bdb
WIP
PhilWindle Nov 13, 2024
5cc95c5
Fixes
PhilWindle Nov 13, 2024
0ac899f
Formatting
PhilWindle Nov 13, 2024
ed8be9f
Additional test case
PhilWindle Nov 13, 2024
c7e64bb
Log formatting
PhilWindle Nov 13, 2024
b0b25bc
More log formatting
PhilWindle Nov 13, 2024
6224fa8
Formatting
PhilWindle Nov 13, 2024
4db7059
Merge branch 'master' into pw/world-state-cleanup
PhilWindle Nov 13, 2024
e9968b7
Merge branch 'master' into pw/world-state-cleanup
PhilWindle Nov 13, 2024
4704900
Data directory config
PhilWindle Nov 14, 2024
7a0ed9b
WIP
PhilWindle Nov 14, 2024
5d229eb
WIP
PhilWindle Nov 14, 2024
62d9a9a
Changed default value
PhilWindle Nov 15, 2024
5dc7e55
Merge remote-tracking branch 'origin/master' into pw/data-config
PhilWindle Nov 17, 2024
192b4dc
Merge branch 'master' into pw/data-config
PhilWindle Nov 18, 2024
9bfb0d7
Merge branch 'master' into pw/data-config
PhilWindle Nov 18, 2024
b0b6057
Fixes
PhilWindle Nov 18, 2024
34ee499
Fixes
PhilWindle Nov 19, 2024
cf757f5
Fix
PhilWindle Nov 19, 2024
d69b3fd
Test fixes
PhilWindle Nov 19, 2024
5683889
Merge branch 'master' into pw/data-config
PhilWindle Nov 19, 2024
5b14855
Fixed prover coordination test
PhilWindle Nov 19, 2024
5aba28e
Disable uniswap test
PhilWindle Nov 19, 2024
70fec90
Documentation
PhilWindle Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void check_historic_sibling_path(TreeType& tree,
void commit_tree(TreeType& tree, bool expected_success = true)
{
Signal signal;
auto completion = [&](const Response& response) -> void {
TreeType::CommitCallback completion = [&](const TypedResponse<CommitResponse>& response) -> void {
EXPECT_EQ(response.success, expected_success);
signal.signal_level();
};
Expand All @@ -163,7 +163,7 @@ void rollback_tree(TreeType& tree)
void remove_historic_block(TreeType& tree, const index_t& blockNumber, bool expected_success = true)
{
Signal signal;
auto completion = [&](const Response& response) -> void {
auto completion = [&](const TypedResponse<RemoveHistoricResponse>& response) -> void {
EXPECT_EQ(response.success, expected_success);
signal.signal_level();
};
Expand All @@ -174,7 +174,7 @@ void remove_historic_block(TreeType& tree, const index_t& blockNumber, bool expe
void unwind_block(TreeType& tree, const index_t& blockNumber, bool expected_success = true)
{
Signal signal;
auto completion = [&](const Response& response) -> void {
auto completion = [&](const TypedResponse<UnwindResponse>& response) -> void {
EXPECT_EQ(response.success, expected_success);
signal.signal_level();
};
Expand Down Expand Up @@ -455,10 +455,13 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, reports_an_error_if_tree_is_
}
add_values(tree, values);

std::stringstream ss;
ss << "Unable to append leaves to tree " << name << " new size: 17 max size: 16";

Signal signal;
auto add_completion = [&](const TypedResponse<AddDataResponse>& response) {
EXPECT_EQ(response.success, false);
EXPECT_EQ(response.message, "Tree is full");
EXPECT_EQ(response.message, ss.str());
signal.signal_level();
};
tree.add_value(VALUES[16], add_completion);
Expand Down Expand Up @@ -501,7 +504,7 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, errors_are_caught_and_handle

// trying to commit that should fail
Signal signal;
auto completion = [&](const Response& response) -> void {
auto completion = [&](const TypedResponse<CommitResponse>& response) -> void {
EXPECT_EQ(response.success, false);
signal.signal_level();
};
Expand Down Expand Up @@ -1041,7 +1044,7 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, can_add_single_whilst_readin
Signal signal(1 + num_reads);

auto add_completion = [&](const TypedResponse<AddDataResponse>&) {
auto commit_completion = [&](const Response&) { signal.signal_decrement(); };
auto commit_completion = [&](const TypedResponse<CommitResponse>&) { signal.signal_decrement(); };
tree.commit(commit_completion);
};
tree.add_value(VALUES[0], add_completion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ inline ThreadPoolPtr make_thread_pool(uint64_t numThreads)
void inline print_store_data(LMDBTreeStore::SharedPtr db, std::ostream& os)
{
LMDBTreeStore::ReadTransaction::Ptr tx = db->create_read_transaction();
StatsMap stats;
TreeDBStats stats;
db->get_stats(stats, *tx);

for (const auto& m : stats) {
os << m.first << m.second << std::endl;
}
os << stats;
}
} // namespace bb::crypto::merkle_tree

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ template <typename TypeOfTree> void check_unfinalised_block_height(TypeOfTree& t
template <typename TypeOfTree> void commit_tree(TypeOfTree& tree, bool expectedSuccess = true)
{
Signal signal;
auto completion = [&](const Response& response) -> void {
auto completion = [&](const TypedResponse<CommitResponse>& response) -> void {
EXPECT_EQ(response.success, expectedSuccess);
signal.signal_level();
};
Expand Down Expand Up @@ -387,7 +387,7 @@ template <typename TypeOfTree>
void remove_historic_block(TypeOfTree& tree, const index_t& blockNumber, bool expected_success = true)
{
Signal signal;
auto completion = [&](const Response& response) -> void {
auto completion = [&](const TypedResponse<RemoveHistoricResponse>& response) -> void {
EXPECT_EQ(response.success, expected_success);
signal.signal_level();
};
Expand All @@ -411,7 +411,7 @@ template <typename TypeOfTree>
void unwind_block(TypeOfTree& tree, const index_t& blockNumber, bool expected_success = true)
{
Signal signal;
auto completion = [&](const Response& response) -> void {
auto completion = [&](const TypedResponse<UnwindResponse>& response) -> void {
EXPECT_EQ(response.success, expected_success);
signal.signal_level();
};
Expand Down Expand Up @@ -505,10 +505,13 @@ TEST_F(PersistedContentAddressedIndexedTreeTest, reports_an_error_if_tree_is_ove
}
add_values(tree, values);

std::stringstream ss;
ss << "Unable to insert values into tree " << name << " new size: 17 max size: 16";

Signal signal;
auto add_completion = [&](const TypedResponse<AddIndexedDataResponse<NullifierLeafValue>>& response) {
EXPECT_EQ(response.success, false);
EXPECT_EQ(response.message, "Tree is full");
EXPECT_EQ(response.message, ss.str());
signal.signal_level();
};
tree.add_or_update_value(NullifierLeafValue(VALUES[16]), add_completion);
Expand Down Expand Up @@ -939,10 +942,13 @@ TEST_F(PersistedContentAddressedIndexedTreeTest, reports_an_error_if_batch_conta
}
values[8] = values[0];

std::stringstream ss;
ss << "Duplicate key not allowed in same batch, key value: " << values[0].value << ", tree: " << name;

Signal signal;
auto add_completion = [&](const TypedResponse<AddIndexedDataResponse<NullifierLeafValue>>& response) {
EXPECT_EQ(response.success, false);
EXPECT_EQ(response.message, "Duplicate key not allowed in same batch");
EXPECT_EQ(response.message, ss.str());
signal.signal_level();
};
tree.add_or_update_values(values, add_completion);
Expand Down Expand Up @@ -1205,7 +1211,7 @@ TEST_F(PersistedContentAddressedIndexedTreeTest, can_add_single_whilst_reading)
Signal signal(1 + num_reads);

auto add_completion = [&](const TypedResponse<AddIndexedDataResponse<NullifierLeafValue>>&) {
auto commit_completion = [&](const Response&) { signal.signal_decrement(); };
auto commit_completion = [&](const TypedResponse<CommitResponse>&) { signal.signal_decrement(); };
tree.commit(commit_completion);
};
tree.add_or_update_value(VALUES[0], add_completion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ struct NullifierLeafValue {
static NullifierLeafValue empty() { return { fr::zero() }; }

static NullifierLeafValue padding(index_t i) { return { i }; }

static std::string name() { return std::string("NullifierLeafValue"); };
};

struct PublicDataLeafValue {
Expand Down Expand Up @@ -117,6 +119,8 @@ struct PublicDataLeafValue {
static PublicDataLeafValue empty() { return { fr::zero(), fr::zero() }; }

static PublicDataLeafValue padding(index_t i) { return { i, fr::zero() }; }

static std::string name() { return std::string("PublicDataLeafValue"); };
};

template <typename LeafType> struct IndexedLeaf {
Expand All @@ -128,7 +132,7 @@ template <typename LeafType> struct IndexedLeaf {

IndexedLeaf() = default;

IndexedLeaf(const LeafType& val, index_t nextIdx, fr nextVal)
IndexedLeaf(const LeafType& val, const index_t& nextIdx, const fr& nextVal)
: value(val)
, nextIndex(nextIdx)
, nextValue(nextVal)
Expand All @@ -140,6 +144,8 @@ template <typename LeafType> struct IndexedLeaf {

static bool is_updateable() { return LeafType::is_updateable(); }

static std::string name() { return LeafType::name(); }

bool operator==(IndexedLeaf<LeafType> const& other) const
{
return value == other.value && nextValue == other.nextValue && nextIndex == other.nextIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <endian.h>
#include <functional>
#include <vector>

Expand All @@ -29,7 +30,7 @@ void deserialise_key(void* data, uint8_t& key)
// 64 bit integers are stored in little endian byte order
std::vector<uint8_t> serialise_key(uint64_t key)
{
uint64_t le = key;
uint64_t le = htole64(key);
const uint8_t* p = reinterpret_cast<uint8_t*>(&le);
return std::vector<uint8_t>(p, p + sizeof(key));
}
Expand All @@ -38,10 +39,10 @@ void deserialise_key(void* data, uint64_t& key)
{
uint64_t le = 0;
std::memcpy(&le, data, sizeof(le));
key = le;
key = le64toh(le);
}

std::vector<uint8_t> serialise_key(uint256_t key)
std::vector<uint8_t> serialise_key(const uint256_t& key)
{
std::vector<uint8_t> buf(32);
std::memcpy(buf.data(), key.data, 32);
Expand All @@ -58,10 +59,7 @@ int size_cmp(const MDB_val* a, const MDB_val* b)
if (a->mv_size < b->mv_size) {
return -1;
}
if (a->mv_size > b->mv_size) {
return 1;
}
return 0;
return (a->mv_size > b->mv_size) ? 1 : 0;
}

std::vector<uint8_t> mdb_val_to_vector(const MDB_val& dbVal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int size_cmp(const MDB_val* a, const MDB_val* b);

std::vector<uint8_t> serialise_key(uint8_t key);
std::vector<uint8_t> serialise_key(uint64_t key);
std::vector<uint8_t> serialise_key(uint256_t key);
std::vector<uint8_t> serialise_key(const uint256_t& key);

void deserialise_key(void* data, uint8_t& key);
void deserialise_key(void* data, uint64_t& key);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "barretenberg/crypto/merkle_tree/lmdb_store/lmdb_database.hpp"

#include "barretenberg/crypto/merkle_tree/lmdb_store/callbacks.hpp"
#include "barretenberg/crypto/merkle_tree/lmdb_store/lmdb_db_transaction.hpp"
#include "barretenberg/crypto/merkle_tree/lmdb_store/lmdb_environment.hpp"
#include <utility>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#pragma once
#include "barretenberg/crypto/merkle_tree/lmdb_store/callbacks.hpp"
#include "barretenberg/crypto/merkle_tree/lmdb_store/lmdb_db_transaction.hpp"
#include "barretenberg/crypto/merkle_tree/lmdb_store/lmdb_environment.hpp"

namespace bb::crypto::merkle_tree {

class LMDBDatabaseCreationTransaction;
/**
* RAII wrapper atound the opening and closing of an LMDB database
* Contains a reference to its LMDB environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ void LMDBTransaction::abort()
call_lmdb_func(mdb_txn_abort, _transaction);
state = TransactionState::ABORTED;
}

bool LMDBTransaction::get_value(std::vector<uint8_t>& key, std::vector<uint8_t>& data, const LMDBDatabase& db) const
{
return lmdb_queries::get_value(key, data, db, *this);
}
} // namespace bb::crypto::merkle_tree
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once
#include "barretenberg/crypto/merkle_tree/lmdb_store/lmdb_database.hpp"
#include "barretenberg/crypto/merkle_tree/lmdb_store/lmdb_environment.hpp"
#include "barretenberg/crypto/merkle_tree/lmdb_store/queries.hpp"
#include <functional>
#include <vector>

namespace bb::crypto::merkle_tree {

Expand Down Expand Up @@ -33,9 +37,68 @@ class LMDBTransaction {
*/
virtual void abort();

template <typename T>
bool get_value_or_previous(T& key,
std::vector<uint8_t>& data,
const LMDBDatabase& db,
const std::function<bool(const std::vector<uint8_t>&)>& is_valid) const;

template <typename T> bool get_value_or_previous(T& key, std::vector<uint8_t>& data, const LMDBDatabase& db) const;

template <typename T> bool get_value(T& key, std::vector<uint8_t>& data, const LMDBDatabase& db) const;

template <typename T>
void get_all_values_greater_or_equal_key(const T& key,
std::vector<std::vector<uint8_t>>& data,
const LMDBDatabase& db) const;

template <typename T>
void get_all_values_lesser_or_equal_key(const T& key,
std::vector<std::vector<uint8_t>>& data,
const LMDBDatabase& db) const;

bool get_value(std::vector<uint8_t>& key, std::vector<uint8_t>& data, const LMDBDatabase& db) const;

protected:
std::shared_ptr<LMDBEnvironment> _environment;
MDB_txn* _transaction;
TransactionState state;
};

template <typename T> bool LMDBTransaction::get_value(T& key, std::vector<uint8_t>& data, const LMDBDatabase& db) const
{
std::vector<uint8_t> keyBuffer = serialise_key(key);
return get_value(keyBuffer, data, db);
}

template <typename T>
bool LMDBTransaction::get_value_or_previous(T& key, std::vector<uint8_t>& data, const LMDBDatabase& db) const
{
return lmdb_queries::get_value_or_previous(key, data, db, *this);
}

template <typename T>
bool LMDBTransaction::get_value_or_previous(T& key,
std::vector<uint8_t>& data,
const LMDBDatabase& db,
const std::function<bool(const std::vector<uint8_t>&)>& is_valid) const
{
return lmdb_queries::get_value_or_previous(key, data, db, is_valid, *this);
}

template <typename T>
void LMDBTransaction::get_all_values_greater_or_equal_key(const T& key,
std::vector<std::vector<uint8_t>>& data,
const LMDBDatabase& db) const
{
lmdb_queries::get_all_values_greater_or_equal_key(key, data, db, *this);
}

template <typename T>
void LMDBTransaction::get_all_values_lesser_or_equal_key(const T& key,
std::vector<std::vector<uint8_t>>& data,
const LMDBDatabase& db) const
{
lmdb_queries::get_all_values_lesser_or_equal_key(key, data, db, *this);
}
} // namespace bb::crypto::merkle_tree
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,4 @@ void LMDBTreeReadTransaction::abort()
LMDBTransaction::abort();
_environment->release_reader();
}

bool LMDBTreeReadTransaction::get_value(std::vector<uint8_t>& key,
std::vector<uint8_t>& data,
const LMDBDatabase& db) const
{
MDB_val dbKey;
dbKey.mv_size = key.size();
dbKey.mv_data = (void*)key.data();

MDB_val dbVal;
if (!call_lmdb_func(mdb_get, underlying(), db.underlying(), &dbKey, &dbVal)) {
return false;
}
copy_to_vector(dbVal, data);
return true;
}
} // namespace bb::crypto::merkle_tree
Loading
Loading