Skip to content

Commit

Permalink
fix: check rent exemptions manually after the simulation (#285)
Browse files Browse the repository at this point in the history
* fix: check rent exemptions manually after the simulation

This is in progress on litesvm package:
LiteSVM/litesvm#98

* More profiling + better docs
  • Loading branch information
m30m authored Dec 6, 2024
1 parent 44dbd9d commit 0213f8c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
5 changes: 4 additions & 1 deletion auction-server/src/auction/service/handle_bid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ impl<T: ChainTrait> Service<T>
where
Service<T>: Verification<T>,
{
#[tracing::instrument(skip_all, fields(bid_id, profile_name, simulation_error))]
#[tracing::instrument(
skip_all,
fields(bid_id, profile_name, simulation_error, permission_key)
)]
pub async fn handle_bid(
&self,
input: HandleBidInput<T>,
Expand Down
30 changes: 30 additions & 0 deletions auction-server/src/auction/service/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,35 @@ impl Simulator {
svm
}


#[allow(clippy::result_large_err)]
fn check_rent_exemption(
svm: &LiteSVM,
simulation_result: Result<SimulatedTransactionInfo, FailedTransactionMetadata>,
) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata> {
let tx_info = simulation_result?;
for (pubkey, data) in &tx_info.post_accounts {
// Ignore if lamports are zero since the account may be closed in the transaction
if 0 < data.lamports()
&& data.lamports() < svm.minimum_balance_for_rent_exemption(data.data().len())
{
let mut metadata = tx_info.meta.clone();
metadata
.logs
.push(format!("Insufficient Funds For Rent: {}", pubkey));
return Err(FailedTransactionMetadata {
//TODO: account_index is not correct, we should find it from the transaction
// the meta logs reflect a successful transaction which is inconsistent with the error
err: solana_sdk::transaction::TransactionError::InsufficientFundsForRent {
account_index: 0,
},
meta: metadata,
});
}
}
Ok(tx_info)
}

/// Simulates a transaction with the current state of the chain
/// applying pending transactions beforehand. The simulation is done locally via fetching
/// all the necessary accounts from the RPC.
Expand All @@ -348,6 +377,7 @@ impl Simulator {
let _ = svm.send_transaction(tx);
});
let res = svm.simulate_transaction(transaction.clone());
let res = Self::check_rent_exemption(&svm, res);
Ok(Response {
value: res,
context: accounts_config_with_context.context,
Expand Down
3 changes: 3 additions & 0 deletions auction-server/src/auction/service/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ impl Verification<Evm> for Service<Evm> {
input: VerifyBidInput<Evm>,
) -> Result<VerificationResult<Evm>, RestError> {
let bid = input.bid_create;
tracing::Span::current()
.record("permission_key", bid.chain_data.permission_key.to_string());
let call = self.get_simulation_call(
bid.chain_data.permission_key.clone(),
vec![MulticallData::from((
Expand Down Expand Up @@ -671,6 +673,7 @@ impl Verification<Svm> for Service<Svm> {
transaction: bid.chain_data.transaction.clone(),
};
let permission_key = bid_chain_data.get_permission_key();
tracing::Span::current().record("permission_key", bid_data.permission_account.to_string());
self.check_deadline(&permission_key, bid_data.deadline)
.await?;
self.verify_signatures(&bid, &bid_chain_data).await?;
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/express_relay/svm/limo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_init_if_needed_wsol_create_and_close_ixs(
Returns necessary instructions to create, fill and close a wrapped SOL account.
Creation instruction is idempotent.
Filling instruction doesn't take into account the current WSOL balance.
Closing instruction unwraps all the WSOL back to the owner, even if it was deposited by another transaction.
Closing instruction always closes the WSOL account and unwraps all WSOL back to SOL.
Args:
owner: Who owns the WSOL token account
payer: Who pays for the instructions
Expand Down

0 comments on commit 0213f8c

Please sign in to comment.