Skip to content

Commit 94bf848

Browse files
committed
wip acceptor contributes in tests
1 parent 2940545 commit 94bf848

File tree

2 files changed

+252
-66
lines changed

2 files changed

+252
-66
lines changed

lightning/src/ln/channel.rs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7092,6 +7092,18 @@ impl<SP: Deref> FundedChannel<SP> where
70927092
assert!(self.context.channel_state.is_monitor_update_in_progress());
70937093
self.context.channel_state.clear_monitor_update_in_progress();
70947094

7095+
// For channels established with V2 establishment we won't send a `tx_signatures` when we're in
7096+
// MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
7097+
// transaction and waits for us to do it).
7098+
let tx_signatures = self.context.monitor_pending_tx_signatures.take();
7099+
if tx_signatures.is_some() {
7100+
if self.context.channel_state.is_their_tx_signatures_sent() {
7101+
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
7102+
} else {
7103+
self.context.channel_state.set_our_tx_signatures_ready();
7104+
}
7105+
}
7106+
70957107
// If we're past (or at) the AwaitingChannelReady stage on an outbound (or V2-established) channel,
70967108
// try to (re-)broadcast the funding transaction as we may have declined to broadcast it when we
70977109
// first received the funding_signed.
@@ -7131,17 +7143,6 @@ impl<SP: Deref> FundedChannel<SP> where
71317143
mem::swap(&mut finalized_claimed_htlcs, &mut self.context.monitor_pending_finalized_fulfills);
71327144
let mut pending_update_adds = Vec::new();
71337145
mem::swap(&mut pending_update_adds, &mut self.context.monitor_pending_update_adds);
7134-
// For channels established with V2 establishment we won't send a `tx_signatures` when we're in
7135-
// MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
7136-
// transaction and waits for us to do it).
7137-
let tx_signatures = self.context.monitor_pending_tx_signatures.take();
7138-
if tx_signatures.is_some() {
7139-
if self.context.channel_state.is_their_tx_signatures_sent() {
7140-
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
7141-
} else {
7142-
self.context.channel_state.set_our_tx_signatures_ready();
7143-
}
7144-
}
71457146

71467147
if self.context.channel_state.is_peer_disconnected() {
71477148
self.context.monitor_pending_revoke_and_ack = false;
@@ -8386,7 +8387,7 @@ impl<SP: Deref> FundedChannel<SP> where
83868387
/// advanced state.
83878388
pub fn is_awaiting_initial_mon_persist(&self) -> bool {
83888389
if !self.is_awaiting_monitor_update() { return false; }
8389-
if matches!(
8390+
if self.context.channel_state.is_interactive_signing() || matches!(
83908391
self.context.channel_state, ChannelState::AwaitingChannelReady(flags)
83918392
if flags.clone().clear(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY | FundedStateFlags::PEER_DISCONNECTED | FundedStateFlags::MONITOR_UPDATE_IN_PROGRESS | AwaitingChannelReadyFlags::WAITING_FOR_BATCH).is_empty()
83928393
) {
@@ -10668,6 +10669,31 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1066810669
our_funding_inputs: our_funding_inputs.clone(),
1066910670
};
1067010671

10672+
// Optionally add change output
10673+
let change_script = signer_provider.get_destination_script(context.channel_keys_id)
10674+
.map_err(|_| ChannelError::close("Error getting change destination script".to_string()))?;
10675+
let change_value_opt = calculate_change_output_value(
10676+
funding.is_outbound(), dual_funding_context.our_funding_satoshis,
10677+
&our_funding_inputs, &vec![],
10678+
dual_funding_context.funding_feerate_sat_per_1000_weight,
10679+
change_script.minimal_non_dust().to_sat(),
10680+
).map_err(|_| ChannelError::close("Error calculating change output value".to_string()))?;
10681+
let mut our_funding_outputs = vec![];
10682+
if let Some(change_value) = change_value_opt {
10683+
let mut change_output = TxOut {
10684+
value: Amount::from_sat(change_value),
10685+
script_pubkey: change_script,
10686+
};
10687+
let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
10688+
let change_output_fee = fee_for_weight(dual_funding_context.funding_feerate_sat_per_1000_weight, change_output_weight);
10689+
let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
10690+
// Check dust limit again
10691+
if change_value_decreased_with_fee > context.holder_dust_limit_satoshis {
10692+
change_output.value = Amount::from_sat(change_value_decreased_with_fee);
10693+
our_funding_outputs.push(OutputOwned::Single(change_output));
10694+
}
10695+
}
10696+
1067110697
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
1067210698
InteractiveTxConstructorArgs {
1067310699
entropy_source,
@@ -10678,7 +10704,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1067810704
funding_tx_locktime: dual_funding_context.funding_tx_locktime,
1067910705
is_initiator: false,
1068010706
inputs_to_contribute: our_funding_inputs,
10681-
outputs_to_contribute: Vec::new(),
10707+
outputs_to_contribute: our_funding_outputs,
1068210708
expected_remote_shared_funding_output: Some((funding.get_funding_redeemscript().to_p2wsh(), funding.get_value_satoshis())),
1068310709
}
1068410710
).map_err(|_| ChannelError::Close((

0 commit comments

Comments
 (0)