Skip to content

Commit

Permalink
Router fuzz: macroize first_hops construction
Browse files Browse the repository at this point in the history
For reuse in fuzzing blinded payment pathfinding.
  • Loading branch information
valentinewallace committed Jul 25, 2023
1 parent 685f266 commit d75ede5
Showing 1 changed file with 50 additions and 44 deletions.
94 changes: 50 additions & 44 deletions fuzz/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,55 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
let mut node_pks = HashSet::new();
let mut scid = 42;

macro_rules! first_hops {
($first_hops_vec: expr) => {
match get_slice!(1)[0] {
0 => None,
count => {
for _ in 0..count {
scid += 1;
let rnid = node_pks.iter().skip(u16::from_be_bytes(get_slice!(2).try_into().unwrap()) as usize % node_pks.len()).next().unwrap();
let capacity = u64::from_be_bytes(get_slice!(8).try_into().unwrap());
$first_hops_vec.push(ChannelDetails {
channel_id: [0; 32],
counterparty: ChannelCounterparty {
node_id: *rnid,
features: channelmanager::provided_init_features(&UserConfig::default()),
unspendable_punishment_reserve: 0,
forwarding_info: None,
outbound_htlc_minimum_msat: None,
outbound_htlc_maximum_msat: None,
},
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
channel_type: None,
short_channel_id: Some(scid),
inbound_scid_alias: None,
outbound_scid_alias: None,
channel_value_satoshis: capacity,
user_channel_id: 0, inbound_capacity_msat: 0,
unspendable_punishment_reserve: None,
confirmations_required: None,
confirmations: None,
force_close_spend_delay: None,
is_outbound: true, is_channel_ready: true,
is_usable: true, is_public: true,
balance_msat: 0,
outbound_capacity_msat: capacity.saturating_mul(1000),
next_outbound_htlc_limit_msat: capacity.saturating_mul(1000),
next_outbound_htlc_minimum_msat: 0,
inbound_htlc_minimum_msat: None,
inbound_htlc_maximum_msat: None,
config: None,
feerate_sat_per_1000_weight: None,
channel_shutdown_state: Some(channelmanager::ChannelShutdownState::NotShuttingDown),
});
}
Some(&$first_hops_vec[..])
},
}
}
}

loop {
match get_slice!(1)[0] {
0 => {
Expand Down Expand Up @@ -232,50 +281,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
_ if node_pks.is_empty() => {},
_ => {
let mut first_hops_vec = Vec::new();
let first_hops = match get_slice!(1)[0] {
0 => None,
count => {
for _ in 0..count {
scid += 1;
let rnid = node_pks.iter().skip(u16::from_be_bytes(get_slice!(2).try_into().unwrap()) as usize % node_pks.len()).next().unwrap();
let capacity = u64::from_be_bytes(get_slice!(8).try_into().unwrap());
first_hops_vec.push(ChannelDetails {
channel_id: [0; 32],
counterparty: ChannelCounterparty {
node_id: *rnid,
features: channelmanager::provided_init_features(&UserConfig::default()),
unspendable_punishment_reserve: 0,
forwarding_info: None,
outbound_htlc_minimum_msat: None,
outbound_htlc_maximum_msat: None,
},
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
channel_type: None,
short_channel_id: Some(scid),
inbound_scid_alias: None,
outbound_scid_alias: None,
channel_value_satoshis: capacity,
user_channel_id: 0, inbound_capacity_msat: 0,
unspendable_punishment_reserve: None,
confirmations_required: None,
confirmations: None,
force_close_spend_delay: None,
is_outbound: true, is_channel_ready: true,
is_usable: true, is_public: true,
balance_msat: 0,
outbound_capacity_msat: capacity.saturating_mul(1000),
next_outbound_htlc_limit_msat: capacity.saturating_mul(1000),
next_outbound_htlc_minimum_msat: 0,
inbound_htlc_minimum_msat: None,
inbound_htlc_maximum_msat: None,
config: None,
feerate_sat_per_1000_weight: None,
channel_shutdown_state: Some(channelmanager::ChannelShutdownState::NotShuttingDown),
});
}
Some(&first_hops_vec[..])
},
};
let first_hops = first_hops!(first_hops_vec);
let mut last_hops = Vec::new();
{
let count = get_slice!(1)[0];
Expand Down

0 comments on commit d75ede5

Please sign in to comment.