-
Notifications
You must be signed in to change notification settings - Fork 8
NDEV-1837 Remove syscall_stub #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
e195254
7ea5e86
81dbffe
839b9b9
2cfbfc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ pub struct EmulatorAccountStorage<'rpc, T: Rpc> { | |
| chains: Vec<ChainInfo>, | ||
| block_number: u64, | ||
| block_timestamp: i64, | ||
| rent: Rent, | ||
| state_overrides: Option<AccountOverrides>, | ||
| } | ||
|
|
||
|
|
@@ -86,6 +87,25 @@ impl<'rpc, T: Rpc + BuildConfigSimulator> EmulatorAccountStorage<'rpc, T> { | |
| Some(chains) => chains, | ||
| }; | ||
|
|
||
| // TODO: is it correct to get rent from the account | ||
| let mut rent_account = rpc | ||
| .get_account(&solana_sdk::sysvar::rent::id()) | ||
| .await? | ||
| .value | ||
| .unwrap(); | ||
|
||
| let rent = Rent::from_account_info(&AccountInfo { | ||
|
||
| key: &solana_sdk::sysvar::rent::id(), | ||
| is_signer: false, | ||
| is_writable: false, | ||
| lamports: Rc::new(RefCell::new(&mut rent_account.lamports)), | ||
| data: Rc::new(RefCell::new(&mut rent_account.data)), | ||
| owner: &rent_account.owner, | ||
| executable: rent_account.executable, | ||
| rent_epoch: rent_account.rent_epoch, | ||
| })?; | ||
|
|
||
| info!("Rent: {rent:?}"); | ||
|
|
||
| Ok(Self { | ||
| accounts: RefCell::new(HashMap::new()), | ||
| program_id, | ||
|
|
@@ -95,6 +115,7 @@ impl<'rpc, T: Rpc + BuildConfigSimulator> EmulatorAccountStorage<'rpc, T> { | |
| block_number, | ||
| block_timestamp, | ||
| state_overrides, | ||
| rent, | ||
| }) | ||
| } | ||
|
|
||
|
|
@@ -213,8 +234,6 @@ impl<T: Rpc> EmulatorAccountStorage<'_, T> { | |
| pub async fn apply_actions(&mut self, actions: Vec<Action>) -> Result<(), NeonError> { | ||
| info!("apply_actions"); | ||
|
|
||
| let rent = Rent::get()?; | ||
|
|
||
| let mut new_balance_accounts = HashSet::new(); | ||
|
|
||
| for action in actions { | ||
|
|
@@ -262,12 +281,13 @@ impl<T: Rpc> EmulatorAccountStorage<'_, T> { | |
| let empty_size = StorageCell::required_account_size(0); | ||
|
|
||
| let gas = if account.is_none() { | ||
| rent.minimum_balance(cell_size) | ||
| self.rent.minimum_balance(cell_size) | ||
| } else { | ||
| let existing_value = self.storage(address, index).await; | ||
| if existing_value == [0_u8; 32] { | ||
| rent.minimum_balance(cell_size) | ||
| .saturating_sub(rent.minimum_balance(empty_size)) | ||
| self.rent | ||
| .minimum_balance(cell_size) | ||
| .saturating_sub(self.rent.minimum_balance(empty_size)) | ||
| } else { | ||
| 0 | ||
| } | ||
|
|
@@ -294,7 +314,7 @@ impl<T: Rpc> EmulatorAccountStorage<'_, T> { | |
| self.use_contract_account(address, true).await?; | ||
|
|
||
| let space = ContractAccount::required_account_size(&code); | ||
| self.gas = self.gas.saturating_add(rent.minimum_balance(space)); | ||
| self.gas = self.gas.saturating_add(self.rent.minimum_balance(space)); | ||
| } | ||
| Action::EvmSelfDestruct { address } => { | ||
| info!("selfdestruct {address}"); | ||
|
|
@@ -320,7 +340,8 @@ impl<T: Rpc> EmulatorAccountStorage<'_, T> { | |
| } | ||
|
|
||
| self.gas = self.gas.saturating_add( | ||
| rent.minimum_balance(BalanceAccount::required_account_size()) | ||
| self.rent | ||
| .minimum_balance(BalanceAccount::required_account_size()) | ||
| .saturating_mul(new_balance_accounts.len() as u64), | ||
| ); | ||
|
|
||
|
|
@@ -331,8 +352,6 @@ impl<T: Rpc> EmulatorAccountStorage<'_, T> { | |
| let mut accounts = self.accounts.borrow_mut(); | ||
| let mut additional_balances = Vec::new(); | ||
|
|
||
| let rent = Rent::get()?; | ||
|
|
||
| for (key, account) in accounts.iter_mut() { | ||
| let Some(account_data) = account.data.as_mut() else { | ||
| continue; | ||
|
|
@@ -361,7 +380,9 @@ impl<T: Rpc> EmulatorAccountStorage<'_, T> { | |
|
|
||
| if (legacy_data.code_size > 0) || (legacy_data.generation > 0) { | ||
| // This is a contract, we need additional gas for conversion | ||
| let lamports = rent.minimum_balance(BalanceAccount::required_account_size()); | ||
| let lamports = self | ||
| .rent | ||
| .minimum_balance(BalanceAccount::required_account_size()); | ||
| self.gas = self.gas.saturating_add(lamports); | ||
| } | ||
| } | ||
|
|
@@ -533,6 +554,16 @@ impl<T: Rpc> AccountStorage for EmulatorAccountStorage<'_, T> { | |
| self.block_timestamp.try_into().unwrap() | ||
| } | ||
|
|
||
| fn rent(&self) -> &Rent { | ||
| &self.rent | ||
| } | ||
|
|
||
| fn return_data(&self) -> Option<(Pubkey, Vec<u8>)> { | ||
| info!("return_data"); | ||
| // TODO: implement return_data() method with SyncedAccountStorage implementation | ||
| unimplemented!(); | ||
| } | ||
|
|
||
| async fn block_hash(&self, slot: u64) -> [u8; 32] { | ||
| info!("block_hash {slot}"); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed