solana-program-library
solana-program-library copied to clipboard
Account compression: Init with root allowing trees with a canopy
Initializing a tree with a root
This PR modifies the account-compression
program allowing the creation of the trees that were prepared offline. It allows creating trees with or without a canopy.
Verification of the validity, events, any additional checks and fields (URLs, hashes, etc.), and any additional permissions for the created tree are left to the discretion of the calling program.
The workflow
sequenceDiagram
autonumber
actor TC as Tree creator program
participant AC as account-compression
activate TC
TC ->> AC: prepare_tree(tree_account, max_depth, max_buffer_size)
AC -> AC: initializes the header, but not the tree
loop For a tree with a canopy
TC ->> AC: append_canopy_nodes(tree_account, start_index, canopy_nodes)
end
TC ->> AC: finalize_merkle_tree_with_root(tree_account, root, rightmost_leaf, rightmost_index, proof)
AC -> AC: verifies the canopy is valid
AC -> AC: initializes the tree
The separation of a single init_with_root
is based on the fact that some trees to be created might require knowing the pubkey of the tree, like with the bubblegum, where asset ids are derived from the tree pubkey and the index in that tree. Thus the user should first create the tree account and assign all the required permissions and then may take time to prepare the tree itself.
If the tree has a canopy - all canopy leaves should be initialized, otherwise the finalization will fail.
This change is inspired by #6441