Skip to content
Open
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
2 changes: 2 additions & 0 deletions smite-scenarios/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,8 @@ fn recv_non_ping(conn: &mut impl Connection, timeout: Duration) -> Result<Messag
| Message::NodeAnnouncement(_)
| Message::ChannelUpdate(_)
| Message::AnnouncementSignatures(_)
| Message::QueryShortChannelIds(_)
| Message::ReplyShortChannelIdsEnd(_)
Comment thread
devvaansh marked this conversation as resolved.
| Message::GossipTimestampFilter(_) => {
log::debug!("skipping gossip message {msg}");
}
Expand Down
17 changes: 16 additions & 1 deletion smite-scenarios/src/executor/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use bitcoin::Amount;
use bitcoin::secp256k1::{Secp256k1, SecretKey};
use harness::*;
use programs::*;
use smite::bolt::{AcceptChannelTlvs, GossipTimestampFilter, Init, Ping};
use smite::bolt::{
AcceptChannelTlvs, GossipTimestampFilter, Init, Ping, QueryShortChannelIds,
QueryShortChannelIdsTlvs, ReplyShortChannelIdsEnd,
};
use smite_ir::Instruction;
use smite_ir::builder::ProgramBuilder;
use smite_ir::operation::ShutdownScriptVariant;
Expand Down Expand Up @@ -393,9 +396,21 @@ fn execute_recv_auto_pong() {
#[test]
fn execute_recv_skips_gossip() {
let gossip = GossipTimestampFilter::new([0u8; 32], 0, 86400);
let query = QueryShortChannelIds {
chain_hash: [0u8; 32],
// encoding type 0, then one 8-byte short_channel_id
encoded_short_ids: vec![0x00, 0x00, 0x08, 0x3b, 0x04, 0x00, 0x03, 0x4d, 0x00],
tlvs: QueryShortChannelIdsTlvs::default(),
};
let reply_end = ReplyShortChannelIdsEnd {
chain_hash: [0u8; 32],
full_information: 1,
};

let mut fx = Fixture::new()
.queue(&Message::GossipTimestampFilter(gossip))
.queue(&Message::QueryShortChannelIds(query))
.queue(&Message::ReplyShortChannelIdsEnd(reply_end))
.queue(&Message::AcceptChannel(sample_accept_channel()));
fx.run(&negotiate_channel_program(&announced_open_channel()));

Expand Down
72 changes: 72 additions & 0 deletions smite/src/bolt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ mod open_channel;
mod open_channel2;
mod ping;
mod pong;
mod query_short_channel_ids;
mod reply_short_channel_ids_end;
mod revoke_and_ack;
mod shutdown;
mod tlv;
Expand Down Expand Up @@ -63,6 +65,8 @@ pub use open_channel::{OpenChannel, OpenChannelTlvs};
pub use open_channel2::{OpenChannel2, OpenChannel2Tlvs};
pub use ping::Ping;
pub use pong::Pong;
pub use query_short_channel_ids::{QueryShortChannelIds, QueryShortChannelIdsTlvs};
pub use reply_short_channel_ids_end::ReplyShortChannelIdsEnd;
pub use revoke_and_ack::RevokeAndAck;
pub use shutdown::{Shutdown, is_acceptable_shutdown_script, is_standard_shutdown_script};
pub use tlv::{TlvRecord, TlvStream};
Expand Down Expand Up @@ -208,6 +212,10 @@ impl MessageType {
pub const CHANNEL_UPDATE: MessageType = MessageType(258);
/// `announcement_signatures` message (BOLT 7).
pub const ANNOUNCEMENT_SIGNATURES: MessageType = MessageType(259);
/// `query_short_channel_ids` message (BOLT 7).
pub const QUERY_SHORT_CHANNEL_IDS: MessageType = MessageType(261);
/// `reply_short_channel_ids_end` message (BOLT 7).
pub const REPLY_SHORT_CHANNEL_IDS_END: MessageType = MessageType(262);
/// Gossip timestamp filter message (BOLT 7).
pub const GOSSIP_TIMESTAMP_FILTER: MessageType = MessageType(265);

Expand Down Expand Up @@ -260,6 +268,8 @@ impl MessageType {
Self::NODE_ANNOUNCEMENT => "node_announcement",
Self::CHANNEL_UPDATE => "channel_update",
Self::ANNOUNCEMENT_SIGNATURES => "announcement_signatures",
Self::QUERY_SHORT_CHANNEL_IDS => "query_short_channel_ids",
Self::REPLY_SHORT_CHANNEL_IDS_END => "reply_short_channel_ids_end",
Self::GOSSIP_TIMESTAMP_FILTER => "gossip_timestamp_filter",
_ => "unknown",
}
Expand Down Expand Up @@ -340,6 +350,10 @@ pub enum Message {
ChannelUpdate(ChannelUpdate),
/// `announcement_signatures` message (type 259).
AnnouncementSignatures(AnnouncementSignatures),
/// `query_short_channel_ids` message (type 261).
QueryShortChannelIds(QueryShortChannelIds),
/// `reply_short_channel_ids_end` message (type 262).
ReplyShortChannelIdsEnd(ReplyShortChannelIdsEnd),
/// Gossip timestamp filter message (type 265).
GossipTimestampFilter(GossipTimestampFilter),
/// Unknown message type.
Expand Down Expand Up @@ -397,6 +411,8 @@ impl Message {
Self::NodeAnnouncement(_) => MessageType::NODE_ANNOUNCEMENT,
Self::ChannelUpdate(_) => MessageType::CHANNEL_UPDATE,
Self::AnnouncementSignatures(_) => MessageType::ANNOUNCEMENT_SIGNATURES,
Self::QueryShortChannelIds(_) => MessageType::QUERY_SHORT_CHANNEL_IDS,
Self::ReplyShortChannelIdsEnd(_) => MessageType::REPLY_SHORT_CHANNEL_IDS_END,
Self::GossipTimestampFilter(_) => MessageType::GOSSIP_TIMESTAMP_FILTER,
Self::Unknown { msg_type, .. } => *msg_type,
}
Expand Down Expand Up @@ -440,6 +456,8 @@ impl Message {
Self::NodeAnnouncement(m) => out.extend(m.encode()),
Self::ChannelUpdate(m) => out.extend(m.encode()),
Self::AnnouncementSignatures(m) => out.extend(m.encode()),
Self::QueryShortChannelIds(m) => out.extend(m.encode()),
Self::ReplyShortChannelIdsEnd(m) => out.extend(m.encode()),
Self::GossipTimestampFilter(m) => out.extend(m.encode()),
Self::Unknown { payload, .. } => out.extend(payload),
}
Expand Down Expand Up @@ -512,6 +530,12 @@ impl Message {
MessageType::ANNOUNCEMENT_SIGNATURES => Ok(Self::AnnouncementSignatures(
AnnouncementSignatures::decode(cursor)?,
)),
MessageType::QUERY_SHORT_CHANNEL_IDS => Ok(Self::QueryShortChannelIds(
QueryShortChannelIds::decode(cursor)?,
)),
MessageType::REPLY_SHORT_CHANNEL_IDS_END => Ok(Self::ReplyShortChannelIdsEnd(
ReplyShortChannelIdsEnd::decode(cursor)?,
)),
MessageType::GOSSIP_TIMESTAMP_FILTER => Ok(Self::GossipTimestampFilter(
GossipTimestampFilter::decode(cursor)?,
)),
Expand Down Expand Up @@ -592,6 +616,8 @@ impl_from_message! {
NodeAnnouncement => NODE_ANNOUNCEMENT,
ChannelUpdate => CHANNEL_UPDATE,
AnnouncementSignatures => ANNOUNCEMENT_SIGNATURES,
QueryShortChannelIds => QUERY_SHORT_CHANNEL_IDS,
ReplyShortChannelIdsEnd => REPLY_SHORT_CHANNEL_IDS_END,
GossipTimestampFilter => GOSSIP_TIMESTAMP_FILTER,
}

Expand Down Expand Up @@ -1261,6 +1287,39 @@ mod tests {
assert_eq!(decoded, Message::AnnouncementSignatures(ann_sigs));
}

/// Valid `QueryShortChannelIds` message for testing.
fn sample_query_short_channel_ids() -> QueryShortChannelIds {
let mut encoded_short_ids = vec![0x00];
encoded_short_ids.extend_from_slice(&[0x00, 0x08, 0x3b, 0x04, 0x00, 0x03, 0x4d, 0x00]);

QueryShortChannelIds {
chain_hash: [0xaa; 32],
encoded_short_ids,
tlvs: QueryShortChannelIdsTlvs {
query_flags: Some(vec![0x00, 0x1f]),
},
}
}

#[test]
fn message_query_short_channel_ids_roundtrip() {
let query = sample_query_short_channel_ids();
let encoded = Message::QueryShortChannelIds(query.clone()).encode();
let decoded = Message::decode(&encoded).unwrap();
assert_eq!(decoded, Message::QueryShortChannelIds(query));
}

#[test]
fn message_reply_short_channel_ids_end_roundtrip() {
let reply = ReplyShortChannelIdsEnd {
chain_hash: [0xaa; 32],
full_information: 0x01,
};
let encoded = Message::ReplyShortChannelIdsEnd(reply.clone()).encode();
let decoded = Message::decode(&encoded).unwrap();
assert_eq!(decoded, Message::ReplyShortChannelIdsEnd(reply));
}

#[test]
fn message_gossip_timestamp_filter_roundtrip() {
let chain_hash = [0x6f; 32];
Expand Down Expand Up @@ -1465,6 +1524,19 @@ mod tests {
"announcement_signatures",
MessageType::ANNOUNCEMENT_SIGNATURES,
),
(
Message::QueryShortChannelIds(sample_query_short_channel_ids()),
"query_short_channel_ids",
MessageType::QUERY_SHORT_CHANNEL_IDS,
),
(
Message::ReplyShortChannelIdsEnd(ReplyShortChannelIdsEnd {
chain_hash: [0xaa; 32],
full_information: 0x01,
}),
"reply_short_channel_ids_end",
MessageType::REPLY_SHORT_CHANNEL_IDS_END,
),
(
Message::GossipTimestampFilter(GossipTimestampFilter::no_gossip([0u8; 32])),
"gossip_timestamp_filter",
Expand Down
Loading
Loading