Skip to content

Commit 3389d10

Browse files
fixup! smite-ir: implement RecvChannelReady operation
1 parent 858425e commit 3389d10

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

smite-ir/src/operation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ impl fmt::Display for Operation {
699699
Self::SendFundingCreated => write!(f, "SendFundingCreated"),
700700
Self::RecvAcceptChannel => write!(f, "RecvAcceptChannel"),
701701
Self::RecvFundingSigned => write!(f, "RecvFundingSigned"),
702-
Self::RecvChannelReady => write!(f, "RecvChannelReady"),
702+
Self::RecvChannelReady => write!(f, "RecvChannelReady()"),
703703
Self::BroadcastTransaction => write!(f, "BroadcastTransaction"),
704704
}
705705
}

smite-ir/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ fn display_build_and_recv_channel_ready_program() {
549549
format!("v3 = LoadShortChannelId({scid})"),
550550
"v4 = BuildChannelReady{include_alias=true}(v0, v2, v3)".into(),
551551
"SendMessage(v4)".into(),
552-
"RecvChannelReady".into(),
552+
"RecvChannelReady()".into(),
553553
];
554554
assert_eq!(lines.len(), expected.len(), "line count mismatch");
555555
for (i, (got, want)) in lines.iter().zip(expected.iter()).enumerate() {

smite-scenarios/src/executor.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ use smite_ir::operation::AcceptChannelField;
2121
use smite_ir::{Operation, Program, Variable};
2222
use 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.
2530
pub 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.
10541056
fn 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

Comments
 (0)