Skip to content

Commit 9c82628

Browse files
committed
f use time, not heights, for expiry in tests, including changing blocks connected in tests to have incrementing time
1 parent ae8e569 commit 9c82628

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3706,10 +3706,6 @@ where
37063706
});
37073707
!htlcs.is_empty() // Only retain this entry if htlcs has at least one entry.
37083708
});
3709-
let mut payment_secrets = self.pending_inbound_payments.lock().unwrap();
3710-
payment_secrets.retain(|_, inbound_payment| {
3711-
inbound_payment.expiry_height > height
3712-
});
37133709
}
37143710
}
37153711

lightning/src/ln/functional_test_utils.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn confirm_transaction_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &T
6666
connect_blocks(node, conf_height - first_connect_height);
6767
}
6868
let mut block = Block {
69-
header: BlockHeader { version: 0x20000000, prev_blockhash: node.best_block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
69+
header: BlockHeader { version: 0x20000000, prev_blockhash: node.best_block_hash(), merkle_root: Default::default(), time: conf_height, bits: 42, nonce: 42 },
7070
txdata: Vec::new(),
7171
};
7272
for _ in 0..*node.network_chan_count.borrow() { // Make sure we don't end up with channels at the same short id by offsetting by chan_count
@@ -102,15 +102,16 @@ pub fn connect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, depth: u32) ->
102102
_ => false,
103103
};
104104

105+
let height = node.best_block_info().1 + 1;
105106
let mut block = Block {
106-
header: BlockHeader { version: 0x2000000, prev_blockhash: node.best_block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
107+
header: BlockHeader { version: 0x2000000, prev_blockhash: node.best_block_hash(), merkle_root: Default::default(), time: height, bits: 42, nonce: 42 },
107108
txdata: vec![],
108109
};
109110
assert!(depth >= 1);
110-
for _ in 0..depth - 1 {
111+
for i in 1..depth {
111112
do_connect_block(node, &block, skip_intermediaries);
112113
block = Block {
113-
header: BlockHeader { version: 0x20000000, prev_blockhash: block.header.block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 },
114+
header: BlockHeader { version: 0x20000000, prev_blockhash: block.header.block_hash(), merkle_root: Default::default(), time: height + i, bits: 42, nonce: 42 },
114115
txdata: vec![],
115116
};
116117
}

lightning/src/ln/functional_tests.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8138,7 +8138,7 @@ fn test_preimage_storage() {
81388138
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id;
81398139

81408140
{
8141-
let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(100_000), 1008, 42);
8141+
let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(100_000), 7200, 42);
81428142

81438143
let logger = test_utils::TestLogger::new();
81448144
let net_graph_msg_handler = &nodes[0].net_graph_msg_handler;
@@ -8176,19 +8176,29 @@ fn test_secret_timeout() {
81768176

81778177
let (payment_hash, payment_secret_1) = nodes[1].node.create_inbound_payment(Some(100_000), 2, 0);
81788178

8179-
// We should fail to register the same payment hash twice, at least until we've connected two
8180-
// blocks.
8179+
// We should fail to register the same payment hash twice, at least until we've connected a
8180+
// block with time 7200 + CHAN_CONFIRM_DEPTH + 2.
81818181
if let Err(APIError::APIMisuseError { err }) = nodes[1].node.create_inbound_payment_for_hash(payment_hash, Some(100_000), 2, 0) {
81828182
assert_eq!(err, "Duplicate payment hash");
81838183
} else { panic!(); }
8184-
connect_blocks(&nodes[1], 1);
8184+
let mut block = Block {
8185+
header: BlockHeader {
8186+
version: 0x2000000,
8187+
prev_blockhash: nodes[1].blocks.borrow().last().unwrap().0.block_hash(),
8188+
merkle_root: Default::default(),
8189+
time: nodes[1].blocks.borrow().len() as u32 + 7200 + 1, bits: 42, nonce: 42 },
8190+
txdata: vec![],
8191+
};
8192+
connect_block(&nodes[1], &block);
81858193
if let Err(APIError::APIMisuseError { err }) = nodes[1].node.create_inbound_payment_for_hash(payment_hash, Some(100_000), 2, 0) {
81868194
assert_eq!(err, "Duplicate payment hash");
81878195
} else { panic!(); }
81888196

81898197
// If we then connect the second block, we should be able to register the same payment hash
81908198
// again with a different user_payment_id (this time getting a new payment secret).
8191-
connect_blocks(&nodes[1], 1);
8199+
block.header.prev_blockhash = block.header.block_hash();
8200+
block.header.time += 1;
8201+
connect_block(&nodes[1], &block);
81928202
let our_payment_secret = nodes[1].node.create_inbound_payment_for_hash(payment_hash, Some(100_000), 2, 42).unwrap();
81938203
assert_ne!(payment_secret_1, our_payment_secret);
81948204

0 commit comments

Comments
 (0)