use std::collections::VecDeque;
use std::path::PathBuf;
use std::sync::mpsc::SyncSender;
- use std::sync::{Arc, Mutex};
+ use std::sync::Arc;
use std::time::Duration;
use std::{env, fs};
#[cfg(c_bindings)]
type LockingWrapper<T> = lightning::routing::scoring::MultiThreadedLockableScore<T>;
#[cfg(not(c_bindings))]
- type LockingWrapper<T> = Mutex<T>;
+ type LockingWrapper<T> = std::sync::Mutex<T>;
type ChannelManager = channelmanager::ChannelManager<
Arc<ChainMonitor>,
let mut nodes = Vec::new();
for i in 0..num_nodes {
let tx_broadcaster = Arc::new(test_utils::TestBroadcaster::new(network));
- let fee_estimator =
- Arc::new(test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) });
+ let fee_estimator = Arc::new(test_utils::TestFeeEstimator::new(253));
let logger = Arc::new(test_utils::TestLogger::with_id(format!("node {}", i)));
let genesis_block = genesis_block(network);
let network_graph = Arc::new(NetworkGraph::new(network, logger.clone()));
use crate::util::test_utils::{TestLogger, TestBroadcaster, TestFeeEstimator};
use crate::util::ser::{ReadableArgs, Writeable};
use crate::util::logger::Logger;
- use crate::sync::{Arc, Mutex};
+ use crate::sync::Arc;
use crate::io;
use crate::ln::features::ChannelTypeFeatures;
let secp_ctx = Secp256k1::new();
let logger = Arc::new(TestLogger::new());
let broadcaster = Arc::new(TestBroadcaster::new(Network::Testnet));
- let fee_estimator = TestFeeEstimator { sat_per_kw: Mutex::new(253) };
+ let fee_estimator = TestFeeEstimator::new(253);
let dummy_key = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
let genesis_block = bitcoin::constants::genesis_block(network);
let tx_broadcaster = test_utils::TestBroadcaster::new(network);
- let fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) };
+ let fee_estimator = test_utils::TestFeeEstimator::new(253);
let logger_a = test_utils::TestLogger::with_id("node a".to_owned());
let scorer = RwLock::new(test_utils::TestScorer::new());
let router = test_utils::TestRouter::new(Arc::new(NetworkGraph::new(network, &logger_a)), &logger_a, &scorer);
// Check that if we serialize and then deserialize all our channel monitors we get the
// same set of outputs to watch for on chain as we have now. Note that if we write
// tests that fully close channels and remove the monitors at some point this may break.
- let feeest = test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) };
+ let feeest = test_utils::TestFeeEstimator::new(253);
let mut deserialized_monitors = Vec::new();
{
for (outpoint, _channel_id) in self.chain_monitor.chain_monitor.list_monitors() {
entropy_source: self.keys_manager,
node_signer: self.keys_manager,
signer_provider: self.keys_manager,
- fee_estimator: &test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) },
+ fee_estimator: &test_utils::TestFeeEstimator::new(253),
router: &test_utils::TestRouter::new(Arc::new(network_graph), &self.logger, &scorer),
chain_monitor: self.chain_monitor,
tx_broadcaster: &broadcaster,
let mut chan_mon_cfgs = Vec::new();
for i in 0..node_count {
let tx_broadcaster = test_utils::TestBroadcaster::new(Network::Testnet);
- let fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) };
+ let fee_estimator = test_utils::TestFeeEstimator::new(253);
let chain_source = test_utils::TestChainSource::new(Network::Testnet);
let logger = test_utils::TestLogger::with_id(format!("node {}", i));
let persister = test_utils::TestPersister::new();
let logger = TestLogger::new();
// We test config.our_to_self > BREAKDOWN_TIMEOUT is enforced in OutboundV1Channel::new()
- if let Err(error) = OutboundV1Channel::new(&LowerBoundedFeeEstimator::new(&test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) }),
+ if let Err(error) = OutboundV1Channel::new(&LowerBoundedFeeEstimator::new(&test_utils::TestFeeEstimator::new(253)),
&nodes[0].keys_manager, &nodes[0].keys_manager, nodes[1].node.get_our_node_id(), &nodes[1].node.init_features(), 1000000, 1000000, 0,
&low_our_to_self_config, 0, 42, None, &logger)
{
nodes[1].node.create_channel(nodes[0].node.get_our_node_id(), 1000000, 1000000, 42, None, None).unwrap();
let mut open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id());
open_channel.common_fields.to_self_delay = 200;
- if let Err(error) = InboundV1Channel::new(&LowerBoundedFeeEstimator::new(&test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) }),
+ if let Err(error) = InboundV1Channel::new(&LowerBoundedFeeEstimator::new(&test_utils::TestFeeEstimator::new(253)),
&nodes[0].keys_manager, &nodes[0].keys_manager, nodes[1].node.get_our_node_id(), &nodes[0].node.channel_type_features(), &nodes[1].node.init_features(), &open_channel, 0,
&low_our_to_self_config, 0, &nodes[0].logger, /*is_0conf=*/false)
{
nodes[1].node.create_channel(nodes[0].node.get_our_node_id(), 1000000, 1000000, 42, None, None).unwrap();
let mut open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id());
open_channel.common_fields.to_self_delay = 200;
- if let Err(error) = InboundV1Channel::new(&LowerBoundedFeeEstimator::new(&test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) }),
+ if let Err(error) = InboundV1Channel::new(&LowerBoundedFeeEstimator::new(&test_utils::TestFeeEstimator::new(253)),
&nodes[0].keys_manager, &nodes[0].keys_manager, nodes[1].node.get_our_node_id(), &nodes[0].node.channel_type_features(), &nodes[1].node.init_features(), &open_channel, 0,
&high_their_to_self_config, 0, &nodes[0].logger, /*is_0conf=*/false)
{
use bitcoin::hash_types::BlockHash;
use crate::prelude::*;
-use crate::sync::Mutex;
use crate::ln::functional_test_utils::*;
}
logger = test_utils::TestLogger::new();
- fee_estimator = test_utils::TestFeeEstimator { sat_per_kw: Mutex::new(253) };
+ fee_estimator = test_utils::TestFeeEstimator::new(253);
persister = test_utils::TestPersister::new();
let keys_manager = &chanmon_cfgs[0].keys_manager;
new_chain_monitor = test_utils::TestChainMonitor::new(Some(nodes[0].chain_source), nodes[0].tx_broadcaster, &logger, &fee_estimator, &persister, keys_manager);
pub struct TestFeeEstimator {
pub sat_per_kw: Mutex<u32>,
+ pub target_override: Mutex<HashMap<ConfirmationTarget, u32>>,
+}
+impl TestFeeEstimator {
+ pub fn new(sat_per_kw: u32) -> Self {
+ Self {
+ sat_per_kw: Mutex::new(sat_per_kw),
+ target_override: Mutex::new(new_hash_map()),
+ }
+ }
}
impl chaininterface::FeeEstimator for TestFeeEstimator {
- fn get_est_sat_per_1000_weight(&self, _confirmation_target: ConfirmationTarget) -> u32 {
- *self.sat_per_kw.lock().unwrap()
+ fn get_est_sat_per_1000_weight(&self, conf_target: ConfirmationTarget) -> u32 {
+ *self.target_override.lock().unwrap().get(&conf_target).unwrap_or(&*self.sat_per_kw.lock().unwrap())
}
}