11use borsh:: BorshDeserialize ;
2- use pinocchio:: instruction:: { Seed , Signer } ;
2+ use pinocchio:: instruction:: Signer ;
33use pinocchio:: pubkey:: { self , pubkey_eq} ;
44use pinocchio:: seeds;
55use pinocchio:: {
@@ -28,7 +28,7 @@ pub fn process_commit_state(
2828 accounts : & [ AccountInfo ] ,
2929 data : & [ u8 ] ,
3030) -> ProgramResult {
31- let args = CommitStateArgs :: try_from_slice ( data) . expect ( "FIXME" ) ;
31+ let args = CommitStateArgs :: try_from_slice ( data) . map_err ( |_| ProgramError :: BorshIoError ) ? ;
3232
3333 let commit_state_bytes: & [ u8 ] = args. data . as_ref ( ) ;
3434 let commit_record_lamports = args. lamports ;
@@ -109,20 +109,18 @@ pub(crate) fn process_commit_state_internal(
109109
110110 // To preserve correct history of account updates we require sequential commits
111111 if args. commit_record_nonce != delegation_metadata. last_update_nonce + 1 {
112- //msg !(
113- // "Nonce {} is incorrect, previous nonce is {}. Rejecting commit",
114- // args.commit_record_nonce,
115- // delegation_metadata.last_update_nonce
116- // );
112+ log ! (
113+ "Nonce {} is incorrect, previous nonce is {}. Rejecting commit" ,
114+ args. commit_record_nonce,
115+ delegation_metadata. last_update_nonce
116+ ) ;
117117 return Err ( DlpError :: NonceOutOfOrder . into ( ) ) ;
118118 }
119119
120120 // Once the account is marked as undelegatable, any subsequent commit should fail
121121 if delegation_metadata. is_undelegatable {
122- //msg!(
123- // "delegation metadata ({}) is already undelegated",
124- // args.delegation_metadata_account.key
125- //);
122+ log ! ( "delegation metadata is already undelegated: " ) ;
123+ pubkey:: log ( args. delegation_metadata_account . key ( ) ) ;
126124 return Err ( DlpError :: AlreadyUndelegated . into ( ) ) ;
127125 }
128126
@@ -139,25 +137,21 @@ pub(crate) fn process_commit_state_internal(
139137 . map_err ( to_pinocchio_program_error) ?;
140138
141139 // Check that the authority is allowed to commit
142- if !pubkey_eq (
143- & delegation_record. authority . as_array ( ) ,
144- args. validator . key ( ) ,
145- ) && !pubkey_eq ( delegation_record. authority . as_array ( ) , & Pubkey :: default ( ) )
140+ if !pubkey_eq ( delegation_record. authority . as_array ( ) , args. validator . key ( ) )
141+ && !pubkey_eq ( delegation_record. authority . as_array ( ) , & Pubkey :: default ( ) )
146142 {
147- //msg!(
148- // "validator ({}) is not the delegation authority ({})",
149- // args.validator.key,
150- // delegation_record.authority
151- //);
143+ log ! ( "validator is not the delegation authority. validator: " ) ;
144+ pubkey:: log ( args. validator . key ( ) ) ;
145+ log ! ( "delegation authority: " ) ;
146+ pubkey:: log ( delegation_record. authority . as_array ( ) ) ;
152147 return Err ( DlpError :: InvalidAuthority . into ( ) ) ;
153148 }
154149
155150 // If there was an issue with the lamport accounting in the past, abort (this should never happen)
156151 if args. delegated_account . lamports ( ) < delegation_record. lamports {
157- //msg!(
158- // "delegated account ({}) has less lamports than the delegation record indicates",
159- // args.delegated_account.key
160- //);
152+ log ! (
153+ "delegated account has less lamports than the delegation record indicates. delegation account: " ) ;
154+ pubkey:: log ( args. delegated_account . key ( ) ) ;
161155 return Err ( DlpError :: InvalidDelegatedState . into ( ) ) ;
162156 }
163157
@@ -192,12 +186,10 @@ pub(crate) fn process_commit_state_internal(
192186 . map_err ( to_pinocchio_program_error) ?;
193187 if !program_config
194188 . approved_validators
195- . contains ( & args. validator . key ( ) . clone ( ) . into ( ) )
189+ . contains ( & ( * args. validator . key ( ) ) . into ( ) )
196190 {
197- //msg!(
198- // "validator ({}) is not whitelisted in the program config",
199- // args.validator.key
200- //);
191+ log ! ( "validator is not whitelisted in the program config: " ) ;
192+ pubkey:: log ( args. validator . key ( ) ) ;
201193 return Err ( DlpError :: InvalidWhitelistProgramConfig . into ( ) ) ;
202194 }
203195 }
@@ -223,8 +215,6 @@ pub(crate) fn process_commit_state_internal(
223215 args. commit_state_account ,
224216 & crate :: fast:: ID ,
225217 args. commit_state_bytes . len ( ) ,
226- //commit_state_seeds_from_delegated_account!(args.delegated_account.key),
227- //commit_state_bump,
228218 & [ Signer :: from ( & seeds ! (
229219 pda:: COMMIT_STATE_TAG ,
230220 args. delegated_account. key( ) ,
@@ -248,8 +238,8 @@ pub(crate) fn process_commit_state_internal(
248238
249239 // Initialize the commit record
250240 let commit_record = CommitRecord {
251- identity : args. validator . key ( ) . clone ( ) . into ( ) ,
252- account : args. delegated_account . key ( ) . clone ( ) . into ( ) ,
241+ identity : ( * args. validator . key ( ) ) . into ( ) ,
242+ account : ( * args. delegated_account . key ( ) ) . into ( ) ,
253243 nonce : args. commit_record_nonce ,
254244 lamports : args. commit_record_lamports ,
255245 } ;
0 commit comments