global: fixes

This commit is contained in:
nym21
2026-04-27 12:52:02 +02:00
parent b24bfdc15c
commit 76869ed2b6
114 changed files with 6623 additions and 1981 deletions

View File

@@ -62,10 +62,7 @@ impl Fetcher {
/// Parent txids referenced by `new_raws` inputs that aren't already
/// resolvable: not in the mempool store, not in `new_raws` itself.
fn unique_confirmed_parents(
new_raws: &FxHashMap<Txid, RawTx>,
known: &TxStore,
) -> Vec<Txid> {
fn unique_confirmed_parents(new_raws: &FxHashMap<Txid, RawTx>, known: &TxStore) -> Vec<Txid> {
let mut set: FxHashSet<Txid> = FxHashSet::default();
for raw in new_raws.values() {
for txin in &raw.tx.input {

View File

@@ -37,12 +37,9 @@ fn synthetic_mempool(n: usize) -> Vec<Option<Entry>> {
_ if i > 1 => {
let p1 = (i.wrapping_mul(7919)) % i;
let p2 = (i.wrapping_mul(6151)) % i;
[
TxidPrefix::from(&txids[p1]),
TxidPrefix::from(&txids[p2]),
]
.into_iter()
.collect()
[TxidPrefix::from(&txids[p1]), TxidPrefix::from(&txids[p2])]
.into_iter()
.collect()
}
_ => SmallVec::new(),
};

View File

@@ -52,7 +52,12 @@ pub fn linearize_clusters(graph: &Graph) -> Vec<Package> {
continue;
}
for (chunk_order, chunk) in sfl::linearize(&cluster).iter().enumerate() {
packages.push(chunk_to_package(&cluster, chunk, cluster_id, chunk_order as u32));
packages.push(chunk_to_package(
&cluster,
chunk,
cluster_id,
chunk_order as u32,
));
}
}

View File

@@ -327,7 +327,10 @@ fn random_dag(n: usize, seed: u64) -> FvAndEdges {
(fees_vsizes, edges)
}
#[expect(dead_code, reason = "kept for ad-hoc oracle sweeps; called via uncommented stress tests")]
#[expect(
dead_code,
reason = "kept for ad-hoc oracle sweeps; called via uncommented stress tests"
)]
fn assert_optimal_on_random(n: usize, seed: u64) {
let (fv, edges) = random_dag(n, seed);
let cluster = super::make_cluster(&fv, &edges);
@@ -376,7 +379,11 @@ fn optimality_gap_of(got: &[(u64, u64)], want: &[(u64, u64)]) -> Option<u128> {
worst_gap = worst_gap.max(fb - fa);
}
}
if worst_gap == 0 { None } else { Some(worst_gap) }
if worst_gap == 0 {
None
} else {
Some(worst_gap)
}
}
/// Gap for the production linearizer on one random DAG.
@@ -479,10 +486,7 @@ fn perf_linearize() {
} else {
format!("{} ns", avg_ns)
};
eprintln!(
" {:<4} {:<8} {:<10} {:.2?}",
n, calls, pretty, elapsed
);
eprintln!(" {:<4} {:<8} {:<10} {:.2?}", n, calls, pretty, elapsed);
}
eprintln!();
}

View File

@@ -15,10 +15,7 @@ const LOOK_AHEAD_COUNT: usize = 100;
/// Look-ahead respects intra-cluster order: a chunk is only taken once
/// every earlier-rate chunk of the same cluster has been placed, so a
/// child chunk never lands in an earlier block than its parent chunk.
pub fn partition_into_blocks(
mut packages: Vec<Package>,
num_blocks: usize,
) -> Vec<Vec<Package>> {
pub fn partition_into_blocks(mut packages: Vec<Package>, num_blocks: usize) -> Vec<Vec<Package>> {
// Stable sort preserves SFL's per-cluster non-increasing-rate emission
// order in the global list, which is what `cluster_next` relies on.
packages.sort_by_key(|p| Reverse(p.fee_rate));
@@ -67,7 +64,13 @@ fn fill_normal_blocks(
let remaining_space = BLOCK_VSIZE.saturating_sub(current_vsize);
if pkg.vsize <= remaining_space {
take(slots, idx, &mut current_block, &mut current_vsize, cluster_next);
take(
slots,
idx,
&mut current_block,
&mut current_vsize,
cluster_next,
);
idx += 1;
continue;
}
@@ -75,7 +78,13 @@ fn fill_normal_blocks(
if current_block.is_empty() {
// Oversized package with no partial block to preserve; take it
// anyway so we don't stall on a package larger than BLOCK_VSIZE.
take(slots, idx, &mut current_block, &mut current_vsize, cluster_next);
take(
slots,
idx,
&mut current_block,
&mut current_vsize,
cluster_next,
);
idx += 1;
continue;
}

View File

@@ -45,12 +45,7 @@ impl Verifier {
}
}
fn live_entry(
entries: &[Option<Entry>],
tx_index: TxIndex,
b: usize,
p: usize,
) -> &Entry {
fn live_entry(entries: &[Option<Entry>], tx_index: TxIndex, b: usize, p: usize) -> &Entry {
entries[tx_index.as_usize()]
.as_ref()
.unwrap_or_else(|| panic!("block {b} pkg {p}: dead tx_index {tx_index:?}"))
@@ -65,10 +60,7 @@ impl Verifier {
) {
for parent in &entry.depends {
if in_pool.contains(parent) && !placed.contains(parent) {
panic!(
"block {b} pkg {p}: {} placed before its parent",
entry.txid
);
panic!("block {b} pkg {p}: {} placed before its parent", entry.txid);
}
}
}

View File

@@ -60,7 +60,10 @@ impl EntryPool {
/// Remove an entry by its txid prefix, returning it if present.
pub fn remove(&mut self, prefix: &TxidPrefix) -> Option<Entry> {
let idx = self.prefix_to_idx.remove(prefix)?;
let entry = self.entries.get_mut(idx.as_usize()).and_then(Option::take)?;
let entry = self
.entries
.get_mut(idx.as_usize())
.and_then(Option::take)?;
self.free_slots.push(idx);
Some(entry)
}

View File

@@ -15,7 +15,12 @@ pub struct Tombstone {
}
impl Tombstone {
pub(super) fn new(tx: Transaction, entry: Entry, removal: Removal, removed_at: Instant) -> Self {
pub(super) fn new(
tx: Transaction,
entry: Entry,
removal: Removal,
removed_at: Instant,
) -> Self {
Self {
tx,
entry,

View File

@@ -36,9 +36,9 @@ impl TxGraveyard {
&'a self,
replacer: &'a Txid,
) -> impl Iterator<Item = (&'a Txid, &'a Tombstone)> {
self.tombstones
.iter()
.filter_map(move |(txid, ts)| (ts.replaced_by() == Some(replacer)).then_some((txid, ts)))
self.tombstones.iter().filter_map(move |(txid, ts)| {
(ts.replaced_by() == Some(replacer)).then_some((txid, ts))
})
}
pub fn bury(&mut self, txid: Txid, tx: Transaction, entry: Entry, removal: Removal) {