Skip to content

Commit 55a74b5

Browse files
committed
Use non-funder's funding block wait instead of max with ours
This is both required by the protocol and also makes sense - if we're the funder we don't mind accepting payment on the channel after one confirmation because we assume we won't double-spend ourselves.
1 parent 4d964d4 commit 55a74b5

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/ln/channel.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ pub(super) struct Channel {
326326
//implied by BREAKDOWN_TIMEOUT: our_to_self_delay: u16,
327327
their_max_accepted_htlcs: u16,
328328
//implied by OUR_MAX_HTLCS: our_max_accepted_htlcs: u16,
329+
minimum_depth: u32,
329330

330331
their_funding_pubkey: Option<PublicKey>,
331332
their_revocation_basepoint: Option<PublicKey>,
@@ -413,11 +414,6 @@ impl Channel {
413414
CONF_TARGET
414415
}
415416

416-
fn derive_maximum_minimum_depth(_channel_value_satoshis_msat: u64, _value_to_self_msat: u64) -> u32 {
417-
const CONF_TARGET: u32 = 12; //TODO: Should be much higher
418-
CONF_TARGET * 2
419-
}
420-
421417
// Constructors:
422418
pub fn new_outbound(fee_estimator: &FeeEstimator, keys_provider: &Arc<KeysInterface>, their_node_id: PublicKey, channel_value_satoshis: u64, push_msat: u64, announce_publicly: bool, user_id: u64, logger: Arc<Logger>) -> Result<Channel, APIError> {
423419
let chan_keys = keys_provider.get_channel_keys(false);
@@ -498,6 +494,7 @@ impl Channel {
498494
our_htlc_minimum_msat: Channel::derive_our_htlc_minimum_msat(feerate),
499495
their_to_self_delay: 0,
500496
their_max_accepted_htlcs: 0,
497+
minimum_depth: 0, // Filled in in accept_channel
501498

502499
their_funding_pubkey: None,
503500
their_revocation_basepoint: None,
@@ -662,6 +659,7 @@ impl Channel {
662659
our_htlc_minimum_msat: Channel::derive_our_htlc_minimum_msat(msg.feerate_per_kw as u64),
663660
their_to_self_delay: msg.to_self_delay,
664661
their_max_accepted_htlcs: msg.max_accepted_htlcs,
662+
minimum_depth: Channel::derive_minimum_depth(msg.funding_satoshis*1000, msg.push_msat),
665663

666664
their_funding_pubkey: Some(msg.funding_pubkey),
667665
their_revocation_basepoint: Some(msg.revocation_basepoint),
@@ -1290,9 +1288,6 @@ impl Channel {
12901288
if msg.htlc_minimum_msat >= (self.channel_value_satoshis - msg.channel_reserve_satoshis) * 1000 {
12911289
return Err(ChannelError::Close("Minimum htlc value is full channel value"));
12921290
}
1293-
if msg.minimum_depth > Channel::derive_maximum_minimum_depth(self.channel_value_satoshis*1000, self.value_to_self_msat) {
1294-
return Err(ChannelError::Close("minimum_depth too large"));
1295-
}
12961291
if msg.to_self_delay > MAX_LOCAL_BREAKDOWN_TIMEOUT {
12971292
return Err(ChannelError::Close("They wanted our payments to be delayed by a needlessly long period"));
12981293
}
@@ -1320,6 +1315,7 @@ impl Channel {
13201315
self.their_htlc_minimum_msat = msg.htlc_minimum_msat;
13211316
self.their_to_self_delay = msg.to_self_delay;
13221317
self.their_max_accepted_htlcs = msg.max_accepted_htlcs;
1318+
self.minimum_depth = msg.minimum_depth;
13231319
self.their_funding_pubkey = Some(msg.funding_pubkey);
13241320
self.their_revocation_basepoint = Some(msg.revocation_basepoint);
13251321
self.their_payment_basepoint = Some(msg.payment_basepoint);
@@ -2708,7 +2704,7 @@ impl Channel {
27082704
self.channel_monitor.last_block_hash = self.last_block_connected;
27092705
if self.funding_tx_confirmations > 0 {
27102706
self.funding_tx_confirmations += 1;
2711-
if self.funding_tx_confirmations == Channel::derive_minimum_depth(self.channel_value_satoshis*1000, self.value_to_self_msat) as u64 {
2707+
if self.funding_tx_confirmations == self.minimum_depth as u64 {
27122708
let need_commitment_update = if non_shutdown_state == ChannelState::FundingSent as u32 {
27132709
self.channel_state |= ChannelState::OurFundingLocked as u32;
27142710
true
@@ -2785,7 +2781,7 @@ impl Channel {
27852781
}
27862782
}
27872783
if Some(header.bitcoin_hash()) == self.funding_tx_confirmed_in {
2788-
self.funding_tx_confirmations = Channel::derive_minimum_depth(self.channel_value_satoshis*1000, self.value_to_self_msat) as u64 - 1;
2784+
self.funding_tx_confirmations = self.minimum_depth as u64 - 1;
27892785
}
27902786
self.last_block_connected = header.bitcoin_hash();
27912787
self.channel_monitor.last_block_hash = self.last_block_connected;
@@ -2851,7 +2847,7 @@ impl Channel {
28512847
max_htlc_value_in_flight_msat: Channel::get_our_max_htlc_value_in_flight_msat(self.channel_value_satoshis),
28522848
channel_reserve_satoshis: Channel::get_our_channel_reserve_satoshis(self.channel_value_satoshis),
28532849
htlc_minimum_msat: self.our_htlc_minimum_msat,
2854-
minimum_depth: Channel::derive_minimum_depth(self.channel_value_satoshis*1000, self.value_to_self_msat),
2850+
minimum_depth: self.minimum_depth,
28552851
to_self_delay: BREAKDOWN_TIMEOUT,
28562852
max_accepted_htlcs: OUR_MAX_HTLCS,
28572853
funding_pubkey: PublicKey::from_secret_key(&self.secp_ctx, &self.local_keys.funding_key),
@@ -3482,6 +3478,7 @@ impl Writeable for Channel {
34823478
self.our_htlc_minimum_msat.write(writer)?;
34833479
self.their_to_self_delay.write(writer)?;
34843480
self.their_max_accepted_htlcs.write(writer)?;
3481+
self.minimum_depth.write(writer)?;
34853482

34863483
write_option!(self.their_funding_pubkey);
34873484
write_option!(self.their_revocation_basepoint);
@@ -3655,6 +3652,7 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
36553652
let our_htlc_minimum_msat = Readable::read(reader)?;
36563653
let their_to_self_delay = Readable::read(reader)?;
36573654
let their_max_accepted_htlcs = Readable::read(reader)?;
3655+
let minimum_depth = Readable::read(reader)?;
36583656

36593657
let their_funding_pubkey = read_option!();
36603658
let their_revocation_basepoint = read_option!();
@@ -3731,6 +3729,7 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
37313729
our_htlc_minimum_msat,
37323730
their_to_self_delay,
37333731
their_max_accepted_htlcs,
3732+
minimum_depth,
37343733

37353734
their_funding_pubkey,
37363735
their_revocation_basepoint,

0 commit comments

Comments
 (0)