Skip to content

Commit e17eedb

Browse files
committed
wip acceptor contributes in tests
1 parent 6f28378 commit e17eedb

File tree

2 files changed

+253
-55
lines changed

2 files changed

+253
-55
lines changed

lightning/src/ln/channel.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8254,6 +8254,20 @@ where
82548254
self.context.channel_state.clear_monitor_update_in_progress();
82558255
assert_eq!(self.blocked_monitor_updates_pending(), 0);
82568256

8257+
// For channels established with V2 establishment we won't send a `tx_signatures` when we're in
8258+
// MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
8259+
// transaction and waits for us to do it).
8260+
let tx_signatures_ready = self.context.monitor_pending_tx_signatures;
8261+
self.context.monitor_pending_tx_signatures = false;
8262+
let tx_signatures = if tx_signatures_ready {
8263+
if self.context.channel_state.is_their_tx_signatures_sent() {
8264+
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8265+
} else {
8266+
self.context.channel_state.set_our_tx_signatures_ready();
8267+
}
8268+
self.interactive_tx_signing_session.as_ref().and_then(|session| session.holder_tx_signatures().clone())
8269+
} else { None };
8270+
82578271
// If we're past (or at) the AwaitingChannelReady stage on an outbound (or V2-established) channel,
82588272
// try to (re-)broadcast the funding transaction as we may have declined to broadcast it when we
82598273
// first received the funding_signed.
@@ -9714,7 +9728,7 @@ where
97149728
#[rustfmt::skip]
97159729
pub fn is_awaiting_initial_mon_persist(&self) -> bool {
97169730
if !self.is_awaiting_monitor_update() { return false; }
9717-
if matches!(
9731+
if self.context.channel_state.is_interactive_signing() || matches!(
97189732
self.context.channel_state, ChannelState::AwaitingChannelReady(flags)
97199733
if flags.clone().clear(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY | FundedStateFlags::PEER_DISCONNECTED | FundedStateFlags::MONITOR_UPDATE_IN_PROGRESS | AwaitingChannelReadyFlags::WAITING_FOR_BATCH).is_empty()
97209734
) {
@@ -12615,6 +12629,31 @@ where
1261512629
script_pubkey: funding.get_funding_redeemscript().to_p2wsh(),
1261612630
};
1261712631

12632+
// Optionally add change output
12633+
let change_script = signer_provider.get_destination_script(context.channel_keys_id)
12634+
.map_err(|_| ChannelError::close("Error getting change destination script".to_string()))?;
12635+
let change_value_opt = calculate_change_output_value(
12636+
funding.is_outbound(), dual_funding_context.our_funding_satoshis,
12637+
&our_funding_inputs, None, &shared_funding_output.script_pubkey, &vec![],
12638+
dual_funding_context.funding_feerate_sat_per_1000_weight,
12639+
change_script.minimal_non_dust().to_sat(),
12640+
).map_err(|_| ChannelError::close("Error calculating change output value".to_string()))?;
12641+
let mut our_funding_outputs = vec![];
12642+
if let Some(change_value) = change_value_opt {
12643+
let mut change_output = TxOut {
12644+
value: Amount::from_sat(change_value),
12645+
script_pubkey: change_script,
12646+
};
12647+
let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
12648+
let change_output_fee = fee_for_weight(dual_funding_context.funding_feerate_sat_per_1000_weight, change_output_weight);
12649+
let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
12650+
// Check dust limit again
12651+
if change_value_decreased_with_fee > context.holder_dust_limit_satoshis {
12652+
change_output.value = Amount::from_sat(change_value_decreased_with_fee);
12653+
our_funding_outputs.push(change_output);
12654+
}
12655+
}
12656+
1261812657
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
1261912658
InteractiveTxConstructorArgs {
1262012659
entropy_source,
@@ -12627,7 +12666,7 @@ where
1262712666
inputs_to_contribute: our_funding_inputs,
1262812667
shared_funding_input: None,
1262912668
shared_funding_output: SharedOwnedOutput::new(shared_funding_output, our_funding_satoshis),
12630-
outputs_to_contribute: Vec::new(),
12669+
outputs_to_contribute: our_funding_outputs,
1263112670
}
1263212671
).map_err(|err| {
1263312672
let reason = ClosureReason::ProcessingError { err: err.to_string() };

0 commit comments

Comments
 (0)