Skip to content

Commit e50e94c

Browse files
committed
f thebluematt feedback
1 parent 64614b2 commit e50e94c

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

lightning/src/ln/channel.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,16 +1523,19 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
15231523
}
15241524

15251525
fn initial_commitment_signed<L: Deref>(
1526-
&mut self, channel_id: ChannelId, counterparty_signature: Signature, counterparty_txid: Txid,
1526+
&mut self, channel_id: ChannelId, counterparty_signature: Signature,
15271527
counterparty_commitment_number: u64, best_block: BestBlock, signer_provider: &SP, logger: &L,
1528-
) -> Result<ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>, ChannelError>
1528+
) -> Result<(ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>, CommitmentTransaction), ChannelError>
15291529
where
15301530
L::Target: Logger
15311531
{
15321532
let initial_commitment_tx = match self.check_counterparty_commitment_signature(&counterparty_signature, logger) {
15331533
Ok(res) => res,
15341534
Err(ChannelError::Close(e)) => {
1535-
self.context_mut().channel_transaction_parameters.funding_outpoint = None;
1535+
// TODO(dual_funding): Update for V2 established channels.
1536+
if !self.context().is_outbound() {
1537+
self.context_mut().channel_transaction_parameters.funding_outpoint = None;
1538+
}
15361539
return Err(ChannelError::Close(e));
15371540
},
15381541
Err(e) => {
@@ -1596,15 +1599,15 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
15961599
obscure_factor,
15971600
holder_commitment_tx, best_block, context.counterparty_node_id, context.channel_id());
15981601
channel_monitor.provide_initial_counterparty_commitment_tx(
1599-
counterparty_txid, Vec::new(),
1602+
counterparty_initial_bitcoin_tx.txid, Vec::new(),
16001603
counterparty_commitment_number,
16011604
context.counterparty_cur_commitment_point.unwrap(),
16021605
counterparty_initial_commitment_tx.feerate_per_kw(),
16031606
counterparty_initial_commitment_tx.to_broadcaster_value_sat(),
16041607
counterparty_initial_commitment_tx.to_countersignatory_value_sat(),
16051608
logger);
16061609

1607-
Ok(channel_monitor)
1610+
Ok((channel_monitor, counterparty_initial_commitment_tx))
16081611
}
16091612
}
16101613

@@ -7998,24 +8001,20 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
79988001
panic!("Should not have advanced channel commitment tx numbers prior to funding_created");
79998002
}
80008003

8001-
let counterparty_keys = self.context.build_remote_transaction_keys();
8002-
let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
8003-
let counterparty_trusted_tx = counterparty_initial_commitment_tx.trust();
8004-
let counterparty_initial_bitcoin_tx = counterparty_trusted_tx.built_transaction();
8005-
8006-
log_trace!(logger, "Initial counterparty tx for channel {} is: txid {} tx {}",
8007-
&self.context.channel_id(), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
8008-
8009-
let channel_monitor = match self.initial_commitment_signed(
8004+
let (channel_monitor, counterparty_initial_commitment_tx) = match self.initial_commitment_signed(
80108005
self.context.channel_id(),
8011-
msg.signature, counterparty_initial_bitcoin_tx.txid,
8012-
self.context.cur_counterparty_commitment_transaction_number,
8006+
msg.signature, self.context.cur_counterparty_commitment_transaction_number,
80138007
best_block, signer_provider, logger
80148008
) {
80158009
Ok(channel_monitor) => channel_monitor,
80168010
Err(err) => return Err((self, err)),
80178011
};
80188012

8013+
let counterparty_trusted_tx = counterparty_initial_commitment_tx.trust();
8014+
let counterparty_initial_bitcoin_tx = counterparty_trusted_tx.built_transaction();
8015+
log_trace!(logger, "Initial counterparty tx for channel {} is: txid {} tx {}",
8016+
&self.context.channel_id(), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
8017+
80198018
self.context.cur_counterparty_commitment_transaction_number -= 1;
80208019
log_info!(logger, "Received funding_signed from peer for channel {}", &self.context.channel_id());
80218020

@@ -8233,20 +8232,16 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
82338232
// check_funding_created_signature may fail.
82348233
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
82358234

8236-
self.context.cur_counterparty_commitment_transaction_number -= 1;
8237-
let counterparty_keys = self.context.build_remote_transaction_keys();
8238-
let counterparty_initial_commitment_tx = self.context.build_commitment_transaction(self.context.cur_counterparty_commitment_transaction_number + 1, &counterparty_keys, false, false, logger).tx;
8239-
8240-
let channel_monitor = match self.initial_commitment_signed(
8235+
let (channel_monitor, counterparty_initial_commitment_tx) = match self.initial_commitment_signed(
82418236
ChannelId::v1_from_funding_outpoint(funding_txo),
8242-
msg.signature, counterparty_initial_commitment_tx.trust().txid(),
8243-
self.context.cur_counterparty_commitment_transaction_number + 1,
8237+
msg.signature, self.context.cur_counterparty_commitment_transaction_number,
82448238
best_block, signer_provider, logger
82458239
) {
82468240
Ok(channel_monitor) => channel_monitor,
82478241
Err(err) => return Err((self, err)),
82488242
};
82498243

8244+
self.context.cur_counterparty_commitment_transaction_number -= 1;
82508245
let funding_signed = self.context.get_funding_signed_msg(logger, counterparty_initial_commitment_tx);
82518246

82528247
log_info!(logger, "{} funding_signed for peer for channel {}",

0 commit comments

Comments
 (0)