Skip to content

Commit 165f1c7

Browse files
mothrannuke-web3
andauthored
BM-198: Adds TXN timeout config to finalize batch (github#37)
This PR adds a configurable timeout to wait for transactions to be included, currently only configured for the submitter but we can add it to all places we need additional time. We hit a TXN Timeout while waiting for the fulfill batch on Sepolia. Also closes BM-207 by attempting to just trigger a supervisor recover when the event listener fails. --------- Co-authored-by: Nuke <[email protected]>
1 parent 772441d commit 165f1c7

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

broker.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ max_file_size = 50_000_000
1313
status_poll_ms = 1000
1414
bonsai_r0_zkvm_ver = "1.1.1"
1515
req_retry_count = 3
16-
set_builder_guest_path = "./target/riscv-guest/riscv32im-risc0-zkvm-elf/release/set-builder-guest"
17-
assessor_set_guest_path = "./target/riscv-guest/riscv32im-risc0-zkvm-elf/release/assessor-guest"
16+
# set_builder_guest_path = "./target/riscv-guest/riscv32im-risc0-zkvm-elf/release/set-builder-guest"
17+
# assessor_set_guest_path = "./target/riscv-guest/riscv32im-risc0-zkvm-elf/release/assessor-guest"
1818

1919
[batcher]
2020
batch_max_time = 1000
2121
batch_size = 1
2222
block_deadline_buffer_secs = 120
23+
# txn_timeout = 30

crates/broker/src/config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ pub struct BatcherConfig {
116116
/// Number of seconds before the lowest block deadline in the order batch
117117
/// to flush the batch. This should be approximately snark_proving_time * 2
118118
pub block_deadline_buffer_secs: u64,
119+
/// Timeout, in seconds for transaction confirmations
120+
pub txn_timeout: Option<u64>,
119121
}
120122

121123
impl Default for BatcherConfig {
@@ -125,6 +127,7 @@ impl Default for BatcherConfig {
125127
batch_size: Some(2),
126128
batch_max_fees: None,
127129
block_deadline_buffer_secs: 120,
130+
txn_timeout: None,
128131
}
129132
}
130133
}
@@ -330,7 +333,8 @@ req_retry_count = 0
330333
[batcher]
331334
batch_max_time = 300
332335
batch_size = 2
333-
block_deadline_buffer_secs = 120"#;
336+
block_deadline_buffer_secs = 120
337+
txn_timeout = 45"#;
334338

335339
const BAD_CONFIG: &str = r#"
336340
[market]
@@ -372,6 +376,7 @@ error = ?"#;
372376
assert_eq!(config.batcher.batch_size, Some(2));
373377
assert_eq!(config.batcher.batch_max_fees, Some("0.1".into()));
374378
assert_eq!(config.batcher.block_deadline_buffer_secs, 120);
379+
assert_eq!(config.batcher.txn_timeout, None);
375380
}
376381

377382
#[tokio::test]
@@ -413,6 +418,7 @@ error = ?"#;
413418
assert_eq!(config.market.allow_client_addresses, Some(vec![Address::ZERO]));
414419
assert_eq!(config.prover.status_poll_ms, 1000);
415420
assert!(config.prover.bonsai_r0_zkvm_ver.is_none());
421+
assert_eq!(config.batcher.txn_timeout, Some(45));
416422
}
417423
tracing::debug!("closing...");
418424
}

crates/broker/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,13 @@ where
511511

512512
let submitter = Arc::new(submitter::Submitter::new(
513513
self.db.clone(),
514+
self.config_watcher.config.clone(),
514515
prover.clone(),
515516
self.provider.clone(),
516517
self.args.set_verifier_addr,
517518
self.args.proof_market_addr,
518519
set_builder_img_data.0,
519-
));
520+
)?);
520521
supervisor_tasks.spawn(async move {
521522
task::supervisor(1, submitter).await.context("Failed to start submitter service")?;
522523
Ok(())

crates/broker/src/market_monitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ where
188188
})
189189
.await;
190190

191-
Ok(())
191+
anyhow::bail!("Event polling exited, polling failed (possible RPC error)");
192192
}
193193
}
194194

crates/broker/src/submitter.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// All rights reserved.
44

5-
use std::sync::Arc;
5+
use std::{sync::Arc, time::Duration};
66

77
use aggregation_set::{SetInclusionReceipt, SetInclusionReceiptVerifierParameters};
88
use alloy::{
@@ -22,6 +22,7 @@ use risc0_zkvm::{
2222
};
2323

2424
use crate::{
25+
config::ConfigLock,
2526
db::DbObj,
2627
provers::ProverObj,
2728
task::{RetryRes, RetryTask, SupervisorErr},
@@ -45,24 +46,34 @@ where
4546
#[allow(clippy::too_many_arguments)]
4647
pub fn new(
4748
db: DbObj,
49+
config: ConfigLock,
4850
prover: ProverObj,
4951
provider: Arc<P>,
5052
set_verifier_addr: Address,
5153
market_addr: Address,
5254
set_builder_img_id: Digest,
53-
) -> Self {
54-
let market = ProofMarketService::new(
55+
) -> Result<Self> {
56+
let txn_timeout_opt = {
57+
let config = config.lock_all().context("Failed to read config")?;
58+
config.batcher.txn_timeout
59+
};
60+
61+
let mut market = ProofMarketService::new(
5562
market_addr,
5663
provider.clone(),
5764
provider.default_signer_address(),
5865
);
66+
if let Some(txn_timeout) = txn_timeout_opt {
67+
market = market.with_timeout(Duration::from_secs(txn_timeout));
68+
}
69+
5970
let set_verifier = SetVerifierService::new(
6071
set_verifier_addr,
6172
provider.clone(),
6273
provider.default_signer_address(),
6374
);
6475

65-
Self { db, prover, market, set_verifier, set_builder_img_id }
76+
Ok(Self { db, prover, market, set_verifier, set_builder_img_id })
6677
}
6778

6879
async fn fetch_encode_g16(&self, g16_proof_id: &str) -> Result<Vec<u8>> {
@@ -537,14 +548,17 @@ mod tests {
537548

538549
market.lockin_request(&order.request, &client_sig.into(), None).await.unwrap();
539550

551+
let config = ConfigLock::default();
540552
let submitter = Submitter::new(
541553
db.clone(),
554+
config,
542555
prover.clone(),
543556
provider.clone(),
544557
*set_verifier.address(),
545558
*proof_market.address(),
546559
set_builder_id,
547-
);
560+
)
561+
.unwrap();
548562

549563
assert!(submitter.process_next_batch().await.unwrap());
550564

0 commit comments

Comments
 (0)