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: rollover state trees #1371

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions programs/account-compression/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ pub enum AccountCompressionErrorCode {
InvalidBatch,
LeafIndexNotInBatch,
UnsupportedParameters,
InvalidTreeType,
InvalidNetworkFee,
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,13 @@ pub fn bytes_to_struct_checked<T: Clone + Copy + Discriminator, const INIT: bool

if INIT {
if bytes[0..8] != [0; 8] {
#[cfg(target_os = "solana")]
msg!("Discriminator bytes must be zero for initialization.");
return err!(AccountCompressionErrorCode::InvalidDiscriminator);
}
bytes[0..8].copy_from_slice(&T::DISCRIMINATOR);
} else if T::DISCRIMINATOR != bytes[0..8] {
#[cfg(target_os = "solana")]
msg!(
"Expected discriminator: {:?}, actual {:?} ",
T::DISCRIMINATOR,
Expand Down Expand Up @@ -377,10 +379,7 @@ pub fn assert_mt_zero_copy_inited(
ref_account,
"metadata mismatch"
);
println!(
"zero_copy_account.root_history.capacity(): {}",
zero_copy_account.root_history.metadata().capacity()
);

assert_eq!(
zero_copy_account.root_history.capacity(),
ref_account.root_history_capacity as usize,
Expand Down Expand Up @@ -421,6 +420,7 @@ pub fn get_output_queue_account_default(
associated_merkle_tree: Pubkey,
height: u32,
num_batches: u64,
network_fee: u64,
) -> BatchedQueueAccount {
let rollover_fee = match rollover_threshold {
Some(rollover_threshold) => compute_rollover_fee(rollover_threshold, height, rent)
Expand All @@ -441,7 +441,7 @@ pub fn get_output_queue_account_default(
rolledover_slot: u64::MAX,
rollover_threshold: rollover_threshold.unwrap_or(u64::MAX),
rollover_fee,
network_fee: 5000,
network_fee,
additional_bytes,
},
queue_type: QueueType::Output as u64,
Expand Down Expand Up @@ -566,6 +566,7 @@ pub mod tests {
mt_pubkey,
params.height,
params.output_queue_num_batches,
params.network_fee.unwrap_or_default(),
);
assert_queue_zero_copy_inited(
output_queue_account_data.as_mut_slice(),
Expand Down
3 changes: 3 additions & 0 deletions programs/account-compression/src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ pub use batch_nullify::*;

pub mod batch_append;
pub use batch_append::*;

pub mod rollover_batch_state_merkle_tree;
pub use rollover_batch_state_merkle_tree::*;
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'info> GroupAccounts<'info> for RolloverAddressMerkleTreeAndQueue<'info> {
///
/// Actions:
/// 1. mark Merkle tree as rolled over in this slot
/// 2. initialize new Merkle tree and nullifier queue with the same parameters
/// 2. initialize new Merkle tree and queue with the same parameters
pub fn process_rollover_address_merkle_tree_and_queue<'a, 'b, 'c: 'info, 'info>(
ctx: Context<'a, 'b, 'c, 'info, RolloverAddressMerkleTreeAndQueue<'info>>,
) -> Result<()> {
Expand Down
Loading
Loading