@@ -41,7 +41,7 @@ use crate::canopy::{fill_in_proof_from_canopy, update_canopy};
41
41
use crate :: data_wrapper:: { wrap_event, Wrapper } ;
42
42
use crate :: error:: AccountCompressionError ;
43
43
use crate :: events:: ChangeLogEvent ;
44
- use crate :: state:: ConcurrentMerkleTreeHeader ;
44
+ use crate :: state:: { ConcurrentMerkleTreeHeader , CONCURRENT_MERKLE_TREE_HEADER_SIZE_V1 } ;
45
45
use crate :: zero_copy:: ZeroCopy ;
46
46
47
47
/// Exported for Anchor / Solita
@@ -132,7 +132,7 @@ macro_rules! merkle_tree_depth_size_apply_fn {
132
132
133
133
fn merkle_tree_get_size ( header : & ConcurrentMerkleTreeHeader ) -> Result < usize > {
134
134
// Note: max_buffer_size MUST be a power of 2
135
- match ( header. max_depth , header. max_buffer_size ) {
135
+ match ( header. get_max_depth ( ) , header. get_max_buffer_size ( ) ) {
136
136
( 3 , 8 ) => Ok ( size_of :: < ConcurrentMerkleTree < 3 , 8 > > ( ) ) ,
137
137
( 5 , 8 ) => Ok ( size_of :: < ConcurrentMerkleTree < 5 , 8 > > ( ) ) ,
138
138
( 14 , 64 ) => Ok ( size_of :: < ConcurrentMerkleTree < 14 , 64 > > ( ) ) ,
@@ -157,8 +157,8 @@ fn merkle_tree_get_size(header: &ConcurrentMerkleTreeHeader) -> Result<usize> {
157
157
_ => {
158
158
msg ! (
159
159
"Failed to get size of max depth {} and max buffer size {}" ,
160
- header. max_depth ,
161
- header. max_buffer_size
160
+ header. get_max_depth ( ) ,
161
+ header. get_max_buffer_size ( )
162
162
) ;
163
163
err ! ( AccountCompressionError :: ConcurrentMerkleTreeConstantsError )
164
164
}
@@ -171,7 +171,7 @@ fn merkle_tree_get_size(header: &ConcurrentMerkleTreeHeader) -> Result<usize> {
171
171
macro_rules! merkle_tree_apply_fn {
172
172
( $header: ident, $id: ident, $bytes: ident, $func: ident, $( $arg: tt) * ) => {
173
173
// Note: max_buffer_size MUST be a power of 2
174
- match ( $header. max_depth , $header. max_buffer_size ) {
174
+ match ( $header. get_max_depth ( ) , $header. get_max_buffer_size ( ) ) {
175
175
( 3 , 8 ) => merkle_tree_depth_size_apply_fn!( 3 , 8 , $id, $bytes, $func, $( $arg) * ) ,
176
176
( 5 , 8 ) => merkle_tree_depth_size_apply_fn!( 5 , 8 , $id, $bytes, $func, $( $arg) * ) ,
177
177
( 14 , 64 ) => merkle_tree_depth_size_apply_fn!( 14 , 64 , $id, $bytes, $func, $( $arg) * ) ,
@@ -194,7 +194,7 @@ macro_rules! merkle_tree_apply_fn {
194
194
( 30 , 1024 ) => merkle_tree_depth_size_apply_fn!( 30 , 1024 , $id, $bytes, $func, $( $arg) * ) ,
195
195
( 30 , 2048 ) => merkle_tree_depth_size_apply_fn!( 30 , 2048 , $id, $bytes, $func, $( $arg) * ) ,
196
196
_ => {
197
- msg!( "Failed to apply {} on concurrent merkle tree with max depth {} and max buffer size {}" , stringify!( $func) , $header. max_depth , $header. max_buffer_size ) ;
197
+ msg!( "Failed to apply {} on concurrent merkle tree with max depth {} and max buffer size {}" , stringify!( $func) , $header. get_max_depth ( ) , $header. get_max_buffer_size ( ) ) ;
198
198
err!( AccountCompressionError :: ConcurrentMerkleTreeConstantsError )
199
199
}
200
200
}
@@ -230,7 +230,7 @@ pub mod spl_account_compression {
230
230
let mut merkle_tree_bytes = ctx. accounts . merkle_tree . try_borrow_mut_data ( ) ?;
231
231
232
232
let ( mut header_bytes, rest) =
233
- merkle_tree_bytes. split_at_mut ( size_of :: < ConcurrentMerkleTreeHeader > ( ) ) ;
233
+ merkle_tree_bytes. split_at_mut ( CONCURRENT_MERKLE_TREE_HEADER_SIZE_V1 ) ;
234
234
235
235
let mut header = ConcurrentMerkleTreeHeader :: try_from_slice ( header_bytes) ?;
236
236
header. initialize (
@@ -246,7 +246,7 @@ pub mod spl_account_compression {
246
246
let change_log = merkle_tree_apply_fn ! ( header, id, tree_bytes, initialize, ) ?;
247
247
wrap_event ( change_log. try_to_vec ( ) ?, & ctx. accounts . log_wrapper ) ?;
248
248
emit ! ( * change_log) ;
249
- update_canopy ( canopy_bytes, header. max_depth , None )
249
+ update_canopy ( canopy_bytes, header. get_max_depth ( ) , None )
250
250
}
251
251
252
252
/// Note:
@@ -276,7 +276,7 @@ pub mod spl_account_compression {
276
276
// let mut merkle_tree_bytes = ctx.accounts.merkle_tree.try_borrow_mut_data()?;
277
277
278
278
// let (mut header_bytes, rest) =
279
- // merkle_tree_bytes.split_at_mut(size_of::<ConcurrentMerkleTreeHeader>() );
279
+ // merkle_tree_bytes.split_at_mut(CONCURRENT_MERKLE_TREE_HEADER_SIZE_V1 );
280
280
281
281
// let mut header = ConcurrentMerkleTreeHeader::try_from_slice(&header_bytes)?;
282
282
// header.initialize(
@@ -331,7 +331,7 @@ pub mod spl_account_compression {
331
331
) ;
332
332
let mut merkle_tree_bytes = ctx. accounts . merkle_tree . try_borrow_mut_data ( ) ?;
333
333
let ( header_bytes, rest) =
334
- merkle_tree_bytes. split_at_mut ( size_of :: < ConcurrentMerkleTreeHeader > ( ) ) ;
334
+ merkle_tree_bytes. split_at_mut ( CONCURRENT_MERKLE_TREE_HEADER_SIZE_V1 ) ;
335
335
336
336
let header = ConcurrentMerkleTreeHeader :: try_from_slice ( header_bytes) ?;
337
337
header. assert_valid_authority ( & ctx. accounts . authority . key ( ) ) ?;
@@ -343,7 +343,7 @@ pub mod spl_account_compression {
343
343
for node in ctx. remaining_accounts . iter ( ) {
344
344
proof. push ( node. key ( ) . to_bytes ( ) ) ;
345
345
}
346
- fill_in_proof_from_canopy ( canopy_bytes, header. max_depth , index, & mut proof) ?;
346
+ fill_in_proof_from_canopy ( canopy_bytes, header. get_max_depth ( ) , index, & mut proof) ?;
347
347
let id = ctx. accounts . merkle_tree . key ( ) ;
348
348
// A call is made to ConcurrentMerkleTree::set_leaf(root, previous_leaf, new_leaf, proof, index)
349
349
let change_log = merkle_tree_apply_fn ! (
@@ -359,7 +359,7 @@ pub mod spl_account_compression {
359
359
) ?;
360
360
wrap_event ( change_log. try_to_vec ( ) ?, & ctx. accounts . log_wrapper ) ?;
361
361
emit ! ( * change_log) ;
362
- update_canopy ( canopy_bytes, header. max_depth , Some ( change_log) )
362
+ update_canopy ( canopy_bytes, header. get_max_depth ( ) , Some ( change_log) )
363
363
}
364
364
365
365
/// Transfers `authority`.
@@ -375,13 +375,12 @@ pub mod spl_account_compression {
375
375
) ;
376
376
let mut merkle_tree_bytes = ctx. accounts . merkle_tree . try_borrow_mut_data ( ) ?;
377
377
let ( mut header_bytes, _) =
378
- merkle_tree_bytes. split_at_mut ( size_of :: < ConcurrentMerkleTreeHeader > ( ) ) ;
378
+ merkle_tree_bytes. split_at_mut ( CONCURRENT_MERKLE_TREE_HEADER_SIZE_V1 ) ;
379
379
380
380
let mut header = ConcurrentMerkleTreeHeader :: try_from_slice ( header_bytes) ?;
381
381
header. assert_valid_authority ( & ctx. accounts . authority . key ( ) ) ?;
382
382
383
- header. authority = new_authority;
384
- msg ! ( "Authority transferred to: {:?}" , header. authority) ;
383
+ header. set_new_authority ( & new_authority) ;
385
384
header. serialize ( & mut header_bytes) ?;
386
385
387
386
Ok ( ( ) )
@@ -402,7 +401,7 @@ pub mod spl_account_compression {
402
401
) ;
403
402
let mut merkle_tree_bytes = ctx. accounts . merkle_tree . try_borrow_mut_data ( ) ?;
404
403
let ( header_bytes, rest) =
405
- merkle_tree_bytes. split_at_mut ( size_of :: < ConcurrentMerkleTreeHeader > ( ) ) ;
404
+ merkle_tree_bytes. split_at_mut ( CONCURRENT_MERKLE_TREE_HEADER_SIZE_V1 ) ;
406
405
407
406
let header = ConcurrentMerkleTreeHeader :: try_from_slice ( header_bytes) ?;
408
407
header. assert_valid ( ) ?;
@@ -414,7 +413,7 @@ pub mod spl_account_compression {
414
413
for node in ctx. remaining_accounts . iter ( ) {
415
414
proof. push ( node. key ( ) . to_bytes ( ) ) ;
416
415
}
417
- fill_in_proof_from_canopy ( canopy_bytes, header. max_depth , index, & mut proof) ?;
416
+ fill_in_proof_from_canopy ( canopy_bytes, header. get_max_depth ( ) , index, & mut proof) ?;
418
417
let id = ctx. accounts . merkle_tree . key ( ) ;
419
418
420
419
merkle_tree_apply_fn ! ( header, id, tree_bytes, prove_leaf, root, leaf, & proof, index) ?;
@@ -435,7 +434,7 @@ pub mod spl_account_compression {
435
434
) ;
436
435
let mut merkle_tree_bytes = ctx. accounts . merkle_tree . try_borrow_mut_data ( ) ?;
437
436
let ( header_bytes, rest) =
438
- merkle_tree_bytes. split_at_mut ( size_of :: < ConcurrentMerkleTreeHeader > ( ) ) ;
437
+ merkle_tree_bytes. split_at_mut ( CONCURRENT_MERKLE_TREE_HEADER_SIZE_V1 ) ;
439
438
440
439
let header = ConcurrentMerkleTreeHeader :: try_from_slice ( header_bytes) ?;
441
440
header. assert_valid_authority ( & ctx. accounts . authority . key ( ) ) ?;
@@ -446,7 +445,7 @@ pub mod spl_account_compression {
446
445
let change_log = merkle_tree_apply_fn ! ( header, id, tree_bytes, append, leaf) ?;
447
446
wrap_event ( change_log. try_to_vec ( ) ?, & ctx. accounts . log_wrapper ) ?;
448
447
emit ! ( * change_log) ;
449
- update_canopy ( canopy_bytes, header. max_depth , Some ( change_log) )
448
+ update_canopy ( canopy_bytes, header. get_max_depth ( ) , Some ( change_log) )
450
449
}
451
450
452
451
/// This instruction takes a proof, and will attempt to write the given leaf
@@ -466,7 +465,7 @@ pub mod spl_account_compression {
466
465
) ;
467
466
let mut merkle_tree_bytes = ctx. accounts . merkle_tree . try_borrow_mut_data ( ) ?;
468
467
let ( header_bytes, rest) =
469
- merkle_tree_bytes. split_at_mut ( size_of :: < ConcurrentMerkleTreeHeader > ( ) ) ;
468
+ merkle_tree_bytes. split_at_mut ( CONCURRENT_MERKLE_TREE_HEADER_SIZE_V1 ) ;
470
469
471
470
let header = ConcurrentMerkleTreeHeader :: try_from_slice ( header_bytes) ?;
472
471
header. assert_valid_authority ( & ctx. accounts . authority . key ( ) ) ?;
@@ -478,7 +477,7 @@ pub mod spl_account_compression {
478
477
for node in ctx. remaining_accounts . iter ( ) {
479
478
proof. push ( node. key ( ) . to_bytes ( ) ) ;
480
479
}
481
- fill_in_proof_from_canopy ( canopy_bytes, header. max_depth , index, & mut proof) ?;
480
+ fill_in_proof_from_canopy ( canopy_bytes, header. get_max_depth ( ) , index, & mut proof) ?;
482
481
// A call is made to ConcurrentMerkleTree::fill_empty_or_append
483
482
let id = ctx. accounts . merkle_tree . key ( ) ;
484
483
let change_log = merkle_tree_apply_fn ! (
@@ -493,6 +492,6 @@ pub mod spl_account_compression {
493
492
) ?;
494
493
wrap_event ( change_log. try_to_vec ( ) ?, & ctx. accounts . log_wrapper ) ?;
495
494
emit ! ( * change_log) ;
496
- update_canopy ( canopy_bytes, header. max_depth , Some ( change_log) )
495
+ update_canopy ( canopy_bytes, header. get_max_depth ( ) , Some ( change_log) )
497
496
}
498
497
}
0 commit comments