Skip to content

Commit 3c7bfd7

Browse files
committed
Skip fee reads in full_stack_target when connecting many blocks
When we connect 100 blocks in a row, requiring the fuzz input to contain 100 fee estimator results is uneccessary, so add a bool that lets us skip those reads.
1 parent 9f4d907 commit 3c7bfd7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fuzz/src/full_stack.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use std::cell::RefCell;
6868
use std::convert::TryInto;
6969
use std::cmp;
7070
use std::sync::{Arc, Mutex};
71-
use std::sync::atomic::{AtomicU64,AtomicUsize,Ordering};
71+
use std::sync::atomic::{AtomicU64,AtomicUsize,AtomicBool,Ordering};
7272
use bitcoin::bech32::u5;
7373

7474
#[inline]
@@ -95,6 +95,7 @@ pub fn slice_to_be24(v: &[u8]) -> u32 {
9595
struct InputData {
9696
data: Vec<u8>,
9797
read_pos: AtomicUsize,
98+
halt_fee_est_reads: AtomicBool,
9899
}
99100
impl InputData {
100101
fn get_slice(&self, len: usize) -> Option<&[u8]> {
@@ -121,6 +122,9 @@ struct FuzzEstimator {
121122
}
122123
impl FeeEstimator for FuzzEstimator {
123124
fn get_est_sat_per_1000_weight(&self, _: ConfirmationTarget) -> u32 {
125+
if self.input.halt_fee_est_reads.load(Ordering::Acquire) {
126+
return 253;
127+
}
124128
//TODO: We should actually be testing at least much more than 64k...
125129
match self.input.get_slice(2) {
126130
Some(slice) => cmp::max(slice_to_be16(slice) as u32, 253),
@@ -441,6 +445,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
441445
let input = Arc::new(InputData {
442446
data: data.to_vec(),
443447
read_pos: AtomicUsize::new(0),
448+
halt_fee_est_reads: AtomicBool::new(false),
444449
});
445450
let fee_est = Arc::new(FuzzEstimator {
446451
input: input.clone(),
@@ -698,10 +703,12 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
698703
11 => {
699704
let mut txn = broadcast.txn_broadcasted.lock().unwrap().split_off(0);
700705
if !txn.is_empty() {
706+
input.halt_fee_est_reads.store(true, Ordering::Release);
701707
loss_detector.connect_block(&txn[..]);
702708
for _ in 2..100 {
703709
loss_detector.connect_block(&[]);
704710
}
711+
input.halt_fee_est_reads.store(false, Ordering::Release);
705712
}
706713
for tx in txn.drain(..) {
707714
loss_detector.funding_txn.push(tx);

0 commit comments

Comments
 (0)