Skip to content

Commit 06226ef

Browse files
committed
f check scid
1 parent e21e90a commit 06226ef

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use ln::features::{InitFeatures, InvoiceFeatures};
2121
use ln::msgs;
2222
use ln::msgs::{ChannelMessageHandler,RoutingMessageHandler};
2323
use util::enforcing_trait_impls::EnforcingSigner;
24+
use util::scid_utils;
2425
use util::test_utils;
2526
use util::test_utils::{panicking, TestChainMonitor};
2627
use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose};
@@ -48,9 +49,13 @@ pub const CHAN_CONFIRM_DEPTH: u32 = 10;
4849

4950
/// Mine the given transaction in the next block and then mine CHAN_CONFIRM_DEPTH - 1 blocks on
5051
/// top, giving the given transaction CHAN_CONFIRM_DEPTH confirmations.
51-
pub fn confirm_transaction<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction) {
52-
confirm_transaction_at(node, tx, node.best_block_info().1 + 1);
52+
///
53+
/// Returns the SCID a channel confirmed in the given transaction will have, assuming the funding
54+
/// output is the 1st output in the transaction.
55+
pub fn confirm_transaction<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction) -> u64 {
56+
let scid = confirm_transaction_at(node, tx, node.best_block_info().1 + 1);
5357
connect_blocks(node, CHAN_CONFIRM_DEPTH - 1);
58+
scid
5459
}
5560
/// Mine a signle block containing the given transaction
5661
pub fn mine_transaction<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction) {
@@ -59,7 +64,10 @@ pub fn mine_transaction<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transac
5964
}
6065
/// Mine the given transaction at the given height, mining blocks as required to build to that
6166
/// height
62-
pub fn confirm_transaction_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction, conf_height: u32) {
67+
///
68+
/// Returns the SCID a channel confirmed in the given transaction will have, assuming the funding
69+
/// output is the 1st output in the transaction.
70+
pub fn confirm_transaction_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction, conf_height: u32) -> u64 {
6371
let first_connect_height = node.best_block_info().1 + 1;
6472
assert!(first_connect_height <= conf_height);
6573
if conf_height > first_connect_height {
@@ -74,6 +82,7 @@ pub fn confirm_transaction_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &T
7482
}
7583
block.txdata.push(tx.clone());
7684
connect_block(node, &block);
85+
scid_utils::scid_from_parts(conf_height as u64, block.txdata.len() as u64 - 1, 0).unwrap()
7786
}
7887

7988
/// The possible ways we may notify a ChannelManager of a new block

lightning/src/ln/priv_short_conf_tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,9 @@ fn test_public_0_conf_channel() {
808808
// We can use the channel immediately, but we can't announce it until we get 6+ confirmations
809809
send_payment(&nodes[0], &[&nodes[1]], 100_000);
810810

811-
confirm_transaction(&nodes[0], &tx);
811+
let scid = confirm_transaction(&nodes[0], &tx);
812812
let as_announcement_sigs = get_event_msg!(nodes[0], MessageSendEvent::SendAnnouncementSignatures, nodes[1].node.get_our_node_id());
813-
confirm_transaction(&nodes[1], &tx);
813+
assert_eq!(confirm_transaction(&nodes[1], &tx), scid);
814814
let bs_announcement_sigs = get_event_msg!(nodes[1], MessageSendEvent::SendAnnouncementSignatures, nodes[0].node.get_our_node_id());
815815

816816
nodes[1].node.handle_announcement_signatures(&nodes[0].node.get_our_node_id(), &as_announcement_sigs);
@@ -833,6 +833,7 @@ fn test_public_0_conf_channel() {
833833
match as_announcement[0] {
834834
MessageSendEvent::BroadcastChannelAnnouncement { ref msg, ref update_msg } => {
835835
assert!(announcement == *msg);
836+
assert_eq!(update_msg.contents.short_channel_id, scid);
836837
assert_eq!(update_msg.contents.short_channel_id, announcement.contents.short_channel_id);
837838
assert_eq!(update_msg.contents.short_channel_id, bs_update.contents.short_channel_id);
838839
},

0 commit comments

Comments
 (0)