Skip to content

Commit ae2d7ef

Browse files
feat: add config to allow selecting to skip or not the pre-flight (#34)
1 parent 90b20ec commit ae2d7ef

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

vrf-oracle/src/args.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ pub struct Args {
2020

2121
#[arg(long, env = "VRF_ORACLE_HTTP_PORT")]
2222
pub http_port: Option<u16>,
23+
24+
// Whether to skip preflight when submitting transactions
25+
#[arg(long, env = "VRF_ORACLE_SKIP_PREFLIGHT", default_value_t = true)]
26+
pub skip_preflight: bool,
2327
}

vrf-oracle/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ async fn main() -> Result<()> {
7575
args.websocket_url,
7676
args.laserstream_endpoint,
7777
args.laserstream_api_key,
78+
args.skip_preflight,
7879
));
7980

8081
// Start minimal HTTP server exposing /stats

vrf-oracle/src/oracle/client.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub struct OracleClient {
4848
pub response_counts: Arc<RwLock<HashMap<String, u64>>>,
4949
// In-flight requests per queue: request_id -> enqueue slot
5050
pub inflight_requests: Arc<RwLock<InflightRequestsMap>>,
51+
// Whether to skip preflight when sending transactions
52+
pub skip_preflight: bool,
5153
}
5254

5355
#[async_trait]
@@ -63,6 +65,7 @@ impl OracleClient {
6365
websocket_url: String,
6466
laserstream_endpoint: Option<String>,
6567
laserstream_api_key: Option<String>,
68+
skip_preflight: bool,
6669
) -> Self {
6770
let (oracle_vrf_sk, oracle_vrf_pk) = generate_vrf_keypair(&keypair);
6871
Self {
@@ -77,6 +80,7 @@ impl OracleClient {
7780
avg_response_slots: Arc::new(RwLock::new(HashMap::new())),
7881
response_counts: Arc::new(RwLock::new(HashMap::new())),
7982
inflight_requests: Arc::new(RwLock::new(HashMap::new())),
83+
skip_preflight,
8084
}
8185
}
8286

vrf-oracle/src/oracle/processor.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub async fn process_oracle_queue(
192192
Err(_) => {
193193
warn!("Failed to parse signature");
194194
attempts += 1;
195-
sleep(Duration::from_millis(10 * attempts)).await;
195+
sleep(Duration::from_millis(20 * attempts)).await;
196196
continue;
197197
}
198198
};
@@ -202,6 +202,7 @@ pub async fn process_oracle_queue(
202202
Err(_) => {
203203
warn!("Failed to confirm transaction");
204204
attempts += 1;
205+
sleep(Duration::from_millis(20 * attempts)).await;
205206
continue;
206207
}
207208
};
@@ -211,12 +212,14 @@ pub async fn process_oracle_queue(
211212
break;
212213
} else {
213214
warn!("Transaction failed");
215+
sleep(Duration::from_millis(20 * attempts)).await;
214216
attempts += 1;
215217
}
216218
}
217219
Err(e) => {
218220
error!("Failed to send transaction: {e:?}");
219221
attempts += 1;
222+
sleep(Duration::from_millis(20 * attempts)).await;
220223
blockhash_cache.refresh_blockhash().await;
221224
}
222225
}
@@ -301,7 +304,7 @@ impl ProcessableItem {
301304
.send_transaction_with_config(
302305
&tx,
303306
RpcSendTransactionConfig {
304-
skip_preflight: true,
307+
skip_preflight: oracle_client.skip_preflight,
305308
preflight_commitment: Some(
306309
solana_sdk::commitment_config::CommitmentLevel::Processed,
307310
),

0 commit comments

Comments
 (0)