Skip to content

Commit 9431535

Browse files
committed
[fuzz] Reduce overuse of macros/Arcs in chanmon_consistency
In previous versions of related commits, the macros in chanmon_consistency ended up blowing up rustc a bit resulting in 20+GB memory usage and long compile times. Shorter function bodies by avoiding macros where possible fix this.
1 parent 71d22f7 commit 9431535

File tree

1 file changed

+113
-111
lines changed

1 file changed

+113
-111
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 113 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,52 @@ fn check_payment_err(send_err: PaymentSendFailure) {
227227
}
228228
}
229229

230+
type ChanMan = ChannelManager<EnforcingChannelKeys, Arc<TestChainMonitor>, Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>, Arc<dyn Logger>>;
231+
232+
#[inline]
233+
fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, payment_id: &mut u8) -> bool {
234+
let payment_hash = Sha256::hash(&[*payment_id; 1]);
235+
*payment_id = payment_id.wrapping_add(1);
236+
if let Err(err) = source.send_payment(&Route {
237+
paths: vec![vec![RouteHop {
238+
pubkey: dest.get_our_node_id(),
239+
node_features: NodeFeatures::empty(),
240+
short_channel_id: dest_chan_id,
241+
channel_features: ChannelFeatures::empty(),
242+
fee_msat: amt,
243+
cltv_expiry_delta: 200,
244+
}]],
245+
}, PaymentHash(payment_hash.into_inner()), &None) {
246+
check_payment_err(err);
247+
false
248+
} else { true }
249+
}
250+
#[inline]
251+
fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, dest: &ChanMan, dest_chan_id: u64, amt: u64, payment_id: &mut u8) -> bool {
252+
let payment_hash = Sha256::hash(&[*payment_id; 1]);
253+
*payment_id = payment_id.wrapping_add(1);
254+
if let Err(err) = source.send_payment(&Route {
255+
paths: vec![vec![RouteHop {
256+
pubkey: middle.get_our_node_id(),
257+
node_features: NodeFeatures::empty(),
258+
short_channel_id: middle_chan_id,
259+
channel_features: ChannelFeatures::empty(),
260+
fee_msat: 50000,
261+
cltv_expiry_delta: 100,
262+
},RouteHop {
263+
pubkey: dest.get_our_node_id(),
264+
node_features: NodeFeatures::empty(),
265+
short_channel_id: dest_chan_id,
266+
channel_features: ChannelFeatures::empty(),
267+
fee_msat: amt,
268+
cltv_expiry_delta: 200,
269+
}]],
270+
}, PaymentHash(payment_hash.into_inner()), &None) {
271+
check_payment_err(err);
272+
false
273+
} else { true }
274+
}
275+
230276
#[inline]
231277
pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
232278
let fee_est = Arc::new(FuzzEstimator{});
@@ -242,7 +288,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
242288
config.channel_options.fee_proportional_millionths = 0;
243289
config.channel_options.announced_channel = true;
244290
config.peer_channel_config_limits.min_dust_limit_satoshis = 0;
245-
(Arc::new(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, 0)),
291+
(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, 0),
246292
monitor)
247293
} }
248294
}
@@ -279,7 +325,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
279325
channel_monitors: monitor_refs,
280326
};
281327

282-
(<(BlockHash, ChannelManager<EnforcingChannelKeys, Arc<TestChainMonitor>, Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>, Arc<dyn Logger>>)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, chain_monitor)
328+
(<(BlockHash, ChanMan)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, chain_monitor)
283329
} }
284330
}
285331

@@ -389,9 +435,9 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
389435

390436
// 3 nodes is enough to hit all the possible cases, notably unknown-source-unknown-dest
391437
// forwarding.
392-
let (mut node_a, mut monitor_a) = make_node!(0);
393-
let (mut node_b, mut monitor_b) = make_node!(1);
394-
let (mut node_c, mut monitor_c) = make_node!(2);
438+
let (node_a, mut monitor_a) = make_node!(0);
439+
let (node_b, mut monitor_b) = make_node!(1);
440+
let (node_c, mut monitor_c) = make_node!(2);
395441

396442
let mut nodes = [node_a, node_b, node_c];
397443

@@ -407,7 +453,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
407453
let chan_a = nodes[0].list_usable_channels()[0].short_channel_id.unwrap();
408454
let chan_b = nodes[2].list_usable_channels()[0].short_channel_id.unwrap();
409455

410-
let mut payment_id = 0;
456+
let mut payment_id: u8 = 0;
411457

412458
let mut chan_a_disconnected = false;
413459
let mut chan_b_disconnected = false;
@@ -445,47 +491,6 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
445491
}
446492

447493
loop {
448-
macro_rules! send_payment {
449-
($source: expr, $dest: expr, $amt: expr) => { {
450-
let payment_hash = Sha256::hash(&[payment_id; 1]);
451-
payment_id = payment_id.wrapping_add(1);
452-
if let Err(err) = $source.send_payment(&Route {
453-
paths: vec![vec![RouteHop {
454-
pubkey: $dest.0.get_our_node_id(),
455-
node_features: NodeFeatures::empty(),
456-
short_channel_id: $dest.1,
457-
channel_features: ChannelFeatures::empty(),
458-
fee_msat: $amt,
459-
cltv_expiry_delta: 200,
460-
}]],
461-
}, PaymentHash(payment_hash.into_inner()), &None) {
462-
check_payment_err(err);
463-
}
464-
} };
465-
($source: expr, $middle: expr, $dest: expr, $amt: expr) => { {
466-
let payment_hash = Sha256::hash(&[payment_id; 1]);
467-
payment_id = payment_id.wrapping_add(1);
468-
if let Err(err) = $source.send_payment(&Route {
469-
paths: vec![vec![RouteHop {
470-
pubkey: $middle.0.get_our_node_id(),
471-
node_features: NodeFeatures::empty(),
472-
short_channel_id: $middle.1,
473-
channel_features: ChannelFeatures::empty(),
474-
fee_msat: 50000,
475-
cltv_expiry_delta: 100,
476-
},RouteHop {
477-
pubkey: $dest.0.get_our_node_id(),
478-
node_features: NodeFeatures::empty(),
479-
short_channel_id: $dest.1,
480-
channel_features: ChannelFeatures::empty(),
481-
fee_msat: $amt,
482-
cltv_expiry_delta: 200,
483-
}]],
484-
}, PaymentHash(payment_hash.into_inner()), &None) {
485-
check_payment_err(err);
486-
}
487-
} }
488-
}
489494
macro_rules! send_payment_with_secret {
490495
($source: expr, $middle: expr, $dest: expr) => { {
491496
let payment_hash = Sha256::hash(&[payment_id; 1]);
@@ -783,8 +788,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
783788
drain_msg_events_on_disconnect!(0);
784789
}
785790
let (new_node_a, new_monitor_a) = reload_node!(node_a_ser, 0, monitor_a);
786-
node_a = Arc::new(new_node_a);
787-
nodes[0] = node_a.clone();
791+
nodes[0] = new_node_a;
788792
monitor_a = new_monitor_a;
789793
},
790794
0x1d => {
@@ -801,8 +805,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
801805
bc_events.clear();
802806
}
803807
let (new_node_b, new_monitor_b) = reload_node!(node_b_ser, 1, monitor_b);
804-
node_b = Arc::new(new_node_b);
805-
nodes[1] = node_b.clone();
808+
nodes[1] = new_node_b;
806809
monitor_b = new_monitor_b;
807810
},
808811
0x1e => {
@@ -812,70 +815,69 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
812815
drain_msg_events_on_disconnect!(2);
813816
}
814817
let (new_node_c, new_monitor_c) = reload_node!(node_c_ser, 2, monitor_c);
815-
node_c = Arc::new(new_node_c);
816-
nodes[2] = node_c.clone();
818+
nodes[2] = new_node_c;
817819
monitor_c = new_monitor_c;
818820
},
819821

820822
// 1/10th the channel size:
821-
0x20 => send_payment!(nodes[0], (&nodes[1], chan_a), 10_000_000),
822-
0x21 => send_payment!(nodes[1], (&nodes[0], chan_a), 10_000_000),
823-
0x22 => send_payment!(nodes[1], (&nodes[2], chan_b), 10_000_000),
824-
0x23 => send_payment!(nodes[2], (&nodes[1], chan_b), 10_000_000),
825-
0x24 => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 10_000_000),
826-
0x25 => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 10_000_000),
827-
828-
0x26 => send_payment_with_secret!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b)),
829-
0x27 => send_payment_with_secret!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a)),
830-
831-
0x28 => send_payment!(nodes[0], (&nodes[1], chan_a), 1_000_000),
832-
0x29 => send_payment!(nodes[1], (&nodes[0], chan_a), 1_000_000),
833-
0x2a => send_payment!(nodes[1], (&nodes[2], chan_b), 1_000_000),
834-
0x2b => send_payment!(nodes[2], (&nodes[1], chan_b), 1_000_000),
835-
0x2c => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 1_000_000),
836-
0x2d => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 1_000_000),
837-
838-
0x30 => send_payment!(nodes[0], (&nodes[1], chan_a), 100_000),
839-
0x31 => send_payment!(nodes[1], (&nodes[0], chan_a), 100_000),
840-
0x32 => send_payment!(nodes[1], (&nodes[2], chan_b), 100_000),
841-
0x33 => send_payment!(nodes[2], (&nodes[1], chan_b), 100_000),
842-
0x34 => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 100_000),
843-
0x35 => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 100_000),
844-
845-
0x38 => send_payment!(nodes[0], (&nodes[1], chan_a), 10_000),
846-
0x39 => send_payment!(nodes[1], (&nodes[0], chan_a), 10_000),
847-
0x3a => send_payment!(nodes[1], (&nodes[2], chan_b), 10_000),
848-
0x3b => send_payment!(nodes[2], (&nodes[1], chan_b), 10_000),
849-
0x3c => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 10_000),
850-
0x3d => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 10_000),
851-
852-
0x40 => send_payment!(nodes[0], (&nodes[1], chan_a), 1_000),
853-
0x41 => send_payment!(nodes[1], (&nodes[0], chan_a), 1_000),
854-
0x42 => send_payment!(nodes[1], (&nodes[2], chan_b), 1_000),
855-
0x43 => send_payment!(nodes[2], (&nodes[1], chan_b), 1_000),
856-
0x44 => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 1_000),
857-
0x45 => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 1_000),
858-
859-
0x48 => send_payment!(nodes[0], (&nodes[1], chan_a), 100),
860-
0x49 => send_payment!(nodes[1], (&nodes[0], chan_a), 100),
861-
0x4a => send_payment!(nodes[1], (&nodes[2], chan_b), 100),
862-
0x4b => send_payment!(nodes[2], (&nodes[1], chan_b), 100),
863-
0x4c => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 100),
864-
0x4d => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 100),
865-
866-
0x50 => send_payment!(nodes[0], (&nodes[1], chan_a), 10),
867-
0x51 => send_payment!(nodes[1], (&nodes[0], chan_a), 10),
868-
0x52 => send_payment!(nodes[1], (&nodes[2], chan_b), 10),
869-
0x53 => send_payment!(nodes[2], (&nodes[1], chan_b), 10),
870-
0x54 => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 10),
871-
0x55 => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 10),
872-
873-
0x58 => send_payment!(nodes[0], (&nodes[1], chan_a), 1),
874-
0x59 => send_payment!(nodes[1], (&nodes[0], chan_a), 1),
875-
0x5a => send_payment!(nodes[1], (&nodes[2], chan_b), 1),
876-
0x5b => send_payment!(nodes[2], (&nodes[1], chan_b), 1),
877-
0x5c => send_payment!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b), 1),
878-
0x5d => send_payment!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a), 1),
823+
0x20 => { send_payment(&nodes[0], &nodes[1], chan_a, 10_000_000, &mut payment_id); },
824+
0x21 => { send_payment(&nodes[1], &nodes[0], chan_a, 10_000_000, &mut payment_id); },
825+
0x22 => { send_payment(&nodes[1], &nodes[2], chan_b, 10_000_000, &mut payment_id); },
826+
0x23 => { send_payment(&nodes[2], &nodes[1], chan_b, 10_000_000, &mut payment_id); },
827+
0x24 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10_000_000, &mut payment_id); },
828+
0x25 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10_000_000, &mut payment_id); },
829+
830+
0x26 => { send_payment_with_secret!(nodes[0], (&nodes[1], chan_a), (&nodes[2], chan_b)); },
831+
0x27 => { send_payment_with_secret!(nodes[2], (&nodes[1], chan_b), (&nodes[0], chan_a)); },
832+
833+
0x28 => { send_payment(&nodes[0], &nodes[1], chan_a, 1_000_000, &mut payment_id); },
834+
0x29 => { send_payment(&nodes[1], &nodes[0], chan_a, 1_000_000, &mut payment_id); },
835+
0x2a => { send_payment(&nodes[1], &nodes[2], chan_b, 1_000_000, &mut payment_id); },
836+
0x2b => { send_payment(&nodes[2], &nodes[1], chan_b, 1_000_000, &mut payment_id); },
837+
0x2c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1_000_000, &mut payment_id); },
838+
0x2d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1_000_000, &mut payment_id); },
839+
840+
0x30 => { send_payment(&nodes[0], &nodes[1], chan_a, 100_000, &mut payment_id); },
841+
0x31 => { send_payment(&nodes[1], &nodes[0], chan_a, 100_000, &mut payment_id); },
842+
0x32 => { send_payment(&nodes[1], &nodes[2], chan_b, 100_000, &mut payment_id); },
843+
0x33 => { send_payment(&nodes[2], &nodes[1], chan_b, 100_000, &mut payment_id); },
844+
0x34 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 100_000, &mut payment_id); },
845+
0x35 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 100_000, &mut payment_id); },
846+
847+
0x38 => { send_payment(&nodes[0], &nodes[1], chan_a, 10_000, &mut payment_id); },
848+
0x39 => { send_payment(&nodes[1], &nodes[0], chan_a, 10_000, &mut payment_id); },
849+
0x3a => { send_payment(&nodes[1], &nodes[2], chan_b, 10_000, &mut payment_id); },
850+
0x3b => { send_payment(&nodes[2], &nodes[1], chan_b, 10_000, &mut payment_id); },
851+
0x3c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10_000, &mut payment_id); },
852+
0x3d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10_000, &mut payment_id); },
853+
854+
0x40 => { send_payment(&nodes[0], &nodes[1], chan_a, 1_000, &mut payment_id); },
855+
0x41 => { send_payment(&nodes[1], &nodes[0], chan_a, 1_000, &mut payment_id); },
856+
0x42 => { send_payment(&nodes[1], &nodes[2], chan_b, 1_000, &mut payment_id); },
857+
0x43 => { send_payment(&nodes[2], &nodes[1], chan_b, 1_000, &mut payment_id); },
858+
0x44 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1_000, &mut payment_id); },
859+
0x45 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1_000, &mut payment_id); },
860+
861+
0x48 => { send_payment(&nodes[0], &nodes[1], chan_a, 100, &mut payment_id); },
862+
0x49 => { send_payment(&nodes[1], &nodes[0], chan_a, 100, &mut payment_id); },
863+
0x4a => { send_payment(&nodes[1], &nodes[2], chan_b, 100, &mut payment_id); },
864+
0x4b => { send_payment(&nodes[2], &nodes[1], chan_b, 100, &mut payment_id); },
865+
0x4c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 100, &mut payment_id); },
866+
0x4d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 100, &mut payment_id); },
867+
868+
0x50 => { send_payment(&nodes[0], &nodes[1], chan_a, 10, &mut payment_id); },
869+
0x51 => { send_payment(&nodes[1], &nodes[0], chan_a, 10, &mut payment_id); },
870+
0x52 => { send_payment(&nodes[1], &nodes[2], chan_b, 10, &mut payment_id); },
871+
0x53 => { send_payment(&nodes[2], &nodes[1], chan_b, 10, &mut payment_id); },
872+
0x54 => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 10, &mut payment_id); },
873+
0x55 => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 10, &mut payment_id); },
874+
875+
0x58 => { send_payment(&nodes[0], &nodes[1], chan_a, 1, &mut payment_id); },
876+
0x59 => { send_payment(&nodes[1], &nodes[0], chan_a, 1, &mut payment_id); },
877+
0x5a => { send_payment(&nodes[1], &nodes[2], chan_b, 1, &mut payment_id); },
878+
0x5b => { send_payment(&nodes[2], &nodes[1], chan_b, 1, &mut payment_id); },
879+
0x5c => { send_hop_payment(&nodes[0], &nodes[1], chan_a, &nodes[2], chan_b, 1, &mut payment_id); },
880+
0x5d => { send_hop_payment(&nodes[2], &nodes[1], chan_b, &nodes[0], chan_a, 1, &mut payment_id); },
879881

880882
_ => test_return!(),
881883
}

0 commit comments

Comments
 (0)