Skip to content

Commit 0213f8c

Browse files
authored
fix: check rent exemptions manually after the simulation (#285)
* fix: check rent exemptions manually after the simulation This is in progress on litesvm package: LiteSVM/litesvm#98 * More profiling + better docs
1 parent 44dbd9d commit 0213f8c

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

auction-server/src/auction/service/handle_bid.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ impl<T: ChainTrait> Service<T>
2121
where
2222
Service<T>: Verification<T>,
2323
{
24-
#[tracing::instrument(skip_all, fields(bid_id, profile_name, simulation_error))]
24+
#[tracing::instrument(
25+
skip_all,
26+
fields(bid_id, profile_name, simulation_error, permission_key)
27+
)]
2528
pub async fn handle_bid(
2629
&self,
2730
input: HandleBidInput<T>,

auction-server/src/auction/service/simulator.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,35 @@ impl Simulator {
326326
svm
327327
}
328328

329+
330+
#[allow(clippy::result_large_err)]
331+
fn check_rent_exemption(
332+
svm: &LiteSVM,
333+
simulation_result: Result<SimulatedTransactionInfo, FailedTransactionMetadata>,
334+
) -> Result<SimulatedTransactionInfo, FailedTransactionMetadata> {
335+
let tx_info = simulation_result?;
336+
for (pubkey, data) in &tx_info.post_accounts {
337+
// Ignore if lamports are zero since the account may be closed in the transaction
338+
if 0 < data.lamports()
339+
&& data.lamports() < svm.minimum_balance_for_rent_exemption(data.data().len())
340+
{
341+
let mut metadata = tx_info.meta.clone();
342+
metadata
343+
.logs
344+
.push(format!("Insufficient Funds For Rent: {}", pubkey));
345+
return Err(FailedTransactionMetadata {
346+
//TODO: account_index is not correct, we should find it from the transaction
347+
// the meta logs reflect a successful transaction which is inconsistent with the error
348+
err: solana_sdk::transaction::TransactionError::InsufficientFundsForRent {
349+
account_index: 0,
350+
},
351+
meta: metadata,
352+
});
353+
}
354+
}
355+
Ok(tx_info)
356+
}
357+
329358
/// Simulates a transaction with the current state of the chain
330359
/// applying pending transactions beforehand. The simulation is done locally via fetching
331360
/// all the necessary accounts from the RPC.
@@ -348,6 +377,7 @@ impl Simulator {
348377
let _ = svm.send_transaction(tx);
349378
});
350379
let res = svm.simulate_transaction(transaction.clone());
380+
let res = Self::check_rent_exemption(&svm, res);
351381
Ok(Response {
352382
value: res,
353383
context: accounts_config_with_context.context,

auction-server/src/auction/service/verification.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ impl Verification<Evm> for Service<Evm> {
186186
input: VerifyBidInput<Evm>,
187187
) -> Result<VerificationResult<Evm>, RestError> {
188188
let bid = input.bid_create;
189+
tracing::Span::current()
190+
.record("permission_key", bid.chain_data.permission_key.to_string());
189191
let call = self.get_simulation_call(
190192
bid.chain_data.permission_key.clone(),
191193
vec![MulticallData::from((
@@ -671,6 +673,7 @@ impl Verification<Svm> for Service<Svm> {
671673
transaction: bid.chain_data.transaction.clone(),
672674
};
673675
let permission_key = bid_chain_data.get_permission_key();
676+
tracing::Span::current().record("permission_key", bid_data.permission_account.to_string());
674677
self.check_deadline(&permission_key, bid_data.deadline)
675678
.await?;
676679
self.verify_signatures(&bid, &bid_chain_data).await?;

sdk/python/express_relay/svm/limo_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def get_init_if_needed_wsol_create_and_close_ixs(
127127
Returns necessary instructions to create, fill and close a wrapped SOL account.
128128
Creation instruction is idempotent.
129129
Filling instruction doesn't take into account the current WSOL balance.
130-
Closing instruction unwraps all the WSOL back to the owner, even if it was deposited by another transaction.
130+
Closing instruction always closes the WSOL account and unwraps all WSOL back to SOL.
131131
Args:
132132
owner: Who owns the WSOL token account
133133
payer: Who pays for the instructions

0 commit comments

Comments
 (0)