Skip to content

Commit f7e2f0c

Browse files
committed
Move channel_ready check after processing transactions
In preparation for checking for confirmed splice funding transactions, move the channel_ready check to after processing all newly confirmed transactions. This will allow differentiating between the initial funding transaction from a splice funding transaction. The former results in channel_ready while the latter results in a splice_locked. Note that doing this outside the processing loop is necessary because check_get_channel_ready and get_announcement_sigs take &mut self, which isn't possible when iterating over all funding scopes. Moving the checks after processing means any mutations occurring in those methods will not happen if an Err is returned in the processing loop. This should be fine since it would result in a channel closure.
1 parent 7b45811 commit f7e2f0c

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

lightning/src/ln/channel.rs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8161,7 +8161,11 @@ impl<SP: Deref> FundedChannel<SP> where
81618161
NS::Target: NodeSigner,
81628162
L::Target: Logger
81638163
{
8164-
let mut msgs = (None, None);
8164+
struct ConfirmedFunding<'a> {
8165+
funding_tx: &'a Transaction,
8166+
}
8167+
8168+
let mut confirmed_funding = None;
81658169
if let Some(funding_txo) = self.funding.get_funding_txo() {
81668170
for &(index_in_block, tx) in txdata.iter() {
81678171
// Check if the transaction is the expected funding transaction, and if it is,
@@ -8196,28 +8200,16 @@ impl<SP: Deref> FundedChannel<SP> where
81968200
}
81978201
}
81988202
}
8203+
81998204
self.context.funding_tx_confirmation_height = height;
82008205
self.context.funding_tx_confirmed_in = Some(*block_hash);
82018206
self.context.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
82028207
Ok(scid) => Some(scid),
82038208
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
8204-
}
8209+
};
82058210
}
8206-
// If this is a coinbase transaction and not a 0-conf channel
8207-
// we should update our min_depth to 100 to handle coinbase maturity
8208-
if tx.is_coinbase() &&
8209-
self.context.minimum_depth.unwrap_or(0) > 0 &&
8210-
self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
8211-
self.context.minimum_depth = Some(COINBASE_MATURITY);
8212-
}
8213-
}
8214-
// If we allow 1-conf funding, we may need to check for channel_ready here and
8215-
// send it immediately instead of waiting for a best_block_updated call (which
8216-
// may have already happened for this block).
8217-
if let Some(channel_ready) = self.check_get_channel_ready(height, logger) {
8218-
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
8219-
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
8220-
msgs = (Some(channel_ready), announcement_sigs);
8211+
8212+
confirmed_funding = Some(ConfirmedFunding { funding_tx: &tx });
82218213
}
82228214
}
82238215
for inp in tx.input.iter() {
@@ -8228,7 +8220,27 @@ impl<SP: Deref> FundedChannel<SP> where
82288220
}
82298221
}
82308222
}
8231-
Ok(msgs)
8223+
8224+
if let Some(ConfirmedFunding { funding_tx }) = confirmed_funding {
8225+
// If this is a coinbase transaction and not a 0-conf channel
8226+
// we should update our min_depth to 100 to handle coinbase maturity
8227+
if funding_tx.is_coinbase() &&
8228+
self.context.minimum_depth.unwrap_or(0) > 0 &&
8229+
self.context.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
8230+
self.context.minimum_depth = Some(COINBASE_MATURITY);
8231+
}
8232+
8233+
// If we allow 1-conf funding, we may need to check for channel_ready here and
8234+
// send it immediately instead of waiting for a best_block_updated call (which
8235+
// may have already happened for this block).
8236+
if let Some(channel_ready) = self.check_get_channel_ready(height, logger) {
8237+
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
8238+
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
8239+
return Ok((Some(channel_ready), announcement_sigs));
8240+
}
8241+
}
8242+
8243+
Ok((None, None))
82328244
}
82338245

82348246
/// When a new block is connected, we check the height of the block against outbound holding

0 commit comments

Comments
 (0)