Skip to content

Commit 54f5264

Browse files
authored
feat: light client get cached merkle tree (#1775)
* feat: add Merkle tree getters refactor: rename RpcConnection -> Rpc refactor: rename SolanaRpcConnection -> LightClient, rename RpcConnection -> Rpc rename: SolanaRpcUrl -> RpcUrl fix: make PhotonIndexer flexible for non local host feat: add ValidityProofWithContext::pack_merkle_tree_accounts refactor: pack_merkle_tree_accounts add pack output indices fix: use TreeType in test-utils fix: lint fix: counter example assert chore: set LightProgramTest address Merkle tree to amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2 * refactor: set_account inputs without references * fix: account compression tests! * fix: counter example * rename: indexer::types::Account -> CompressedAccount * refactor: rename CompressedAccount::merkle_context -> tree_info * refactor: light-sdk rename merkle_context -> tree_info, use PackedTreeInfo which contains root_index instead of PackedMerkleContext, rename PackedMerkleTreeAccounts -> PackedTreeAccounts and return one output_tree_index * refactor: split get_compressed_account into two add get_compressed_account_by_hash * chore: remove duplicate TreeMeta type * refactor: pack_tree_accounts output * chore: add log_failed_tx option, log all tx with debug asserts * refactor: light-sdk rename merkle_context -> tree_info * fix: light-program-test * chore: deprecate PackMerkleContext functions * fix: registry test * add light-client tests * test: add program-test indexer trait test * chore: move light-client test to program-tests * refactor: rename account_trees -> state_trees, get_output_tree_index -> pack_output_tree_index * refactor: rename field output_tree_index -> output_state_tree_index
1 parent ebb6b1d commit 54f5264

File tree

145 files changed

+3645
-1965
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+3645
-1965
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
cargo test -p light-sdk
6363
cargo test -p light-program-test
6464
cargo test -p light-client
65+
cargo test-sbf -p client-test
6566
cargo test -p light-sparse-merkle-tree
6667
cargo test -p light-batched-merkle-tree --features test-only -- --skip test_simulate_transactions --skip test_e2e
6768

Cargo.lock

Lines changed: 42 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ members = [
4141
"program-tests/create-address-test-program",
4242
"program-tests/utils",
4343
"program-tests/merkle-tree",
44+
"program-tests/client-test",
4445
"forester-utils",
4546
"forester",
4647
"sparse-merkle-tree",

examples/anchor/counter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ light-compressed-account = { workspace = true }
2929
light-program-test = { workspace = true, features = ["devenv"] }
3030
tokio = "1.43.0"
3131
solana-sdk = { workspace = true }
32+
light-client = { workspace = true }

examples/anchor/counter/src/lib.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use light_sdk::{
66
address::v1::derive_address,
77
cpi::{CpiAccounts, CpiInputs},
88
instruction::{
9-
account_meta::CompressedAccountMeta, merkle_context::PackedAddressMerkleContext,
9+
account_meta::{CompressedAccountMeta, CompressedAccountMetaClose},
10+
tree_info::PackedAddressTreeInfo,
1011
},
11-
LightDiscriminator, LightHasher, NewAddressParamsPacked, ValidityProof,
12+
LightDiscriminator, LightHasher, ValidityProof,
1213
};
1314

1415
declare_id!("GRLu2hKaAiMbxpkAM1HeXzks9YeGuz18SEgXEizVvPqX");
@@ -21,8 +22,8 @@ pub mod counter {
2122
pub fn create_counter<'info>(
2223
ctx: Context<'_, '_, '_, 'info, GenericAnchorAccounts<'info>>,
2324
proof: ValidityProof,
24-
address_merkle_context: PackedAddressMerkleContext,
25-
output_merkle_tree_index: u8,
25+
address_tree_info: PackedAddressTreeInfo,
26+
output_state_tree_index: u8,
2627
) -> Result<()> {
2728
let program_id = crate::ID.into();
2829
// LightAccount::new_init will create an account with empty output state (no input state).
@@ -40,23 +41,17 @@ pub mod counter {
4041
let (address, address_seed) = derive_address(
4142
&[b"counter", ctx.accounts.signer.key().as_ref()],
4243
&light_cpi_accounts.tree_accounts()
43-
[address_merkle_context.address_merkle_tree_pubkey_index as usize]
44+
[address_tree_info.address_merkle_tree_pubkey_index as usize]
4445
.key(),
4546
&crate::ID,
4647
);
4748

48-
let new_address_params = NewAddressParamsPacked {
49-
seed: address_seed,
50-
address_queue_account_index: address_merkle_context.address_queue_pubkey_index,
51-
address_merkle_tree_root_index: address_merkle_context.root_index,
52-
address_merkle_tree_account_index: address_merkle_context
53-
.address_merkle_tree_pubkey_index,
54-
};
49+
let new_address_params = address_tree_info.into_new_address_params_packed(address_seed);
5550

5651
let mut counter = LightAccount::<'_, CounterAccount>::new_init(
5752
&program_id,
5853
Some(address),
59-
output_merkle_tree_index,
54+
output_state_tree_index,
6055
);
6156

6257
counter.owner = ctx.accounts.signer.key();
@@ -198,7 +193,7 @@ pub mod counter {
198193
ctx: Context<'_, '_, '_, 'info, GenericAnchorAccounts<'info>>,
199194
proof: ValidityProof,
200195
counter_value: u64,
201-
account_meta: CompressedAccountMeta,
196+
account_meta: CompressedAccountMetaClose,
202197
) -> Result<()> {
203198
let program_id = crate::ID.into();
204199
// LightAccount::new_close() will create an account with only input state and no output state.

0 commit comments

Comments
 (0)