Skip to content

Commit 66e6ee5

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 88c291a commit 66e6ee5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fuzz/src/full_stack.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use std::cell::RefCell;
7171
use std::convert::TryInto;
7272
use std::cmp;
7373
use std::sync::{Arc, Mutex};
74-
use std::sync::atomic::{AtomicU64,AtomicUsize,Ordering};
74+
use std::sync::atomic::{AtomicU64,AtomicUsize,AtomicBool,Ordering};
7575
use bech32::u5;
7676

7777
#[inline]
@@ -98,6 +98,7 @@ pub fn slice_to_be24(v: &[u8]) -> u32 {
9898
struct InputData {
9999
data: Vec<u8>,
100100
read_pos: AtomicUsize,
101+
halt_fee_est_reads: AtomicBool,
101102
}
102103
impl InputData {
103104
fn get_slice(&self, len: usize) -> Option<&[u8]> {
@@ -124,6 +125,9 @@ struct FuzzEstimator {
124125
}
125126
impl FeeEstimator for FuzzEstimator {
126127
fn get_est_sat_per_1000_weight(&self, _: ConfirmationTarget) -> u32 {
128+
if self.input.halt_fee_est_reads.load(Ordering::Acquire) {
129+
return 253;
130+
}
127131
//TODO: We should actually be testing at least much more than 64k...
128132
match self.input.get_slice(2) {
129133
Some(slice) => cmp::max(slice_to_be16(slice) as u32, 253),
@@ -446,6 +450,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
446450
let input = Arc::new(InputData {
447451
data: data.to_vec(),
448452
read_pos: AtomicUsize::new(0),
453+
halt_fee_est_reads: AtomicBool::new(false),
449454
});
450455
let fee_est = Arc::new(FuzzEstimator {
451456
input: input.clone(),
@@ -703,10 +708,12 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
703708
11 => {
704709
let mut txn = broadcast.txn_broadcasted.lock().unwrap().split_off(0);
705710
if !txn.is_empty() {
711+
input.halt_fee_est_reads.store(true, Ordering::Release);
706712
loss_detector.connect_block(&txn[..]);
707713
for _ in 2..100 {
708714
loss_detector.connect_block(&[]);
709715
}
716+
input.halt_fee_est_reads.store(false, Ordering::Release);
710717
}
711718
for tx in txn.drain(..) {
712719
loss_detector.funding_txn.push(tx);

0 commit comments

Comments
 (0)