Skip to content

Commit

Permalink
Merge pull request lightningdevkit#3129 from optout21/splicing-msgs-u…
Browse files Browse the repository at this point in the history
…pdate

Update splice messages according to new spec draft
  • Loading branch information
jkczyz committed Jun 27, 2024
2 parents b3223ab + 43a6ee3 commit 3ccf064
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 93 deletions.
2 changes: 1 addition & 1 deletion fuzz/src/bin/gen_target.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ GEN_TEST msg_tx_abort msg_targets::

GEN_TEST msg_stfu msg_targets::

GEN_TEST msg_splice msg_targets::
GEN_TEST msg_splice_init msg_targets::
GEN_TEST msg_splice_ack msg_targets::
GEN_TEST msg_splice_locked msg_targets::
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ compile_error!("Fuzz targets need cfg=hashes_fuzz");
compile_error!("Fuzz targets need cfg=secp256k1_fuzz");

extern crate lightning_fuzz;
use lightning_fuzz::msg_targets::msg_splice::*;
use lightning_fuzz::msg_targets::msg_splice_init::*;

#[cfg(feature = "afl")]
#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
fuzz!(|data| {
msg_splice_run(data.as_ptr(), data.len());
msg_splice_init_run(data.as_ptr(), data.len());
});
}

Expand All @@ -40,7 +40,7 @@ fn main() {
fn main() {
loop {
fuzz!(|data| {
msg_splice_run(data.as_ptr(), data.len());
msg_splice_init_run(data.as_ptr(), data.len());
});
}
}
Expand All @@ -49,7 +49,7 @@ fn main() {
#[macro_use] extern crate libfuzzer_sys;
#[cfg(feature = "libfuzzer_fuzz")]
fuzz_target!(|data: &[u8]| {
msg_splice_run(data.as_ptr(), data.len());
msg_splice_init_run(data.as_ptr(), data.len());
});

#[cfg(feature = "stdin_fuzz")]
Expand All @@ -58,7 +58,7 @@ fn main() {

let mut data = Vec::with_capacity(8192);
std::io::stdin().read_to_end(&mut data).unwrap();
msg_splice_run(data.as_ptr(), data.len());
msg_splice_init_run(data.as_ptr(), data.len());
}

#[test]
Expand All @@ -70,11 +70,11 @@ fn run_test_cases() {
use std::sync::{atomic, Arc};
{
let data: Vec<u8> = vec![0];
msg_splice_run(data.as_ptr(), data.len());
msg_splice_init_run(data.as_ptr(), data.len());
}
let mut threads = Vec::new();
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
if let Ok(tests) = fs::read_dir("test_cases/msg_splice") {
if let Ok(tests) = fs::read_dir("test_cases/msg_splice_init") {
for test in tests {
let mut data: Vec<u8> = Vec::new();
let path = test.unwrap().path();
Expand All @@ -89,7 +89,7 @@ fn run_test_cases() {

let panic_logger = string_logger.clone();
let res = if ::std::panic::catch_unwind(move || {
msg_splice_test(&data, panic_logger);
msg_splice_init_test(&data, panic_logger);
}).is_err() {
Some(string_logger.into_string())
} else { None };
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/msg_targets/gen_target.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ GEN_TEST lightning::ln::msgs::TxAbort test_msg_simple ""

GEN_TEST lightning::ln::msgs::Stfu test_msg_simple ""

GEN_TEST lightning::ln::msgs::Splice test_msg_simple ""
GEN_TEST lightning::ln::msgs::SpliceInit test_msg_simple ""
GEN_TEST lightning::ln::msgs::SpliceAck test_msg_simple ""
GEN_TEST lightning::ln::msgs::SpliceLocked test_msg_simple ""
2 changes: 1 addition & 1 deletion fuzz/src/msg_targets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ pub mod msg_tx_init_rbf;
pub mod msg_tx_ack_rbf;
pub mod msg_tx_abort;
pub mod msg_stfu;
pub mod msg_splice;
pub mod msg_splice_init;
pub mod msg_splice_ack;
pub mod msg_splice_locked;
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use crate::msg_targets::utils::VecWriter;
use crate::utils::test_logger;

#[inline]
pub fn msg_splice_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
test_msg_simple!(lightning::ln::msgs::Splice, data);
pub fn msg_splice_init_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
test_msg_simple!(lightning::ln::msgs::SpliceInit, data);
}

#[no_mangle]
pub extern "C" fn msg_splice_run(data: *const u8, datalen: usize) {
pub extern "C" fn msg_splice_init_run(data: *const u8, datalen: usize) {
let data = unsafe { std::slice::from_raw_parts(data, datalen) };
test_msg_simple!(lightning::ln::msgs::Splice, data);
test_msg_simple!(lightning::ln::msgs::SpliceInit, data);
}
2 changes: 1 addition & 1 deletion fuzz/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ void msg_tx_init_rbf_run(const unsigned char* data, size_t data_len);
void msg_tx_ack_rbf_run(const unsigned char* data, size_t data_len);
void msg_tx_abort_run(const unsigned char* data, size_t data_len);
void msg_stfu_run(const unsigned char* data, size_t data_len);
void msg_splice_run(const unsigned char* data, size_t data_len);
void msg_splice_init_run(const unsigned char* data, size_t data_len);
void msg_splice_ack_run(const unsigned char* data, size_t data_len);
void msg_splice_locked_run(const unsigned char* data, size_t data_len);
2 changes: 1 addition & 1 deletion lightning-net-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ mod tests {
fn handle_accept_channel_v2(&self, _their_node_id: &PublicKey, _msg: &AcceptChannelV2) {}
fn handle_stfu(&self, _their_node_id: &PublicKey, _msg: &Stfu) {}
#[cfg(splicing)]
fn handle_splice(&self, _their_node_id: &PublicKey, _msg: &Splice) {}
fn handle_splice_init(&self, _their_node_id: &PublicKey, _msg: &SpliceInit) {}
#[cfg(splicing)]
fn handle_splice_ack(&self, _their_node_id: &PublicKey, _msg: &SpliceAck) {}
#[cfg(splicing)]
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2059,12 +2059,12 @@ pub enum MessageSendEvent {
/// The message which should be sent.
msg: msgs::Stfu,
},
/// Used to indicate that a splice message should be sent to the peer with the given node id.
SendSplice {
/// Used to indicate that a splice_init message should be sent to the peer with the given node id.
SendSpliceInit {
/// The node_id of the node which should receive this message
node_id: PublicKey,
/// The message which should be sent.
msg: msgs::Splice,
msg: msgs::SpliceInit,
},
/// Used to indicate that a splice_ack message should be sent to the peer with the given node id.
SendSpliceAck {
Expand Down
1 change: 1 addition & 0 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7272,6 +7272,7 @@ impl<SP: Deref> Channel<SP> where
channel_id: self.context.channel_id,
signature,
htlc_signatures,
batch: None,
#[cfg(taproot)]
partial_signature_with_nonce: None,
}, (counterparty_commitment_txid, commitment_stats.htlcs_included)))
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9693,7 +9693,7 @@ where
}

#[cfg(splicing)]
fn handle_splice(&self, counterparty_node_id: &PublicKey, msg: &msgs::Splice) {
fn handle_splice_init(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceInit) {
let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
"Splicing not supported".to_owned(),
msg.channel_id.clone())), *counterparty_node_id);
Expand Down Expand Up @@ -9900,7 +9900,7 @@ where
// Quiescence
&events::MessageSendEvent::SendStfu { .. } => false,
// Splicing
&events::MessageSendEvent::SendSplice { .. } => false,
&events::MessageSendEvent::SendSpliceInit { .. } => false,
&events::MessageSendEvent::SendSpliceAck { .. } => false,
&events::MessageSendEvent::SendSpliceLocked { .. } => false,
// Interactive Transaction Construction
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ pub fn remove_first_msg_event_to_node(msg_node_id: &PublicKey, msg_events: &mut
MessageSendEvent::SendStfu { node_id, .. } => {
node_id == msg_node_id
},
MessageSendEvent::SendSplice { node_id, .. } => {
MessageSendEvent::SendSpliceInit { node_id, .. } => {
node_id == msg_node_id
},
MessageSendEvent::SendSpliceAck { node_id, .. } => {
Expand Down
2 changes: 2 additions & 0 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ fn test_update_fee_that_funder_cannot_afford() {
channel_id: chan.2,
signature: res.0,
htlc_signatures: res.1,
batch: None,
#[cfg(taproot)]
partial_signature_with_nonce: None,
};
Expand Down Expand Up @@ -1532,6 +1533,7 @@ fn test_fee_spike_violation_fails_htlc() {
channel_id: chan.2,
signature: res.0,
htlc_signatures: res.1,
batch: None,
#[cfg(taproot)]
partial_signature_with_nonce: None,
};
Expand Down
1 change: 1 addition & 0 deletions lightning/src/ln/interactivetxs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ impl InteractiveTxConstructor {
prevtx,
prevtx_out: input.previous_output.vout,
sequence: input.sequence.to_consensus_u32(),
shared_input_txid: None,
};
do_state_transition!(self, sent_tx_add_input, &msg)?;
Ok(InteractiveTxMessageSend::TxAddInput(msg))
Expand Down
Loading

0 comments on commit 3ccf064

Please sign in to comment.