Skip to content

Commit 2284788

Browse files
authored
BM-221: Multiple small broker fixes (github#54)
This PR: * Adds the timeout config to the lockin txns * Increases the configured timeout for txns to 45 seconds to wait for confirmations to try and help improve order finalization success * Fixes the docker build that were failing for broker * Makes `assumption_price` optional and notes its not used * bring back priority gas settings for `lockin` * Fixed the bonsai zkvm version for Bonsai proving backends closes BM-221
1 parent 2028d51 commit 2284788

File tree

7 files changed

+54
-35
lines changed

7 files changed

+54
-35
lines changed

broker.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ max_stake = "0.5"
88
skip_preflight_ids = []
99
max_file_size = 50_000_000
1010
# allow_client_addresses = []
11+
# lockin_priority_gas = 100
1112

1213
[prover]
1314
status_poll_ms = 1000
14-
bonsai_r0_zkvm_ver = "1.1"
15+
bonsai_r0_zkvm_ver = "1.1.1"
1516
req_retry_count = 3
1617
# set_builder_guest_path = "./target/riscv-guest/riscv32im-risc0-zkvm-elf/release/set-builder-guest"
1718
# assessor_set_guest_path = "./target/riscv-guest/riscv32im-risc0-zkvm-elf/release/assessor-guest"
@@ -20,4 +21,4 @@ req_retry_count = 3
2021
batch_max_time = 1000
2122
batch_size = 1
2223
block_deadline_buffer_secs = 120
23-
# txn_timeout = 30
24+
txn_timeout = 45

crates/boundless-market/src/contracts/proof_market.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ where
214214
&self,
215215
request: &ProvingRequest,
216216
client_sig: &Bytes,
217-
_priority_gas: Option<u128>,
217+
priority_gas: Option<u128>,
218218
) -> Result<u64, MarketError> {
219219
tracing::debug!("Calling requestIsLocked({:x})", request.id);
220220
let is_locked_in: bool =
@@ -225,23 +225,22 @@ where
225225

226226
tracing::debug!("Calling lockin({:?}, {:?})", request, client_sig);
227227

228-
let call = self.instance.lockin(request.clone(), client_sig.clone()).from(self.caller);
228+
let mut call = self.instance.lockin(request.clone(), client_sig.clone()).from(self.caller);
229229

230-
// if let Some(gas) = priority_gas {
231-
// let priority_fee = self
232-
// .instance
233-
// .provider()
234-
// .estimate_eip1559_fees(None)
235-
// .await
236-
// .context("Failed to get priority gas fee")?;
230+
if let Some(gas) = priority_gas {
231+
let priority_fee = self
232+
.instance
233+
.provider()
234+
.estimate_eip1559_fees(None)
235+
.await
236+
.context("Failed to get priority gas fee")?;
237237

238-
// call = call
239-
// .max_fee_per_gas(priority_fee.max_fee_per_gas + gas)
240-
// .max_priority_fee_per_gas(priority_fee.max_priority_fee_per_gas + gas);
241-
// }
238+
call = call
239+
.max_fee_per_gas(priority_fee.max_fee_per_gas + gas)
240+
.max_priority_fee_per_gas(priority_fee.max_priority_fee_per_gas + gas);
241+
}
242242

243-
// let pending_tx = call.send().await.map_err(IProofMarketErrors::decode_error)?;
244-
let pending_tx = call.send().await.context("Failed to lock")?;
243+
let pending_tx = call.send().await.map_err(IProofMarketErrors::decode_error)?;
245244

246245
tracing::debug!("Broadcasting tx {}", pending_tx.tx_hash());
247246

crates/broker/src/config.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ pub struct MarketConf {
2424
/// Mega Cycle price (in native token)
2525
pub mcycle_price: String,
2626
/// Assumption price (in native token)
27-
pub assumption_price: String,
27+
///
28+
/// UNUSED CURRENTLY
29+
pub assumption_price: Option<String>,
2830
/// Peak single proof performance in kHz
2931
///
3032
/// Used for sanity checking bids to prevent slashing
@@ -57,7 +59,7 @@ impl Default for MarketConf {
5759
fn default() -> Self {
5860
Self {
5961
mcycle_price: "0.1".to_string(),
60-
assumption_price: "0.1".to_string(),
62+
assumption_price: None,
6163
peak_prove_khz: None,
6264
min_deadline: 150, // ~300 seconds aka 5 mins
6365
lookback_blocks: 100,
@@ -295,7 +297,6 @@ mod tests {
295297
const CONFIG_TEMPL: &str = r#"
296298
[market]
297299
mcycle_price = "0.1"
298-
assumption_price = "0.1"
299300
peak_prove_khz = 500
300301
min_deadline = 150
301302
lookback_blocks = 100
@@ -353,7 +354,7 @@ error = ?"#;
353354
let config = Config::load(config_temp.path()).await.unwrap();
354355

355356
assert_eq!(config.market.mcycle_price, "0.1");
356-
assert_eq!(config.market.assumption_price, "0.1");
357+
assert_eq!(config.market.assumption_price, None);
357358
assert_eq!(config.market.peak_prove_khz, Some(500));
358359
assert_eq!(config.market.min_deadline, 150);
359360
assert_eq!(config.market.lookback_blocks, 100);
@@ -397,7 +398,7 @@ error = ?"#;
397398
{
398399
let config = config_mgnr.config.lock_all().unwrap();
399400
assert_eq!(config.market.mcycle_price, "0.1");
400-
assert_eq!(config.market.assumption_price, "0.1");
401+
assert_eq!(config.market.assumption_price, None);
401402
assert_eq!(config.market.peak_prove_khz, Some(500));
402403
assert_eq!(config.market.min_deadline, 150);
403404
assert_eq!(config.market.lookback_blocks, 100);
@@ -411,7 +412,7 @@ error = ?"#;
411412
tracing::debug!("Locking config for reading...");
412413
let config = config_mgnr.config.lock_all().unwrap();
413414
assert_eq!(config.market.mcycle_price, "0.1");
414-
assert_eq!(config.market.assumption_price, "0.1");
415+
assert_eq!(config.market.assumption_price, Some("0.1".into()));
415416
assert_eq!(config.market.peak_prove_khz, Some(10000));
416417
assert_eq!(config.market.min_deadline, 150);
417418
assert_eq!(config.market.lookback_blocks, 100);

crates/broker/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ where
461461
self.config_watcher.config.clone(),
462462
block_times,
463463
self.args.proof_market_addr,
464-
));
464+
)?);
465465
supervisor_tasks.spawn(async move {
466466
task::supervisor(1, order_monitor).await.context("Failed to start order monitor")?;
467467
Ok(())

crates/broker/src/order_monitor.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use alloy::{
1717
use anyhow::{bail, Context, Result};
1818
use boundless_market::contracts::{proof_market::ProofMarketService, ProofStatus};
1919
use std::sync::Arc;
20+
use std::time::Duration;
2021

2122
#[derive(Clone)]
2223
pub struct OrderMonitor<T, P> {
@@ -38,14 +39,22 @@ where
3839
config: ConfigLock,
3940
block_time: u64,
4041
market_addr: Address,
41-
) -> Self {
42-
let market = ProofMarketService::new(
42+
) -> Result<Self> {
43+
let txn_timeout_opt = {
44+
let config = config.lock_all().context("Failed to read config")?;
45+
config.batcher.txn_timeout
46+
};
47+
48+
let mut market = ProofMarketService::new(
4349
market_addr,
4450
provider.clone(),
4551
provider.default_signer_address(),
4652
);
53+
if let Some(txn_timeout) = txn_timeout_opt {
54+
market = market.with_timeout(Duration::from_secs(txn_timeout));
55+
}
4756

48-
Self { db, provider, block_time, config, market }
57+
Ok(Self { db, provider, block_time, config, market })
4958
}
5059

5160
async fn lock_order(&self, order_id: U256, order: &Order) -> Result<()> {
@@ -312,7 +321,8 @@ mod tests {
312321
config.clone(),
313322
block_time,
314323
contract_address,
315-
);
324+
)
325+
.unwrap();
316326

317327
let orders = monitor.back_scan_locks().await.unwrap();
318328
assert_eq!(orders, 1);
@@ -409,7 +419,8 @@ mod tests {
409419
config.clone(),
410420
block_time,
411421
contract_address,
412-
);
422+
)
423+
.unwrap();
413424

414425
monitor.start_monitor(Some(4)).await.unwrap();
415426

crates/broker/src/order_picker.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,17 @@ where
171171
.try_into()
172172
.context("Failed to convert U256 exec limit to u64")?;
173173

174+
if exec_limit == 0 {
175+
tracing::warn!(
176+
"Removing order {order_id:x} because it's mcycle price limit is below 0 mcycles"
177+
);
178+
self.db
179+
.skip_order(order_id)
180+
.await
181+
.context("Order max price below min mcycle price, limit 0")?;
182+
return Ok(());
183+
}
184+
174185
tracing::debug!(
175186
"Starting preflight execution of {order_id:x} exec limit {exec_limit} mcycles"
176187
);

dockerfiles/broker.dockerfile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ RUN curl -L https://foundry.paradigm.xyz | bash && \
1414

1515
# RUN curl -L https://risczero.com/install | bash
1616
RUN \
17-
# --mount=type=cache,target=/root/.cache/sccache/ \
17+
# --mount=type=cache,target=/root/.cache/sccache/,id=bndlss_broker_sccache \
1818
# --mount=type=cache,target=/usr/local/cargo/git/db \
1919
# --mount=type=cache,target=/usr/local/cargo/registry/ \
20-
source ./sccache-config.sh && \
20+
# source ./sccache-config.sh && \
2121
cargo install --version 1.6.9 cargo-binstall && \
2222
cargo binstall -y --force cargo-risczero --version 1.1 && \
2323
cargo risczero install
@@ -39,10 +39,6 @@ ENV PATH="$PATH:/root/.foundry/bin"
3939
RUN forge build
4040

4141
RUN \
42-
# --mount=type=cache,target=target,rw,id=spear_broker \
43-
# --mount=type=cache,target=/root/.cargo/,rw,id=spear_broker_cargo \
44-
# --mount=type=cache,target=/root/.cache/sccache/,rw,id=spear_broker_sccache \
45-
# source ./sccache-config.sh && \
4642
cargo build --release --bin broker && \
4743
cp /src/target/release/broker /src/broker
4844

0 commit comments

Comments
 (0)