Skip to content

Commit eca9943

Browse files
committed
f Account for new MaxDustHTLCExposure enum
1 parent 63656fa commit eca9943

File tree

4 files changed

+86
-12
lines changed

4 files changed

+86
-12
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]
@@ -203,11 +203,18 @@ dictionary ChannelConfig {
203203
u32 forwarding_fee_proportional_millionths = 0;
204204
u32 forwarding_fee_base_msat = 1000;
205205
u16 cltv_expiry_delta = 72;
206-
u64 max_dust_htlc_exposure_msat = 5000000;
206+
MaxDustHTLCExposure max_dust_htlc_exposure;
207207
u64 force_close_avoidance_max_fee_satoshis = 1000;
208208
boolean accept_underpaying_htlcs = false;
209209
};
210210

211+
interface MaxDustHTLCExposure {
212+
[Name=from_fixed_limit]
213+
constructor(u64 limit);
214+
[Name=from_fee_multiplier]
215+
constructor(u64 multiplier);
216+
};
217+
211218
enum LogLevel {
212219
"Gossip",
213220
"Trace",

src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ use error::Error;
100100

101101
pub use event::Event;
102102
pub use types::NetAddress;
103+
pub use types::ChannelConfig;
103104

104105
pub use io::utils::generate_entropy_mnemonic;
105106

@@ -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, Scorer};
122-
pub use types::{ChannelDetails, ChannelId, PeerDetails, UserChannelId};
123+
pub use types::{ChannelDetails, ChannelId, PeerDetails, UserChannelId, MaxDustHTLCExposure};
123124
use wallet::Wallet;
124125

125126
use logger::{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;
@@ -924,7 +925,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
924925
announced_channel: announce_channel,
925926
..Default::default()
926927
},
927-
channel_config: channel_config.unwrap_or_default(),
928+
channel_config: channel_config.unwrap_or_default().into(),
928929
..Default::default()
929930
};
930931

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

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: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use lightning::routing::router::DefaultRouter;
1111
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
1212
use lightning::sign::InMemorySigner;
1313
use lightning::util::ser::{Hostname, Readable, Writeable, Writer};
14-
use lightning_net_tokio::SocketDescriptor;
15-
use lightning_transaction_sync::EsploraSyncClient;
14+
use lightning::util::config::ChannelConfig as LdkChannelConfig;
15+
use lightning::util::config::MaxDustHTLCExposure as LdkMaxDustHTLCExposure;
16+
use lightning_net_tokio::SocketDescriptor; use lightning_transaction_sync::EsploraSyncClient;
1617

1718
use bitcoin::secp256k1::PublicKey;
1819
use bitcoin::OutPoint;
@@ -393,3 +394,68 @@ impl Readable for NetAddress {
393394
Ok(Self(addr))
394395
}
395396
}
397+
398+
/// Options which apply on a per-channel basis.
399+
pub struct ChannelConfig {
400+
/// See documentation of [`LdkChannelConfig::forwarding_fee_proportional_millionths`].
401+
pub forwarding_fee_proportional_millionths: u32,
402+
/// See documentation of [`LdkChannelConfig::forwarding_fee_base_msat`].
403+
pub forwarding_fee_base_msat: u32,
404+
/// See documentation of [`LdkChannelConfig::cltv_expiry_delta`].
405+
pub cltv_expiry_delta: u16,
406+
/// See documentation of [`LdkChannelConfig::max_dust_htlc_exposure`].
407+
pub max_dust_htlc_exposure: Arc<MaxDustHTLCExposure>,
408+
/// See documentation of [`LdkChannelConfig::force_close_avoidance_max_fee_satoshis`].
409+
pub force_close_avoidance_max_fee_satoshis: u64,
410+
/// See documentation of [`LdkChannelConfig::accept_underpaying_htlcs`].
411+
pub accept_underpaying_htlcs: bool,
412+
}
413+
414+
impl From<LdkChannelConfig> for ChannelConfig {
415+
fn from(value: LdkChannelConfig) -> Self {
416+
Self {
417+
forwarding_fee_proportional_millionths: value.forwarding_fee_proportional_millionths,
418+
forwarding_fee_base_msat: value.forwarding_fee_base_msat,
419+
cltv_expiry_delta: value.cltv_expiry_delta,
420+
max_dust_htlc_exposure: Arc::new(MaxDustHTLCExposure(value.max_dust_htlc_exposure)),
421+
force_close_avoidance_max_fee_satoshis: value.force_close_avoidance_max_fee_satoshis,
422+
accept_underpaying_htlcs: value.accept_underpaying_htlcs,
423+
}
424+
}
425+
}
426+
427+
impl From<ChannelConfig> for LdkChannelConfig {
428+
fn from(value: ChannelConfig) -> Self {
429+
Self {
430+
forwarding_fee_proportional_millionths: value.forwarding_fee_proportional_millionths,
431+
forwarding_fee_base_msat: value.forwarding_fee_base_msat,
432+
cltv_expiry_delta: value.cltv_expiry_delta,
433+
max_dust_htlc_exposure: value.max_dust_htlc_exposure.0.clone(),
434+
force_close_avoidance_max_fee_satoshis: value.force_close_avoidance_max_fee_satoshis,
435+
accept_underpaying_htlcs: value.accept_underpaying_htlcs,
436+
}
437+
}
438+
}
439+
440+
impl Default for ChannelConfig {
441+
fn default() -> Self {
442+
LdkChannelConfig::default().into()
443+
}
444+
}
445+
446+
/// Options for how to set the max dust HTLC exposure allowed on a channel.
447+
///
448+
/// See documentation of [`LdkMaxDustHTLCExposure`] for details.
449+
pub struct MaxDustHTLCExposure (pub LdkMaxDustHTLCExposure);
450+
451+
impl MaxDustHTLCExposure {
452+
/// See documentation of [`LdkMaxDustHTLCExposure::FixedLimitMsat`] for details.
453+
pub fn from_fixed_limit(limit_msat: u64) -> Self {
454+
Self ( LdkMaxDustHTLCExposure::FixedLimitMsat(limit_msat) )
455+
}
456+
457+
/// See documentation of [`LdkMaxDustHTLCExposure::FeeRateMultiplier`] for details.
458+
pub fn from_fee_multiplier(multiplier: u64) -> Self {
459+
Self ( LdkMaxDustHTLCExposure::FeeRateMultiplier(multiplier) )
460+
}
461+
}

0 commit comments

Comments
 (0)