Skip to content

Commit 12980d0

Browse files
authored
BM-1858: add removed sanity check from refactor (#1297)
Adding the `check_work_receipt` sanity check, which was removed in the CLI refactor should be sufficient, but I noticed there were some other sanity checks that did not match upstream r0 so I added those to future proof in case those others could be hit in the future in some case.
1 parent bc33a10 commit 12980d0

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

crates/boundless-cli/src/commands/rewards/prepare_mining.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,21 @@ fn check_work_receipt<T: Borrow<WorkReceipt>>(
343343
log_id
344344
);
345345

346+
ensure!(
347+
work_claim.nonce_max.log == log_id,
348+
"Receipt has a log ID that does not match the work log: receipt: {:x}, work log: {:x}",
349+
work_claim.nonce_max.log,
350+
log_id
351+
);
352+
353+
ensure!(
354+
work_claim.nonce_min.job == work_claim.nonce_max.job,
355+
"Work claim nonce min and max job numbers do not match: {} != {}",
356+
work_claim.nonce_min.job,
357+
work_claim.nonce_max.job
358+
);
359+
ensure!(work_claim.nonce_min.segment == 0, "work claim nonce min segment number is not 0");
360+
346361
ensure!(
347362
!work_log.jobs.contains_key(&work_claim.nonce_min.job),
348363
"Receipt has job ID that is already in the work log: {}",
@@ -442,8 +457,13 @@ async fn fetch_work_receipts(
442457
let mut work_receipts = Vec::new();
443458
for key in keys_to_fetch {
444459
// NOTE: We return the result so that the caller can decide whether to skip or bail
445-
let work_receipt =
446-
fetch_work_receipt(bento_url, &key).await.context("Failed to fetch work receipt");
460+
let work_receipt = fetch_work_receipt(bento_url, &key)
461+
.await
462+
.context("Failed to fetch work receipt")
463+
.and_then(|receipt| {
464+
check_work_receipt(log_id, work_log, receipt)
465+
.with_context(|| format!("Receipt with key: {}", key))
466+
});
447467

448468
if work_receipt.is_ok() {
449469
tracing::debug!("Loaded receipt with key: {key}");

0 commit comments

Comments
 (0)