2

Keep getting CanopyLengthMismatch error

How do you calculate the canopy length?

2 Answers 2

2

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.

0

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(),
    );

Source: https://github.com/solana-labs/solana-program-library/blob/45764e6737cc7101fad13708ed76e13d8827aa8f/account-compression/programs/account-compression/src/canopy.rs#LL28C24-L28C24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.