Skip to content

Commit 609330f

Browse files
committed
Run rustfmt on update_fee_tests
1 parent 73461d4 commit 609330f

File tree

1 file changed

+104
-56
lines changed

1 file changed

+104
-56
lines changed

lightning/src/ln/update_fee_tests.rs

Lines changed: 104 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use crate::ln::msgs::{
1616
};
1717
use crate::ln::outbound_payment::RecipientOnionFields;
1818
use crate::sign::ecdsa::EcdsaChannelSigner;
19+
use crate::types::features::ChannelTypeFeatures;
1920
use crate::util::config::UserConfig;
2021
use crate::util::errors::APIError;
21-
use crate::types::features::ChannelTypeFeatures;
2222

2323
use lightning_macros::xtest;
2424

@@ -66,17 +66,20 @@ pub fn test_async_inbound_update_fee() {
6666

6767
let events_0 = nodes[0].node.get_and_clear_pending_msg_events();
6868
assert_eq!(events_0.len(), 1);
69-
let (update_msg, commitment_signed) = match events_0[0] { // (1)
70-
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. }, .. } => {
71-
(update_fee.as_ref(), commitment_signed)
72-
},
69+
let (update_msg, commitment_signed) = match events_0[0] {
70+
// (1)
71+
MessageSendEvent::UpdateHTLCs {
72+
updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. },
73+
..
74+
} => (update_fee.as_ref(), commitment_signed),
7375
_ => panic!("Unexpected event"),
7476
};
7577

7678
nodes[1].node.handle_update_fee(node_a_id, update_msg.unwrap());
7779

7880
// ...but before it's delivered, nodes[1] starts to send a payment back to nodes[0]...
79-
let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 40000);
81+
let (route, our_payment_hash, _, our_payment_secret) =
82+
get_route_and_payment_hash!(nodes[1], nodes[0], 40000);
8083
let onion = RecipientOnionFields::secret_only(our_payment_secret);
8184
let id = PaymentId(our_payment_hash.0);
8285
nodes[1].node.send_payment_with_route(route, our_payment_hash, onion, id).unwrap();
@@ -136,7 +139,7 @@ pub fn test_async_inbound_update_fee() {
136139
let events_2 = nodes[0].node.get_and_clear_pending_events();
137140
assert_eq!(events_2.len(), 1);
138141
match events_2[0] {
139-
Event::PendingHTLCsForwardable {..} => {}, // If we actually processed we'd receive the payment
142+
Event::PendingHTLCsForwardable { .. } => {}, // If we actually processed we'd receive the payment
140143
_ => panic!("Unexpected event"),
141144
}
142145

@@ -171,17 +174,20 @@ pub fn test_update_fee_unordered_raa() {
171174

172175
let events_0 = nodes[0].node.get_and_clear_pending_msg_events();
173176
assert_eq!(events_0.len(), 1);
174-
let update_msg = match events_0[0] { // (1)
175-
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, .. }, .. } => {
176-
update_fee.as_ref()
177-
},
177+
let update_msg = match events_0[0] {
178+
// (1)
179+
MessageSendEvent::UpdateHTLCs {
180+
updates: msgs::CommitmentUpdate { ref update_fee, .. },
181+
..
182+
} => update_fee.as_ref(),
178183
_ => panic!("Unexpected event"),
179184
};
180185

181186
nodes[1].node.handle_update_fee(node_a_id, update_msg.unwrap());
182187

183188
// ...but before it's delivered, nodes[1] starts to send a payment back to nodes[0]...
184-
let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 40000);
189+
let (route, our_payment_hash, _, our_payment_secret) =
190+
get_route_and_payment_hash!(nodes[1], nodes[0], 40000);
185191
let onion = RecipientOnionFields::secret_only(our_payment_secret);
186192
let id = PaymentId(our_payment_hash.0);
187193
nodes[1].node.send_payment_with_route(route, our_payment_hash, onion, id).unwrap();
@@ -251,10 +257,12 @@ pub fn test_multi_flight_update_fee() {
251257

252258
let events_0 = nodes[0].node.get_and_clear_pending_msg_events();
253259
assert_eq!(events_0.len(), 1);
254-
let (update_msg_1, commitment_signed_1) = match events_0[0] { // (1)
255-
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. }, .. } => {
256-
(update_fee.as_ref().unwrap(), commitment_signed)
257-
},
260+
let (update_msg_1, commitment_signed_1) = match events_0[0] {
261+
// (1)
262+
MessageSendEvent::UpdateHTLCs {
263+
updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. },
264+
..
265+
} => (update_fee.as_ref().unwrap(), commitment_signed),
258266
_ => panic!("Unexpected event"),
259267
};
260268

@@ -296,7 +304,10 @@ pub fn test_multi_flight_update_fee() {
296304
assert!(as_second_update.update_fail_malformed_htlcs.is_empty());
297305
// Check that the update_fee newly generated matches what we delivered:
298306
assert_eq!(as_second_update.update_fee.as_ref().unwrap().channel_id, update_msg_2.channel_id);
299-
assert_eq!(as_second_update.update_fee.as_ref().unwrap().feerate_per_kw, update_msg_2.feerate_per_kw);
307+
assert_eq!(
308+
as_second_update.update_fee.as_ref().unwrap().feerate_per_kw,
309+
update_msg_2.feerate_per_kw
310+
);
300311

301312
// Deliver (2) commitment_signed
302313
nodes[0].node.handle_commitment_signed_batch_test(node_b_id, &bs_commitment_signed);
@@ -309,7 +320,9 @@ pub fn test_multi_flight_update_fee() {
309320
check_added_monitors(&nodes[1], 1);
310321

311322
// Delever (4)
312-
nodes[1].node.handle_commitment_signed_batch_test(node_a_id, &as_second_update.commitment_signed);
323+
nodes[1]
324+
.node
325+
.handle_commitment_signed_batch_test(node_a_id, &as_second_update.commitment_signed);
313326
let (bs_second_revoke, bs_second_commitment) = get_revoke_commit_msgs!(nodes[1], node_a_id);
314327
check_added_monitors(&nodes[1], 1);
315328

@@ -349,9 +362,10 @@ pub fn test_update_fee_vanilla() {
349362
let events_0 = nodes[0].node.get_and_clear_pending_msg_events();
350363
assert_eq!(events_0.len(), 1);
351364
let (update_msg, commitment_signed) = match events_0[0] {
352-
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. }, .. } => {
353-
(update_fee.as_ref(), commitment_signed)
354-
},
365+
MessageSendEvent::UpdateHTLCs {
366+
updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. },
367+
..
368+
} => (update_fee.as_ref(), commitment_signed),
355369
_ => panic!("Unexpected event"),
356370
};
357371
nodes[1].node.handle_update_fee(node_a_id, update_msg.unwrap());
@@ -386,7 +400,13 @@ pub fn test_update_fee_that_funder_cannot_afford() {
386400

387401
let channel_value = 5000;
388402
let push_sats = 700;
389-
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, channel_value, push_sats * 1000);
403+
let chan = create_announced_chan_between_nodes_with_value(
404+
&nodes,
405+
0,
406+
1,
407+
channel_value,
408+
push_sats * 1000,
409+
);
390410
let channel_id = chan.2;
391411
let secp_ctx = Secp256k1::new();
392412
let default_config = UserConfig::default();
@@ -399,8 +419,12 @@ pub fn test_update_fee_that_funder_cannot_afford() {
399419
// CONCURRENT_INBOUND_HTLC_FEE_BUFFER HTLCs before actually running out of local balance, so we
400420
// calculate two different feerates here - the expected local limit as well as the expected
401421
// remote limit.
402-
let feerate = ((channel_value - bs_channel_reserve_sats - push_sats) * 1000 / (commitment_tx_base_weight(&channel_type_features) + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC)) as u32;
403-
let non_buffer_feerate = ((channel_value - bs_channel_reserve_sats - push_sats) * 1000 / commitment_tx_base_weight(&channel_type_features)) as u32;
422+
let feerate = ((channel_value - bs_channel_reserve_sats - push_sats) * 1000
423+
/ (commitment_tx_base_weight(&channel_type_features)
424+
+ CONCURRENT_INBOUND_HTLC_FEE_BUFFER as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC))
425+
as u32;
426+
let non_buffer_feerate = ((channel_value - bs_channel_reserve_sats - push_sats) * 1000
427+
/ commitment_tx_base_weight(&channel_type_features)) as u32;
404428
{
405429
let mut feerate_lock = chanmon_cfgs[0].fee_estimator.sat_per_kw.lock().unwrap();
406430
*feerate_lock = feerate;
@@ -420,7 +444,8 @@ pub fn test_update_fee_that_funder_cannot_afford() {
420444
//We made sure neither party's funds are below the dust limit and there are no HTLCs here
421445
assert_eq!(commitment_tx.output.len(), 2);
422446
let total_fee: u64 = commit_tx_fee_msat(feerate, 0, &channel_type_features) / 1000;
423-
let mut actual_fee = commitment_tx.output.iter().fold(0, |acc, output| acc + output.value.to_sat());
447+
let mut actual_fee =
448+
commitment_tx.output.iter().fold(0, |acc, output| acc + output.value.to_sat());
424449
actual_fee = channel_value - actual_fee;
425450
assert_eq!(total_fee, actual_fee);
426451
}
@@ -451,15 +476,18 @@ pub fn test_update_fee_that_funder_cannot_afford() {
451476
let mut per_peer_lock;
452477
let mut peer_state_lock;
453478

454-
let local_chan = get_channel_ref!(nodes[0], nodes[1], per_peer_lock, peer_state_lock, chan.2);
479+
let local_chan =
480+
get_channel_ref!(nodes[0], nodes[1], per_peer_lock, peer_state_lock, chan.2);
455481
let local_chan_signer = local_chan.as_funded().unwrap().get_signer();
456482

457483
let nondust_htlcs: Vec<HTLCOutputInCommitment> = vec![];
458484
let commitment_tx = CommitmentTransaction::new(
459485
INITIAL_COMMITMENT_NUMBER - 1,
460486
&remote_point,
461487
push_sats,
462-
channel_value - push_sats - commit_tx_fee_msat(non_buffer_feerate + 4, 0, &channel_type_features) / 1000,
488+
channel_value
489+
- push_sats - commit_tx_fee_msat(non_buffer_feerate + 4, 0, &channel_type_features)
490+
/ 1000,
463491
non_buffer_feerate + 4,
464492
nondust_htlcs,
465493
&local_chan.funding().channel_transaction_parameters.as_counterparty_broadcastable(),
@@ -482,10 +510,7 @@ pub fn test_update_fee_that_funder_cannot_afford() {
482510
partial_signature_with_nonce: None,
483511
};
484512

485-
let update_fee = msgs::UpdateFee {
486-
channel_id: chan.2,
487-
feerate_per_kw: non_buffer_feerate + 4,
488-
};
513+
let update_fee = msgs::UpdateFee { channel_id: chan.2, feerate_per_kw: non_buffer_feerate + 4 };
489514

490515
nodes[1].node.handle_update_fee(node_a_id, &update_fee);
491516

@@ -512,7 +537,8 @@ pub fn test_update_fee_that_saturates_subs() {
512537

513538
let chanmon_cfgs = create_chanmon_cfgs(2);
514539
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
515-
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(default_config.clone()), Some(default_config)]);
540+
let node_chanmgrs =
541+
create_node_chanmgrs(2, &node_cfgs, &[Some(default_config.clone()), Some(default_config)]);
516542
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
517543

518544
let node_a_id = nodes[0].node.get_our_node_id();
@@ -544,7 +570,8 @@ pub fn test_update_fee_that_saturates_subs() {
544570
let mut per_peer_lock;
545571
let mut peer_state_lock;
546572

547-
let local_chan = get_channel_ref!(nodes[0], nodes[1], per_peer_lock, peer_state_lock, chan_id);
573+
let local_chan =
574+
get_channel_ref!(nodes[0], nodes[1], per_peer_lock, peer_state_lock, chan_id);
548575
let local_chan_signer = local_chan.as_funded().unwrap().get_signer();
549576
let nondust_htlcs: Vec<HTLCOutputInCommitment> = vec![];
550577
let commitment_tx = CommitmentTransaction::new(
@@ -576,10 +603,7 @@ pub fn test_update_fee_that_saturates_subs() {
576603
partial_signature_with_nonce: None,
577604
};
578605

579-
let update_fee = msgs::UpdateFee {
580-
channel_id: chan_id,
581-
feerate_per_kw: FEERATE,
582-
};
606+
let update_fee = msgs::UpdateFee { channel_id: chan_id, feerate_per_kw: FEERATE };
583607

584608
nodes[1].node.handle_update_fee(node_a_id, &update_fee);
585609

@@ -617,17 +641,19 @@ pub fn test_update_fee_with_fundee_update_add_htlc() {
617641
let events_0 = nodes[0].node.get_and_clear_pending_msg_events();
618642
assert_eq!(events_0.len(), 1);
619643
let (update_msg, commitment_signed) = match events_0[0] {
620-
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. }, .. } => {
621-
(update_fee.as_ref(), commitment_signed)
622-
},
644+
MessageSendEvent::UpdateHTLCs {
645+
updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. },
646+
..
647+
} => (update_fee.as_ref(), commitment_signed),
623648
_ => panic!("Unexpected event"),
624649
};
625650
nodes[1].node.handle_update_fee(node_a_id, update_msg.unwrap());
626651
nodes[1].node.handle_commitment_signed_batch_test(node_a_id, commitment_signed);
627652
let (revoke_msg, commitment_signed) = get_revoke_commit_msgs!(nodes[1], node_a_id);
628653
check_added_monitors(&nodes[1], 1);
629654

630-
let (route, our_payment_hash, our_payment_preimage, our_payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 800000);
655+
let (route, our_payment_hash, our_payment_preimage, our_payment_secret) =
656+
get_route_and_payment_hash!(nodes[1], nodes[0], 800000);
631657

632658
// nothing happens since node[1] is in AwaitingRemoteRevoke
633659
let onion = RecipientOnionFields::secret_only(our_payment_secret);
@@ -658,7 +684,9 @@ pub fn test_update_fee_with_fundee_update_add_htlc() {
658684
assert_eq!(commitment_update.update_fee.is_none(), true);
659685

660686
nodes[0].node.handle_update_add_htlc(node_b_id, &commitment_update.update_add_htlcs[0]);
661-
nodes[0].node.handle_commitment_signed_batch_test(node_b_id, &commitment_update.commitment_signed);
687+
nodes[0]
688+
.node
689+
.handle_commitment_signed_batch_test(node_b_id, &commitment_update.commitment_signed);
662690
check_added_monitors(&nodes[0], 1);
663691
let (revoke, commitment_signed) = get_revoke_commit_msgs!(nodes[0], node_b_id);
664692

@@ -680,7 +708,7 @@ pub fn test_update_fee_with_fundee_update_add_htlc() {
680708
let events = nodes[0].node.get_and_clear_pending_events();
681709
assert_eq!(events.len(), 1);
682710
match events[0] {
683-
Event::PaymentClaimable { .. } => { },
711+
Event::PaymentClaimable { .. } => {},
684712
_ => panic!("Unexpected event"),
685713
};
686714

@@ -735,9 +763,10 @@ pub fn test_update_fee() {
735763
let events_0 = nodes[0].node.get_and_clear_pending_msg_events();
736764
assert_eq!(events_0.len(), 1);
737765
let (update_msg, commitment_signed) = match events_0[0] {
738-
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. }, .. } => {
739-
(update_fee.as_ref(), commitment_signed)
740-
},
766+
MessageSendEvent::UpdateHTLCs {
767+
updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. },
768+
..
769+
} => (update_fee.as_ref(), commitment_signed),
741770
_ => panic!("Unexpected event"),
742771
};
743772
nodes[1].node.handle_update_fee(node_a_id, update_msg.unwrap());
@@ -762,9 +791,10 @@ pub fn test_update_fee() {
762791
let events_0 = nodes[0].node.get_and_clear_pending_msg_events();
763792
assert_eq!(events_0.len(), 1);
764793
let (update_msg, commitment_signed) = match events_0[0] {
765-
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. }, .. } => {
766-
(update_fee.as_ref(), commitment_signed)
767-
},
794+
MessageSendEvent::UpdateHTLCs {
795+
updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. },
796+
..
797+
} => (update_fee.as_ref(), commitment_signed),
768798
_ => panic!("Unexpected event"),
769799
};
770800

@@ -797,7 +827,9 @@ pub fn test_update_fee() {
797827
check_added_monitors(&nodes[1], 1);
798828

799829
// Deliver (7)
800-
nodes[0].node.handle_commitment_signed_batch_test(node_b_id, &commitment_update.commitment_signed);
830+
nodes[0]
831+
.node
832+
.handle_commitment_signed_batch_test(node_b_id, &commitment_update.commitment_signed);
801833
check_added_monitors(&nodes[0], 1);
802834
let revoke_msg = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, node_b_id);
803835
// No commitment_signed so get_event_msg's assert(len == 1) passes
@@ -834,22 +866,29 @@ pub fn test_chan_init_feerate_unaffordability() {
834866
// Set the push_msat amount such that nodes[0] will not be able to afford to add even a single
835867
// HTLC.
836868
let mut push_amt = 100_000_000;
837-
push_amt -= commit_tx_fee_msat(feerate_per_kw, MIN_AFFORDABLE_HTLC_COUNT as u64, &channel_type_features);
869+
push_amt -= commit_tx_fee_msat(
870+
feerate_per_kw,
871+
MIN_AFFORDABLE_HTLC_COUNT as u64,
872+
&channel_type_features,
873+
);
838874
assert_eq!(nodes[0].node.create_channel(node_b_id, 100_000, push_amt + 1, 42, None, None).unwrap_err(),
839875
APIError::APIMisuseError { err: "Funding amount (356) can't even pay fee for initial commitment transaction fee of 357.".to_string() });
840876

841877
// During open, we don't have a "counterparty channel reserve" to check against, so that
842878
// requirement only comes into play on the open_channel handling side.
843879
push_amt -= get_holder_selected_channel_reserve_satoshis(100_000, &default_config) * 1000;
844880
nodes[0].node.create_channel(node_b_id, 100_000, push_amt, 42, None, None).unwrap();
845-
let mut open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id);
881+
let mut open_channel_msg =
882+
get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id);
846883
open_channel_msg.push_msat += 1;
847884
nodes[1].node.handle_open_channel(node_a_id, &open_channel_msg);
848885

849886
let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
850887
assert_eq!(msg_events.len(), 1);
851888
match msg_events[0] {
852-
MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, .. } => {
889+
MessageSendEvent::HandleError {
890+
action: ErrorAction::SendErrorMessage { ref msg }, ..
891+
} => {
853892
assert_eq!(msg.data, "Insufficient funding amount for initial reserve");
854893
},
855894
_ => panic!("Unexpected event"),
@@ -887,7 +926,10 @@ pub fn accept_busted_but_better_fee() {
887926
let events = nodes[0].node.get_and_clear_pending_msg_events();
888927
assert_eq!(events.len(), 1);
889928
match events[0] {
890-
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. }, .. } => {
929+
MessageSendEvent::UpdateHTLCs {
930+
updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. },
931+
..
932+
} => {
891933
nodes[1].node.handle_update_fee(node_a_id, update_fee.as_ref().unwrap());
892934
commitment_signed_dance!(nodes[1], nodes[0], commitment_signed, false);
893935
},
@@ -906,7 +948,10 @@ pub fn accept_busted_but_better_fee() {
906948
let events = nodes[0].node.get_and_clear_pending_msg_events();
907949
assert_eq!(events.len(), 1);
908950
match events[0] {
909-
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. }, .. } => {
951+
MessageSendEvent::UpdateHTLCs {
952+
updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. },
953+
..
954+
} => {
910955
nodes[1].node.handle_update_fee(node_a_id, update_fee.as_ref().unwrap());
911956
commitment_signed_dance!(nodes[1], nodes[0], commitment_signed, false);
912957
},
@@ -925,7 +970,10 @@ pub fn accept_busted_but_better_fee() {
925970
let events = nodes[0].node.get_and_clear_pending_msg_events();
926971
assert_eq!(events.len(), 1);
927972
match events[0] {
928-
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, .. }, .. } => {
973+
MessageSendEvent::UpdateHTLCs {
974+
updates: msgs::CommitmentUpdate { ref update_fee, .. },
975+
..
976+
} => {
929977
nodes[1].node.handle_update_fee(node_a_id, update_fee.as_ref().unwrap());
930978
let reason = ClosureReason::PeerFeerateTooLow {
931979
peer_feerate_sat_per_kw: 1000,

0 commit comments

Comments
 (0)