@@ -2,43 +2,42 @@ use crate::*;
22use oapp:: endpoint_cpi:: { get_accounts_for_clear, LzAccount } ;
33use oapp:: { endpoint:: ID as ENDPOINT_ID , LzReceiveParams } ;
44
5- /// LzReceiveTypes instruction provides a list of accounts that are used in the LzReceive
6- /// instruction. The list of accounts required by this LzReceiveTypes instruction can be found
7- /// from the specific PDA account that is generated by the LZ_RECEIVE_TYPES_SEED.
5+ /// `lz_receive_types` is queried off-chain by the Executor before calling
6+ /// `lz_receive`. It must return **every** account that will be touched by the
7+ /// actual `lz_receive` instruction as well as the accounts required by
8+ /// `Endpoint::clear`.
9+ ///
10+ /// The return order must match exactly what `lz_receive` expects or the
11+ /// cross-program invocation will fail.
812#[ derive( Accounts ) ]
913pub struct LzReceiveTypes < ' info > {
1014 #[ account( seeds = [ STORE_SEED ] , bump = store. bump) ]
1115 pub store : Account < ' info , Store > ,
1216}
1317
1418impl LzReceiveTypes < ' _ > {
15- /// The list of accounts should follow the rules below:
16- /// 1. Include all the accounts that are used in the LzReceive instruction, including the
17- /// accounts that are used by the Endpoint program.
18- /// 2. Set the account is a signer with ZERO address if the LzReceive instruction needs a payer
19- /// to pay fee, like rent.
20- /// 3. Set the account is writable if the LzReceive instruction needs to modify the account.
2119 pub fn apply (
2220 ctx : & Context < LzReceiveTypes > ,
2321 params : & LzReceiveParams ,
2422 ) -> Result < Vec < LzAccount > > {
25- // There are two accounts that are used in the LzReceive instruction,
26- // except those accounts for endpoint program.
27- // The first account is the store account, that is the fixed one .
23+ // 1. The store PDA is always the first account and is mutable. If your
24+ // program derives the store PDA with additional seeds, ensure the same
25+ // seeds are used when providing the store account.
2826 let store = ctx. accounts . store . key ( ) ;
2927
30- // The second account is the peer account, we find it by the params.src_eid .
28+ // 2. The peer PDA for the remote chain needs to be retrieved, for later verification of the ` params.sender` .
3129 let peer_seeds = [ PEER_SEED , & store. to_bytes ( ) , & params. src_eid . to_be_bytes ( ) ] ;
3230 let ( peer, _) = Pubkey :: find_program_address ( & peer_seeds, ctx. program_id ) ;
3331
32+ // Accounts used directly by `lz_receive`
3433 let mut accounts = vec ! [
35- // count
34+ // store (mutable)
3635 LzAccount { pubkey: store, is_signer: false , is_writable: true } ,
37- // peer
36+ // peer (read-only)
3837 LzAccount { pubkey: peer, is_signer: false , is_writable: false }
3938 ] ;
4039
41- // append the accounts for the clear ix
40+ // Append the additional accounts required for `Endpoint:: clear`
4241 let accounts_for_clear = get_accounts_for_clear (
4342 ENDPOINT_ID ,
4443 & store,
0 commit comments