mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 23:30:59 +01:00
Add new block ConnectionStyle
s for transaction_unconfirmed
Previously `transaction_unconfirmed` was never called in tests!
This commit is contained in:
parent
12e8e9f3db
commit
9ac483bc84
2 changed files with 38 additions and 13 deletions
|
@ -79,26 +79,33 @@ pub fn confirm_transaction_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &T
|
||||||
/// The possible ways we may notify a ChannelManager of a new block
|
/// The possible ways we may notify a ChannelManager of a new block
|
||||||
#[derive(Clone, Copy, PartialEq)]
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
pub enum ConnectStyle {
|
pub enum ConnectStyle {
|
||||||
/// Calls best_block_updated first, detecting transactions in the block only after receiving the
|
/// Calls `best_block_updated` first, detecting transactions in the block only after receiving
|
||||||
/// header and height information.
|
/// the header and height information.
|
||||||
BestBlockFirst,
|
BestBlockFirst,
|
||||||
/// The same as BestBlockFirst, however when we have multiple blocks to connect, we only
|
/// The same as `BestBlockFirst`, however when we have multiple blocks to connect, we only
|
||||||
/// make a single best_block_updated call.
|
/// make a single `best_block_updated` call.
|
||||||
BestBlockFirstSkippingBlocks,
|
BestBlockFirstSkippingBlocks,
|
||||||
/// Calls transactions_confirmed first, detecting transactions in the block before updating the
|
/// The same as `BestBlockFirst` when connecting blocks. During disconnection only
|
||||||
/// header and height information.
|
/// `transaction_unconfirmed` is called.
|
||||||
|
BestBlockFirstReorgsOnlyTip,
|
||||||
|
/// Calls `transactions_confirmed` first, detecting transactions in the block before updating
|
||||||
|
/// the header and height information.
|
||||||
TransactionsFirst,
|
TransactionsFirst,
|
||||||
/// The same as TransactionsFirst, however when we have multiple blocks to connect, we only
|
/// The same as `TransactionsFirst`, however when we have multiple blocks to connect, we only
|
||||||
/// make a single best_block_updated call.
|
/// make a single `best_block_updated` call.
|
||||||
TransactionsFirstSkippingBlocks,
|
TransactionsFirstSkippingBlocks,
|
||||||
/// Provides the full block via the chain::Listen interface. In the current code this is
|
/// The same as `TransactionsFirst` when connecting blocks. During disconnection only
|
||||||
/// equivalent to TransactionsFirst with some additional assertions.
|
/// `transaction_unconfirmed` is called.
|
||||||
|
TransactionsFirstReorgsOnlyTip,
|
||||||
|
/// Provides the full block via the `chain::Listen` interface. In the current code this is
|
||||||
|
/// equivalent to `TransactionsFirst` with some additional assertions.
|
||||||
FullBlockViaListen,
|
FullBlockViaListen,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn connect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, depth: u32) -> BlockHash {
|
pub fn connect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, depth: u32) -> BlockHash {
|
||||||
let skip_intermediaries = match *node.connect_style.borrow() {
|
let skip_intermediaries = match *node.connect_style.borrow() {
|
||||||
ConnectStyle::BestBlockFirstSkippingBlocks|ConnectStyle::TransactionsFirstSkippingBlocks => true,
|
ConnectStyle::BestBlockFirstSkippingBlocks|ConnectStyle::TransactionsFirstSkippingBlocks|
|
||||||
|
ConnectStyle::BestBlockFirstReorgsOnlyTip|ConnectStyle::TransactionsFirstReorgsOnlyTip => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -138,14 +145,14 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
|
||||||
if !skip_intermediaries {
|
if !skip_intermediaries {
|
||||||
let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
|
let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
|
||||||
match *node.connect_style.borrow() {
|
match *node.connect_style.borrow() {
|
||||||
ConnectStyle::BestBlockFirst|ConnectStyle::BestBlockFirstSkippingBlocks => {
|
ConnectStyle::BestBlockFirst|ConnectStyle::BestBlockFirstSkippingBlocks|ConnectStyle::BestBlockFirstReorgsOnlyTip => {
|
||||||
node.chain_monitor.chain_monitor.best_block_updated(&block.header, height);
|
node.chain_monitor.chain_monitor.best_block_updated(&block.header, height);
|
||||||
call_claimable_balances(node);
|
call_claimable_balances(node);
|
||||||
node.chain_monitor.chain_monitor.transactions_confirmed(&block.header, &txdata, height);
|
node.chain_monitor.chain_monitor.transactions_confirmed(&block.header, &txdata, height);
|
||||||
node.node.best_block_updated(&block.header, height);
|
node.node.best_block_updated(&block.header, height);
|
||||||
node.node.transactions_confirmed(&block.header, &txdata, height);
|
node.node.transactions_confirmed(&block.header, &txdata, height);
|
||||||
},
|
},
|
||||||
ConnectStyle::TransactionsFirst|ConnectStyle::TransactionsFirstSkippingBlocks => {
|
ConnectStyle::TransactionsFirst|ConnectStyle::TransactionsFirstSkippingBlocks|ConnectStyle::TransactionsFirstReorgsOnlyTip => {
|
||||||
node.chain_monitor.chain_monitor.transactions_confirmed(&block.header, &txdata, height);
|
node.chain_monitor.chain_monitor.transactions_confirmed(&block.header, &txdata, height);
|
||||||
call_claimable_balances(node);
|
call_claimable_balances(node);
|
||||||
node.chain_monitor.chain_monitor.best_block_updated(&block.header, height);
|
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)
|
||||||
node.node.best_block_updated(&prev.0.header, prev.1);
|
node.node.best_block_updated(&prev.0.header, prev.1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
ConnectStyle::BestBlockFirstReorgsOnlyTip|ConnectStyle::TransactionsFirstReorgsOnlyTip => {
|
||||||
|
for tx in orig.0.txdata {
|
||||||
|
node.chain_monitor.chain_monitor.transaction_unconfirmed(&tx.txid());
|
||||||
|
node.node.transaction_unconfirmed(&tx.txid());
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => {
|
_ => {
|
||||||
node.chain_monitor.chain_monitor.best_block_updated(&prev.0.header, prev.1);
|
node.chain_monitor.chain_monitor.best_block_updated(&prev.0.header, prev.1);
|
||||||
node.node.best_block_updated(&prev.0.header, prev.1);
|
node.node.best_block_updated(&prev.0.header, prev.1);
|
||||||
|
|
|
@ -314,6 +314,11 @@ fn test_unconf_chan() {
|
||||||
do_test_unconf_chan(false, true, false, ConnectStyle::BestBlockFirstSkippingBlocks);
|
do_test_unconf_chan(false, true, false, ConnectStyle::BestBlockFirstSkippingBlocks);
|
||||||
do_test_unconf_chan(true, false, false, ConnectStyle::BestBlockFirstSkippingBlocks);
|
do_test_unconf_chan(true, false, false, ConnectStyle::BestBlockFirstSkippingBlocks);
|
||||||
do_test_unconf_chan(false, false, false, ConnectStyle::BestBlockFirstSkippingBlocks);
|
do_test_unconf_chan(false, false, false, ConnectStyle::BestBlockFirstSkippingBlocks);
|
||||||
|
|
||||||
|
do_test_unconf_chan(true, true, false, ConnectStyle::BestBlockFirstReorgsOnlyTip);
|
||||||
|
do_test_unconf_chan(false, true, false, ConnectStyle::BestBlockFirstReorgsOnlyTip);
|
||||||
|
do_test_unconf_chan(true, false, false, ConnectStyle::BestBlockFirstReorgsOnlyTip);
|
||||||
|
do_test_unconf_chan(false, false, false, ConnectStyle::BestBlockFirstReorgsOnlyTip);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -331,6 +336,11 @@ fn test_unconf_chan_via_funding_unconfirmed() {
|
||||||
do_test_unconf_chan(true, false, true, ConnectStyle::BestBlockFirstSkippingBlocks);
|
do_test_unconf_chan(true, false, true, ConnectStyle::BestBlockFirstSkippingBlocks);
|
||||||
do_test_unconf_chan(false, false, true, ConnectStyle::BestBlockFirstSkippingBlocks);
|
do_test_unconf_chan(false, false, true, ConnectStyle::BestBlockFirstSkippingBlocks);
|
||||||
|
|
||||||
|
do_test_unconf_chan(true, true, true, ConnectStyle::BestBlockFirstReorgsOnlyTip);
|
||||||
|
do_test_unconf_chan(false, true, true, ConnectStyle::BestBlockFirstReorgsOnlyTip);
|
||||||
|
do_test_unconf_chan(true, false, true, ConnectStyle::BestBlockFirstReorgsOnlyTip);
|
||||||
|
do_test_unconf_chan(false, false, true, ConnectStyle::BestBlockFirstReorgsOnlyTip);
|
||||||
|
|
||||||
do_test_unconf_chan(true, true, true, ConnectStyle::FullBlockViaListen);
|
do_test_unconf_chan(true, true, true, ConnectStyle::FullBlockViaListen);
|
||||||
do_test_unconf_chan(false, true, true, ConnectStyle::FullBlockViaListen);
|
do_test_unconf_chan(false, true, true, ConnectStyle::FullBlockViaListen);
|
||||||
do_test_unconf_chan(true, false, true, ConnectStyle::FullBlockViaListen);
|
do_test_unconf_chan(true, false, true, ConnectStyle::FullBlockViaListen);
|
||||||
|
@ -539,7 +549,9 @@ fn do_test_to_remote_after_local_detection(style: ConnectStyle) {
|
||||||
fn test_to_remote_after_local_detection() {
|
fn test_to_remote_after_local_detection() {
|
||||||
do_test_to_remote_after_local_detection(ConnectStyle::BestBlockFirst);
|
do_test_to_remote_after_local_detection(ConnectStyle::BestBlockFirst);
|
||||||
do_test_to_remote_after_local_detection(ConnectStyle::BestBlockFirstSkippingBlocks);
|
do_test_to_remote_after_local_detection(ConnectStyle::BestBlockFirstSkippingBlocks);
|
||||||
|
do_test_to_remote_after_local_detection(ConnectStyle::BestBlockFirstReorgsOnlyTip);
|
||||||
do_test_to_remote_after_local_detection(ConnectStyle::TransactionsFirst);
|
do_test_to_remote_after_local_detection(ConnectStyle::TransactionsFirst);
|
||||||
do_test_to_remote_after_local_detection(ConnectStyle::TransactionsFirstSkippingBlocks);
|
do_test_to_remote_after_local_detection(ConnectStyle::TransactionsFirstSkippingBlocks);
|
||||||
|
do_test_to_remote_after_local_detection(ConnectStyle::TransactionsFirstReorgsOnlyTip);
|
||||||
do_test_to_remote_after_local_detection(ConnectStyle::FullBlockViaListen);
|
do_test_to_remote_after_local_detection(ConnectStyle::FullBlockViaListen);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue