Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiyaTarasova committed Oct 15, 2024
1 parent 3874068 commit 7e7f2f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion evm_loader/program/config/common.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ gas_limit_multiplier_no_chainid = 1000
storage_entries_in_contract_account = [64, "usize"]
treasury_pool_count = 128
treasury_pool_seed = "treasury_pool"
timeout = 100
cancel_timeout = 100
16 changes: 8 additions & 8 deletions evm_loader/program/src/account/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ struct Data {
pub priority_fee_used: U256,
/// Steps executed in the transaction
pub steps_executed: u64,
/// Timeout from the last transaction usage
pub timeout: u64,
/// Last slot that was used by the transaction
pub last_used_slot: u64,
}

// Stores relative offsets for the corresponding objects as allocated by the AccountAllocator.
Expand Down Expand Up @@ -197,7 +197,7 @@ impl<'a> StateAccount<'a> {
gas_used: U256::ZERO,
priority_fee_used: U256::ZERO,
steps_executed: 0_u64,
timeout: solana_program::clock::Clock::get()
last_used_slot: solana_program::clock::Clock::get()
.map(|clock| clock.slot.as_u256().as_u64())?,
});

Expand Down Expand Up @@ -235,9 +235,9 @@ impl<'a> StateAccount<'a> {
let mut state = Self::from_account(program_id, info)?;

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

let is_touched_account = |key: &Pubkey| -> bool {
Expand Down Expand Up @@ -451,8 +451,8 @@ impl<'a> StateAccount<'a> {
}

#[must_use]
pub fn timeout(&self) -> u64 {
self.data.timeout
pub fn last_used_slot(&self) -> u64 {
self.data.last_used_slot
}

pub fn dealloc_executor_state(&self) {
Expand Down Expand Up @@ -622,7 +622,7 @@ impl<'a> StateAccount<'a> {
.collect();

let steps = read_unaligned(addr_of!((*data_ptr).steps_executed));
let last_slot = read_unaligned(addr_of!((*data_ptr).timeout));
let last_slot = read_unaligned(addr_of!((*data_ptr).last_used_slot));

Ok((tx, owner, origin, accounts, steps, last_slot))
}
Expand Down
11 changes: 7 additions & 4 deletions evm_loader/program/src/instruction/transaction_cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ pub fn process<'a>(

let current_timestamp =
solana_program::clock::Clock::get().map(|clock| clock.slot.as_u256().as_u64())?;
let storage_timeout = storage.timeout();
let config_timeout = crate::config::TIMEOUT;
let last_used_slot = storage.last_used_slot();
let config_cancel_timeout = crate::config::CANCEL_TIMEOUT;

let is_timeout = (current_timestamp - storage_timeout) > config_timeout;
let is_timeout = (current_timestamp - storage_timeout) > config_cancel_timeout;
log_msg!("process -> current_timestamp = {}", current_timestamp);
log_msg!("process -> storage.timeout = {}", storage_timeout);
log_msg!("process -> crate::config::TIMEOUT = {}", config_timeout);
log_msg!(
"process -> crate::config::TIMEOUT = {}",
config_cancel_timeout
);

log_msg!("process -> is_timeout = {}", is_timeout);

Expand Down

0 comments on commit 7e7f2f8

Please sign in to comment.