Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions smite-ir/src/mutators/operation_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ fn mutate_operation(op: &mut Operation, rng: &mut impl Rng) -> bool {
| Operation::SendOpenChannel
| Operation::SendFundingCreated
| Operation::RecvAcceptChannel
| Operation::RecvFundingSigned
| Operation::BroadcastTransaction => {
unreachable!("is_param_mutable returned true for {op:?}")
}
Expand Down
17 changes: 13 additions & 4 deletions smite-ir/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ pub enum Operation {
/// Receive and parse an `accept_channel` response.
/// Produces an `AcceptChannel` compound variable.
RecvAcceptChannel,
/// Receive and parse a `funding_signed` response.
/// Produces the `ChannelId` carried in the message.
/// TODO: Add `ExtractFundingSigned` when implementing force-close scenarios.
RecvFundingSigned,
/// Mines the given number of blocks on the Bitcoin network.
MineBlocks(u8),
/// Sign wallet inputs of the transaction and broadcast it via `bitcoin-cli`.
Expand Down Expand Up @@ -606,7 +610,7 @@ fn format_hex(bytes: &[u8]) -> String {
}

/// Print an Operation. Operations that take no variable inputs include parens
/// (e.g., `LoadAmount(100000)`, `RecvAcceptChannel()`). Operations that do take
/// (e.g., `LoadAmount(100000)`, `LoadChainHashFromContext()`). Operations that do take
/// inputs omit parens so `Program::Display` can append them `(v0, v1, ...)`.
impl fmt::Display for Operation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand All @@ -629,9 +633,7 @@ impl fmt::Display for Operation {
Self::LoadChannelType(v) => write!(f, "LoadChannelType({v})"),
Self::LoadTargetPubkeyFromContext => write!(f, "LoadTargetPubkeyFromContext()"),
Self::LoadChainHashFromContext => write!(f, "LoadChainHashFromContext()"),
Self::RecvAcceptChannel => write!(f, "RecvAcceptChannel()"),
Self::MineBlocks(v) => write!(f, "MineBlocks({v})"),
Self::BroadcastTransaction => write!(f, "BroadcastTransaction"),
// Operations with inputs: parens added by Program::Display.
Self::DerivePoint => write!(f, "DerivePoint"),
Self::ExtractAcceptChannel(field) => write!(f, "Extract{field}"),
Expand All @@ -649,6 +651,9 @@ impl fmt::Display for Operation {
Self::SendMessage => write!(f, "SendMessage"),
Self::SendOpenChannel => write!(f, "SendOpenChannel"),
Self::SendFundingCreated => write!(f, "SendFundingCreated"),
Self::RecvAcceptChannel => write!(f, "RecvAcceptChannel"),
Self::RecvFundingSigned => write!(f, "RecvFundingSigned"),
Self::BroadcastTransaction => write!(f, "BroadcastTransaction"),
}
}
}
Expand All @@ -670,7 +675,7 @@ impl Operation {
Self::LoadBytes(_) | Self::LoadShutdownScript(_) => Some(VariableType::Bytes),
Self::LoadFeatures(_) | Self::LoadChannelType(_) => Some(VariableType::Features),
Self::LoadPrivateKey(_) => Some(VariableType::PrivateKey),
Self::LoadChannelId(_) => Some(VariableType::ChannelId),
Self::LoadChannelId(_) | Self::RecvFundingSigned => Some(VariableType::ChannelId),
Self::LoadTargetPubkeyFromContext | Self::DerivePoint => Some(VariableType::Point),
Self::LoadChainHashFromContext => Some(VariableType::ChainHash),
Self::ExtractAcceptChannel(field) => Some(field.output_type()),
Expand Down Expand Up @@ -722,6 +727,7 @@ impl Operation {
Self::SendOpenChannel => vec![VariableType::OpenChannelMessage],
Self::SendFundingCreated => vec![VariableType::FundingCreatedMessage],
Self::RecvAcceptChannel => vec![VariableType::SentOpenChannel],
Self::RecvFundingSigned => vec![VariableType::SentFundingCreated],
Self::BroadcastTransaction => vec![VariableType::FundingTransaction],

Self::BuildOpenChannel => vec![
Expand Down Expand Up @@ -838,6 +844,7 @@ impl Operation {
| Self::SendMessage
| Self::SendOpenChannel
| Self::SendFundingCreated
| Self::RecvFundingSigned
| Self::MineBlocks(_)
| Self::BroadcastTransaction => vec![],

Expand All @@ -857,6 +864,7 @@ impl Operation {
| Self::SendOpenChannel
| Self::SendFundingCreated
| Self::RecvAcceptChannel
| Self::RecvFundingSigned
| Self::MineBlocks(_)
| Self::CreateFundingTransaction
| Self::BroadcastTransaction => true,
Expand Down Expand Up @@ -921,6 +929,7 @@ impl Operation {
| Self::SendOpenChannel
| Self::SendFundingCreated
| Self::RecvAcceptChannel
| Self::RecvFundingSigned
| Self::BroadcastTransaction => false,
}
}
Expand Down
17 changes: 12 additions & 5 deletions smite-ir/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ fn display_open_channel_program() {
],
},
Instruction {
operation: Operation::SendMessage,
operation: Operation::SendOpenChannel,
inputs: vec![26],
},
// Receive accept_channel and extract fields.
Instruction {
operation: Operation::RecvAcceptChannel,
inputs: vec![],
inputs: vec![27],
},
Instruction {
operation: Operation::ExtractAcceptChannel(AcceptChannelField::FundingPubkey),
Expand Down Expand Up @@ -203,8 +203,8 @@ fn display_open_channel_program() {
"v24 = LoadShutdownScript(Empty)".into(),
"v25 = LoadFeatures()".into(),
"v26 = BuildOpenChannel(v13, v12, v14, v15, v16, v17, v18, v19, v20, v21, v22, v1, v3, v5, v7, v9, v11, v23, v24, v25)".into(),
"SendMessage(v26)".into(),
"v28 = RecvAcceptChannel()".into(),
"v27 = SendOpenChannel(v26)".into(),
"v28 = RecvAcceptChannel(v27)".into(),
"v29 = ExtractFundingPubkey(v28)".into(),
"v30 = ExtractFirstPerCommitmentPoint(v28)".into(),
];
Expand Down Expand Up @@ -597,7 +597,8 @@ fn displays_create_and_broadcast_tx_program() {
}

#[test]
fn displays_build_and_send_funding_created_program() {
#[allow(clippy::too_many_lines)]
fn displays_send_funding_created_recv_funding_signed_program() {
let instructions = vec![
// Funding transaction.
Instruction {
Expand Down Expand Up @@ -673,6 +674,11 @@ fn displays_build_and_send_funding_created_program() {
operation: Operation::SendFundingCreated,
inputs: vec![15],
},
// receive funding_signed.
Instruction {
operation: Operation::RecvFundingSigned,
inputs: vec![16],
},
];

let program = Program { instructions };
Expand Down Expand Up @@ -700,6 +706,7 @@ fn displays_build_and_send_funding_created_program() {
"v14 = LoadFeeratePerKw(253)".into(),
"v15 = BuildFundingCreated(v4, v2, v5, v0, v7, v7, v7, v8, v9, v11, v11, v11, v11, v8, v9, v12, v13, v14, v7, v11)".into(),
"v16 = SendFundingCreated(v15)".into(),
"v17 = RecvFundingSigned(v16)".into(),
];

assert_eq!(lines.len(), expected.len(), "line count mismatch");
Expand Down
Loading