use crate::chain::channelmonitor::MonitorEvent;
use crate::chain::transaction::OutPoint;
use crate::chain::keysinterface;
+use crate::events;
use crate::ln::channelmanager;
use crate::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
use crate::ln::{msgs, wire};
use crate::routing::scoring::{ChannelUsage, Score};
use crate::util::config::UserConfig;
use crate::util::enforcing_trait_impls::{EnforcingSigner, EnforcementState};
-use crate::util::events;
use crate::util::logger::{Logger, Level, Record};
use crate::util::ser::{Readable, ReadableArgs, Writer, Writeable};
fn derive_channel_signer(&self, _channel_value_satoshis: u64, _channel_keys_id: [u8; 32]) -> Self::Signer { unreachable!(); }
fn read_chan_signer(&self, mut reader: &[u8]) -> Result<Self::Signer, msgs::DecodeError> {
- let inner: InMemorySigner = Readable::read(&mut reader)?;
+ let inner: InMemorySigner = ReadableArgs::read(&mut reader, self)?;
let state = Arc::new(Mutex::new(EnforcementState::new()));
Ok(EnforcingSigner::new_with_revoked(
}
impl TestBroadcaster {
- pub fn new(blocks: Arc<Mutex<Vec<(Block, u32)>>>) -> TestBroadcaster {
- TestBroadcaster { txn_broadcasted: Mutex::new(Vec::new()), blocks }
+ pub fn new(network: Network) -> Self {
+ Self {
+ txn_broadcasted: Mutex::new(Vec::new()),
+ blocks: Arc::new(Mutex::new(vec![(genesis_block(network), 0)])),
+ }
+ }
+
+ pub fn with_blocks(blocks: Arc<Mutex<Vec<(Block, u32)>>>) -> Self {
+ Self { txn_broadcasted: Mutex::new(Vec::new()), blocks }
+ }
+
+ pub fn txn_broadcast(&self) -> Vec<Transaction> {
+ self.txn_broadcasted.lock().unwrap().split_off(0)
+ }
+
+ pub fn unique_txn_broadcast(&self) -> Vec<Transaction> {
+ let mut txn = self.txn_broadcasted.lock().unwrap().split_off(0);
+ let mut seen = HashSet::new();
+ txn.retain(|tx| seen.insert(tx.txid()));
+ txn
}
}
fn broadcast_transaction(&self, tx: &Transaction) {
let lock_time = tx.lock_time.0;
assert!(lock_time < 1_500_000_000);
- if lock_time > self.blocks.lock().unwrap().len() as u32 + 1 && lock_time < 500_000_000 {
+ if bitcoin::LockTime::from(tx.lock_time).is_block_height() && lock_time > self.blocks.lock().unwrap().last().unwrap().1 {
for inp in tx.input.iter() {
if inp.sequence != Sequence::MAX {
panic!("We should never broadcast a transaction before its locktime ({})!", tx.lock_time);
/// 1. belongs to the specified module and
/// 2. contains `line` in it.
/// And asserts if the number of occurrences is the same with the given `count`
- pub fn assert_log_contains(&self, module: String, line: String, count: usize) {
+ pub fn assert_log_contains(&self, module: &str, line: &str, count: usize) {
let log_entries = self.lines.lock().unwrap();
let l: usize = log_entries.iter().filter(|&(&(ref m, ref l), _c)| {
- m == &module && l.contains(line.as_str())
+ m == module && l.contains(line)
}).map(|(_, c) | { c }).sum();
assert_eq!(l, count)
}
/// 1. belong to the specified module and
/// 2. match the given regex pattern.
/// Assert that the number of occurrences equals the given `count`
- pub fn assert_log_regex(&self, module: String, pattern: regex::Regex, count: usize) {
+ pub fn assert_log_regex(&self, module: &str, pattern: regex::Regex, count: usize) {
let log_entries = self.lines.lock().unwrap();
let l: usize = log_entries.iter().filter(|&(&(ref m, ref l), _c)| {
- m == &module && pattern.is_match(&l)
+ m == module && pattern.is_match(&l)
}).map(|(_, c) | { c }).sum();
assert_eq!(l, count)
}
fn read_chan_signer(&self, buffer: &[u8]) -> Result<Self::Signer, msgs::DecodeError> {
let mut reader = io::Cursor::new(buffer);
- let inner: InMemorySigner = Readable::read(&mut reader)?;
+ let inner: InMemorySigner = ReadableArgs::read(&mut reader, self)?;
let state = self.make_enforcement_state_cell(inner.commitment_seed);
Ok(EnforcingSigner::new_with_revoked(