Skip to content

Commit 48a79b2

Browse files
authored
Add option '--skip-tx-preflight' to disable preflight checks (#59)
* Add option '--skip-tx-preflight' to disable preflight checks on tx sending
1 parent 18e4125 commit 48a79b2

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Options:
105105
--commitment solana commitment level for state updates [processed|confirmed|finalized] (default: confirmed)
106106
--default-sub-account-id default sub-account ID for account related operations (default: 0)
107107
--verbose enable debug logging
108+
--skip-tx-preflight skip tx preflight checks
108109
```
109110

110111
### Delegated Signing Mode

src/controller.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ pub struct AppState {
6060
tx_commitment: CommitmentConfig,
6161
/// default sub_account_id to use if not provided
6262
default_subaccount_id: u16,
63+
/// skip tx preflight on send or not (default: false)
64+
skip_tx_preflight: bool,
6365
}
6466

6567
impl AppState {
@@ -85,6 +87,7 @@ impl AppState {
8587
wallet: Wallet,
8688
commitment: Option<(CommitmentConfig, CommitmentConfig)>,
8789
default_subaccount_id: Option<u16>,
90+
skip_tx_preflight: bool,
8891
) -> Self {
8992
let (state_commitment, tx_commitment) =
9093
commitment.unwrap_or((CommitmentConfig::confirmed(), CommitmentConfig::confirmed()));
@@ -113,6 +116,7 @@ impl AppState {
113116
dlob_client: DLOBClient::new(dlob_endpoint),
114117
tx_commitment,
115118
default_subaccount_id: default_subaccount_id.unwrap_or(0),
119+
skip_tx_preflight,
116120
}
117121
}
118122

@@ -519,17 +523,16 @@ impl AppState {
519523
.await
520524
.map_err(SdkError::from)?;
521525
let tx = self.wallet.sign_tx(tx, recent_block_hash)?;
526+
let tx_config = RpcSendTransactionConfig {
527+
max_retries: Some(0),
528+
preflight_commitment: Some(self.tx_commitment.commitment),
529+
skip_preflight: self.skip_tx_preflight,
530+
..Default::default()
531+
};
522532
let result = self
523533
.client
524534
.inner()
525-
.send_transaction_with_config(
526-
&tx,
527-
RpcSendTransactionConfig {
528-
max_retries: Some(0),
529-
preflight_commitment: Some(self.tx_commitment.commitment),
530-
..Default::default()
531-
},
532-
)
535+
.send_transaction_with_config(&tx, tx_config)
533536
.await
534537
.map(|s| {
535538
debug!(target: LOG_TARGET, "sent tx ({reason}): {s}");
@@ -547,18 +550,10 @@ impl AppState {
547550

548551
// double send the tx to help chances of landing
549552
let client = Arc::clone(&self.client);
550-
let commitment = self.tx_commitment.commitment;
551553
tokio::spawn(async move {
552554
if let Err(err) = client
553555
.inner()
554-
.send_transaction_with_config(
555-
&tx,
556-
RpcSendTransactionConfig {
557-
max_retries: Some(0),
558-
preflight_commitment: Some(commitment),
559-
..Default::default()
560-
},
561-
)
556+
.send_transaction_with_config(&tx, tx_config)
562557
.await
563558
{
564559
warn!(target: LOG_TARGET, "retry tx failed: {err:?}");

src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ async fn main() -> std::io::Result<()> {
235235
wallet,
236236
Some((state_commitment, tx_commitment)),
237237
Some(config.default_sub_account_id),
238+
config.skip_tx_preflight,
238239
)
239240
.await;
240241

@@ -387,9 +388,12 @@ struct GatewayConfig {
387388
/// default sub_account_id to use (default: 0)
388389
#[argh(option, default = "0")]
389390
default_sub_account_id: u16,
390-
#[argh(switch)]
391391
/// enable debug logging
392+
#[argh(switch)]
392393
verbose: bool,
394+
/// skip tx preflight checks
395+
#[argh(switch)]
396+
skip_tx_preflight: bool,
393397
}
394398

395399
#[cfg(test)]
@@ -416,7 +420,7 @@ mod tests {
416420
} else {
417421
create_wallet(None, emulate, None)
418422
};
419-
AppState::new(TEST_ENDPOINT, true, wallet, None, None).await
423+
AppState::new(TEST_ENDPOINT, true, wallet, None, None, false).await
420424
}
421425

422426
#[actix_web::test]

0 commit comments

Comments
 (0)