Skip to content

Commit

Permalink
added update_last_usage_slot method
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiyaTarasova committed Oct 15, 2024
1 parent c813347 commit 389c7c4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
15 changes: 8 additions & 7 deletions evm_loader/program/src/account/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,10 @@ impl<'a> StateAccount<'a> {
program_id: &Pubkey,
info: &AccountInfo<'a>,
accounts: &AccountsDB,
update_last_usage: bool,
) -> Result<(Self, AccountsStatus)> {
let mut status = AccountsStatus::Ok;
let mut state = Self::from_account(program_id, info)?;

if update_last_usage {
let current_slot =
solana_program::clock::Clock::get().map(|clock| clock.slot.as_u256().as_u64())?;
state.data.last_used_slot = current_slot;
}

let is_touched_account = |key: &Pubkey| -> bool {
state
.data
Expand Down Expand Up @@ -272,6 +265,14 @@ impl<'a> StateAccount<'a> {
Ok((state, status))
}

pub fn update_last_usage_slot(program_id: &Pubkey, info: &AccountInfo<'a>) -> Result<()> {
let mut state = Self::from_account(program_id, info)?;
state.data.last_used_slot =
solana_program::clock::Clock::get().map(|clock| clock.slot.as_u256().as_u64())?;

Ok(())
}

pub fn finalize(self, program_id: &Pubkey) -> Result<()> {
debug_print!("Finalize Storage {}", self.account.key);

Expand Down
2 changes: 1 addition & 1 deletion evm_loader/program/src/instruction/transaction_cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn process<'a>(
log_data(&[b"MINER", operator_balance.address().as_bytes()]);

let accounts_db = AccountsDB::new(&accounts[3..], operator, Some(operator_balance), None, None);
let (storage, _) = StateAccount::restore(program_id, &storage_info, &accounts_db, false)?;
let (storage, _) = StateAccount::restore(program_id, &storage_info, &accounts_db)?;

let current_timestamp =
solana_program::clock::Clock::get().map(|clock| clock.slot.as_u256().as_u64())?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ pub fn process_inner<'a>(
}
TAG_STATE => {
let (storage, accounts_status) =
StateAccount::restore(program_id, &holder_or_storage, &accounts_db, true)?;
StateAccount::restore(program_id, &holder_or_storage, &accounts_db)?;
StateAccount::update_last_usage_slot(program_id, &holder_or_storage)?;

operator_balance.validate_transaction(storage.trx())?;
let miner_address = operator_balance.miner(storage.trx_origin());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ pub fn process<'a>(
}
TAG_STATE => {
let (storage, accounts_status) =
StateAccount::restore(program_id, &storage_info, &accounts_db, true)?;
StateAccount::restore(program_id, &storage_info, &accounts_db)?;
StateAccount::update_last_usage_slot(program_id, &storage_info)?;

operator_balance.validate_transaction(storage.trx())?;
let miner_address = operator_balance.miner(storage.trx_origin());
Expand Down

0 comments on commit 389c7c4

Please sign in to comment.