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: Insert public data tree leaves one by one #9989

Merged
merged 41 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
04d5a51
separate base rollups
sirasistant Nov 14, 2024
3859497
update public data write strategy
sirasistant Nov 14, 2024
770eb08
wip
sirasistant Nov 14, 2024
34d630a
fixes
sirasistant Nov 15, 2024
26e1d07
remove prints
sirasistant Nov 15, 2024
89ffdcc
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 15, 2024
93a1814
fix inputvalue typing
sirasistant Nov 15, 2024
3a8a30a
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 15, 2024
34614ff
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 15, 2024
7e113d4
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 15, 2024
c661500
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 15, 2024
3bb783e
wip fix noir tests
sirasistant Nov 15, 2024
4725d45
Merge branch 'arv/insertion_strategy_avm' of github.com:AztecProtocol…
sirasistant Nov 15, 2024
ee578e9
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 15, 2024
f0fade5
fix private base rollup tests
sirasistant Nov 15, 2024
b7af176
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 15, 2024
7b26661
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 18, 2024
576a171
wip public base rollup tests
sirasistant Nov 18, 2024
0649da6
restore public base tests
sirasistant Nov 18, 2024
912fef0
Merge branch 'arv/insertion_strategy_avm' of github.com:AztecProtocol…
sirasistant Nov 18, 2024
89233f7
fmt
sirasistant Nov 18, 2024
7279728
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 18, 2024
9ed6b6b
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 18, 2024
9a32057
Merge branch 'arv/insertion_strategy_avm' of github.com:AztecProtocol…
sirasistant Nov 19, 2024
3aad930
refactor rename
sirasistant Nov 19, 2024
54f7bb5
fix commit as a block
sirasistant Nov 19, 2024
c5fd6b2
fix test
sirasistant Nov 19, 2024
06c0935
remove prints
sirasistant Nov 19, 2024
c3950dc
update comments
sirasistant Nov 19, 2024
1ed6cf9
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 19, 2024
ab77747
fix merge
sirasistant Nov 19, 2024
89addc3
remove padding writes
sirasistant Nov 19, 2024
2f7ac68
remove subtree height usage
sirasistant Nov 19, 2024
993f05c
remove old constants
sirasistant Nov 19, 2024
27ea93f
fix units
sirasistant Nov 19, 2024
89d6798
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 19, 2024
2ed3706
refactor public base
sirasistant Nov 19, 2024
c4eb74a
more base rollup refactor
sirasistant Nov 19, 2024
937bb4a
comments
sirasistant Nov 19, 2024
0108e72
Merge branch 'master' into arv/insertion_strategy_avm
sirasistant Nov 19, 2024
9d00674
refactor
sirasistant Nov 20, 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 @@ -188,7 +188,7 @@ void LMDBTreeStore::increment_node_reference_count(const fr& nodeHash, WriteTran
NodePayload nodePayload;
bool success = get_node_data(nodeHash, nodePayload, tx);
if (!success) {
throw std::runtime_error("Failed to find node when attempting to increases reference count");
throw std::runtime_error("Failed to find node when attempting to increase reference count");
}
++nodePayload.ref;
// std::cout << "Incrementing siblng at " << nodeHash << ", to " << nodePayload.ref << std::endl;
Expand All @@ -212,7 +212,7 @@ void LMDBTreeStore::decrement_node_reference_count(const fr& nodeHash, NodePaylo
{
bool success = get_node_data(nodeHash, nodeData, tx);
if (!success) {
throw std::runtime_error("Failed to find node when attempting to increases reference count");
throw std::runtime_error("Failed to find node when attempting to decrease reference count");
}
if (--nodeData.ref == 0) {
// std::cout << "Deleting node at " << nodeHash << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "msgpack/assert.hpp"
#include <cstdint>
#include <exception>
#include <iostream>
#include <memory>
#include <mutex>
#include <optional>
Expand Down Expand Up @@ -643,17 +644,13 @@ void ContentAddressedCachedTreeStore<LeafValueType>::commit(TreeMeta& finalMeta,

// if the meta datas are different, we have uncommitted data
bool metaToCommit = committedMeta != uncommittedMeta;
if (!metaToCommit) {
if (!metaToCommit && !asBlock) {
return;
}

auto currentRootIter = nodes_.find(uncommittedMeta.root);
dataPresent = currentRootIter != nodes_.end();
if (!dataPresent) {
// no uncommitted data present, if we were asked to commit as a block then we can't
if (asBlock) {
throw std::runtime_error("Can't commit as block if no data present");
}
} else {
if (dataPresent) {
// data is present, hydrate persisted indices
hydrate_indices_from_persisted_store(*tx);
}
Expand All @@ -665,19 +662,27 @@ void ContentAddressedCachedTreeStore<LeafValueType>::commit(TreeMeta& finalMeta,
// std::cout << "Persisting data for block " << uncommittedMeta.unfinalisedBlockHeight + 1 << std::endl;
persist_leaf_indices(*tx);
persist_leaf_keys(uncommittedMeta.committedSize, *tx);
}
// If we are commiting a block, we need to persist the root, since the new block "references" this root
// However, if the root is the empty root we can't persist it, since it's not a real node
// We are abusing the trees in some tests, trying to add empty blocks to initial empty trees
// That is not expected behavior since the unwind operation will fail trying to decrease refcount
// for the empty root, which doesn't exist.
if (dataPresent || (asBlock && uncommittedMeta.size > 0)) {
persist_node(std::optional<fr>(uncommittedMeta.root), 0, *tx);
if (asBlock) {
++uncommittedMeta.unfinalisedBlockHeight;
if (uncommittedMeta.oldestHistoricBlock == 0) {
uncommittedMeta.oldestHistoricBlock = 1;
}
// std::cout << "New root " << uncommittedMeta.root << std::endl;
BlockPayload block{ .size = uncommittedMeta.size,
.blockNumber = uncommittedMeta.unfinalisedBlockHeight,
.root = uncommittedMeta.root };
dataStore_->write_block_data(uncommittedMeta.unfinalisedBlockHeight, block, *tx);
}
if (asBlock) {
++uncommittedMeta.unfinalisedBlockHeight;
if (uncommittedMeta.oldestHistoricBlock == 0) {
uncommittedMeta.oldestHistoricBlock = 1;
}
// std::cout << "New root " << uncommittedMeta.root << std::endl;
BlockPayload block{ .size = uncommittedMeta.size,
.blockNumber = uncommittedMeta.unfinalisedBlockHeight,
.root = uncommittedMeta.root };
dataStore_->write_block_data(uncommittedMeta.unfinalisedBlockHeight, block, *tx);
}

uncommittedMeta.committedSize = uncommittedMeta.size;
persist_meta(uncommittedMeta, *tx);
tx->commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ bool WorldStateAddon::sync_block(msgpack::object& obj, msgpack::sbuffer& buf)
request.value.paddedNoteHashes,
request.value.paddedL1ToL2Messages,
request.value.paddedNullifiers,
request.value.batchesOfPaddedPublicDataWrites);
request.value.batchesOfPublicDataWrites);

MsgHeader header(request.header.messageId);
messaging::TypedMessage<WorldStateStatusFull> resp_msg(WorldStateMessageType::SYNC_BLOCK, header, { status });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ struct SyncBlockRequest {
bb::fr blockHeaderHash;
std::vector<bb::fr> paddedNoteHashes, paddedL1ToL2Messages;
std::vector<crypto::merkle_tree::NullifierLeafValue> paddedNullifiers;
std::vector<std::vector<crypto::merkle_tree::PublicDataLeafValue>> batchesOfPaddedPublicDataWrites;
std::vector<std::vector<crypto::merkle_tree::PublicDataLeafValue>> batchesOfPublicDataWrites;

MSGPACK_FIELDS(blockNumber,
blockStateRef,
blockHeaderHash,
paddedNoteHashes,
paddedL1ToL2Messages,
paddedNullifiers,
batchesOfPaddedPublicDataWrites);
batchesOfPublicDataWrites);
};

} // namespace bb::world_state
Expand Down
1 change: 0 additions & 1 deletion l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ library Constants {
uint256 internal constant L1_TO_L2_MSG_SUBTREE_HEIGHT = 4;
uint256 internal constant NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH = 34;
uint256 internal constant NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH = 34;
uint256 internal constant PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH = 34;
uint256 internal constant L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = 35;
uint256 internal constant MAX_NOTE_HASHES_PER_TX = 64;
uint256 internal constant MAX_NULLIFIERS_PER_TX = 64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use dep::types::{
utils::reader::Reader,
};

global BASE_ROLLUP_TYPE = 0;
global MERGE_ROLLUP_TYPE = 1;
pub(crate) global BASE_ROLLUP_TYPE = 0;
pub(crate) global MERGE_ROLLUP_TYPE = 1;

pub struct BaseOrMergeRollupPublicInputs {
// rollup_type is either 0 (base) or 1 (merge)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use dep::types::{

pub struct ConstantRollupData {
// Archive tree snapshot at the very beginning of the entire rollup.
last_archive: AppendOnlyTreeSnapshot,
vk_tree_root: Field,
protocol_contract_tree_root: Field,
global_variables: GlobalVariables,
pub last_archive: AppendOnlyTreeSnapshot,
pub vk_tree_root: Field,
pub protocol_contract_tree_root: Field,
pub global_variables: GlobalVariables,
}

impl Eq for ConstantRollupData {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod constant_rollup_data;
mod base_or_merge_rollup_public_inputs;
mod block_root_or_block_merge_public_inputs;
mod previous_rollup_data;
mod previous_rollup_block_data;
pub(crate) mod constant_rollup_data;
pub(crate) mod base_or_merge_rollup_public_inputs;
pub(crate) mod block_root_or_block_merge_public_inputs;
pub(crate) mod previous_rollup_data;
pub(crate) mod previous_rollup_block_data;
Loading
Loading