Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkgs/id/src/currency_poc/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ impl<B: LedgerBackend, S: IntentStore> ConversionExecutor<B, S> {

let mut transfer_ids = HashSet::with_capacity(request.transfer_ids.len());
for id in &request.transfer_ids {
// TigerBeetle reserves 0 and u128::MAX as transfer IDs
// and refuses them outright at submission (#6194, the
// #6135 finding): reject them here, in preflight, before
// any intent is persisted — otherwise the write-ahead
// intent strands as a poison Submitted record.
if *id == 0 || *id == u128::MAX {
bail!(
"preflight: transfer ID {id} is reserved (zero and u128::MAX are refused by TigerBeetle)"
);
}
if !transfer_ids.insert(*id) {
bail!("preflight: duplicate transfer ID {id}");
}
Expand Down
41 changes: 41 additions & 0 deletions pkgs/id/src/currency_poc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,47 @@ fn duplicate_t1_and_t3_transfer_ids_fail_preflight_before_persisting_intent() {
);
}

#[test]
fn reserved_transfer_ids_fail_preflight_before_persisting_intent() {
// Oracle: #6194 — real TigerBeetle refuses transfer IDs 0 and
// u128::MAX outright, so preflight must reject them in every leg
// position (T1, fee, T3), naming the offending ID, before any
// intent is persisted or anything is submitted. Pre-fix, the
// creator probe executed all of these Ok Posted.
for position in 0..3 {
for reserved in [0, u128::MAX] {
let mut executor = executor();
let mut bad = request();
bad.transfer_ids[position] = reserved;

let error = executor
.prepare(&bad)
.expect_err("a reserved transfer ID must fail preflight");
assert!(
error
.to_string()
.contains(&format!("transfer ID {reserved} is reserved")),
"the error must name the reserved ID, got: {error}"
);
assert!(executor.store.get(777).unwrap().is_none());
assert!(
executor
.backend
.transfers_with_user_data_128(777)
.is_empty()
);
}
}

// The sane-ID control (the probe's 601/602/603) still executes
// identically: the rejection did not widen to ordinary IDs.
let mut executor = executor();
let record = executor
.execute(&request())
.expect("sane transfer IDs must still post");
assert_eq!(record.state, IntentState::Posted);
}

#[test]
fn fee_without_account_fails_preflight_before_persisting_intent() {
let mut executor = executor();
Expand Down
Loading