@@ -6,7 +6,6 @@ use crate::processor::utils::loaders::{
66 load_signer, load_uninitialized_pda,
77} ;
88use crate :: processor:: utils:: pda:: create_pda;
9- use crate :: processor:: utils:: verify:: verify_state;
109use crate :: state:: { CommitRecord , DelegationMetadata , DelegationRecord , ProgramConfig } ;
1110use crate :: {
1211 commit_record_seeds_from_delegated_account, commit_state_seeds_from_delegated_account,
@@ -15,8 +14,8 @@ use borsh::BorshDeserialize;
1514use solana_program:: program:: invoke;
1615use solana_program:: program_error:: ProgramError ;
1716use solana_program:: system_instruction:: transfer;
18- use solana_program:: system_program;
1917use solana_program:: { account_info:: AccountInfo , entrypoint:: ProgramResult , pubkey:: Pubkey } ;
18+ use solana_program:: { msg, system_program} ;
2019
2120/// Commit a new state of a delegated Pda
2221///
@@ -55,17 +54,24 @@ pub fn process_commit_state(
5554 let mut delegation_metadata =
5655 DelegationMetadata :: try_from_bytes_with_discriminator ( & delegation_metadata_data) ?;
5756
57+ // If the commit slot is greater than the last update slot, we can proceed.
58+ // If the slot is equal or less, we simply do not commit.
59+ // Since commit instructions are typically bundled, we return without error
60+ // so that correct commits are executed.
61+ if commit_record_slot <= delegation_metadata. last_update_external_slot {
62+ msg ! (
63+ "Slot {} is outdated, previous slot is {}. Skipping commit" ,
64+ commit_record_slot,
65+ delegation_metadata. last_update_external_slot
66+ ) ;
67+ return Ok ( ( ) ) ;
68+ }
69+
5870 // Once the account is marked as undelegatable, any subsequent commit should fail
5971 if delegation_metadata. is_undelegatable {
6072 return Err ( DlpError :: AlreadyUndelegated . into ( ) ) ;
6173 }
6274
63- // If the commit slot is greater than the last update slot, we can proceed
64- // If slot is equal or less, we simply do not commit
65- if commit_record_slot <= delegation_metadata. last_update_external_slot {
66- return Err ( DlpError :: OutdatedSlot . into ( ) ) ;
67- }
68-
6975 // Update delegation metadata undelegation flag
7076 delegation_metadata. is_undelegatable = args. allow_undelegation ;
7177 delegation_metadata. to_bytes_with_discriminator ( & mut delegation_metadata_data. as_mut ( ) ) ?;
@@ -160,14 +166,7 @@ pub fn process_commit_state(
160166 let mut commit_state_data = commit_state_account. try_borrow_mut_data ( ) ?;
161167 ( * commit_state_data) . copy_from_slice ( commit_state_bytes) ;
162168
163- // TODO - We'll need to implement state validation
164- // TODO - fix: this logic should probably be done in either commit_state OR finalize IX, not both
165- verify_state (
166- validator,
167- delegation_record,
168- & commit_record,
169- commit_state_account,
170- ) ?;
169+ // TODO - Add additional validation for the commitment, e.g. sufficient validator stake
171170
172171 Ok ( ( ) )
173172}
0 commit comments