Skip to content

Commit 3ca9856

Browse files
committed
Add new block ConnectionStyles for transaction_unconfirmed
Previously `transaction_unconfirmed` was never called in tests!
1 parent 12e8e9f commit 3ca9856

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,27 @@ pub enum ConnectStyle {
8585
/// The same as BestBlockFirst, however when we have multiple blocks to connect, we only
8686
/// make a single best_block_updated call.
8787
BestBlockFirstSkippingBlocks,
88+
/// Calls transactions_confirmed first, but only when connecting blocks. During disconnection
89+
/// only `transaction_unconfirmed` is called.
90+
BestBlockFirstReorgsOnlyTip,
8891
/// Calls transactions_confirmed first, detecting transactions in the block before updating the
8992
/// header and height information.
9093
TransactionsFirst,
9194
/// The same as TransactionsFirst, however when we have multiple blocks to connect, we only
9295
/// make a single best_block_updated call.
9396
TransactionsFirstSkippingBlocks,
97+
/// Calls best_block_updated first, but only when connecting blocks. During disconnection only
98+
/// `transaction_unconfirmed` is called.
99+
TransactionsFirstReorgsOnlyTip,
94100
/// Provides the full block via the chain::Listen interface. In the current code this is
95101
/// equivalent to TransactionsFirst with some additional assertions.
96102
FullBlockViaListen,
97103
}
98104

99105
pub fn connect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, depth: u32) -> BlockHash {
100106
let skip_intermediaries = match *node.connect_style.borrow() {
101-
ConnectStyle::BestBlockFirstSkippingBlocks|ConnectStyle::TransactionsFirstSkippingBlocks => true,
107+
ConnectStyle::BestBlockFirstSkippingBlocks|ConnectStyle::TransactionsFirstSkippingBlocks|
108+
ConnectStyle::BestBlockFirstReorgsOnlyTip|ConnectStyle::TransactionsFirstReorgsOnlyTip => true,
102109
_ => false,
103110
};
104111

@@ -138,14 +145,14 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
138145
if !skip_intermediaries {
139146
let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
140147
match *node.connect_style.borrow() {
141-
ConnectStyle::BestBlockFirst|ConnectStyle::BestBlockFirstSkippingBlocks => {
148+
ConnectStyle::BestBlockFirst|ConnectStyle::BestBlockFirstSkippingBlocks|ConnectStyle::BestBlockFirstReorgsOnlyTip => {
142149
node.chain_monitor.chain_monitor.best_block_updated(&block.header, height);
143150
call_claimable_balances(node);
144151
node.chain_monitor.chain_monitor.transactions_confirmed(&block.header, &txdata, height);
145152
node.node.best_block_updated(&block.header, height);
146153
node.node.transactions_confirmed(&block.header, &txdata, height);
147154
},
148-
ConnectStyle::TransactionsFirst|ConnectStyle::TransactionsFirstSkippingBlocks => {
155+
ConnectStyle::TransactionsFirst|ConnectStyle::TransactionsFirstSkippingBlocks|ConnectStyle::TransactionsFirstReorgsOnlyTip => {
149156
node.chain_monitor.chain_monitor.transactions_confirmed(&block.header, &txdata, height);
150157
call_claimable_balances(node);
151158
node.chain_monitor.chain_monitor.best_block_updated(&block.header, height);
@@ -181,6 +188,12 @@ pub fn disconnect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, count: u32)
181188
node.node.best_block_updated(&prev.0.header, prev.1);
182189
}
183190
},
191+
ConnectStyle::BestBlockFirstReorgsOnlyTip|ConnectStyle::TransactionsFirstReorgsOnlyTip => {
192+
for tx in orig.0.txdata {
193+
node.chain_monitor.chain_monitor.transaction_unconfirmed(&tx.txid());
194+
node.node.transaction_unconfirmed(&tx.txid());
195+
}
196+
},
184197
_ => {
185198
node.chain_monitor.chain_monitor.best_block_updated(&prev.0.header, prev.1);
186199
node.node.best_block_updated(&prev.0.header, prev.1);

lightning/src/ln/reorg_tests.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ fn test_unconf_chan() {
314314
do_test_unconf_chan(false, true, false, ConnectStyle::BestBlockFirstSkippingBlocks);
315315
do_test_unconf_chan(true, false, false, ConnectStyle::BestBlockFirstSkippingBlocks);
316316
do_test_unconf_chan(false, false, false, ConnectStyle::BestBlockFirstSkippingBlocks);
317+
318+
do_test_unconf_chan(true, true, false, ConnectStyle::BestBlockFirstReorgsOnlyTip);
319+
do_test_unconf_chan(false, true, false, ConnectStyle::BestBlockFirstReorgsOnlyTip);
320+
do_test_unconf_chan(true, false, false, ConnectStyle::BestBlockFirstReorgsOnlyTip);
321+
do_test_unconf_chan(false, false, false, ConnectStyle::BestBlockFirstReorgsOnlyTip);
317322
}
318323

319324
#[test]
@@ -331,6 +336,11 @@ fn test_unconf_chan_via_funding_unconfirmed() {
331336
do_test_unconf_chan(true, false, true, ConnectStyle::BestBlockFirstSkippingBlocks);
332337
do_test_unconf_chan(false, false, true, ConnectStyle::BestBlockFirstSkippingBlocks);
333338

339+
do_test_unconf_chan(true, true, true, ConnectStyle::BestBlockFirstReorgsOnlyTip);
340+
do_test_unconf_chan(false, true, true, ConnectStyle::BestBlockFirstReorgsOnlyTip);
341+
do_test_unconf_chan(true, false, true, ConnectStyle::BestBlockFirstReorgsOnlyTip);
342+
do_test_unconf_chan(false, false, true, ConnectStyle::BestBlockFirstReorgsOnlyTip);
343+
334344
do_test_unconf_chan(true, true, true, ConnectStyle::FullBlockViaListen);
335345
do_test_unconf_chan(false, true, true, ConnectStyle::FullBlockViaListen);
336346
do_test_unconf_chan(true, false, true, ConnectStyle::FullBlockViaListen);
@@ -539,7 +549,9 @@ fn do_test_to_remote_after_local_detection(style: ConnectStyle) {
539549
fn test_to_remote_after_local_detection() {
540550
do_test_to_remote_after_local_detection(ConnectStyle::BestBlockFirst);
541551
do_test_to_remote_after_local_detection(ConnectStyle::BestBlockFirstSkippingBlocks);
552+
do_test_to_remote_after_local_detection(ConnectStyle::BestBlockFirstReorgsOnlyTip);
542553
do_test_to_remote_after_local_detection(ConnectStyle::TransactionsFirst);
543554
do_test_to_remote_after_local_detection(ConnectStyle::TransactionsFirstSkippingBlocks);
555+
do_test_to_remote_after_local_detection(ConnectStyle::TransactionsFirstReorgsOnlyTip);
544556
do_test_to_remote_after_local_detection(ConnectStyle::FullBlockViaListen);
545557
}

0 commit comments

Comments
 (0)