Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
7753283
WIP
PhilWindle Dec 20, 2024
2f1b2af
WIP
PhilWindle Dec 24, 2024
77df462
WIP
PhilWindle Jan 14, 2025
e0012b2
Merge branch 'master' into pw/tree-concurrency
PhilWindle Jan 14, 2025
fe1ee9b
WIP
PhilWindle Jan 14, 2025
c4cc155
WIP
PhilWindle Jan 14, 2025
44f02f2
WIP
PhilWindle Jan 15, 2025
dce4701
Moving files
PhilWindle Jan 15, 2025
be77033
Moving files around
PhilWindle Jan 15, 2025
d02755f
Renamed transactions
PhilWindle Jan 15, 2025
124682b
Initial LMDBStore class
PhilWindle Jan 15, 2025
321543c
fix: remove circular includes
Jan 15, 2025
18c3945
chore: move files
Jan 15, 2025
2b5a514
refactor: extract module init outside of world_state
Jan 15, 2025
67de053
refactor!: rename world_state_napi -> nodejs_module
Jan 15, 2025
1878207
WIP
PhilWindle Jan 15, 2025
b41e3e3
Merge branch 'feat/lmdb-wrapper' of github.com:AztecProtocol/aztec-pa…
PhilWindle Jan 15, 2025
df48bf5
Merge remote-tracking branch 'origin/master' into feat/lmdb-wrapper
PhilWindle Jan 15, 2025
2b4e4ae
feat: first pass
Jan 15, 2025
9ccfd36
refactor: extract msg processing
Jan 16, 2025
6f063a6
feat: add @aztec/native
Jan 16, 2025
5ab8325
WIP
PhilWindle Jan 16, 2025
0ee01c1
WIP
PhilWindle Jan 17, 2025
d6996f3
Merge branch 'feat/lmdb-wrapper' of github.com:AztecProtocol/aztec-pa…
PhilWindle Jan 17, 2025
58359d3
More work on cursors and duplicates
PhilWindle Jan 17, 2025
bd0702f
Work on duplicates
PhilWindle Jan 18, 2025
35133ed
Refactoring of tree stores
PhilWindle Jan 21, 2025
77d8591
Test refactoring
PhilWindle Jan 21, 2025
8c5e594
Batch put operations
PhilWindle Jan 21, 2025
66e3ec7
feat: nodejs lmdb wrapper (dummy backend)
Jan 21, 2025
c001e19
refactor: @aztec/native
Jan 21, 2025
22be98d
Merge branch 'master' into feat/lmdb-wrapper
Jan 21, 2025
553862e
fix: add dep to external lib
Jan 21, 2025
37ea38c
fix: remove unused import
Jan 21, 2025
789d05c
fix: lint
Jan 21, 2025
797296b
chore: fix boxes/yarn.lock
Jan 21, 2025
7959d9c
WIP
PhilWindle Jan 24, 2025
7755f76
WIP
PhilWindle Jan 24, 2025
4d38c91
WIP
PhilWindle Jan 25, 2025
b6fc54b
More tests
PhilWindle Jan 27, 2025
d7d5bb2
Merge remote-tracking branch 'origin/master' into feat/lmdb-wrapper
Jan 27, 2025
f2891fe
Test with realistic values
PhilWindle Jan 27, 2025
9c766a5
feat: native nodejs module for lmdb
Jan 27, 2025
d90c544
feat: new store
Jan 27, 2025
ca5438e
feat: add map and single value
Jan 27, 2025
654d4ee
feat: Archiver uses new store backend
Jan 27, 2025
8a4ef33
feat: ProvingBroker using new store backend
Jan 27, 2025
57ecd47
feat: mempool using new store backend
Jan 27, 2025
6e85f72
Merge remote-tracking branch 'origin/feat/lmdb-wrapper' into pw/check…
PhilWindle Jan 28, 2025
b1c8b1b
Merge fixes
PhilWindle Jan 28, 2025
1a898aa
WIP
PhilWindle Jan 28, 2025
5dad5d8
Minor refactor
PhilWindle Jan 29, 2025
cccde3e
Fixed issue tracking new leaf keys
PhilWindle Jan 29, 2025
7a44b0e
Test fix
PhilWindle Jan 29, 2025
944dd66
Renames
PhilWindle Jan 29, 2025
0274d3c
More tests
PhilWindle Jan 29, 2025
15dbbb9
More tests
PhilWindle Jan 29, 2025
fbb441f
Test fix
PhilWindle Jan 29, 2025
fda1b25
Merge remote-tracking branch 'origin/master' into pw/checkpointing
PhilWindle Feb 5, 2025
cf741fc
Fix merge issues
PhilWindle Feb 5, 2025
db7d233
Merge fixes
PhilWindle Feb 5, 2025
bda03ca
Merge fixes
PhilWindle Feb 5, 2025
7b825b6
Comment
PhilWindle Feb 5, 2025
2509c73
Merge fix
PhilWindle Feb 6, 2025
0043032
Merge fix
PhilWindle Feb 6, 2025
c538d0a
Merge fixes
PhilWindle Feb 7, 2025
37697cb
More merge fixes
PhilWindle Feb 7, 2025
c6f6c35
Review changes
PhilWindle Feb 7, 2025
0e88d91
Review changes
PhilWindle Feb 9, 2025
879da26
Fixes
PhilWindle Feb 9, 2025
c98eef6
Merge branch 'master' into pw/checkpointing
PhilWindle Feb 9, 2025
31678d3
Formatting
PhilWindle Feb 9, 2025
2977905
Fix attempt
PhilWindle Feb 10, 2025
27c4ffe
Merge branch 'master' into pw/checkpointing
PhilWindle Feb 10, 2025
b6e64db
Merge branch 'master' into pw/checkpointing
PhilWindle Feb 10, 2025
822040c
Merge branch 'master' into pw/checkpointing
PhilWindle Feb 10, 2025
1967caf
Formatting
PhilWindle Feb 10, 2025
af8527d
Merge remote-tracking branch 'origin/master' into pw/checkpointing
PhilWindle Feb 10, 2025
e348a10
Merge branch 'master' into pw/checkpointing
PhilWindle Feb 10, 2025
ecfad26
Merge branch 'master' into pw/checkpointing
PhilWindle Feb 11, 2025
5c71142
Merge branch 'master' into pw/checkpointing
PhilWindle Feb 11, 2025
31506fc
Merge remote-tracking branch 'origin/master' into pw/checkpointing
PhilWindle Feb 12, 2025
10ebe9e
Merge branch 'master' into pw/checkpointing
PhilWindle Feb 12, 2025
844d736
Fix merge issue
PhilWindle Feb 12, 2025
648eb60
Merge branch 'pw/checkpointing' of github.com:AztecProtocol/aztec-pac…
PhilWindle Feb 12, 2025
957db8c
Merge branch 'master' into pw/checkpointing
PhilWindle Feb 12, 2025
ff743ec
Fixed merge issue
PhilWindle Feb 12, 2025
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
2 changes: 1 addition & 1 deletion barretenberg/cpp/scripts/merkle_tree_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
# run commands relative to parent directory
cd $(dirname $0)/..

DEFAULT_TESTS=PersistedIndexedTreeTest.*:PersistedAppendOnlyTreeTest.*:LMDBTreeStoreTest.*:PersistedContentAddressedIndexedTreeTest.*:PersistedContentAddressedAppendOnlyTreeTest.*
DEFAULT_TESTS=PersistedIndexedTreeTest.*:PersistedAppendOnlyTreeTest.*:LMDBTreeStoreTest.*:PersistedContentAddressedIndexedTreeTest.*:PersistedContentAddressedAppendOnlyTreeTest.*:ContentAddressedCacheTest.*
TEST=${1:-$DEFAULT_TESTS}
PRESET=${PRESET:-clang16}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,21 @@ template <typename Store, typename HashingPolicy> class ContentAddressedAppendOn
using StoreType = Store;

// Asynchronous methods accept these callback function types as arguments
using EmptyResponseCallback = std::function<void(Response&)>;
using AppendCompletionCallback = std::function<void(TypedResponse<AddDataResponse>&)>;
using MetaDataCallback = std::function<void(TypedResponse<TreeMetaResponse>&)>;
using HashPathCallback = std::function<void(TypedResponse<GetSiblingPathResponse>&)>;
using FindLeafCallback = std::function<void(TypedResponse<FindLeafIndexResponse>&)>;
using GetLeafCallback = std::function<void(TypedResponse<GetLeafResponse>&)>;
using CommitCallback = std::function<void(TypedResponse<CommitResponse>&)>;
using RollbackCallback = std::function<void(Response&)>;
using RollbackCallback = EmptyResponseCallback;
using RemoveHistoricBlockCallback = std::function<void(TypedResponse<RemoveHistoricResponse>&)>;
using UnwindBlockCallback = std::function<void(TypedResponse<UnwindResponse>&)>;
using FinaliseBlockCallback = std::function<void(Response&)>;
using FinaliseBlockCallback = EmptyResponseCallback;
using GetBlockForIndexCallback = std::function<void(TypedResponse<BlockForIndexResponse>&)>;
using CheckpointCallback = EmptyResponseCallback;
using CheckpointCommitCallback = EmptyResponseCallback;
using CheckpointRevertCallback = EmptyResponseCallback;

// Only construct from provided store and thread pool, no copies or moves
ContentAddressedAppendOnlyTree(std::unique_ptr<Store> store,
Expand Down Expand Up @@ -223,6 +227,10 @@ template <typename Store, typename HashingPolicy> class ContentAddressedAppendOn

void finalise_block(const block_number_t& blockNumber, const FinaliseBlockCallback& on_completion);

void checkpoint(const CheckpointCallback& on_completion);
void commit_checkpoint(const CheckpointCommitCallback& on_completion);
void revert_checkpoint(const CheckpointRevertCallback& on_completion);

protected:
using ReadTransaction = typename Store::ReadTransaction;
using ReadTransactionPtr = typename Store::ReadTransactionPtr;
Expand Down Expand Up @@ -843,6 +851,34 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::rollback(const Rollba
workers_->enqueue(job);
}

// TODO(PhilWindle): One possible optimisation is for the following 3 functions
// checkpoint, commit_checkpoint and revert_checkpoint to not use the thread pool
// It is not stricly necessary for these operations to use it. The balance is whether
// the cost of using it outweighs the benefit or checkpointing/reverting all tree concurrently

template <typename Store, typename HashingPolicy>
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::checkpoint(const CheckpointCallback& on_completion)
{
auto job = [=, this]() { execute_and_report([=, this]() { store_->checkpoint(); }, on_completion); };
workers_->enqueue(job);
}

template <typename Store, typename HashingPolicy>
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::commit_checkpoint(
const CheckpointCommitCallback& on_completion)
{
auto job = [=, this]() { execute_and_report([=, this]() { store_->commit_checkpoint(); }, on_completion); };
workers_->enqueue(job);
}

template <typename Store, typename HashingPolicy>
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::revert_checkpoint(
const CheckpointRevertCallback& on_completion)
{
auto job = [=, this]() { execute_and_report([=, this]() { store_->revert_checkpoint(); }, on_completion); };
workers_->enqueue(job);
}

template <typename Store, typename HashingPolicy>
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::remove_historic_block(
const block_number_t& blockNumber, const RemoveHistoricBlockCallback& on_completion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <array>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <filesystem>
#include <gtest/gtest.h>
#include <memory>
#include <optional>
#include <stdexcept>
Expand Down Expand Up @@ -151,17 +151,6 @@ void commit_tree(TreeType& tree, bool expected_success = true)
signal.wait_for_level();
}

void rollback_tree(TreeType& tree)
{
Signal signal;
auto completion = [&](const Response& response) -> void {
EXPECT_EQ(response.success, true);
signal.signal_level();
};
tree.rollback(completion);
signal.wait_for_level();
}

void remove_historic_block(TreeType& tree, const block_number_t& blockNumber, bool expected_success = true)
{
Signal signal;
Expand Down Expand Up @@ -1949,3 +1938,112 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, can_not_historically_remove_
}
remove_historic_block(tree, blockToFinalise, false);
}

TEST_F(PersistedContentAddressedAppendOnlyTreeTest, can_checkpoint_and_revert_forks)
{
constexpr size_t depth = 10;
uint32_t blockSize = 16;
std::string name = random_string();
ThreadPoolPtr pool = make_thread_pool(1);
LMDBTreeStore::SharedPtr db = std::make_shared<LMDBTreeStore>(_directory, name, _mapSize, _maxReaders);
MemoryTree<Poseidon2HashPolicy> memdb(depth);

{
std::unique_ptr<Store> store = std::make_unique<Store>(name, depth, db);
TreeType tree(std::move(store), pool);

std::vector<fr> values = create_values(blockSize);
add_values(tree, values);

commit_tree(tree);
}

std::unique_ptr<Store> store = std::make_unique<Store>(name, depth, db);
TreeType tree(std::move(store), pool);

// We apply a number of updates and checkpoint the tree each time

uint32_t stackDepth = 20;

std::vector<fr_sibling_path> paths(stackDepth);
uint32_t index = 0;
for (; index < stackDepth - 1; index++) {
std::vector<fr> values = create_values(blockSize);
add_values(tree, values);

paths[index] = get_sibling_path(tree, 3);

try {
checkpoint_tree(tree);
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
}

// Now add one more depth, this will be un-checkpointed
{
std::vector<fr> values = create_values(blockSize);
add_values(tree, values);
paths[index] = get_sibling_path(tree, 3);
}

index_t checkpointIndex = index;

// The tree is currently at the state of index 19
EXPECT_EQ(get_sibling_path(tree, 3), paths[checkpointIndex]);

// We now alternate committing and reverting the checkpoints half way up the stack

for (; index > stackDepth / 2; index--) {
if (index % 2 == 0) {
revert_checkpoint_tree(tree, true);
checkpointIndex = index - 1;
} else {
commit_checkpoint_tree(tree, true);
}

EXPECT_EQ(get_sibling_path(tree, 3), paths[checkpointIndex]);
}

// Now apply another set of updates and checkpoints back to the original stack depth
for (; index < stackDepth - 1; index++) {
std::vector<fr> values = create_values(blockSize);
add_values(tree, values);

paths[index] = get_sibling_path(tree, 3);

try {
checkpoint_tree(tree);
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
}

// Now add one more depth, this will be un-checkpointed
{
std::vector<fr> values = create_values(blockSize);
add_values(tree, values);
paths[index] = get_sibling_path(tree, 3);
}

// We now alternatively commit and revert all the way back to the start
checkpointIndex = index;

// The tree is currently at the state of index 19
EXPECT_EQ(get_sibling_path(tree, 3), paths[checkpointIndex]);

for (; index > 0; index--) {
if (index % 2 == 0) {
revert_checkpoint_tree(tree, true);
checkpointIndex = index - 1;
} else {
commit_checkpoint_tree(tree, true);
}

EXPECT_EQ(get_sibling_path(tree, 3), paths[checkpointIndex]);
}

Comment thread
alexghr marked this conversation as resolved.
// Should not be able to commit or revert where there is no active checkpoint
revert_checkpoint_tree(tree, false);
commit_checkpoint_tree(tree, false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,10 @@ void ContentAddressedIndexedTree<Store, HashingPolicy>::generate_insertions(
// std::cout << "Failed to find low leaf" << std::endl;
throw std::runtime_error(format("Unable to insert values into tree ",
meta.name,
" failed to find low leaf at index ",
low_leaf_index));
", failed to find low leaf at index ",
low_leaf_index,
", current size: ",
meta.size));
}
// std::cout << "Low leaf hash " << low_leaf_hash.value() << std::endl;

Expand Down Expand Up @@ -1454,7 +1456,7 @@ void ContentAddressedIndexedTree<Store, HashingPolicy>::generate_sequential_inse
if (!low_leaf_hash.has_value()) {
throw std::runtime_error(format("Unable to insert values into tree ",
meta.name,
" failed to find low leaf at index ",
", failed to find low leaf at index ",
low_leaf_index));
}

Expand Down
Loading