Skip to content

Commit 065d76e

Browse files
author
Antoine Riard
committed
Add getter for Minimum Relay Fee in FeeEstimator
We need to ensure that we respect minrelayfee when computing RBF bumped fee.
1 parent 39b562e commit 065d76e

File tree

7 files changed

+35
-13
lines changed

7 files changed

+35
-13
lines changed

fuzz/fuzz_targets/chanmon_fail_consistency.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ impl FeeEstimator for FuzzEstimator {
6262
fn get_est_sat_per_1000_weight(&self, _: ConfirmationTarget) -> u64 {
6363
253
6464
}
65+
fn get_min_relay_sat_per_1000_weight(&self) -> u64 {
66+
0
67+
}
6568
}
6669

6770
pub struct TestBroadcaster {}

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ impl FeeEstimator for FuzzEstimator {
111111
None => 0
112112
}
113113
}
114+
fn get_min_relay_sat_per_1000_weight(&self) -> u64 {
115+
match self.input.get_slice(2) {
116+
Some(slice) => cmp::max(slice_to_be16(slice) as u64, 20),
117+
None => 0
118+
}
119+
}
114120
}
115121

116122
struct TestBroadcaster {}

src/chain/chaininterface.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ pub trait FeeEstimator: Sync + Send {
109109
/// * satoshis-per-byte * 250
110110
/// * ceil(satoshis-per-kbyte / 4)
111111
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u64;
112+
/// Gets satoshis of minimum relay fee required per 1000 Weight-Units.
113+
///
114+
/// Give us back the minimum relay fee setup by node mempool. It's should be accounted in generic fee
115+
/// computation but in case of RBF we need more granularity on fee composition.
116+
fn get_min_relay_sat_per_1000_weight(&self) -> u64;
112117
}
113118

114119
/// Utility for tracking registered txn/outpoints and checking for matches

src/ln/channel.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4124,12 +4124,16 @@ mod tests {
41244124
use std::sync::Arc;
41254125

41264126
struct TestFeeEstimator {
4127-
fee_est: u64
4127+
fee_est: u64,
4128+
minrelayfee: u64
41284129
}
41294130
impl FeeEstimator for TestFeeEstimator {
41304131
fn get_est_sat_per_1000_weight(&self, _: ConfirmationTarget) -> u64 {
41314132
self.fee_est
41324133
}
4134+
fn get_min_relay_sat_per_1000_weight(&self) -> u64 {
4135+
self.minrelayfee
4136+
}
41334137
}
41344138

41354139
#[test]
@@ -4164,7 +4168,7 @@ mod tests {
41644168
#[test]
41654169
fn outbound_commitment_test() {
41664170
// Test vectors from BOLT 3 Appendix C:
4167-
let feeest = TestFeeEstimator{fee_est: 15000};
4171+
let feeest = TestFeeEstimator{fee_est: 15000, minrelayfee: 0};
41684172
let logger : Arc<Logger> = Arc::new(test_utils::TestLogger::new());
41694173
let secp_ctx = Secp256k1::new();
41704174

src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ pub fn create_network(node_count: usize, node_config: &[Option<UserConfig>]) ->
834834

835835
for i in 0..node_count {
836836
let logger: Arc<Logger> = Arc::new(test_utils::TestLogger::with_id(format!("node {}", i)));
837-
let feeest = Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 });
837+
let feeest = Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253, min_relay_sat_per_kw: 0});
838838
let chain_monitor = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Testnet, Arc::clone(&logger)));
839839
let tx_broadcaster = Arc::new(test_utils::TestBroadcaster{txn_broadcasted: Mutex::new(Vec::new())});
840840
let mut seed = [0; 32];

src/ln/functional_tests.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,7 +3285,7 @@ fn test_no_txn_manager_serialize_deserialize() {
32853285
let mut chan_0_monitor_serialized = test_utils::TestVecWriter(Vec::new());
32863286
nodes[0].chan_monitor.simple_monitor.monitors.lock().unwrap().iter().next().unwrap().1.write_for_disk(&mut chan_0_monitor_serialized).unwrap();
32873287

3288-
nodes[0].chan_monitor = Arc::new(test_utils::TestChannelMonitor::new(nodes[0].chain_monitor.clone(), nodes[0].tx_broadcaster.clone(), Arc::new(test_utils::TestLogger::new()), Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 })));
3288+
nodes[0].chan_monitor = Arc::new(test_utils::TestChannelMonitor::new(nodes[0].chain_monitor.clone(), nodes[0].tx_broadcaster.clone(), Arc::new(test_utils::TestLogger::new()), Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253, min_relay_sat_per_kw: 0})));
32893289
let mut chan_0_monitor_read = &chan_0_monitor_serialized.0[..];
32903290
let (_, chan_0_monitor) = <(Sha256dHash, ChannelMonitor)>::read(&mut chan_0_monitor_read, Arc::new(test_utils::TestLogger::new())).unwrap();
32913291
assert!(chan_0_monitor_read.is_empty());
@@ -3299,7 +3299,7 @@ fn test_no_txn_manager_serialize_deserialize() {
32993299
<(Sha256dHash, ChannelManager)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
33003300
default_config: config,
33013301
keys_manager,
3302-
fee_estimator: Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 }),
3302+
fee_estimator: Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253, min_relay_sat_per_kw: 0}),
33033303
monitor: nodes[0].chan_monitor.clone(),
33043304
chain_monitor: nodes[0].chain_monitor.clone(),
33053305
tx_broadcaster: nodes[0].tx_broadcaster.clone(),
@@ -3351,7 +3351,7 @@ fn test_simple_manager_serialize_deserialize() {
33513351
let mut chan_0_monitor_serialized = test_utils::TestVecWriter(Vec::new());
33523352
nodes[0].chan_monitor.simple_monitor.monitors.lock().unwrap().iter().next().unwrap().1.write_for_disk(&mut chan_0_monitor_serialized).unwrap();
33533353

3354-
nodes[0].chan_monitor = Arc::new(test_utils::TestChannelMonitor::new(nodes[0].chain_monitor.clone(), nodes[0].tx_broadcaster.clone(), Arc::new(test_utils::TestLogger::new()), Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 })));
3354+
nodes[0].chan_monitor = Arc::new(test_utils::TestChannelMonitor::new(nodes[0].chain_monitor.clone(), nodes[0].tx_broadcaster.clone(), Arc::new(test_utils::TestLogger::new()), Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253, min_relay_sat_per_kw: 0})));
33553355
let mut chan_0_monitor_read = &chan_0_monitor_serialized.0[..];
33563356
let (_, chan_0_monitor) = <(Sha256dHash, ChannelMonitor)>::read(&mut chan_0_monitor_read, Arc::new(test_utils::TestLogger::new())).unwrap();
33573357
assert!(chan_0_monitor_read.is_empty());
@@ -3364,7 +3364,7 @@ fn test_simple_manager_serialize_deserialize() {
33643364
<(Sha256dHash, ChannelManager)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
33653365
default_config: UserConfig::new(),
33663366
keys_manager,
3367-
fee_estimator: Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 }),
3367+
fee_estimator: Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253, min_relay_sat_per_kw: 0}),
33683368
monitor: nodes[0].chan_monitor.clone(),
33693369
chain_monitor: nodes[0].chain_monitor.clone(),
33703370
tx_broadcaster: nodes[0].tx_broadcaster.clone(),
@@ -3411,7 +3411,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
34113411
node_0_monitors_serialized.push(writer.0);
34123412
}
34133413

3414-
nodes[0].chan_monitor = Arc::new(test_utils::TestChannelMonitor::new(nodes[0].chain_monitor.clone(), nodes[0].tx_broadcaster.clone(), Arc::new(test_utils::TestLogger::new()), Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 })));
3414+
nodes[0].chan_monitor = Arc::new(test_utils::TestChannelMonitor::new(nodes[0].chain_monitor.clone(), nodes[0].tx_broadcaster.clone(), Arc::new(test_utils::TestLogger::new()), Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253, min_relay_sat_per_kw: 0})));
34153415
let mut node_0_monitors = Vec::new();
34163416
for serialized in node_0_monitors_serialized.iter() {
34173417
let mut read = &serialized[..];
@@ -3425,7 +3425,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
34253425
let (_, nodes_0_deserialized) = <(Sha256dHash, ChannelManager)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
34263426
default_config: UserConfig::new(),
34273427
keys_manager,
3428-
fee_estimator: Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 }),
3428+
fee_estimator: Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253, min_relay_sat_per_kw: 0}),
34293429
monitor: nodes[0].chan_monitor.clone(),
34303430
chain_monitor: nodes[0].chain_monitor.clone(),
34313431
tx_broadcaster: nodes[0].tx_broadcaster.clone(),
@@ -5959,7 +5959,7 @@ fn test_user_configurable_csv_delay() {
59595959

59605960
// We test config.our_to_self > BREAKDOWN_TIMEOUT is enforced in Channel::new_outbound()
59615961
let keys_manager: Arc<KeysInterface> = Arc::new(KeysManager::new(&nodes[0].node_seed, Network::Testnet, Arc::new(test_utils::TestLogger::new()), 10, 20));
5962-
if let Err(error) = Channel::new_outbound(&test_utils::TestFeeEstimator { sat_per_kw: 253 }, &keys_manager, nodes[1].node.get_our_node_id(), 1000000, 1000000, 0, Arc::new(test_utils::TestLogger::new()), &low_our_to_self_config) {
5962+
if let Err(error) = Channel::new_outbound(&test_utils::TestFeeEstimator { sat_per_kw: 253, min_relay_sat_per_kw: 0 }, &keys_manager, nodes[1].node.get_our_node_id(), 1000000, 1000000, 0, Arc::new(test_utils::TestLogger::new()), &low_our_to_self_config) {
59635963
match error {
59645964
APIError::APIMisuseError { err } => { assert_eq!(err, "Configured with an unreasonable our_to_self_delay putting user funds at risks"); },
59655965
_ => panic!("Unexpected event"),
@@ -5970,7 +5970,7 @@ fn test_user_configurable_csv_delay() {
59705970
nodes[1].node.create_channel(nodes[0].node.get_our_node_id(), 1000000, 1000000, 42).unwrap();
59715971
let mut open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id());
59725972
open_channel.to_self_delay = 200;
5973-
if let Err(error) = Channel::new_from_req(&test_utils::TestFeeEstimator { sat_per_kw: 253 }, &keys_manager, nodes[1].node.get_our_node_id(), LocalFeatures::new(), &open_channel, 0, Arc::new(test_utils::TestLogger::new()), &low_our_to_self_config) {
5973+
if let Err(error) = Channel::new_from_req(&test_utils::TestFeeEstimator { sat_per_kw: 253, min_relay_sat_per_kw: 0 }, &keys_manager, nodes[1].node.get_our_node_id(), LocalFeatures::new(), &open_channel, 0, Arc::new(test_utils::TestLogger::new()), &low_our_to_self_config) {
59745974
match error {
59755975
ChannelError::Close(err) => { assert_eq!(err, "Configured with an unreasonable our_to_self_delay putting user funds at risks"); },
59765976
_ => panic!("Unexpected event"),
@@ -5997,7 +5997,7 @@ fn test_user_configurable_csv_delay() {
59975997
nodes[1].node.create_channel(nodes[0].node.get_our_node_id(), 1000000, 1000000, 42).unwrap();
59985998
let mut open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id());
59995999
open_channel.to_self_delay = 200;
6000-
if let Err(error) = Channel::new_from_req(&test_utils::TestFeeEstimator { sat_per_kw: 253 }, &keys_manager, nodes[1].node.get_our_node_id(), LocalFeatures::new(), &open_channel, 0, Arc::new(test_utils::TestLogger::new()), &high_their_to_self_config) {
6000+
if let Err(error) = Channel::new_from_req(&test_utils::TestFeeEstimator { sat_per_kw: 253, min_relay_sat_per_kw: 0 }, &keys_manager, nodes[1].node.get_our_node_id(), LocalFeatures::new(), &open_channel, 0, Arc::new(test_utils::TestLogger::new()), &high_their_to_self_config) {
60016001
match error {
60026002
ChannelError::Close(err) => { assert_eq!(err, "They wanted our payments to be delayed by a needlessly long period"); },
60036003
_ => panic!("Unexpected event"),
@@ -6031,7 +6031,7 @@ fn test_data_loss_protect() {
60316031
let chan_monitor = <(Sha256dHash, ChannelMonitor)>::read(&mut ::std::io::Cursor::new(previous_chan_monitor_state.0), Arc::clone(&logger)).unwrap().1;
60326032
let chain_monitor = Arc::new(ChainWatchInterfaceUtil::new(Network::Testnet, Arc::clone(&logger)));
60336033
let tx_broadcaster = Arc::new(test_utils::TestBroadcaster{txn_broadcasted: Mutex::new(Vec::new())});
6034-
let feeest = Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 });
6034+
let feeest = Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253, min_relay_sat_per_kw: 0 });
60356035
let monitor = Arc::new(test_utils::TestChannelMonitor::new(chain_monitor.clone(), tx_broadcaster.clone(), logger.clone(), feeest.clone()));
60366036
let mut channel_monitors = HashMap::new();
60376037
channel_monitors.insert(OutPoint { txid: chan.3.txid(), index: 0 }, &chan_monitor);

src/util/test_utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ impl Writer for TestVecWriter {
3535

3636
pub struct TestFeeEstimator {
3737
pub sat_per_kw: u64,
38+
pub min_relay_sat_per_kw: u64
3839
}
3940
impl chaininterface::FeeEstimator for TestFeeEstimator {
4041
fn get_est_sat_per_1000_weight(&self, _confirmation_target: ConfirmationTarget) -> u64 {
4142
self.sat_per_kw
4243
}
44+
fn get_min_relay_sat_per_1000_weight(&self) -> u64 {
45+
self.min_relay_sat_per_kw
46+
}
4347
}
4448

4549
pub struct TestChannelMonitor {

0 commit comments

Comments
 (0)