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

feat: World State Re-orgs #9035

Merged
merged 155 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
46b24db
feat: add world state
alexghr Jul 17, 2024
87a2642
feat: add world state nodejs addon
alexghr Jul 18, 2024
bd0aab7
feat: add native world state node package
alexghr Jul 18, 2024
eb8ad58
chore: update db size
alexghr Jul 18, 2024
8448cdc
test: enable block synch test
alexghr Jul 18, 2024
7fbb305
refactor: simplify types
alexghr Jul 18, 2024
30a0d5e
chore: update imports and interfaces
alexghr Aug 27, 2024
f8cba90
fix: switch to poseidon
alexghr Aug 27, 2024
5b6284e
Merge remote-tracking branch 'origin/master' into ag/world-state
PhilWindle Aug 29, 2024
af13709
Add yarn command
PhilWindle Aug 29, 2024
b21d995
Another attempt
PhilWindle Aug 29, 2024
60664e8
fix: remove bad includes
alexghr Aug 29, 2024
bd0bae9
Fix for gcc
PhilWindle Aug 29, 2024
c86cb35
fix: test
alexghr Aug 29, 2024
1697a23
fix: update hashes
alexghr Aug 29, 2024
8db2c50
Fix build attempt
PhilWindle Aug 29, 2024
01bd840
Merge branch 'ag/world-state' of github.com:AztecProtocol/aztec-packa…
PhilWindle Aug 29, 2024
cee7209
More build fixes
PhilWindle Aug 29, 2024
115e9be
Fixes
PhilWindle Aug 29, 2024
91f37cc
Fix bootstrap
PhilWindle Aug 29, 2024
dd914ef
More build fixes
PhilWindle Aug 29, 2024
8997dd3
More build stuff
PhilWindle Aug 29, 2024
72b5fa8
Fix
PhilWindle Aug 29, 2024
a0d3b33
Build fix
PhilWindle Aug 29, 2024
399492e
Updates for initial state reference
PhilWindle Sep 7, 2024
0f6a272
Merge branch 'ag/world-state' of github.com:AztecProtocol/aztec-packa…
PhilWindle Sep 7, 2024
83aaaca
Content addressed append only tree
PhilWindle Sep 10, 2024
cda2860
Some refactoring
PhilWindle Sep 11, 2024
307e29b
Tests passing
PhilWindle Sep 13, 2024
2df113d
Pending chain increasing
PhilWindle Sep 15, 2024
6ef0218
Historic paths
PhilWindle Sep 15, 2024
bb189b6
Tests passing
PhilWindle Sep 16, 2024
4a9b68d
More fixes
PhilWindle Sep 17, 2024
ff41a25
Block number versions of leaf retrieval
PhilWindle Sep 17, 2024
e0e2367
Minor refactor
PhilWindle Sep 17, 2024
52440b9
Tests
PhilWindle Sep 17, 2024
545b604
Historic data and tree images
PhilWindle Sep 17, 2024
910e7b5
Removed some debug logging
PhilWindle Sep 17, 2024
3c642d4
More tests and bug fixes
PhilWindle Sep 18, 2024
cc41c3f
Benchmark updates
PhilWindle Sep 18, 2024
5d9c985
Refactoring
PhilWindle Sep 18, 2024
ff8de80
Use narrowed key comparison
PhilWindle Sep 18, 2024
afd7a0f
Updated world state
PhilWindle Sep 18, 2024
9e0afd8
Removed logging
PhilWindle Sep 18, 2024
2fe4e8b
Fixes
PhilWindle Sep 18, 2024
77a4c49
Throttle additions to the thread pool
PhilWindle Sep 19, 2024
de1496b
Merge remote-tracking branch 'origin/master' into pw/new-world-state
PhilWindle Sep 19, 2024
fcdf688
Merge fixes
PhilWindle Sep 19, 2024
d77ab63
Fixes
PhilWindle Sep 19, 2024
30868b6
Merge branch 'pw/new-world-state' of github.com:AztecProtocol/aztec-p…
PhilWindle Sep 19, 2024
c7e27e9
TS tests passing
PhilWindle Sep 20, 2024
e17afdd
Creating and deleting forks
PhilWindle Sep 20, 2024
04c66ba
WIP
PhilWindle Sep 23, 2024
5c1d51b
Test updates
PhilWindle Sep 23, 2024
9b9257a
Merge remote-tracking branch 'origin/master' into pw/new-world-state
alexghr Sep 23, 2024
03bde5a
chore: restore lost code after merge
alexghr Sep 23, 2024
83f0d52
perf: batch insert all public writes at the same time
alexghr Sep 23, 2024
d603135
fix: add lock to get_initial_state_reference
alexghr Sep 25, 2024
1bc51b0
fix: handle create/delete fork messages
alexghr Sep 25, 2024
c73bfb2
fix: use correct response msgType when updating the archive tree
alexghr Sep 25, 2024
6036ae9
fix: handle forks at block 0
alexghr Sep 25, 2024
3beddf3
fix: implement getSnapshot on native world state
alexghr Sep 25, 2024
f192da8
fix: circular includes
alexghr Sep 25, 2024
c7740d1
fix: pass fork id along with all writes
alexghr Sep 25, 2024
fbfd5d3
test: add fork test
alexghr Sep 25, 2024
fb4b197
fix: archive tree writes when synching blocks
alexghr Sep 25, 2024
5955387
chore: update Earthly job references
alexghr Sep 25, 2024
8a5768b
Merge remote-tracking branch 'origin/master' into pw/new-world-state
alexghr Sep 25, 2024
beb6333
fix: explicitly capture `this`
alexghr Sep 25, 2024
53757f1
fix: update unit tests
alexghr Sep 25, 2024
42e96f8
fix: add initialisers
alexghr Sep 25, 2024
8fb271c
fix: use move to fix mem leak
alexghr Sep 26, 2024
027c4ae
fix: memory leak in indexed tree
alexghr Sep 26, 2024
52be23e
fix: tighter lock guards
alexghr Sep 26, 2024
49ac72f
fix: properly fix the circular reference
alexghr Sep 26, 2024
19bd6a9
fix: enqueue job under lock
alexghr Sep 27, 2024
ead7b6d
fix: pass-by-value index_t
alexghr Sep 27, 2024
65ab5af
Merge remote-tracking branch 'origin/master' into pw/new-world-state
alexghr Sep 27, 2024
4aa86aa
refactor: take tree heights from constants.nr
alexghr Sep 27, 2024
51bf6b6
Revert "fix: pass-by-value index_t"
alexghr Sep 27, 2024
1572dc5
test: check initial archive root
alexghr Sep 27, 2024
bd7fb8d
fix: include constants in test
alexghr Sep 27, 2024
e102a9e
refactor: rename block_hash to block_header_hash
alexghr Sep 27, 2024
f84bb85
fix: pass full config options to world_state
alexghr Sep 27, 2024
dd4485d
fix: actually test the right fork
alexghr Sep 27, 2024
ed9f638
feat: clear data on rollup address change
alexghr Sep 27, 2024
2e3c5d0
test: remove unnecessary test
alexghr Sep 27, 2024
46f2004
fix: consistently copy the world_state napi module
alexghr Sep 27, 2024
91058e3
WIP
PhilWindle Sep 27, 2024
0c9aedd
Cleanup
PhilWindle Sep 27, 2024
0a4f447
More cleanup work
PhilWindle Sep 27, 2024
f75a6cc
Test fixes
PhilWindle Sep 28, 2024
184d3d5
More cleanup
PhilWindle Sep 28, 2024
1cff79a
Updated benchmarks
PhilWindle Sep 28, 2024
04ddfa0
Cap enqueued ops at size of thread pool
PhilWindle Sep 28, 2024
cc202d2
Merge remote-tracking branch 'origin/master' into pw/new-world-state
alexghr Sep 30, 2024
cba51ff
fix: bad conflict resolution
alexghr Sep 30, 2024
e580483
fix: yarn prepare
alexghr Sep 30, 2024
9fb122b
fix: wait for jobs to settle before stopping prover node
alexghr Sep 30, 2024
48e41ef
Initial work on batch insertion without witness retrieval
PhilWindle Sep 30, 2024
ba1518f
Cleanup
PhilWindle Sep 30, 2024
764c47c
Merge branch 'pw/new-world-state' of github.com:AztecProtocol/aztec-p…
PhilWindle Sep 30, 2024
dade28f
Merge branch 'pw/new-world-state' into pw/world-state-pruning
PhilWindle Oct 1, 2024
b54bfbb
Merge remote-tracking branch 'origin/master' into pw/new-world-state
alexghr Oct 2, 2024
b1a597f
feat: init archive tree (#8908)
alexghr Oct 3, 2024
184666b
test: fix orchestrator_failure race
alexghr Oct 3, 2024
40d4f36
Append only tests passing with leaf key persistance
PhilWindle Oct 3, 2024
4d753df
fix: public write batches (#8986)
alexghr Oct 4, 2024
d85c4fa
Use atomic
PhilWindle Oct 4, 2024
051a924
Merge remote-tracking branch 'origin/master' into pw/new-world-state
PhilWindle Oct 4, 2024
c01d985
Merge branch 'pw/new-world-state' into pw/world-state-pruning
PhilWindle Oct 4, 2024
aa55f0d
feat: forks (#8984)
alexghr Oct 4, 2024
5e7e5e0
chore: fix formatting issue
alexghr Oct 4, 2024
8e8da28
fix: more timeouts
alexghr Oct 4, 2024
07ff556
Merge remote-tracking branch 'origin/master' into pw/new-world-state
alexghr Oct 4, 2024
2c48b54
More WIP
PhilWindle Oct 5, 2024
ead6f2c
Test updates
PhilWindle Oct 5, 2024
4d2a540
Merge remote-tracking branch 'origin/master' into pw/new-world-state
alexghr Oct 5, 2024
5431d20
fix: properly capture errors
alexghr Oct 5, 2024
8503881
State pruning and tests
PhilWindle Oct 5, 2024
e292749
fix: return error
alexghr Oct 5, 2024
6982054
fix: catch dupe nullifier early
alexghr Oct 5, 2024
58c83f5
More tests
PhilWindle Oct 6, 2024
04bd242
Remove gcc pic build
PhilWindle Oct 7, 2024
80f722c
Merge branch 'pw/new-world-state' of github.com:AztecProtocol/aztec-p…
PhilWindle Oct 7, 2024
8412e78
Merge branch 'master' into pw/new-world-state
alexghr Oct 7, 2024
97964fd
Merge branch 'master' into pw/new-world-state
alexghr Oct 8, 2024
d0d57b3
WIP
PhilWindle Oct 8, 2024
7c08711
Merge remote-tracking branch 'origin/pw/new-world-state' into pw/worl…
PhilWindle Oct 8, 2024
770e6b3
State pruning and tests
PhilWindle Oct 9, 2024
3789fbd
Merge remote-tracking branch 'origin/master' into pw/world-state-pruning
PhilWindle Oct 9, 2024
201e362
Merge fixes
PhilWindle Oct 9, 2024
5095704
Merge fix
PhilWindle Oct 9, 2024
3129dfa
Merge fixes
PhilWindle Oct 9, 2024
07b976c
More merge fixes
PhilWindle Oct 9, 2024
37476b6
Merge branch 'master' into pw/world-state-pruning
PhilWindle Oct 9, 2024
4529d52
Merge fixes
PhilWindle Oct 9, 2024
962b4b8
Merge fix
PhilWindle Oct 9, 2024
d2de085
Merge fixes
PhilWindle Oct 9, 2024
b0858a5
fix: Correcttion of batch size calculation (#9144)
PhilWindle Oct 10, 2024
b5aa8a7
Enable finalising multiple blocks
PhilWindle Oct 10, 2024
b92dd48
Merge fix
PhilWindle Oct 10, 2024
c2bb92c
Refactor around google test imports
PhilWindle Oct 10, 2024
950c00b
Merge branch 'master' into pw/world-state-pruning
PhilWindle Oct 10, 2024
a0a87ed
Fix tests and formatting
PhilWindle Oct 10, 2024
f4674d2
Spelling
PhilWindle Oct 10, 2024
a2244b6
Test refactor
PhilWindle Oct 10, 2024
b75d97d
Support forking from block 0 when not latest part 1
PhilWindle Oct 10, 2024
08bf9a2
Handle forks at block 0
PhilWindle Oct 10, 2024
c8bfbb1
Use bb::numeric
PhilWindle Oct 10, 2024
d220da0
Function rename
PhilWindle Oct 10, 2024
6d743b5
Protect against removing the tip of finalised chain
PhilWindle Oct 10, 2024
bcb86c3
Fix fork read after writes
spalladino Oct 11, 2024
53057bf
Fix test
spalladino Oct 11, 2024
05f600e
Merge branch 'master' into pw/world-state-pruning
PhilWindle Oct 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ template <typename Store, typename HashingPolicy> class ContentAddressedAppendOn
using GetLeafCallback = std::function<void(const TypedResponse<GetLeafResponse>&)>;
using CommitCallback = std::function<void(const Response&)>;
using RollbackCallback = std::function<void(const Response&)>;
using RemoveHistoricBlockCallback = std::function<void(const Response&)>;
using UnwindBlockCallback = std::function<void(const Response&)>;
using FinaliseBlockCallback = std::function<void(const Response&)>;

// Only construct from provided store and thread pool, no copies or moves
ContentAddressedAppendOnlyTree(std::unique_ptr<Store> store,
Expand Down Expand Up @@ -167,15 +170,15 @@ template <typename Store, typename HashingPolicy> class ContentAddressedAppendOn
* @brief Returns the index of the provided leaf in the tree only if it exists after the index value provided
*/
void find_leaf_index_from(const fr& leaf,
index_t start_index,
const index_t& start_index,
bool includeUncommitted,
const FindLeafCallback& on_completion) const;

/**
* @brief Returns the index of the provided leaf in the tree only if it exists after the index value provided
*/
void find_leaf_index_from(const fr& leaf,
index_t start_index,
const index_t& start_index,
const index_t& blockNumber,
bool includeUncommitted,
const FindLeafCallback& on_completion) const;
Expand All @@ -195,6 +198,12 @@ template <typename Store, typename HashingPolicy> class ContentAddressedAppendOn
*/
uint32_t depth() const { return depth_; }

void remove_historic_block(const index_t& blockNumber, const RemoveHistoricBlockCallback& on_completion);

void unwind_block(const index_t& blockNumber, const UnwindBlockCallback& on_completion);

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

protected:
using ReadTransaction = typename Store::ReadTransaction;
using ReadTransactionPtr = typename Store::ReadTransactionPtr;
Expand Down Expand Up @@ -355,6 +364,9 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::get_sibling_path(cons
auto job = [=, this]() {
execute_and_report<GetSiblingPathResponse>(
[=, this](TypedResponse<GetSiblingPathResponse>& response) {
if (blockNumber == 0) {
throw std::runtime_error("Invalid block number");
}
Comment on lines +367 to +369
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we ever request the sibling path for the genesis block (0) on the archive tree? Seems not, since this is not blowing up, but I'd've expected to be possible to fetch it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe so.

ReadTransactionPtr tx = store_->create_read_transaction();
BlockPayload blockData;
if (!store_->get_block_data(blockNumber, blockData, *tx)) {
Expand Down Expand Up @@ -409,6 +421,7 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::get_subtree_sibling_p
RequestContext requestContext;
requestContext.includeUncommitted = includeUncommitted;
requestContext.root = store_->get_current_root(*tx, includeUncommitted);
// std::cout << "Current root: " << requestContext.root << std::endl;
OptionalSiblingPath optional_path =
get_subtree_sibling_path_internal(leaf_index, subtree_depth, requestContext, *tx);
response.inner.path = optional_sibling_path_to_full_sibling_path(optional_path);
Expand Down Expand Up @@ -467,7 +480,7 @@ std::optional<fr> ContentAddressedAppendOnlyTree<Store, HashingPolicy>::find_lea
// std::cout << "No child" << std::endl;
return std::nullopt;
}
// std::cout << "Found child" << std::endl;
// std::cout << "Found child " << child.value() << std::endl;

hash = child.value();

Expand Down Expand Up @@ -572,6 +585,9 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::get_leaf(const index_
auto job = [=, this]() {
execute_and_report<GetLeafResponse>(
[=, this](TypedResponse<GetLeafResponse>& response) {
if (blockNumber == 0) {
throw std::runtime_error("Invalid block number");
}
ReadTransactionPtr tx = store_->create_read_transaction();
BlockPayload blockData;
if (!store_->get_block_data(blockNumber, blockData, *tx)) {
Expand Down Expand Up @@ -616,12 +632,12 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::find_leaf_index(const

template <typename Store, typename HashingPolicy>
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::find_leaf_index_from(
const fr& leaf, index_t start_index, bool includeUncommitted, const FindLeafCallback& on_completion) const
const fr& leaf, const index_t& start_index, bool includeUncommitted, const FindLeafCallback& on_completion) const
{
auto job = [=, this]() -> void {
execute_and_report<FindLeafIndexResponse>(
[=, this](TypedResponse<FindLeafIndexResponse>& response) {
typename Store::ReadTransactionPtr tx = store_->create_read_transaction();
ReadTransactionPtr tx = store_->create_read_transaction();
RequestContext requestContext;
requestContext.includeUncommitted = includeUncommitted;
requestContext.root = store_->get_current_root(*tx, includeUncommitted);
Expand All @@ -640,15 +656,18 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::find_leaf_index_from(
template <typename Store, typename HashingPolicy>
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::find_leaf_index_from(
const fr& leaf,
index_t start_index,
const index_t& start_index,
const index_t& blockNumber,
bool includeUncommitted,
const FindLeafCallback& on_completion) const
{
auto job = [=, this]() -> void {
execute_and_report<FindLeafIndexResponse>(
[=, this](TypedResponse<FindLeafIndexResponse>& response) {
typename Store::ReadTransactionPtr tx = store_->create_read_transaction();
if (blockNumber == 0) {
throw std::runtime_error("Invalid block number");
}
ReadTransactionPtr tx = store_->create_read_transaction();
BlockPayload blockData;
if (!store_->get_block_data(blockNumber, blockData, *tx)) {
throw std::runtime_error("Data for block unavailable");
Expand Down Expand Up @@ -712,6 +731,57 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::rollback(const Rollba
workers_->enqueue(job);
}

template <typename Store, typename HashingPolicy>
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::remove_historic_block(
const index_t& blockNumber, const RemoveHistoricBlockCallback& on_completion)
{
auto job = [=, this]() {
execute_and_report(
[=, this]() {
if (blockNumber == 0) {
throw std::runtime_error("Invalid block number");
}
store_->remove_historical_block(blockNumber);
},
on_completion);
};
workers_->enqueue(job);
}

template <typename Store, typename HashingPolicy>
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::unwind_block(
const index_t& blockNumber, const RemoveHistoricBlockCallback& on_completion)
{
auto job = [=, this]() {
execute_and_report(
[=, this]() {
if (blockNumber == 0) {
throw std::runtime_error("Invalid block number");
}
Comment on lines +758 to +760
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we cannot unwind to genesis, which means initial epoch cannot be unwound?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should we check we are not accidentally removing the finalised block, both here and when removing historical? (maybe it's checked somewhere else)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the api here is 'off by one' compared to TS. So unwinding block 1 leaves you at block 0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will protect against removing the current finalised block in either direction.

store_->unwind_block(blockNumber);
},
on_completion);
};
workers_->enqueue(job);
}

template <typename Store, typename HashingPolicy>
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::finalise_block(const index_t& blockNumber,
const FinaliseBlockCallback& on_completion)
{
auto job = [=, this]() {
execute_and_report(
[=, this]() {
if (blockNumber == 0) {
throw std::runtime_error("Invalid block number");
}
store_->advance_finalised_block(blockNumber);
},
on_completion);
};
workers_->enqueue(job);
}

template <typename Store, typename HashingPolicy>
index_t ContentAddressedAppendOnlyTree<Store, HashingPolicy>::get_batch_insertion_size(index_t treeSize,
index_t remainingAppendSize)
Expand All @@ -738,7 +808,7 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::add_values_internal(s
index_t& new_size,
bool update_index)
{
typename Store::ReadTransactionPtr tx = store_->create_read_transaction();
ReadTransactionPtr tx = store_->create_read_transaction();
TreeMeta meta;
store_->get_meta(meta, *tx, true);
index_t sizeToAppend = values->size();
Expand Down
Loading
Loading