Skip to content

Commit 510a398

Browse files
committed
f rustfmt dual_funding_tests.rs
1 parent ee95664 commit 510a398

File tree

1 file changed

+88
-37
lines changed

1 file changed

+88
-37
lines changed

lightning/src/ln/dual_funding_tests.rs

Lines changed: 88 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@
1111
1212
use crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
1313
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider};
14-
use crate::ln::types::ChannelId;
15-
use crate::ln::chan_utils::{make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters, CounterpartyChannelTransactionParameters};
14+
use crate::ln::chan_utils::{
15+
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters,
16+
CounterpartyChannelTransactionParameters,
17+
};
18+
use crate::ln::channel::{
19+
calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS,
20+
};
1621
use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint};
17-
use crate::ln::channel::{calculate_our_funding_satoshis, OutboundV2Channel, MIN_CHAN_DUST_LIMIT_SATOSHIS};
1822
use crate::ln::functional_test_utils::*;
19-
use crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete};
2023
use crate::ln::msgs::ChannelMessageHandler;
24+
use crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete};
25+
use crate::ln::types::ChannelId;
2126
use crate::prelude::*;
27+
use crate::sign::ChannelSigner as _;
2228
use crate::util::ser::TransactionU16LenLimited;
2329
use crate::util::test_utils;
24-
use crate::sign::ChannelSigner as _;
2530

2631
// Dual-funding: V2 Channel Establishment Tests
2732
struct V2ChannelEstablishmentTestSession {
@@ -39,24 +44,49 @@ fn do_test_v2_channel_establishment(session: V2ChannelEstablishmentTestSession)
3944

4045
// Create a funding input for the new channel along with its previous transaction.
4146
let initiator_funding_inputs: Vec<_> = create_dual_funding_utxos_with_prev_txs(
42-
&nodes[0], &[session.initiator_input_value_satoshis]
43-
).into_iter().map(|(txin, tx)| (txin, TransactionU16LenLimited::new(tx).unwrap())).collect();
47+
&nodes[0],
48+
&[session.initiator_input_value_satoshis],
49+
)
50+
.into_iter()
51+
.map(|(txin, tx)| (txin, TransactionU16LenLimited::new(tx).unwrap()))
52+
.collect();
4453

4554
// Alice creates a dual-funded channel as initiator.
46-
let funding_feerate = node_cfgs[0].fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee);
55+
let funding_feerate = node_cfgs[0]
56+
.fee_estimator
57+
.get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee);
4758
let funding_satoshis = calculate_our_funding_satoshis(
48-
true, &initiator_funding_inputs[..], funding_feerate, MIN_CHAN_DUST_LIMIT_SATOSHIS
49-
).unwrap();
50-
let mut channel = OutboundV2Channel::new(
51-
&LowerBoundedFeeEstimator(node_cfgs[0].fee_estimator), &nodes[0].node.entropy_source, &nodes[0].node.signer_provider,
52-
nodes[1].node.get_our_node_id(), &nodes[1].node.init_features(), funding_satoshis,
53-
initiator_funding_inputs.clone(), 42 /* user_channel_id */, &nodes[0].node.get_current_default_configuration(), nodes[0].best_block_info().1,
54-
nodes[0].node.create_and_insert_outbound_scid_alias_for_test(), ConfirmationTarget::NonAnchorChannelFee, &logger_a).unwrap();
59+
true,
60+
&initiator_funding_inputs[..],
61+
funding_feerate,
62+
MIN_CHAN_DUST_LIMIT_SATOSHIS,
63+
)
64+
.unwrap();
65+
let mut channel = OutboundV2Channel::new(
66+
&LowerBoundedFeeEstimator(node_cfgs[0].fee_estimator),
67+
&nodes[0].node.entropy_source,
68+
&nodes[0].node.signer_provider,
69+
nodes[1].node.get_our_node_id(),
70+
&nodes[1].node.init_features(),
71+
funding_satoshis,
72+
initiator_funding_inputs.clone(),
73+
42, /* user_channel_id */
74+
&nodes[0].node.get_current_default_configuration(),
75+
nodes[0].best_block_info().1,
76+
nodes[0].node.create_and_insert_outbound_scid_alias_for_test(),
77+
ConfirmationTarget::NonAnchorChannelFee,
78+
&logger_a,
79+
)
80+
.unwrap();
5581
let open_channel_v2_msg = channel.get_open_channel_v2(nodes[0].chain_source.chain_hash);
5682

5783
nodes[1].node.handle_open_channel_v2(nodes[0].node.get_our_node_id(), &open_channel_v2_msg);
5884

59-
let accept_channel_v2_msg = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannelV2, nodes[0].node.get_our_node_id());
85+
let accept_channel_v2_msg = get_event_msg!(
86+
nodes[1],
87+
MessageSendEvent::SendAcceptChannelV2,
88+
nodes[0].node.get_our_node_id()
89+
);
6090
let channel_id = ChannelId::v2_from_revocation_basepoints(
6191
&RevocationBasepoint::from(accept_channel_v2_msg.common_fields.revocation_basepoint),
6292
&RevocationBasepoint::from(open_channel_v2_msg.common_fields.revocation_basepoint),
@@ -70,12 +100,14 @@ fn do_test_v2_channel_establishment(session: V2ChannelEstablishmentTestSession)
70100
sequence: initiator_funding_inputs[0].0.sequence.0,
71101
shared_input_txid: None,
72102
};
73-
let input_value = tx_add_input_msg.prevtx.as_transaction().output[tx_add_input_msg.prevtx_out as usize].value;
103+
let input_value =
104+
tx_add_input_msg.prevtx.as_transaction().output[tx_add_input_msg.prevtx_out as usize].value;
74105
assert_eq!(input_value.to_sat(), session.initiator_input_value_satoshis);
75106

76107
nodes[1].node.handle_tx_add_input(nodes[0].node.get_our_node_id(), &tx_add_input_msg);
77108

78-
let _tx_complete_msg = get_event_msg!(nodes[1], MessageSendEvent::SendTxComplete, nodes[0].node.get_our_node_id());
109+
let _tx_complete_msg =
110+
get_event_msg!(nodes[1], MessageSendEvent::SendTxComplete, nodes[0].node.get_our_node_id());
79111

80112
let tx_add_output_msg = TxAddOutput {
81113
channel_id,
@@ -84,15 +116,15 @@ fn do_test_v2_channel_establishment(session: V2ChannelEstablishmentTestSession)
84116
script: make_funding_redeemscript(
85117
&open_channel_v2_msg.common_fields.funding_pubkey,
86118
&accept_channel_v2_msg.common_fields.funding_pubkey,
87-
).to_p2wsh(),
119+
)
120+
.to_p2wsh(),
88121
};
89122
nodes[1].node.handle_tx_add_output(nodes[0].node.get_our_node_id(), &tx_add_output_msg);
90123

91-
let _tx_complete_msg = get_event_msg!(nodes[1], MessageSendEvent::SendTxComplete, nodes[0].node.get_our_node_id());
124+
let _tx_complete_msg =
125+
get_event_msg!(nodes[1], MessageSendEvent::SendTxComplete, nodes[0].node.get_our_node_id());
92126

93-
let tx_complete_msg = TxComplete {
94-
channel_id,
95-
};
127+
let tx_complete_msg = TxComplete { channel_id };
96128

97129
nodes[1].node.handle_tx_complete(nodes[0].node.get_our_node_id(), &tx_complete_msg);
98130
let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
@@ -107,28 +139,37 @@ fn do_test_v2_channel_establishment(session: V2ChannelEstablishmentTestSession)
107139

108140
let (funding_outpoint, channel_type_features) = {
109141
let per_peer_state = nodes[1].node.per_peer_state.read().unwrap();
110-
let peer_state = per_peer_state.get(&nodes[0].node.get_our_node_id()).unwrap().lock().unwrap();
111-
let channel_context = peer_state
112-
.channel_by_id.get(&tx_complete_msg.channel_id).unwrap().context();
142+
let peer_state =
143+
per_peer_state.get(&nodes[0].node.get_our_node_id()).unwrap().lock().unwrap();
144+
let channel_context =
145+
peer_state.channel_by_id.get(&tx_complete_msg.channel_id).unwrap().context();
113146
(channel_context.get_funding_txo(), channel_context.get_channel_type().clone())
114147
};
115148

116149
let channel_transaction_parameters = ChannelTransactionParameters {
117150
counterparty_parameters: Some(CounterpartyChannelTransactionParameters {
118151
pubkeys: ChannelPublicKeys {
119152
funding_pubkey: accept_channel_v2_msg.common_fields.funding_pubkey,
120-
revocation_basepoint: RevocationBasepoint(accept_channel_v2_msg.common_fields.revocation_basepoint),
153+
revocation_basepoint: RevocationBasepoint(
154+
accept_channel_v2_msg.common_fields.revocation_basepoint,
155+
),
121156
payment_point: accept_channel_v2_msg.common_fields.payment_basepoint,
122-
delayed_payment_basepoint: DelayedPaymentBasepoint(accept_channel_v2_msg.common_fields.delayed_payment_basepoint),
157+
delayed_payment_basepoint: DelayedPaymentBasepoint(
158+
accept_channel_v2_msg.common_fields.delayed_payment_basepoint,
159+
),
123160
htlc_basepoint: HtlcBasepoint(accept_channel_v2_msg.common_fields.htlc_basepoint),
124161
},
125162
selected_contest_delay: accept_channel_v2_msg.common_fields.to_self_delay,
126163
}),
127164
holder_pubkeys: ChannelPublicKeys {
128165
funding_pubkey: open_channel_v2_msg.common_fields.funding_pubkey,
129-
revocation_basepoint: RevocationBasepoint(open_channel_v2_msg.common_fields.revocation_basepoint),
166+
revocation_basepoint: RevocationBasepoint(
167+
open_channel_v2_msg.common_fields.revocation_basepoint,
168+
),
130169
payment_point: open_channel_v2_msg.common_fields.payment_basepoint,
131-
delayed_payment_basepoint: DelayedPaymentBasepoint(open_channel_v2_msg.common_fields.delayed_payment_basepoint),
170+
delayed_payment_basepoint: DelayedPaymentBasepoint(
171+
open_channel_v2_msg.common_fields.delayed_payment_basepoint,
172+
),
132173
htlc_basepoint: HtlcBasepoint(open_channel_v2_msg.common_fields.htlc_basepoint),
133174
},
134175
holder_selected_contest_delay: open_channel_v2_msg.common_fields.to_self_delay,
@@ -137,23 +178,33 @@ fn do_test_v2_channel_establishment(session: V2ChannelEstablishmentTestSession)
137178
channel_type_features,
138179
};
139180

140-
channel.context.get_mut_signer().as_mut_ecdsa().unwrap().provide_channel_parameters(&channel_transaction_parameters);
181+
channel
182+
.context
183+
.get_mut_signer()
184+
.as_mut_ecdsa()
185+
.unwrap()
186+
.provide_channel_parameters(&channel_transaction_parameters);
141187

142188
let msg_commitment_signed_from_0 = CommitmentSigned {
143189
channel_id,
144-
signature: channel.context.get_initial_counterparty_commitment_signature_for_test(
145-
&&logger_a,
146-
channel_transaction_parameters,
147-
accept_channel_v2_msg.common_fields.first_per_commitment_point,
148-
).unwrap(),
190+
signature: channel
191+
.context
192+
.get_initial_counterparty_commitment_signature_for_test(
193+
&&logger_a,
194+
channel_transaction_parameters,
195+
accept_channel_v2_msg.common_fields.first_per_commitment_point,
196+
)
197+
.unwrap(),
149198
htlc_signatures: vec![],
150199
batch: None,
151200
#[cfg(taproot)]
152201
partial_signature_with_nonce: None,
153202
};
154203

155204
// Handle the initial commitment_signed exchange. Order is not important here.
156-
nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &msg_commitment_signed_from_0);
205+
nodes[1]
206+
.node
207+
.handle_commitment_signed(nodes[0].node.get_our_node_id(), &msg_commitment_signed_from_0);
157208
check_added_monitors(&nodes[1], 1);
158209

159210
let events = nodes[1].node.get_and_clear_pending_events();

0 commit comments

Comments
 (0)