Keep getting CanopyLengthMismatch error
How do you calculate the canopy length?
The canopy length will be 32 * the canopy size you want.
A tree of depth 14 and a canopy size of 7 will mean you need to allocate 7*32 bytes more to the account.
The number 32 is the size of each node of the tree.
The canopy length is the number of levels, from the max_depth, you want to cache. Get it's size by multiplying the canopy levels by 32.
// calculate additional bytes to pass by multiplying the number of levels by 32
let canopy_size = canopy_levels * 32;
// calculate merkle tree account size by passing canopy_size as additional bytes
let merkle_tree_account_size: usize =
CONCURRENT_MERKLE_TREE_HEADER_SIZE_V1 + merkle_tree_account_size + canopy_size as usize;
// create account
let merkle_tree_account = system_instruction::create_account(
&input.payer.pubkey(),
&input.merkle_tree.pubkey(),
lamports,
u64::try_from(merkle_tree_account_size).unwrap(),
&spl_account_compression::id(),
);