mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 23:08:36 +01:00
Add a constructor and per-target override to TestFeeEstimator
This will allow us to test `ConfirmationTarget`s used in functional tests by setting an override on just the target we expect to be used.
This commit is contained in:
parent
14720190b0
commit
3f23e3c288
7 changed files with 24 additions and 17 deletions
|
@ -1107,7 +1107,7 @@ mod tests {
|
|||
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};
|
||||
|
||||
|
@ -1126,7 +1126,7 @@ mod tests {
|
|||
#[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>,
|
||||
|
@ -1532,8 +1532,7 @@ mod tests {
|
|||
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()));
|
||||
|
|
|
@ -5016,7 +5016,7 @@ mod tests {
|
|||
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;
|
||||
|
||||
|
@ -5116,7 +5116,7 @@ mod tests {
|
|||
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());
|
||||
|
||||
|
|
|
@ -14198,7 +14198,7 @@ pub mod bench {
|
|||
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);
|
||||
|
|
|
@ -659,7 +659,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
|
|||
// 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() {
|
||||
|
@ -692,7 +692,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
|
|||
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,
|
||||
|
@ -3176,7 +3176,7 @@ pub fn create_chanmon_cfgs(node_count: usize) -> Vec<TestChanMonCfg> {
|
|||
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();
|
||||
|
|
|
@ -7247,7 +7247,7 @@ fn test_user_configurable_csv_delay() {
|
|||
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)
|
||||
{
|
||||
|
@ -7261,7 +7261,7 @@ fn test_user_configurable_csv_delay() {
|
|||
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)
|
||||
{
|
||||
|
@ -7296,7 +7296,7 @@ fn test_user_configurable_csv_delay() {
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,6 @@ use crate::util::config::UserConfig;
|
|||
use bitcoin::hash_types::BlockHash;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::sync::Mutex;
|
||||
|
||||
use crate::ln::functional_test_utils::*;
|
||||
|
||||
|
@ -388,7 +387,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -99,10 +99,19 @@ impl Writer for TestVecWriter {
|
|||
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue