mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-10 13:35:38 +01:00
Use helper to create dummy blocks
`rust-bitcoin v0.30.0` introduces concrete variants for data members of block `Header`s. To avoid having to update these across every use, we introduce new helpers to create dummy blocks and headers, such that the update process is a bit more straight-forward.
This commit is contained in:
parent
4f9bcb9958
commit
17a74fcfc7
12 changed files with 86 additions and 169 deletions
|
@ -18,8 +18,6 @@
|
||||||
//! send-side handling is correct, other peers. We consider it a failure if any action results in a
|
//! send-side handling is correct, other peers. We consider it a failure if any action results in a
|
||||||
//! channel being force-closed.
|
//! channel being force-closed.
|
||||||
|
|
||||||
use bitcoin::TxMerkleNode;
|
|
||||||
use bitcoin::blockdata::block::BlockHeader;
|
|
||||||
use bitcoin::blockdata::constants::genesis_block;
|
use bitcoin::blockdata::constants::genesis_block;
|
||||||
use bitcoin::blockdata::transaction::{Transaction, TxOut};
|
use bitcoin::blockdata::transaction::{Transaction, TxOut};
|
||||||
use bitcoin::blockdata::script::{Builder, Script};
|
use bitcoin::blockdata::script::{Builder, Script};
|
||||||
|
@ -45,6 +43,7 @@ use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelMana
|
||||||
use lightning::ln::channel::FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
|
use lightning::ln::channel::FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
|
||||||
use lightning::ln::msgs::{self, CommitmentUpdate, ChannelMessageHandler, DecodeError, UpdateAddHTLC, Init};
|
use lightning::ln::msgs::{self, CommitmentUpdate, ChannelMessageHandler, DecodeError, UpdateAddHTLC, Init};
|
||||||
use lightning::ln::script::ShutdownScript;
|
use lightning::ln::script::ShutdownScript;
|
||||||
|
use lightning::ln::functional_test_utils::*;
|
||||||
use lightning::util::enforcing_trait_impls::{EnforcingSigner, EnforcementState};
|
use lightning::util::enforcing_trait_impls::{EnforcingSigner, EnforcementState};
|
||||||
use lightning::util::errors::APIError;
|
use lightning::util::errors::APIError;
|
||||||
use lightning::util::logger::Logger;
|
use lightning::util::logger::Logger;
|
||||||
|
@ -547,11 +546,11 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
|
||||||
macro_rules! confirm_txn {
|
macro_rules! confirm_txn {
|
||||||
($node: expr) => { {
|
($node: expr) => { {
|
||||||
let chain_hash = genesis_block(Network::Bitcoin).block_hash();
|
let chain_hash = genesis_block(Network::Bitcoin).block_hash();
|
||||||
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: chain_hash, merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
let mut header = create_dummy_header(chain_hash, 42);
|
||||||
let txdata: Vec<_> = channel_txn.iter().enumerate().map(|(i, tx)| (i + 1, tx)).collect();
|
let txdata: Vec<_> = channel_txn.iter().enumerate().map(|(i, tx)| (i + 1, tx)).collect();
|
||||||
$node.transactions_confirmed(&header, &txdata, 1);
|
$node.transactions_confirmed(&header, &txdata, 1);
|
||||||
for _ in 2..100 {
|
for _ in 2..100 {
|
||||||
header = BlockHeader { version: 0x20000000, prev_blockhash: header.block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
header = create_dummy_header(header.block_hash(), 42);
|
||||||
}
|
}
|
||||||
$node.best_block_updated(&header, 99);
|
$node.best_block_updated(&header, 99);
|
||||||
} }
|
} }
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
//! or payments to send/ways to handle events generated.
|
//! or payments to send/ways to handle events generated.
|
||||||
//! This test has been very useful, though due to its complexity good starting inputs are critical.
|
//! This test has been very useful, though due to its complexity good starting inputs are critical.
|
||||||
|
|
||||||
use bitcoin::TxMerkleNode;
|
|
||||||
use bitcoin::blockdata::block::BlockHeader;
|
|
||||||
use bitcoin::blockdata::constants::genesis_block;
|
use bitcoin::blockdata::constants::genesis_block;
|
||||||
use bitcoin::blockdata::transaction::{Transaction, TxOut};
|
use bitcoin::blockdata::transaction::{Transaction, TxOut};
|
||||||
use bitcoin::blockdata::script::{Builder, Script};
|
use bitcoin::blockdata::script::{Builder, Script};
|
||||||
|
@ -41,6 +39,7 @@ use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelMana
|
||||||
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor,IgnoringMessageHandler};
|
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor,IgnoringMessageHandler};
|
||||||
use lightning::ln::msgs::{self, DecodeError};
|
use lightning::ln::msgs::{self, DecodeError};
|
||||||
use lightning::ln::script::ShutdownScript;
|
use lightning::ln::script::ShutdownScript;
|
||||||
|
use lightning::ln::functional_test_utils::*;
|
||||||
use lightning::routing::gossip::{P2PGossipSync, NetworkGraph};
|
use lightning::routing::gossip::{P2PGossipSync, NetworkGraph};
|
||||||
use lightning::routing::utxo::UtxoLookup;
|
use lightning::routing::utxo::UtxoLookup;
|
||||||
use lightning::routing::router::{InFlightHtlcs, PaymentParameters, Route, RouteParameters, Router};
|
use lightning::routing::router::{InFlightHtlcs, PaymentParameters, Route, RouteParameters, Router};
|
||||||
|
@ -48,7 +47,7 @@ use lightning::util::config::UserConfig;
|
||||||
use lightning::util::errors::APIError;
|
use lightning::util::errors::APIError;
|
||||||
use lightning::util::enforcing_trait_impls::{EnforcingSigner, EnforcementState};
|
use lightning::util::enforcing_trait_impls::{EnforcingSigner, EnforcementState};
|
||||||
use lightning::util::logger::Logger;
|
use lightning::util::logger::Logger;
|
||||||
use lightning::util::ser::{Readable, ReadableArgs, Writeable};
|
use lightning::util::ser::{ReadableArgs, Writeable};
|
||||||
|
|
||||||
use crate::utils::test_logger;
|
use crate::utils::test_logger;
|
||||||
use crate::utils::test_persister::TestPersister;
|
use crate::utils::test_persister::TestPersister;
|
||||||
|
@ -228,7 +227,7 @@ impl<'a> MoneyLossDetector<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.blocks_connected += 1;
|
self.blocks_connected += 1;
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: self.header_hashes[self.height].0, merkle_root: TxMerkleNode::all_zeros(), time: self.blocks_connected, bits: 42, nonce: 42 };
|
let header = create_dummy_header(self.header_hashes[self.height].0, self.blocks_connected);
|
||||||
self.height += 1;
|
self.height += 1;
|
||||||
self.manager.transactions_confirmed(&header, &txdata, self.height as u32);
|
self.manager.transactions_confirmed(&header, &txdata, self.height as u32);
|
||||||
self.manager.best_block_updated(&header, self.height as u32);
|
self.manager.best_block_updated(&header, self.height as u32);
|
||||||
|
@ -245,7 +244,7 @@ impl<'a> MoneyLossDetector<'a> {
|
||||||
|
|
||||||
fn disconnect_block(&mut self) {
|
fn disconnect_block(&mut self) {
|
||||||
if self.height > 0 && (self.max_height < 6 || self.height >= self.max_height - 6) {
|
if self.height > 0 && (self.max_height < 6 || self.height >= self.max_height - 6) {
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: self.header_hashes[self.height - 1].0, merkle_root: TxMerkleNode::all_zeros(), time: self.header_hashes[self.height].1, bits: 42, nonce: 42 };
|
let header = create_dummy_header(self.header_hashes[self.height - 1].0, self.header_hashes[self.height].1);
|
||||||
self.manager.block_disconnected(&header, self.height as u32);
|
self.manager.block_disconnected(&header, self.height as u32);
|
||||||
self.monitor.block_disconnected(&header, self.height as u32);
|
self.monitor.block_disconnected(&header, self.height as u32);
|
||||||
self.height -= 1;
|
self.height -= 1;
|
||||||
|
|
|
@ -817,7 +817,6 @@ impl Drop for BackgroundProcessor {
|
||||||
|
|
||||||
#[cfg(all(feature = "std", test))]
|
#[cfg(all(feature = "std", test))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use bitcoin::blockdata::block::BlockHeader;
|
|
||||||
use bitcoin::blockdata::constants::genesis_block;
|
use bitcoin::blockdata::constants::genesis_block;
|
||||||
use bitcoin::blockdata::locktime::PackedLockTime;
|
use bitcoin::blockdata::locktime::PackedLockTime;
|
||||||
use bitcoin::blockdata::transaction::{Transaction, TxOut};
|
use bitcoin::blockdata::transaction::{Transaction, TxOut};
|
||||||
|
@ -833,6 +832,7 @@ mod tests {
|
||||||
use lightning::ln::channelmanager;
|
use lightning::ln::channelmanager;
|
||||||
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, MIN_CLTV_EXPIRY_DELTA, PaymentId};
|
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, MIN_CLTV_EXPIRY_DELTA, PaymentId};
|
||||||
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
|
use lightning::ln::features::{ChannelFeatures, NodeFeatures};
|
||||||
|
use lightning::ln::functional_test_utils::*;
|
||||||
use lightning::ln::msgs::{ChannelMessageHandler, Init};
|
use lightning::ln::msgs::{ChannelMessageHandler, Init};
|
||||||
use lightning::ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler};
|
use lightning::ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler};
|
||||||
use lightning::routing::gossip::{NetworkGraph, NodeId, P2PGossipSync};
|
use lightning::routing::gossip::{NetworkGraph, NodeId, P2PGossipSync};
|
||||||
|
@ -849,8 +849,6 @@ mod tests {
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::sync::mpsc::SyncSender;
|
use std::sync::mpsc::SyncSender;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use bitcoin::hashes::Hash;
|
|
||||||
use bitcoin::TxMerkleNode;
|
|
||||||
use lightning_rapid_gossip_sync::RapidGossipSync;
|
use lightning_rapid_gossip_sync::RapidGossipSync;
|
||||||
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};
|
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};
|
||||||
|
|
||||||
|
@ -1189,7 +1187,7 @@ mod tests {
|
||||||
for i in 1..=depth {
|
for i in 1..=depth {
|
||||||
let prev_blockhash = node.best_block.block_hash();
|
let prev_blockhash = node.best_block.block_hash();
|
||||||
let height = node.best_block.height() + 1;
|
let height = node.best_block.height() + 1;
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash, merkle_root: TxMerkleNode::all_zeros(), time: height, bits: 42, nonce: 42 };
|
let header = create_dummy_header(prev_blockhash, height);
|
||||||
let txdata = vec![(0, tx)];
|
let txdata = vec![(0, tx)];
|
||||||
node.best_block = BestBlock::new(header.block_hash(), height);
|
node.best_block = BestBlock::new(header.block_hash(), height);
|
||||||
match i {
|
match i {
|
||||||
|
|
|
@ -136,9 +136,8 @@ mod tests {
|
||||||
extern crate lightning;
|
extern crate lightning;
|
||||||
extern crate bitcoin;
|
extern crate bitcoin;
|
||||||
use crate::FilesystemPersister;
|
use crate::FilesystemPersister;
|
||||||
use bitcoin::blockdata::block::{Block, BlockHeader};
|
|
||||||
use bitcoin::hashes::hex::FromHex;
|
use bitcoin::hashes::hex::FromHex;
|
||||||
use bitcoin::{Txid, TxMerkleNode};
|
use bitcoin::Txid;
|
||||||
use lightning::chain::ChannelMonitorUpdateStatus;
|
use lightning::chain::ChannelMonitorUpdateStatus;
|
||||||
use lightning::chain::chainmonitor::Persist;
|
use lightning::chain::chainmonitor::Persist;
|
||||||
use lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
|
use lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
|
||||||
|
@ -148,7 +147,6 @@ mod tests {
|
||||||
use lightning::ln::functional_test_utils::*;
|
use lightning::ln::functional_test_utils::*;
|
||||||
use lightning::util::test_utils;
|
use lightning::util::test_utils;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use bitcoin::hashes::Hash;
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
use {
|
use {
|
||||||
lightning::get_event_msg,
|
lightning::get_event_msg,
|
||||||
|
@ -247,8 +245,7 @@ mod tests {
|
||||||
let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
|
let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
|
||||||
assert_eq!(node_txn.len(), 1);
|
assert_eq!(node_txn.len(), 1);
|
||||||
|
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
connect_block(&nodes[1], &create_dummy_block(nodes[0].best_block_hash(), 42, vec![node_txn[0].clone(), node_txn[0].clone()]));
|
||||||
connect_block(&nodes[1], &Block { header, txdata: vec![node_txn[0].clone(), node_txn[0].clone()]});
|
|
||||||
check_closed_broadcast!(nodes[1], true);
|
check_closed_broadcast!(nodes[1], true);
|
||||||
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
|
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
|
||||||
check_added_monitors!(nodes[1], 1);
|
check_added_monitors!(nodes[1], 1);
|
||||||
|
|
|
@ -825,8 +825,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use bitcoin::{BlockHeader, TxMerkleNode};
|
|
||||||
use bitcoin::hashes::Hash;
|
|
||||||
use crate::{check_added_monitors, check_closed_broadcast, check_closed_event};
|
use crate::{check_added_monitors, check_closed_broadcast, check_closed_event};
|
||||||
use crate::{expect_payment_sent, expect_payment_claimed, expect_payment_sent_without_paths, expect_payment_path_successful, get_event_msg};
|
use crate::{expect_payment_sent, expect_payment_claimed, expect_payment_sent_without_paths, expect_payment_path_successful, get_event_msg};
|
||||||
use crate::{get_htlc_update_msgs, get_local_commitment_txn, get_revoke_commit_msgs, get_route_and_payment_hash, unwrap_send_err};
|
use crate::{get_htlc_update_msgs, get_local_commitment_txn, get_revoke_commit_msgs, get_route_and_payment_hash, unwrap_send_err};
|
||||||
|
@ -972,10 +970,7 @@ mod tests {
|
||||||
|
|
||||||
// Connect B's commitment transaction, but only to the ChainMonitor/ChannelMonitor. The
|
// Connect B's commitment transaction, but only to the ChainMonitor/ChannelMonitor. The
|
||||||
// channel is now closed, but the ChannelManager doesn't know that yet.
|
// channel is now closed, but the ChannelManager doesn't know that yet.
|
||||||
let new_header = BlockHeader {
|
let new_header = create_dummy_header(nodes[0].best_block_info().0, 0);
|
||||||
version: 2, time: 0, bits: 0, nonce: 0,
|
|
||||||
prev_blockhash: nodes[0].best_block_info().0,
|
|
||||||
merkle_root: TxMerkleNode::all_zeros() };
|
|
||||||
nodes[0].chain_monitor.chain_monitor.transactions_confirmed(&new_header,
|
nodes[0].chain_monitor.chain_monitor.transactions_confirmed(&new_header,
|
||||||
&[(0, &remote_txn[0]), (1, &remote_txn[1])], nodes[0].best_block_info().1 + 1);
|
&[(0, &remote_txn[0]), (1, &remote_txn[1])], nodes[0].best_block_info().1 + 1);
|
||||||
assert!(nodes[0].chain_monitor.release_pending_monitor_events().is_empty());
|
assert!(nodes[0].chain_monitor.release_pending_monitor_events().is_empty());
|
||||||
|
@ -999,10 +994,7 @@ mod tests {
|
||||||
|
|
||||||
if block_timeout {
|
if block_timeout {
|
||||||
// After three blocks, pending MontiorEvents should be released either way.
|
// After three blocks, pending MontiorEvents should be released either way.
|
||||||
let latest_header = BlockHeader {
|
let latest_header = create_dummy_header(nodes[0].best_block_info().0, 0);
|
||||||
version: 2, time: 0, bits: 0, nonce: 0,
|
|
||||||
prev_blockhash: nodes[0].best_block_info().0,
|
|
||||||
merkle_root: TxMerkleNode::all_zeros() };
|
|
||||||
nodes[0].chain_monitor.chain_monitor.best_block_updated(&latest_header, nodes[0].best_block_info().1 + LATENCY_GRACE_PERIOD_BLOCKS);
|
nodes[0].chain_monitor.chain_monitor.best_block_updated(&latest_header, nodes[0].best_block_info().1 + LATENCY_GRACE_PERIOD_BLOCKS);
|
||||||
} else {
|
} else {
|
||||||
let persistences = chanmon_cfgs[0].persister.chain_sync_monitor_persistences.lock().unwrap().clone();
|
let persistences = chanmon_cfgs[0].persister.chain_sync_monitor_persistences.lock().unwrap().clone();
|
||||||
|
|
|
@ -4084,7 +4084,6 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use bitcoin::blockdata::block::BlockHeader;
|
|
||||||
use bitcoin::blockdata::script::{Script, Builder};
|
use bitcoin::blockdata::script::{Script, Builder};
|
||||||
use bitcoin::blockdata::opcodes;
|
use bitcoin::blockdata::opcodes;
|
||||||
use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut, EcdsaSighashType};
|
use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut, EcdsaSighashType};
|
||||||
|
@ -4121,7 +4120,7 @@ mod tests {
|
||||||
use crate::util::ser::{ReadableArgs, Writeable};
|
use crate::util::ser::{ReadableArgs, Writeable};
|
||||||
use crate::sync::{Arc, Mutex};
|
use crate::sync::{Arc, Mutex};
|
||||||
use crate::io;
|
use crate::io;
|
||||||
use bitcoin::{PackedLockTime, Sequence, TxMerkleNode, Witness};
|
use bitcoin::{PackedLockTime, Sequence, Witness};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
fn do_test_funding_spend_refuses_updates(use_local_txn: bool) {
|
fn do_test_funding_spend_refuses_updates(use_local_txn: bool) {
|
||||||
|
@ -4160,10 +4159,7 @@ mod tests {
|
||||||
|
|
||||||
// Connect a commitment transaction, but only to the ChainMonitor/ChannelMonitor. The
|
// Connect a commitment transaction, but only to the ChainMonitor/ChannelMonitor. The
|
||||||
// channel is now closed, but the ChannelManager doesn't know that yet.
|
// channel is now closed, but the ChannelManager doesn't know that yet.
|
||||||
let new_header = BlockHeader {
|
let new_header = create_dummy_header(nodes[0].best_block_info().0, 0);
|
||||||
version: 2, time: 0, bits: 0, nonce: 0,
|
|
||||||
prev_blockhash: nodes[0].best_block_info().0,
|
|
||||||
merkle_root: TxMerkleNode::all_zeros() };
|
|
||||||
let conf_height = nodes[0].best_block_info().1 + 1;
|
let conf_height = nodes[0].best_block_info().1 + 1;
|
||||||
nodes[1].chain_monitor.chain_monitor.transactions_confirmed(&new_header,
|
nodes[1].chain_monitor.chain_monitor.transactions_confirmed(&new_header,
|
||||||
&[(0, broadcast_tx)], conf_height);
|
&[(0, broadcast_tx)], conf_height);
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
//! There are a bunch of these as their handling is relatively error-prone so they are split out
|
//! There are a bunch of these as their handling is relatively error-prone so they are split out
|
||||||
//! here. See also the chanmon_fail_consistency fuzz test.
|
//! here. See also the chanmon_fail_consistency fuzz test.
|
||||||
|
|
||||||
use bitcoin::blockdata::block::{Block, BlockHeader};
|
|
||||||
use bitcoin::blockdata::constants::genesis_block;
|
use bitcoin::blockdata::constants::genesis_block;
|
||||||
use bitcoin::hash_types::BlockHash;
|
use bitcoin::hash_types::BlockHash;
|
||||||
use bitcoin::network::constants::Network;
|
use bitcoin::network::constants::Network;
|
||||||
|
@ -35,7 +34,6 @@ use crate::util::test_utils;
|
||||||
|
|
||||||
use crate::io;
|
use crate::io;
|
||||||
use bitcoin::hashes::Hash;
|
use bitcoin::hashes::Hash;
|
||||||
use bitcoin::TxMerkleNode;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::sync::{Arc, Mutex};
|
use crate::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
@ -121,15 +119,7 @@ fn test_monitor_and_persister_update_fail() {
|
||||||
assert_eq!(chain_mon.watch_channel(outpoint, new_monitor), ChannelMonitorUpdateStatus::Completed);
|
assert_eq!(chain_mon.watch_channel(outpoint, new_monitor), ChannelMonitorUpdateStatus::Completed);
|
||||||
chain_mon
|
chain_mon
|
||||||
};
|
};
|
||||||
let header = BlockHeader {
|
chain_mon.chain_monitor.block_connected(&create_dummy_block(BlockHash::all_zeros(), 42, Vec::new()), 200);
|
||||||
version: 0x20000000,
|
|
||||||
prev_blockhash: BlockHash::all_zeros(),
|
|
||||||
merkle_root: TxMerkleNode::all_zeros(),
|
|
||||||
time: 42,
|
|
||||||
bits: 42,
|
|
||||||
nonce: 42
|
|
||||||
};
|
|
||||||
chain_mon.chain_monitor.block_connected(&Block { header, txdata: vec![] }, 200);
|
|
||||||
|
|
||||||
// Set the persister's return value to be a InProgress.
|
// Set the persister's return value to be a InProgress.
|
||||||
persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
|
persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
|
||||||
|
|
|
@ -9387,10 +9387,7 @@ pub mod bench {
|
||||||
|
|
||||||
assert_eq!(&tx_broadcaster.txn_broadcasted.lock().unwrap()[..], &[tx.clone()]);
|
assert_eq!(&tx_broadcaster.txn_broadcasted.lock().unwrap()[..], &[tx.clone()]);
|
||||||
|
|
||||||
let block = Block {
|
let block = create_dummy_block(BestBlock::from_network(network).block_hash(), 42, vec![tx]);
|
||||||
header: BlockHeader { version: 0x20000000, prev_blockhash: BestBlock::from_network(network).block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 },
|
|
||||||
txdata: vec![tx],
|
|
||||||
};
|
|
||||||
Listen::block_connected(&node_a, &block, 1);
|
Listen::block_connected(&node_a, &block, 1);
|
||||||
Listen::block_connected(&node_b, &block, 1);
|
Listen::block_connected(&node_b, &block, 1);
|
||||||
|
|
||||||
|
|
|
@ -85,16 +85,14 @@ pub fn confirm_transactions_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, txn:
|
||||||
if conf_height > first_connect_height {
|
if conf_height > first_connect_height {
|
||||||
connect_blocks(node, conf_height - first_connect_height);
|
connect_blocks(node, conf_height - first_connect_height);
|
||||||
}
|
}
|
||||||
let mut block = Block {
|
let mut txdata = Vec::new();
|
||||||
header: BlockHeader { version: 0x20000000, prev_blockhash: node.best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: conf_height, bits: 42, nonce: 42 },
|
|
||||||
txdata: Vec::new(),
|
|
||||||
};
|
|
||||||
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
|
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
|
||||||
block.txdata.push(Transaction { version: 0, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() });
|
txdata.push(Transaction { version: 0, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() });
|
||||||
}
|
}
|
||||||
for tx in txn {
|
for tx in txn {
|
||||||
block.txdata.push((*tx).clone());
|
txdata.push((*tx).clone());
|
||||||
}
|
}
|
||||||
|
let block = create_dummy_block(node.best_block_hash(), conf_height, txdata);
|
||||||
connect_block(node, &block);
|
connect_block(node, &block);
|
||||||
scid_utils::scid_from_parts(conf_height as u64, block.txdata.len() as u64 - 1, 0).unwrap()
|
scid_utils::scid_from_parts(conf_height as u64, block.txdata.len() as u64 - 1, 0).unwrap()
|
||||||
}
|
}
|
||||||
|
@ -191,22 +189,31 @@ impl ConnectStyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_dummy_header(prev_blockhash: BlockHash, time: u32) -> BlockHeader {
|
||||||
|
BlockHeader {
|
||||||
|
version: 0x2000_0000,
|
||||||
|
prev_blockhash,
|
||||||
|
merkle_root: TxMerkleNode::all_zeros(),
|
||||||
|
time,
|
||||||
|
bits: 42,
|
||||||
|
nonce: 42,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_dummy_block(prev_blockhash: BlockHash, time: u32, txdata: Vec<Transaction>) -> Block {
|
||||||
|
Block { header: create_dummy_header(prev_blockhash, time), txdata }
|
||||||
|
}
|
||||||
|
|
||||||
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 = node.connect_style.borrow().skips_blocks();
|
let skip_intermediaries = node.connect_style.borrow().skips_blocks();
|
||||||
|
|
||||||
let height = node.best_block_info().1 + 1;
|
let height = node.best_block_info().1 + 1;
|
||||||
let mut block = Block {
|
let mut block = create_dummy_block(node.best_block_hash(), height, Vec::new());
|
||||||
header: BlockHeader { version: 0x2000000, prev_blockhash: node.best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: height, bits: 42, nonce: 42 },
|
|
||||||
txdata: vec![],
|
|
||||||
};
|
|
||||||
assert!(depth >= 1);
|
assert!(depth >= 1);
|
||||||
for i in 1..depth {
|
for i in 1..depth {
|
||||||
let prev_blockhash = block.header.block_hash();
|
let prev_blockhash = block.header.block_hash();
|
||||||
do_connect_block(node, block, skip_intermediaries);
|
do_connect_block(node, block, skip_intermediaries);
|
||||||
block = Block {
|
block = create_dummy_block(prev_blockhash, height + i, Vec::new());
|
||||||
header: BlockHeader { version: 0x20000000, prev_blockhash, merkle_root: TxMerkleNode::all_zeros(), time: height + i, bits: 42, nonce: 42 },
|
|
||||||
txdata: vec![],
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
let hash = block.header.block_hash();
|
let hash = block.header.block_hash();
|
||||||
do_connect_block(node, block, false);
|
do_connect_block(node, block, false);
|
||||||
|
|
|
@ -38,12 +38,11 @@ use crate::util::string::UntrustedString;
|
||||||
use crate::util::config::UserConfig;
|
use crate::util::config::UserConfig;
|
||||||
|
|
||||||
use bitcoin::hash_types::BlockHash;
|
use bitcoin::hash_types::BlockHash;
|
||||||
use bitcoin::blockdata::block::{Block, BlockHeader};
|
|
||||||
use bitcoin::blockdata::script::{Builder, Script};
|
use bitcoin::blockdata::script::{Builder, Script};
|
||||||
use bitcoin::blockdata::opcodes;
|
use bitcoin::blockdata::opcodes;
|
||||||
use bitcoin::blockdata::constants::genesis_block;
|
use bitcoin::blockdata::constants::genesis_block;
|
||||||
use bitcoin::network::constants::Network;
|
use bitcoin::network::constants::Network;
|
||||||
use bitcoin::{PackedLockTime, Sequence, Transaction, TxIn, TxMerkleNode, TxOut, Witness};
|
use bitcoin::{PackedLockTime, Sequence, Transaction, TxIn, TxOut, Witness};
|
||||||
use bitcoin::OutPoint as BitcoinOutPoint;
|
use bitcoin::OutPoint as BitcoinOutPoint;
|
||||||
|
|
||||||
use bitcoin::secp256k1::Secp256k1;
|
use bitcoin::secp256k1::Secp256k1;
|
||||||
|
@ -509,10 +508,7 @@ fn do_test_sanity_on_in_flight_opens(steps: u8) {
|
||||||
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
|
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
|
||||||
|
|
||||||
if steps & 0b1000_0000 != 0{
|
if steps & 0b1000_0000 != 0{
|
||||||
let block = Block {
|
let block = create_dummy_block(nodes[0].best_block_hash(), 42, Vec::new());
|
||||||
header: BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 },
|
|
||||||
txdata: vec![],
|
|
||||||
};
|
|
||||||
connect_block(&nodes[0], &block);
|
connect_block(&nodes[0], &block);
|
||||||
connect_block(&nodes[1], &block);
|
connect_block(&nodes[1], &block);
|
||||||
}
|
}
|
||||||
|
@ -2763,8 +2759,7 @@ fn test_htlc_on_chain_success() {
|
||||||
assert_eq!(node_txn[1].lock_time.0, 0);
|
assert_eq!(node_txn[1].lock_time.0, 0);
|
||||||
|
|
||||||
// Verify that B's ChannelManager is able to extract preimage from HTLC Success tx and pass it backward
|
// Verify that B's ChannelManager is able to extract preimage from HTLC Success tx and pass it backward
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42};
|
connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, vec![commitment_tx[0].clone(), node_txn[0].clone(), node_txn[1].clone()]));
|
||||||
connect_block(&nodes[1], &Block { header, txdata: vec![commitment_tx[0].clone(), node_txn[0].clone(), node_txn[1].clone()]});
|
|
||||||
connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
|
connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
|
||||||
{
|
{
|
||||||
let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap();
|
let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap();
|
||||||
|
@ -2900,8 +2895,7 @@ fn test_htlc_on_chain_success() {
|
||||||
// we already checked the same situation with A.
|
// we already checked the same situation with A.
|
||||||
|
|
||||||
// Verify that A's ChannelManager is able to extract preimage from preimage tx and generate PaymentSent
|
// Verify that A's ChannelManager is able to extract preimage from preimage tx and generate PaymentSent
|
||||||
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42};
|
connect_block(&nodes[0], &create_dummy_block(nodes[0].best_block_hash(), 42, vec![node_a_commitment_tx[0].clone(), commitment_spend.clone()]));
|
||||||
connect_block(&nodes[0], &Block { header, txdata: vec![node_a_commitment_tx[0].clone(), commitment_spend.clone()] });
|
|
||||||
connect_blocks(&nodes[0], TEST_FINAL_CLTV + MIN_CLTV_EXPIRY_DELTA as u32); // Confirm blocks until the HTLC expires
|
connect_blocks(&nodes[0], TEST_FINAL_CLTV + MIN_CLTV_EXPIRY_DELTA as u32); // Confirm blocks until the HTLC expires
|
||||||
check_closed_broadcast!(nodes[0], true);
|
check_closed_broadcast!(nodes[0], true);
|
||||||
check_added_monitors!(nodes[0], 1);
|
check_added_monitors!(nodes[0], 1);
|
||||||
|
@ -3463,15 +3457,15 @@ fn test_htlc_ignore_latest_remote_commitment() {
|
||||||
assert_eq!(node_txn.len(), 3);
|
assert_eq!(node_txn.len(), 3);
|
||||||
assert_eq!(node_txn[0].txid(), node_txn[1].txid());
|
assert_eq!(node_txn[0].txid(), node_txn[1].txid());
|
||||||
|
|
||||||
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
let block = create_dummy_block(nodes[1].best_block_hash(), 42, vec![node_txn[0].clone(), node_txn[1].clone()]);
|
||||||
connect_block(&nodes[1], &Block { header, txdata: vec![node_txn[0].clone(), node_txn[1].clone()]});
|
connect_block(&nodes[1], &block);
|
||||||
check_closed_broadcast!(nodes[1], true);
|
check_closed_broadcast!(nodes[1], true);
|
||||||
check_added_monitors!(nodes[1], 1);
|
check_added_monitors!(nodes[1], 1);
|
||||||
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
|
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
|
||||||
|
|
||||||
// Duplicate the connect_block call since this may happen due to other listeners
|
// Duplicate the connect_block call since this may happen due to other listeners
|
||||||
// registering new transactions
|
// registering new transactions
|
||||||
connect_block(&nodes[1], &Block { header, txdata: vec![node_txn[0].clone(), node_txn[2].clone()]});
|
connect_block(&nodes[1], &block);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -4152,10 +4146,7 @@ fn do_test_htlc_timeout(send_partial_mpp: bool) {
|
||||||
route_payment(&nodes[0], &[&nodes[1]], 100000).1
|
route_payment(&nodes[0], &[&nodes[1]], 100000).1
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut block = Block {
|
let mut block = create_dummy_block(nodes[0].best_block_hash(), 42, Vec::new());
|
||||||
header: BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 },
|
|
||||||
txdata: vec![],
|
|
||||||
};
|
|
||||||
connect_block(&nodes[0], &block);
|
connect_block(&nodes[0], &block);
|
||||||
connect_block(&nodes[1], &block);
|
connect_block(&nodes[1], &block);
|
||||||
let block_count = TEST_FINAL_CLTV + CHAN_CONFIRM_DEPTH + 2 - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS;
|
let block_count = TEST_FINAL_CLTV + CHAN_CONFIRM_DEPTH + 2 - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS;
|
||||||
|
@ -4534,8 +4525,7 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx() {
|
||||||
assert_ne!(revoked_htlc_txn[0].lock_time.0, 0); // HTLC-Timeout
|
assert_ne!(revoked_htlc_txn[0].lock_time.0, 0); // HTLC-Timeout
|
||||||
|
|
||||||
// B will generate justice tx from A's revoked commitment/HTLC tx
|
// B will generate justice tx from A's revoked commitment/HTLC tx
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, vec![revoked_local_txn[0].clone(), revoked_htlc_txn[0].clone()]));
|
||||||
connect_block(&nodes[1], &Block { header, txdata: vec![revoked_local_txn[0].clone(), revoked_htlc_txn[0].clone()] });
|
|
||||||
check_closed_broadcast!(nodes[1], true);
|
check_closed_broadcast!(nodes[1], true);
|
||||||
check_added_monitors!(nodes[1], 1);
|
check_added_monitors!(nodes[1], 1);
|
||||||
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
|
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
|
||||||
|
@ -4605,8 +4595,7 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() {
|
||||||
assert_eq!(revoked_local_txn[0].output[unspent_local_txn_output].script_pubkey.len(), 2 + 20); // P2WPKH
|
assert_eq!(revoked_local_txn[0].output[unspent_local_txn_output].script_pubkey.len(), 2 + 20); // P2WPKH
|
||||||
|
|
||||||
// A will generate justice tx from B's revoked commitment/HTLC tx
|
// A will generate justice tx from B's revoked commitment/HTLC tx
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
connect_block(&nodes[0], &create_dummy_block(nodes[0].best_block_hash(), 42, vec![revoked_local_txn[0].clone(), revoked_htlc_txn[0].clone()]));
|
||||||
connect_block(&nodes[0], &Block { header, txdata: vec![revoked_local_txn[0].clone(), revoked_htlc_txn[0].clone()] });
|
|
||||||
check_closed_broadcast!(nodes[0], true);
|
check_closed_broadcast!(nodes[0], true);
|
||||||
check_added_monitors!(nodes[0], 1);
|
check_added_monitors!(nodes[0], 1);
|
||||||
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
|
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
|
||||||
|
@ -4699,8 +4688,7 @@ fn test_onchain_to_onchain_claim() {
|
||||||
assert_eq!(c_txn[0].lock_time.0, 0); // Success tx
|
assert_eq!(c_txn[0].lock_time.0, 0); // Success tx
|
||||||
|
|
||||||
// So we broadcast C's commitment tx and HTLC-Success on B's chain, we should successfully be able to extract preimage and update downstream monitor
|
// So we broadcast C's commitment tx and HTLC-Success on B's chain, we should successfully be able to extract preimage and update downstream monitor
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42};
|
connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, vec![commitment_tx[0].clone(), c_txn[0].clone()]));
|
||||||
connect_block(&nodes[1], &Block { header, txdata: vec![commitment_tx[0].clone(), c_txn[0].clone()]});
|
|
||||||
check_added_monitors!(nodes[1], 1);
|
check_added_monitors!(nodes[1], 1);
|
||||||
let events = nodes[1].node.get_and_clear_pending_events();
|
let events = nodes[1].node.get_and_clear_pending_events();
|
||||||
assert_eq!(events.len(), 2);
|
assert_eq!(events.len(), 2);
|
||||||
|
@ -5457,10 +5445,7 @@ fn do_htlc_claim_local_commitment_only(use_dust: bool) {
|
||||||
check_added_monitors!(nodes[1], 1);
|
check_added_monitors!(nodes[1], 1);
|
||||||
|
|
||||||
let starting_block = nodes[1].best_block_info();
|
let starting_block = nodes[1].best_block_info();
|
||||||
let mut block = Block {
|
let mut block = create_dummy_block(starting_block.0, 42, Vec::new());
|
||||||
header: BlockHeader { version: 0x20000000, prev_blockhash: starting_block.0, merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 },
|
|
||||||
txdata: vec![],
|
|
||||||
};
|
|
||||||
for _ in starting_block.1 + 1..TEST_FINAL_CLTV - CLTV_CLAIM_BUFFER + starting_block.1 + 2 {
|
for _ in starting_block.1 + 1..TEST_FINAL_CLTV - CLTV_CLAIM_BUFFER + starting_block.1 + 2 {
|
||||||
connect_block(&nodes[1], &block);
|
connect_block(&nodes[1], &block);
|
||||||
block.header.prev_blockhash = block.block_hash();
|
block.header.prev_blockhash = block.block_hash();
|
||||||
|
@ -5490,11 +5475,11 @@ fn do_htlc_claim_current_remote_commitment_only(use_dust: bool) {
|
||||||
// to "time out" the HTLC.
|
// to "time out" the HTLC.
|
||||||
|
|
||||||
let starting_block = nodes[1].best_block_info();
|
let starting_block = nodes[1].best_block_info();
|
||||||
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: starting_block.0, merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
let mut block = create_dummy_block(starting_block.0, 42, Vec::new());
|
||||||
|
|
||||||
for _ in starting_block.1 + 1..TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + starting_block.1 + 2 {
|
for _ in starting_block.1 + 1..TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + starting_block.1 + 2 {
|
||||||
connect_block(&nodes[0], &Block { header, txdata: Vec::new()});
|
connect_block(&nodes[0], &block);
|
||||||
header.prev_blockhash = header.block_hash();
|
block.header.prev_blockhash = block.block_hash();
|
||||||
}
|
}
|
||||||
test_txn_broadcast(&nodes[0], &chan, None, HTLCType::NONE);
|
test_txn_broadcast(&nodes[0], &chan, None, HTLCType::NONE);
|
||||||
check_closed_broadcast!(nodes[0], true);
|
check_closed_broadcast!(nodes[0], true);
|
||||||
|
@ -5536,10 +5521,7 @@ fn do_htlc_claim_previous_remote_commitment_only(use_dust: bool, check_revoke_no
|
||||||
}
|
}
|
||||||
|
|
||||||
let starting_block = nodes[1].best_block_info();
|
let starting_block = nodes[1].best_block_info();
|
||||||
let mut block = Block {
|
let mut block = create_dummy_block(starting_block.0, 42, Vec::new());
|
||||||
header: BlockHeader { version: 0x20000000, prev_blockhash: starting_block.0, merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 },
|
|
||||||
txdata: vec![],
|
|
||||||
};
|
|
||||||
for _ in starting_block.1 + 1..TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + CHAN_CONFIRM_DEPTH + 2 {
|
for _ in starting_block.1 + 1..TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + CHAN_CONFIRM_DEPTH + 2 {
|
||||||
connect_block(&nodes[0], &block);
|
connect_block(&nodes[0], &block);
|
||||||
block.header.prev_blockhash = block.block_hash();
|
block.header.prev_blockhash = block.block_hash();
|
||||||
|
@ -7212,8 +7194,7 @@ fn test_bump_penalty_txn_on_revoked_commitment() {
|
||||||
|
|
||||||
// Actually revoke tx by claiming a HTLC
|
// Actually revoke tx by claiming a HTLC
|
||||||
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
|
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: header_114, merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
connect_block(&nodes[1], &create_dummy_block(header_114, 42, vec![revoked_txn[0].clone()]));
|
||||||
connect_block(&nodes[1], &Block { header, txdata: vec![revoked_txn[0].clone()] });
|
|
||||||
check_added_monitors!(nodes[1], 1);
|
check_added_monitors!(nodes[1], 1);
|
||||||
|
|
||||||
// One or more justice tx should have been broadcast, check it
|
// One or more justice tx should have been broadcast, check it
|
||||||
|
@ -7312,9 +7293,8 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
|
||||||
// Revoke local commitment tx
|
// Revoke local commitment tx
|
||||||
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
|
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
|
||||||
|
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
|
||||||
// B will generate both revoked HTLC-timeout/HTLC-preimage txn from revoked commitment tx
|
// B will generate both revoked HTLC-timeout/HTLC-preimage txn from revoked commitment tx
|
||||||
connect_block(&nodes[1], &Block { header, txdata: vec![revoked_local_txn[0].clone()] });
|
connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, vec![revoked_local_txn[0].clone()]));
|
||||||
check_closed_broadcast!(nodes[1], true);
|
check_closed_broadcast!(nodes[1], true);
|
||||||
check_added_monitors!(nodes[1], 1);
|
check_added_monitors!(nodes[1], 1);
|
||||||
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
|
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
|
||||||
|
@ -7338,10 +7318,10 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
|
||||||
|
|
||||||
// Broadcast set of revoked txn on A
|
// Broadcast set of revoked txn on A
|
||||||
let hash_128 = connect_blocks(&nodes[0], 40);
|
let hash_128 = connect_blocks(&nodes[0], 40);
|
||||||
let header_11 = BlockHeader { version: 0x20000000, prev_blockhash: hash_128, merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
let block_11 = create_dummy_block(hash_128, 42, vec![revoked_local_txn[0].clone()]);
|
||||||
connect_block(&nodes[0], &Block { header: header_11, txdata: vec![revoked_local_txn[0].clone()] });
|
connect_block(&nodes[0], &block_11);
|
||||||
let header_129 = BlockHeader { version: 0x20000000, prev_blockhash: header_11.block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
let block_129 = create_dummy_block(block_11.block_hash(), 42, vec![revoked_htlc_txn[0].clone(), revoked_htlc_txn[1].clone()]);
|
||||||
connect_block(&nodes[0], &Block { header: header_129, txdata: vec![revoked_htlc_txn[0].clone(), revoked_htlc_txn[1].clone()] });
|
connect_block(&nodes[0], &block_129);
|
||||||
let events = nodes[0].node.get_and_clear_pending_events();
|
let events = nodes[0].node.get_and_clear_pending_events();
|
||||||
expect_pending_htlcs_forwardable_from_events!(nodes[0], events[0..1], true);
|
expect_pending_htlcs_forwardable_from_events!(nodes[0], events[0..1], true);
|
||||||
match events.last().unwrap() {
|
match events.last().unwrap() {
|
||||||
|
@ -7392,10 +7372,10 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect one more block to see if bumped penalty are issued for HTLC txn
|
// Connect one more block to see if bumped penalty are issued for HTLC txn
|
||||||
let header_130 = BlockHeader { version: 0x20000000, prev_blockhash: header_129.block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
let block_130 = create_dummy_block(block_129.block_hash(), 42, penalty_txn);
|
||||||
connect_block(&nodes[0], &Block { header: header_130, txdata: penalty_txn });
|
connect_block(&nodes[0], &block_130);
|
||||||
let header_131 = BlockHeader { version: 0x20000000, prev_blockhash: header_130.block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
let block_131 = create_dummy_block(block_130.block_hash(), 42, Vec::new());
|
||||||
connect_block(&nodes[0], &Block { header: header_131, txdata: Vec::new() });
|
connect_block(&nodes[0], &block_131);
|
||||||
|
|
||||||
// Few more blocks to confirm penalty txn
|
// Few more blocks to confirm penalty txn
|
||||||
connect_blocks(&nodes[0], 4);
|
connect_blocks(&nodes[0], 4);
|
||||||
|
@ -7417,8 +7397,7 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
|
||||||
txn
|
txn
|
||||||
};
|
};
|
||||||
// Broadcast claim txn and confirm blocks to avoid further bumps on this outputs
|
// Broadcast claim txn and confirm blocks to avoid further bumps on this outputs
|
||||||
let header_145 = BlockHeader { version: 0x20000000, prev_blockhash: header_144, merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
connect_block(&nodes[0], &create_dummy_block(header_144, 42, node_txn));
|
||||||
connect_block(&nodes[0], &Block { header: header_145, txdata: node_txn });
|
|
||||||
connect_blocks(&nodes[0], 20);
|
connect_blocks(&nodes[0], 20);
|
||||||
{
|
{
|
||||||
let mut node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
|
let mut node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
|
||||||
|
@ -7630,8 +7609,7 @@ fn test_bump_txn_sanitize_tracking_maps() {
|
||||||
node_txn.clear();
|
node_txn.clear();
|
||||||
penalty_txn
|
penalty_txn
|
||||||
};
|
};
|
||||||
let header_130 = BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
connect_block(&nodes[0], &create_dummy_block(nodes[0].best_block_hash(), 42, penalty_txn));
|
||||||
connect_block(&nodes[0], &Block { header: header_130, txdata: penalty_txn });
|
|
||||||
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
|
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
|
||||||
{
|
{
|
||||||
let monitor = nodes[0].chain_monitor.chain_monitor.get_monitor(OutPoint { txid: chan.3.txid(), index: 0 }).unwrap();
|
let monitor = nodes[0].chain_monitor.chain_monitor.get_monitor(OutPoint { txid: chan.3.txid(), index: 0 }).unwrap();
|
||||||
|
@ -8275,14 +8253,7 @@ fn test_secret_timeout() {
|
||||||
} else { panic!(); }
|
} else { panic!(); }
|
||||||
let mut block = {
|
let mut block = {
|
||||||
let node_1_blocks = nodes[1].blocks.lock().unwrap();
|
let node_1_blocks = nodes[1].blocks.lock().unwrap();
|
||||||
Block {
|
create_dummy_block(node_1_blocks.last().unwrap().0.block_hash(), node_1_blocks.len() as u32 + 7200, Vec::new())
|
||||||
header: BlockHeader {
|
|
||||||
version: 0x2000000,
|
|
||||||
prev_blockhash: node_1_blocks.last().unwrap().0.block_hash(),
|
|
||||||
merkle_root: TxMerkleNode::all_zeros(),
|
|
||||||
time: node_1_blocks.len() as u32 + 7200, bits: 42, nonce: 42 },
|
|
||||||
txdata: vec![],
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
connect_block(&nodes[1], &block);
|
connect_block(&nodes[1], &block);
|
||||||
if let Err(APIError::APIMisuseError { err }) = nodes[1].node.create_inbound_payment_for_hash_legacy(payment_hash, Some(100_000), 2) {
|
if let Err(APIError::APIMisuseError { err }) = nodes[1].node.create_inbound_payment_for_hash_legacy(payment_hash, Some(100_000), 2) {
|
||||||
|
@ -8430,8 +8401,7 @@ fn test_update_err_monitor_lockdown() {
|
||||||
assert_eq!(watchtower.watch_channel(outpoint, new_monitor), ChannelMonitorUpdateStatus::Completed);
|
assert_eq!(watchtower.watch_channel(outpoint, new_monitor), ChannelMonitorUpdateStatus::Completed);
|
||||||
watchtower
|
watchtower
|
||||||
};
|
};
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: BlockHash::all_zeros(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
let block = create_dummy_block(BlockHash::all_zeros(), 42, Vec::new());
|
||||||
let block = Block { header, txdata: vec![] };
|
|
||||||
// Make the tx_broadcaster aware of enough blocks that it doesn't think we're violating
|
// Make the tx_broadcaster aware of enough blocks that it doesn't think we're violating
|
||||||
// transaction lock time requirements here.
|
// transaction lock time requirements here.
|
||||||
chanmon_cfgs[0].tx_broadcaster.blocks.lock().unwrap().resize(200, (block.clone(), 200));
|
chanmon_cfgs[0].tx_broadcaster.blocks.lock().unwrap().resize(200, (block.clone(), 200));
|
||||||
|
@ -8501,8 +8471,7 @@ fn test_concurrent_monitor_claim() {
|
||||||
assert_eq!(watchtower.watch_channel(outpoint, new_monitor), ChannelMonitorUpdateStatus::Completed);
|
assert_eq!(watchtower.watch_channel(outpoint, new_monitor), ChannelMonitorUpdateStatus::Completed);
|
||||||
watchtower
|
watchtower
|
||||||
};
|
};
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: BlockHash::all_zeros(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
let block = create_dummy_block(BlockHash::all_zeros(), 42, Vec::new());
|
||||||
let block = Block { header, txdata: vec![] };
|
|
||||||
// Make Alice aware of enough blocks that it doesn't think we're violating transaction lock time
|
// Make Alice aware of enough blocks that it doesn't think we're violating transaction lock time
|
||||||
// requirements here.
|
// requirements here.
|
||||||
const HTLC_TIMEOUT_BROADCAST: u32 = CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS;
|
const HTLC_TIMEOUT_BROADCAST: u32 = CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS;
|
||||||
|
@ -8533,8 +8502,7 @@ fn test_concurrent_monitor_claim() {
|
||||||
assert_eq!(watchtower.watch_channel(outpoint, new_monitor), ChannelMonitorUpdateStatus::Completed);
|
assert_eq!(watchtower.watch_channel(outpoint, new_monitor), ChannelMonitorUpdateStatus::Completed);
|
||||||
watchtower
|
watchtower
|
||||||
};
|
};
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: BlockHash::all_zeros(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
watchtower_bob.chain_monitor.block_connected(&create_dummy_block(BlockHash::all_zeros(), 42, Vec::new()), HTLC_TIMEOUT_BROADCAST - 1);
|
||||||
watchtower_bob.chain_monitor.block_connected(&Block { header, txdata: vec![] }, HTLC_TIMEOUT_BROADCAST - 1);
|
|
||||||
|
|
||||||
// Route another payment to generate another update with still previous HTLC pending
|
// Route another payment to generate another update with still previous HTLC pending
|
||||||
let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 3000000);
|
let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 3000000);
|
||||||
|
@ -8560,8 +8528,7 @@ fn test_concurrent_monitor_claim() {
|
||||||
check_added_monitors!(nodes[0], 1);
|
check_added_monitors!(nodes[0], 1);
|
||||||
|
|
||||||
//// Provide one more block to watchtower Bob, expect broadcast of commitment and HTLC-Timeout
|
//// Provide one more block to watchtower Bob, expect broadcast of commitment and HTLC-Timeout
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: BlockHash::all_zeros(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
watchtower_bob.chain_monitor.block_connected(&create_dummy_block(BlockHash::all_zeros(), 42, Vec::new()), HTLC_TIMEOUT_BROADCAST);
|
||||||
watchtower_bob.chain_monitor.block_connected(&Block { header, txdata: vec![] }, HTLC_TIMEOUT_BROADCAST);
|
|
||||||
|
|
||||||
// Watchtower Bob should have broadcast a commitment/HTLC-timeout
|
// Watchtower Bob should have broadcast a commitment/HTLC-timeout
|
||||||
let bob_state_y;
|
let bob_state_y;
|
||||||
|
@ -8572,12 +8539,11 @@ fn test_concurrent_monitor_claim() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// We confirm Bob's state Y on Alice, she should broadcast a HTLC-timeout
|
// We confirm Bob's state Y on Alice, she should broadcast a HTLC-timeout
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: BlockHash::all_zeros(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
|
||||||
let height = HTLC_TIMEOUT_BROADCAST + 1;
|
let height = HTLC_TIMEOUT_BROADCAST + 1;
|
||||||
connect_blocks(&nodes[0], height - nodes[0].best_block_info().1);
|
connect_blocks(&nodes[0], height - nodes[0].best_block_info().1);
|
||||||
check_closed_broadcast(&nodes[0], 1, true);
|
check_closed_broadcast(&nodes[0], 1, true);
|
||||||
check_closed_event(&nodes[0], 1, ClosureReason::CommitmentTxConfirmed, false);
|
check_closed_event(&nodes[0], 1, ClosureReason::CommitmentTxConfirmed, false);
|
||||||
watchtower_alice.chain_monitor.block_connected(&Block { header, txdata: vec![bob_state_y.clone()] }, height);
|
watchtower_alice.chain_monitor.block_connected(&create_dummy_block(BlockHash::all_zeros(), 42, vec![bob_state_y.clone()]), height);
|
||||||
check_added_monitors(&nodes[0], 1);
|
check_added_monitors(&nodes[0], 1);
|
||||||
{
|
{
|
||||||
let htlc_txn = alice_broadcaster.txn_broadcast();
|
let htlc_txn = alice_broadcaster.txn_broadcast();
|
||||||
|
@ -8652,11 +8618,11 @@ fn test_htlc_no_detection() {
|
||||||
check_spends!(local_txn[0], chan_1.3);
|
check_spends!(local_txn[0], chan_1.3);
|
||||||
|
|
||||||
// Timeout HTLC on A's chain and so it can generate a HTLC-Timeout tx
|
// Timeout HTLC on A's chain and so it can generate a HTLC-Timeout tx
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
let block = create_dummy_block(nodes[0].best_block_hash(), 42, vec![local_txn[0].clone()]);
|
||||||
connect_block(&nodes[0], &Block { header, txdata: vec![local_txn[0].clone()] });
|
connect_block(&nodes[0], &block);
|
||||||
// We deliberately connect the local tx twice as this should provoke a failure calling
|
// We deliberately connect the local tx twice as this should provoke a failure calling
|
||||||
// this test before #653 fix.
|
// this test before #653 fix.
|
||||||
chain::Listen::block_connected(&nodes[0].chain_monitor.chain_monitor, &Block { header, txdata: vec![local_txn[0].clone()] }, nodes[0].best_block_info().1 + 1);
|
chain::Listen::block_connected(&nodes[0].chain_monitor.chain_monitor, &block, nodes[0].best_block_info().1 + 1);
|
||||||
check_closed_broadcast!(nodes[0], true);
|
check_closed_broadcast!(nodes[0], true);
|
||||||
check_added_monitors!(nodes[0], 1);
|
check_added_monitors!(nodes[0], 1);
|
||||||
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
|
check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed);
|
||||||
|
@ -8671,8 +8637,7 @@ fn test_htlc_no_detection() {
|
||||||
node_txn[0].clone()
|
node_txn[0].clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let header_201 = BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
connect_block(&nodes[0], &create_dummy_block(nodes[0].best_block_hash(), 42, vec![htlc_timeout.clone()]));
|
||||||
connect_block(&nodes[0], &Block { header: header_201, txdata: vec![htlc_timeout.clone()] });
|
|
||||||
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
|
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
|
||||||
expect_payment_failed!(nodes[0], our_payment_hash, false);
|
expect_payment_failed!(nodes[0], our_payment_hash, false);
|
||||||
}
|
}
|
||||||
|
@ -8732,8 +8697,7 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain
|
||||||
true => alice_txn.clone(),
|
true => alice_txn.clone(),
|
||||||
false => get_local_commitment_txn!(nodes[1], chan_ab.2)
|
false => get_local_commitment_txn!(nodes[1], chan_ab.2)
|
||||||
};
|
};
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42};
|
connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, vec![txn_to_broadcast[0].clone()]));
|
||||||
connect_block(&nodes[1], &Block { header, txdata: vec![txn_to_broadcast[0].clone()]});
|
|
||||||
if broadcast_alice {
|
if broadcast_alice {
|
||||||
check_closed_broadcast!(nodes[1], true);
|
check_closed_broadcast!(nodes[1], true);
|
||||||
check_added_monitors!(nodes[1], 1);
|
check_added_monitors!(nodes[1], 1);
|
||||||
|
@ -8812,8 +8776,7 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain
|
||||||
let mut txn_to_broadcast = alice_txn.clone();
|
let mut txn_to_broadcast = alice_txn.clone();
|
||||||
if !broadcast_alice { txn_to_broadcast = get_local_commitment_txn!(nodes[1], chan_ab.2); }
|
if !broadcast_alice { txn_to_broadcast = get_local_commitment_txn!(nodes[1], chan_ab.2); }
|
||||||
if !go_onchain_before_fulfill {
|
if !go_onchain_before_fulfill {
|
||||||
let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42};
|
connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, vec![txn_to_broadcast[0].clone()]));
|
||||||
connect_block(&nodes[1], &Block { header, txdata: vec![txn_to_broadcast[0].clone()]});
|
|
||||||
// If Bob was the one to force-close, he will have already passed these checks earlier.
|
// If Bob was the one to force-close, he will have already passed these checks earlier.
|
||||||
if broadcast_alice {
|
if broadcast_alice {
|
||||||
check_closed_broadcast!(nodes[1], true);
|
check_closed_broadcast!(nodes[1], true);
|
||||||
|
|
|
@ -30,8 +30,6 @@ use crate::util::errors::APIError;
|
||||||
use crate::util::ser::Writeable;
|
use crate::util::ser::Writeable;
|
||||||
use crate::util::string::UntrustedString;
|
use crate::util::string::UntrustedString;
|
||||||
|
|
||||||
use bitcoin::{Block, BlockHeader, TxMerkleNode};
|
|
||||||
use bitcoin::hashes::Hash;
|
|
||||||
use bitcoin::network::constants::Network;
|
use bitcoin::network::constants::Network;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -693,8 +691,7 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool, co
|
||||||
check_added_monitors!(nodes[1], 1);
|
check_added_monitors!(nodes[1], 1);
|
||||||
expect_payment_claimed!(nodes[1], payment_hash, 10_000_000);
|
expect_payment_claimed!(nodes[1], payment_hash, 10_000_000);
|
||||||
|
|
||||||
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, vec![node_txn[1].clone()]));
|
||||||
connect_block(&nodes[1], &Block { header, txdata: vec![node_txn[1].clone()]});
|
|
||||||
check_closed_broadcast!(nodes[1], true);
|
check_closed_broadcast!(nodes[1], true);
|
||||||
check_added_monitors!(nodes[1], 1);
|
check_added_monitors!(nodes[1], 1);
|
||||||
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
|
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
|
||||||
|
@ -702,15 +699,13 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool, co
|
||||||
assert_eq!(claim_txn.len(), 1);
|
assert_eq!(claim_txn.len(), 1);
|
||||||
check_spends!(claim_txn[0], node_txn[1]);
|
check_spends!(claim_txn[0], node_txn[1]);
|
||||||
|
|
||||||
header.prev_blockhash = nodes[0].best_block_hash();
|
connect_block(&nodes[0], &create_dummy_block(nodes[0].best_block_hash(), 42, vec![node_txn[1].clone()]));
|
||||||
connect_block(&nodes[0], &Block { header, txdata: vec![node_txn[1].clone()]});
|
|
||||||
|
|
||||||
if confirm_commitment_tx {
|
if confirm_commitment_tx {
|
||||||
connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32 - 1);
|
connect_blocks(&nodes[0], BREAKDOWN_TIMEOUT as u32 - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
header.prev_blockhash = nodes[0].best_block_hash();
|
let claim_block = create_dummy_block(nodes[0].best_block_hash(), 42, if payment_timeout { timeout_txn } else { vec![claim_txn[0].clone()] });
|
||||||
let claim_block = Block { header, txdata: if payment_timeout { timeout_txn } else { vec![claim_txn[0].clone()] } };
|
|
||||||
|
|
||||||
if payment_timeout {
|
if payment_timeout {
|
||||||
assert!(confirm_commitment_tx); // Otherwise we're spending below our CSV!
|
assert!(confirm_commitment_tx); // Otherwise we're spending below our CSV!
|
||||||
|
@ -1522,10 +1517,7 @@ fn do_test_intercepted_payment(test: InterceptTest) {
|
||||||
_ => panic!("Unexpected event")
|
_ => panic!("Unexpected event")
|
||||||
}
|
}
|
||||||
} else if test == InterceptTest::Timeout {
|
} else if test == InterceptTest::Timeout {
|
||||||
let mut block = Block {
|
let mut block = create_dummy_block(nodes[0].best_block_hash(), 42, Vec::new());
|
||||||
header: BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 },
|
|
||||||
txdata: vec![],
|
|
||||||
};
|
|
||||||
connect_block(&nodes[0], &block);
|
connect_block(&nodes[0], &block);
|
||||||
connect_block(&nodes[1], &block);
|
connect_block(&nodes[1], &block);
|
||||||
for _ in 0..TEST_FINAL_CLTV {
|
for _ in 0..TEST_FINAL_CLTV {
|
||||||
|
|
|
@ -19,14 +19,11 @@ use crate::util::test_utils;
|
||||||
use crate::util::ser::Writeable;
|
use crate::util::ser::Writeable;
|
||||||
use crate::util::string::UntrustedString;
|
use crate::util::string::UntrustedString;
|
||||||
|
|
||||||
use bitcoin::blockdata::block::{Block, BlockHeader};
|
|
||||||
use bitcoin::blockdata::script::Builder;
|
use bitcoin::blockdata::script::Builder;
|
||||||
use bitcoin::blockdata::opcodes;
|
use bitcoin::blockdata::opcodes;
|
||||||
use bitcoin::secp256k1::Secp256k1;
|
use bitcoin::secp256k1::Secp256k1;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use bitcoin::hashes::Hash;
|
|
||||||
use bitcoin::TxMerkleNode;
|
|
||||||
|
|
||||||
use crate::ln::functional_test_utils::*;
|
use crate::ln::functional_test_utils::*;
|
||||||
|
|
||||||
|
@ -67,7 +64,6 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) {
|
||||||
check_added_monitors!(nodes[2], 1);
|
check_added_monitors!(nodes[2], 1);
|
||||||
get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
|
get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
|
||||||
|
|
||||||
let mut header = BlockHeader { version: 0x2000_0000, prev_blockhash: nodes[2].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
|
|
||||||
let claim_txn = if local_commitment {
|
let claim_txn = if local_commitment {
|
||||||
// Broadcast node 1 commitment txn to broadcast the HTLC-Timeout
|
// Broadcast node 1 commitment txn to broadcast the HTLC-Timeout
|
||||||
let node_1_commitment_txn = get_local_commitment_txn!(nodes[1], chan_2.2);
|
let node_1_commitment_txn = get_local_commitment_txn!(nodes[1], chan_2.2);
|
||||||
|
@ -77,7 +73,7 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) {
|
||||||
check_spends!(node_1_commitment_txn[1], node_1_commitment_txn[0]);
|
check_spends!(node_1_commitment_txn[1], node_1_commitment_txn[0]);
|
||||||
|
|
||||||
// Give node 2 node 1's transactions and get its response (claiming the HTLC instead).
|
// Give node 2 node 1's transactions and get its response (claiming the HTLC instead).
|
||||||
connect_block(&nodes[2], &Block { header, txdata: node_1_commitment_txn.clone() });
|
connect_block(&nodes[2], &create_dummy_block(nodes[2].best_block_hash(), 42, node_1_commitment_txn.clone()));
|
||||||
check_added_monitors!(nodes[2], 1);
|
check_added_monitors!(nodes[2], 1);
|
||||||
check_closed_broadcast!(nodes[2], true); // We should get a BroadcastChannelUpdate (and *only* a BroadcstChannelUpdate)
|
check_closed_broadcast!(nodes[2], true); // We should get a BroadcastChannelUpdate (and *only* a BroadcstChannelUpdate)
|
||||||
check_closed_event!(nodes[2], 1, ClosureReason::CommitmentTxConfirmed);
|
check_closed_event!(nodes[2], 1, ClosureReason::CommitmentTxConfirmed);
|
||||||
|
@ -88,8 +84,7 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) {
|
||||||
// Make sure node 1's height is the same as the !local_commitment case
|
// Make sure node 1's height is the same as the !local_commitment case
|
||||||
connect_blocks(&nodes[1], 1);
|
connect_blocks(&nodes[1], 1);
|
||||||
// Confirm node 1's commitment txn (and HTLC-Timeout) on node 1
|
// Confirm node 1's commitment txn (and HTLC-Timeout) on node 1
|
||||||
header.prev_blockhash = nodes[1].best_block_hash();
|
connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, node_1_commitment_txn.clone()));
|
||||||
connect_block(&nodes[1], &Block { header, txdata: node_1_commitment_txn.clone() });
|
|
||||||
|
|
||||||
// ...but return node 1's commitment tx in case claim is set and we're preparing to reorg
|
// ...but return node 1's commitment tx in case claim is set and we're preparing to reorg
|
||||||
vec![node_1_commitment_txn[0].clone(), node_2_commitment_txn[0].clone()]
|
vec![node_1_commitment_txn[0].clone(), node_2_commitment_txn[0].clone()]
|
||||||
|
@ -125,11 +120,7 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) {
|
||||||
// Disconnect Node 1's HTLC-Timeout which was connected above
|
// Disconnect Node 1's HTLC-Timeout which was connected above
|
||||||
disconnect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
|
disconnect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
|
||||||
|
|
||||||
let block = Block {
|
connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, claim_txn));
|
||||||
header: BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 },
|
|
||||||
txdata: claim_txn,
|
|
||||||
};
|
|
||||||
connect_block(&nodes[1], &block);
|
|
||||||
|
|
||||||
// ChannelManager only polls chain::Watch::release_pending_monitor_events when we
|
// ChannelManager only polls chain::Watch::release_pending_monitor_events when we
|
||||||
// probe it for events, so we probe non-message events here (which should just be the
|
// probe it for events, so we probe non-message events here (which should just be the
|
||||||
|
@ -137,11 +128,7 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) {
|
||||||
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), true, true);
|
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), true, true);
|
||||||
} else {
|
} else {
|
||||||
// Confirm the timeout tx and check that we fail the HTLC backwards
|
// Confirm the timeout tx and check that we fail the HTLC backwards
|
||||||
let block = Block {
|
connect_block(&nodes[1], &create_dummy_block(nodes[1].best_block_hash(), 42, Vec::new()));
|
||||||
header: BlockHeader { version: 0x20000000, prev_blockhash: nodes[1].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 },
|
|
||||||
txdata: vec![],
|
|
||||||
};
|
|
||||||
connect_block(&nodes[1], &block);
|
|
||||||
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCDestination::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_2.2 }]);
|
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCDestination::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_2.2 }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue