@@ -21,6 +21,11 @@ use smite_ir::operation::AcceptChannelField;
2121use smite_ir:: { Operation , Program , Variable } ;
2222use std:: collections:: HashMap ;
2323
24+ /// Default maximum `minimum_depth` that Lightning implementations advertise in
25+ /// `accept_channel`. Once the funding transaction reaches this many
26+ /// confirmations the target is guaranteed to have sent its `channel_ready`.
27+ const MAX_MINIMUM_DEPTH : u32 = 8 ;
28+
2429/// Abstraction over bitcoin-cli operations, allowing mock implementations in tests.
2530pub trait BitcoinRpc {
2631 /// Mines the given number of blocks.
@@ -372,7 +377,7 @@ impl<C: Connection, B: BitcoinRpc> Executor<C, B> {
372377 }
373378
374379 Operation :: RecvChannelReady => {
375- if is_channel_ready_expected ( & mut self . channel_states , & mut self . bitcoin_cli ) {
380+ if is_channel_ready_expected ( & self . channel_states , & mut self . bitcoin_cli ) {
376381 log:: debug!( "[{:?}] RecvChannelReady: waiting" , start. elapsed( ) ) ;
377382 recv_channel_ready ( & mut self . conn , & mut self . channel_states ) ?;
378383 log:: debug!( "[{:?}] RecvChannelReady: received" , start. elapsed( ) ) ;
@@ -1038,7 +1043,7 @@ fn recv_channel_ready(
10381043 let state = channel_states
10391044 . get_mut ( & cr. channel_id )
10401045 . ok_or ( ExecuteError :: UnknownChannel ( cr. channel_id ) ) ?;
1041- * state. next_per_commitment_point_mut ( false ) = Some ( cr. second_per_commitment_point ) ;
1046+ * state. next_counterparty_per_commitment_point_mut ( ) = Some ( cr. second_per_commitment_point ) ;
10421047
10431048 Ok ( ( ) )
10441049}
@@ -1047,18 +1052,16 @@ fn recv_channel_ready(
10471052///
10481053/// A `channel_ready` is expected when a tracked channel is still at commitment
10491054/// number 0, the counterparty's next per-commitment point is unknown, and the
1050- /// funding transaction has at least 8 confirmations. Since Lightning
1051- /// implementations typically use a default maximum `minimum_depth` of 8 in
1052- /// `accept_channel`, reaching 8 confirmations guarantees the target has sent
1053- /// its `channel_ready`.
1055+ /// funding transaction has at least [`MAX_MINIMUM_DEPTH`] confirmations.
10541056fn is_channel_ready_expected (
1055- channel_states : & mut HashMap < ChannelId , ChannelState > ,
1057+ channel_states : & HashMap < ChannelId , ChannelState > ,
10561058 bitcoin_cli : & mut impl BitcoinRpc ,
10571059) -> bool {
1058- channel_states. values_mut ( ) . any ( |state| {
1060+ channel_states. values ( ) . any ( |state| {
10591061 state. commitment . commitment_number == 0
1060- && state. next_per_commitment_point_mut ( false ) . is_none ( )
1061- && bitcoin_cli. get_transaction_confirmations ( state. config . funding_outpoint . txid ) >= 8
1062+ && state. next_counterparty_per_commitment_point ( ) . is_none ( )
1063+ && bitcoin_cli. get_transaction_confirmations ( state. config . funding_outpoint . txid )
1064+ >= MAX_MINIMUM_DEPTH
10621065 } )
10631066}
10641067
@@ -2841,7 +2844,7 @@ mod tests {
28412844 // The target's next per-commitment point is still unknown and the queued
28422845 // `channel_ready` remains untouched.
28432846 let state = executor. channel_states . get_mut ( & channel_id) . unwrap ( ) ;
2844- assert ! ( state. next_per_commitment_point_mut ( false ) . is_none( ) ) ;
2847+ assert ! ( state. next_counterparty_per_commitment_point ( ) . is_none( ) ) ;
28452848 assert_eq ! ( executor. conn. recv_queue. len( ) , 1 ) ;
28462849 }
28472850
@@ -2876,7 +2879,7 @@ mod tests {
28762879 // point is now recorded.
28772880 let state = executor. channel_states . get_mut ( & channel_id) . unwrap ( ) ;
28782881 assert_eq ! (
2879- * state. next_per_commitment_point_mut ( false ) ,
2882+ * state. next_counterparty_per_commitment_point ( ) ,
28802883 Some ( target_pcp)
28812884 ) ;
28822885 assert ! ( executor. conn. recv_queue. is_empty( ) ) ;
0 commit comments