Skip to content

Commit 6fff268

Browse files
committed
f Account for new MaxDustHTLCExposure enum
1 parent 491a448 commit 6fff268

File tree

4 files changed

+85
-10
lines changed

4 files changed

+85
-10
lines changed

bindings/ldk_node.udl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ interface LDKNode {
6262
[Throws=NodeError]
6363
void close_channel([ByRef]ChannelId channel_id, PublicKey counterparty_node_id);
6464
[Throws=NodeError]
65-
void update_channel_config([ByRef]ChannelId channel_id, PublicKey counterparty_node_id, [ByRef]ChannelConfig channel_config);
65+
void update_channel_config([ByRef]ChannelId channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
6666
[Throws=NodeError]
6767
void sync_wallets();
6868
[Throws=NodeError]
@@ -208,11 +208,18 @@ dictionary ChannelConfig {
208208
u32 forwarding_fee_proportional_millionths = 0;
209209
u32 forwarding_fee_base_msat = 1000;
210210
u16 cltv_expiry_delta = 72;
211-
u64 max_dust_htlc_exposure_msat = 5000000;
211+
MaxDustHTLCExposure max_dust_htlc_exposure;
212212
u64 force_close_avoidance_max_fee_satoshis = 1000;
213213
boolean accept_underpaying_htlcs = false;
214214
};
215215

216+
interface MaxDustHTLCExposure {
217+
[Name=from_fixed_limit]
218+
constructor(u64 limit);
219+
[Name=from_fee_multiplier]
220+
constructor(u64 multiplier);
221+
};
222+
216223
enum LogLevel {
217224
"Gossip",
218225
"Trace",

src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub use error::Error as NodeError;
9999
use error::Error;
100100

101101
pub use event::Event;
102+
pub use types::ChannelConfig;
102103
pub use types::NetAddress;
103104

104105
pub use io::utils::generate_entropy_mnemonic;
@@ -119,7 +120,7 @@ use payment_store::PaymentStore;
119120
pub use payment_store::{PaymentDetails, PaymentDirection, PaymentStatus};
120121
use peer_store::{PeerInfo, PeerStore};
121122
use types::{ChainMonitor, ChannelManager, KeysManager, NetworkGraph, PeerManager, Router, Scorer};
122-
pub use types::{ChannelDetails, ChannelId, PeerDetails, UserChannelId};
123+
pub use types::{ChannelDetails, ChannelId, MaxDustHTLCExposure, PeerDetails, UserChannelId};
123124
use wallet::Wallet;
124125

125126
use logger::{log_debug, log_error, log_info, log_trace, FilesystemLogger, Logger};
@@ -129,7 +130,7 @@ use lightning::ln::channelmanager::{self, PaymentId, RecipientOnionFields, Retry
129130
use lightning::ln::{PaymentHash, PaymentPreimage};
130131
use lightning::sign::EntropySource;
131132

132-
use lightning::util::config::{ChannelConfig, ChannelHandshakeConfig, UserConfig};
133+
use lightning::util::config::{ChannelHandshakeConfig, UserConfig};
133134
pub use lightning::util::logger::Level as LogLevel;
134135

135136
use lightning_background_processor::process_events_async;
@@ -925,7 +926,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
925926
announced_channel: announce_channel,
926927
..Default::default()
927928
},
928-
channel_config: channel_config.unwrap_or_default(),
929+
channel_config: channel_config.unwrap_or_default().into(),
929930
..Default::default()
930931
};
931932

@@ -1029,10 +1030,10 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
10291030
/// Update the config for a previously opened channel.
10301031
pub fn update_channel_config(
10311032
&self, channel_id: &ChannelId, counterparty_node_id: PublicKey,
1032-
channel_config: &ChannelConfig,
1033+
channel_config: ChannelConfig,
10331034
) -> Result<(), Error> {
10341035
self.channel_manager
1035-
.update_channel_config(&counterparty_node_id, &[channel_id.0], channel_config)
1036+
.update_channel_config(&counterparty_node_id, &[channel_id.0], &channel_config.into())
10361037
.map_err(|_| Error::ChannelConfigUpdateFailed)
10371038
}
10381039

src/test/functional_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
137137
};
138138

139139
println!("\nB receive_payment");
140-
let invoice_amount_1_msat = 1000000;
140+
let invoice_amount_1_msat = 2500_000;
141141
let invoice = node_b.receive_payment(invoice_amount_1_msat, &"asdf", 9217).unwrap();
142142

143143
println!("\nA send_payment");
@@ -181,7 +181,7 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
181181
assert_eq!(node_b.payment(&payment_hash).unwrap().amount_msat, Some(invoice_amount_1_msat));
182182

183183
// Test under-/overpayment
184-
let invoice_amount_2_msat = 1000_000;
184+
let invoice_amount_2_msat = 2500_000;
185185
let invoice = node_b.receive_payment(invoice_amount_2_msat, &"asdf", 9217).unwrap();
186186

187187
let underpaid_amount = invoice_amount_2_msat - 1;
@@ -214,7 +214,7 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
214214

215215
// Test "zero-amount" invoice payment
216216
let variable_amount_invoice = node_b.receive_variable_amount_payment(&"asdf", 9217).unwrap();
217-
let determined_amount_msat = 1234_567;
217+
let determined_amount_msat = 2345_678;
218218
assert_eq!(Err(Error::InvalidInvoice), node_a.send_payment(&variable_amount_invoice));
219219
let payment_hash =
220220
node_a.send_payment_using_amount(&variable_amount_invoice, determined_amount_msat).unwrap();

src/types.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use lightning::routing::gossip;
1010
use lightning::routing::router::DefaultRouter;
1111
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
1212
use lightning::sign::InMemorySigner;
13+
use lightning::util::config::ChannelConfig as LdkChannelConfig;
14+
use lightning::util::config::MaxDustHTLCExposure as LdkMaxDustHTLCExposure;
1315
use lightning::util::ser::{Hostname, Readable, Writeable, Writer};
1416
use lightning_net_tokio::SocketDescriptor;
1517
use lightning_transaction_sync::EsploraSyncClient;
@@ -393,3 +395,68 @@ impl Readable for NetAddress {
393395
Ok(Self(addr))
394396
}
395397
}
398+
399+
/// Options which apply on a per-channel basis.
400+
pub struct ChannelConfig {
401+
/// See documentation of [`LdkChannelConfig::forwarding_fee_proportional_millionths`].
402+
pub forwarding_fee_proportional_millionths: u32,
403+
/// See documentation of [`LdkChannelConfig::forwarding_fee_base_msat`].
404+
pub forwarding_fee_base_msat: u32,
405+
/// See documentation of [`LdkChannelConfig::cltv_expiry_delta`].
406+
pub cltv_expiry_delta: u16,
407+
/// See documentation of [`LdkChannelConfig::max_dust_htlc_exposure`].
408+
pub max_dust_htlc_exposure: Arc<MaxDustHTLCExposure>,
409+
/// See documentation of [`LdkChannelConfig::force_close_avoidance_max_fee_satoshis`].
410+
pub force_close_avoidance_max_fee_satoshis: u64,
411+
/// See documentation of [`LdkChannelConfig::accept_underpaying_htlcs`].
412+
pub accept_underpaying_htlcs: bool,
413+
}
414+
415+
impl From<LdkChannelConfig> for ChannelConfig {
416+
fn from(value: LdkChannelConfig) -> Self {
417+
Self {
418+
forwarding_fee_proportional_millionths: value.forwarding_fee_proportional_millionths,
419+
forwarding_fee_base_msat: value.forwarding_fee_base_msat,
420+
cltv_expiry_delta: value.cltv_expiry_delta,
421+
max_dust_htlc_exposure: Arc::new(MaxDustHTLCExposure(value.max_dust_htlc_exposure)),
422+
force_close_avoidance_max_fee_satoshis: value.force_close_avoidance_max_fee_satoshis,
423+
accept_underpaying_htlcs: value.accept_underpaying_htlcs,
424+
}
425+
}
426+
}
427+
428+
impl From<ChannelConfig> for LdkChannelConfig {
429+
fn from(value: ChannelConfig) -> Self {
430+
Self {
431+
forwarding_fee_proportional_millionths: value.forwarding_fee_proportional_millionths,
432+
forwarding_fee_base_msat: value.forwarding_fee_base_msat,
433+
cltv_expiry_delta: value.cltv_expiry_delta,
434+
max_dust_htlc_exposure: value.max_dust_htlc_exposure.0.clone(),
435+
force_close_avoidance_max_fee_satoshis: value.force_close_avoidance_max_fee_satoshis,
436+
accept_underpaying_htlcs: value.accept_underpaying_htlcs,
437+
}
438+
}
439+
}
440+
441+
impl Default for ChannelConfig {
442+
fn default() -> Self {
443+
LdkChannelConfig::default().into()
444+
}
445+
}
446+
447+
/// Options for how to set the max dust HTLC exposure allowed on a channel.
448+
///
449+
/// See documentation of [`LdkMaxDustHTLCExposure`] for details.
450+
pub struct MaxDustHTLCExposure(pub LdkMaxDustHTLCExposure);
451+
452+
impl MaxDustHTLCExposure {
453+
/// See documentation of [`LdkMaxDustHTLCExposure::FixedLimitMsat`] for details.
454+
pub fn from_fixed_limit(limit_msat: u64) -> Self {
455+
Self(LdkMaxDustHTLCExposure::FixedLimitMsat(limit_msat))
456+
}
457+
458+
/// See documentation of [`LdkMaxDustHTLCExposure::FeeRateMultiplier`] for details.
459+
pub fn from_fee_multiplier(multiplier: u64) -> Self {
460+
Self(LdkMaxDustHTLCExposure::FeeRateMultiplier(multiplier))
461+
}
462+
}

0 commit comments

Comments
 (0)