Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to LDK 0.0.116 #105

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ panic = 'abort' # Abort on panic
default = []

[dependencies]
lightning = { version = "0.0.115", features = ["max_level_trace", "std"] }
lightning-invoice = { version = "0.23" }
lightning-net-tokio = { version = "0.0.115" }
lightning-persister = { version = "0.0.115" }
lightning-background-processor = { version = "0.0.115", features = ["futures"] }
lightning-rapid-gossip-sync = { version = "0.0.115" }
lightning-transaction-sync = { version = "0.0.115", features = ["esplora-async-https"] }
lightning = { version = "0.0.116", features = ["max_level_trace", "std"] }
lightning-invoice = { version = "0.24.0" }
lightning-net-tokio = { version = "0.0.116" }
lightning-persister = { version = "0.0.116" }
lightning-background-processor = { version = "0.0.116", features = ["futures"] }
lightning-rapid-gossip-sync = { version = "0.0.116" }
lightning-transaction-sync = { version = "0.0.116", features = ["esplora-async-https"] }

#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["max_level_trace", "std"] }
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
Expand Down
34 changes: 21 additions & 13 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ interface LDKNode {
[Throws=NodeError]
void close_channel([ByRef]ChannelId channel_id, PublicKey counterparty_node_id);
[Throws=NodeError]
void update_channel_config([ByRef]ChannelId channel_id, PublicKey counterparty_node_id, [ByRef]ChannelConfig channel_config);
void update_channel_config([ByRef]ChannelId channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
[Throws=NodeError]
void sync_wallets();
[Throws=NodeError]
PaymentHash send_payment([ByRef]Invoice invoice);
PaymentHash send_payment([ByRef]Bolt11Invoice invoice);
[Throws=NodeError]
PaymentHash send_payment_using_amount([ByRef]Invoice invoice, u64 amount_msat);
PaymentHash send_payment_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);
[Throws=NodeError]
PaymentHash send_spontaneous_payment(u64 amount_msat, PublicKey node_id);
[Throws=NodeError]
void send_payment_probe([ByRef]Invoice invoice);
void send_payment_probe([ByRef]Bolt11Invoice invoice);
[Throws=NodeError]
void send_spontaneous_payment_probe(u64 amount_msat, PublicKey node_id);
[Throws=NodeError]
Invoice receive_payment(u64 amount_msat, [ByRef]string description, u32 expiry_secs);
Bolt11Invoice receive_payment(u64 amount_msat, [ByRef]string description, u32 expiry_secs);
[Throws=NodeError]
Invoice receive_variable_amount_payment([ByRef]string description, u32 expiry_secs);
Bolt11Invoice receive_variable_amount_payment([ByRef]string description, u32 expiry_secs);
PaymentDetails? payment([ByRef]PaymentHash payment_hash);
[Throws=NodeError]
boolean remove_payment([ByRef]PaymentHash payment_hash);
Expand Down Expand Up @@ -204,12 +204,20 @@ dictionary PeerDetails {
boolean is_connected;
};

dictionary ChannelConfig {
u32 forwarding_fee_proportional_millionths;
u32 forwarding_fee_base_msat;
u16 cltv_expiry_delta;
u64 max_dust_htlc_exposure_msat;
u64 force_close_avoidance_max_fee_satoshis;
interface ChannelConfig {
constructor();
u32 forwarding_fee_proportional_millionths();
void set_forwarding_fee_proportional_millionths(u32 value);
u32 forwarding_fee_base_msat();
void set_forwarding_fee_base_msat(u32 fee_msat);
u16 cltv_expiry_delta();
void set_cltv_expiry_delta(u16 value);
u64 force_close_avoidance_max_fee_satoshis();
void set_force_close_avoidance_max_fee_satoshis(u64 value_sat);
boolean accept_underpaying_htlcs();
void set_accept_underpaying_htlcs(boolean value);
void set_max_dust_htlc_exposure_from_fixed_limit(u64 limit_msat);
void set_max_dust_htlc_exposure_from_fee_rate_multiplier(u64 multiplier);
};

enum LogLevel {
Expand All @@ -234,7 +242,7 @@ typedef string PublicKey;
typedef string Address;

[Custom]
typedef string Invoice;
typedef string Bolt11Invoice;

[Custom]
typedef string PaymentHash;
Expand Down
24 changes: 14 additions & 10 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::logger::{log_error, FilesystemLogger, Logger};
use crate::payment_store::PaymentStore;
use crate::peer_store::PeerStore;
use crate::types::{
ChainMonitor, ChannelManager, GossipSync, KeysManager, NetAddress, NetworkGraph,
OnionMessenger, PeerManager,
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, NetAddress,
NetworkGraph, OnionMessenger, PeerManager,
};
use crate::wallet::Wallet;
use crate::LogLevel;
Expand All @@ -18,13 +18,15 @@ use crate::{
WALLET_KEYS_SEED_LEN,
};

use lightning::chain::keysinterface::EntropySource;
use lightning::chain::{chainmonitor, BestBlock, Watch};
use lightning::ln::channelmanager::{self, ChainParameters, ChannelManagerReadArgs};
use lightning::ln::msgs::RoutingMessageHandler;
use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler};
use lightning::routing::router::DefaultRouter;
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters};
use lightning::routing::scoring::{
ProbabilisticScorer, ProbabilisticScoringDecayParameters, ProbabilisticScoringFeeParameters,
};
use lightning::sign::EntropySource;

use lightning::util::config::UserConfig;
use lightning::util::ser::ReadableArgs;
Expand Down Expand Up @@ -505,7 +507,7 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
Ok(scorer) => Arc::new(Mutex::new(scorer)),
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
let params = ProbabilisticScoringParameters::default();
let params = ProbabilisticScoringDecayParameters::default();
Arc::new(Mutex::new(ProbabilisticScorer::new(
params,
Arc::clone(&network_graph),
Expand All @@ -517,11 +519,13 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
}
};

let scoring_fee_params = ProbabilisticScoringFeeParameters::default();
let router = Arc::new(DefaultRouter::new(
Arc::clone(&network_graph),
Arc::clone(&logger),
keys_manager.get_secure_random_bytes(),
Arc::clone(&scorer),
scoring_fee_params,
));

// Read ChannelMonitor state from store
Expand Down Expand Up @@ -594,6 +598,7 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
Arc::clone(&keys_manager),
user_config,
chain_params,
cur_time.as_secs() as u32,
)
}
};
Expand All @@ -611,14 +616,12 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&logger),
Arc::new(FakeMessageRouter {}),
IgnoringMessageHandler {},
IgnoringMessageHandler {},
));
let ephemeral_bytes: [u8; 32] = keys_manager.get_secure_random_bytes();

let cur_time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.map_err(|_| BuildError::InvalidSystemTime)?;

// Initialize the GossipSource
// Use the configured gossip source, if the user set one, otherwise default to P2PNetwork.
let gossip_source_config = gossip_source_config.unwrap_or(&GossipSourceConfig::P2PNetwork);
Expand Down Expand Up @@ -658,12 +661,14 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
route_handler: Arc::clone(&p2p_gossip_sync)
as Arc<dyn RoutingMessageHandler + Sync + Send>,
onion_message_handler: onion_messenger,
custom_message_handler: IgnoringMessageHandler {},
},
GossipSync::Rapid(_) => MessageHandler {
chan_handler: Arc::clone(&channel_manager),
route_handler: Arc::new(IgnoringMessageHandler {})
as Arc<dyn RoutingMessageHandler + Sync + Send>,
onion_message_handler: onion_messenger,
custom_message_handler: IgnoringMessageHandler {},
},
GossipSync::None => {
unreachable!("We must always have a gossip sync!");
Expand All @@ -675,7 +680,6 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
cur_time.as_secs().try_into().map_err(|_| BuildError::InvalidSystemTime)?,
&ephemeral_bytes,
Arc::clone(&logger),
IgnoringMessageHandler {},
Arc::clone(&keys_manager),
));

Expand Down
18 changes: 16 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use lightning::util::errors::APIError;
use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};

use bitcoin::secp256k1::{PublicKey, Secp256k1};
use bitcoin::OutPoint;
use bitcoin::{LockTime, OutPoint, PackedLockTime};
use rand::{thread_rng, Rng};
use std::collections::VecDeque;
use std::ops::Deref;
Expand Down Expand Up @@ -270,11 +270,16 @@ where
// channel.
let confirmation_target = ConfirmationTarget::Normal;

// We set nLockTime to the current height to discourage fee sniping.
tnull marked this conversation as resolved.
Show resolved Hide resolved
let cur_height = self.channel_manager.current_best_block().height();
let locktime = LockTime::from_height(cur_height).unwrap_or(LockTime::ZERO);

// Sign the final funding transaction and broadcast it.
match self.wallet.create_funding_transaction(
output_script,
channel_value_satoshis,
confirmation_target,
locktime,
) {
Ok(final_tx) => {
// Give the funding transaction back to LDK for opening the channel.
Expand Down Expand Up @@ -329,6 +334,7 @@ where
via_user_channel_id: _,
claim_deadline: _,
onion_fields: _,
counterparty_skimmed_fee_msat: _,
} => {
if let Some(info) = self.payment_store.get(&payment_hash) {
if info.status == PaymentStatus::Succeeded {
Expand Down Expand Up @@ -556,15 +562,22 @@ where
let output_descriptors = &outputs.iter().collect::<Vec<_>>();
let tx_feerate =
self.wallet.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);

// We set nLockTime to the current height to discourage fee sniping.
let cur_height = self.channel_manager.current_best_block().height();
let locktime: PackedLockTime =
LockTime::from_height(cur_height).map_or(PackedLockTime::ZERO, |l| l.into());
let res = self.keys_manager.spend_spendable_outputs(
output_descriptors,
Vec::new(),
destination_address.script_pubkey(),
tx_feerate,
Some(locktime),
&Secp256k1::new(),
);

match res {
Ok(Some(spending_tx)) => self.wallet.broadcast_transaction(&spending_tx),
Ok(Some(spending_tx)) => self.wallet.broadcast_transactions(&[&spending_tx]),
Ok(None) => {
log_debug!(self.logger, "Omitted spending static outputs: {:?}", outputs);
}
Expand Down Expand Up @@ -747,6 +760,7 @@ where
}
LdkEvent::DiscardFunding { .. } => {}
LdkEvent::HTLCIntercepted { .. } => {}
LdkEvent::BumpTransaction(_) => {}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/io/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::peer_store::PeerStore;
use crate::{Error, EventQueue, PaymentDetails};

use lightning::chain::channelmonitor::ChannelMonitor;
use lightning::chain::keysinterface::{EntropySource, SignerProvider};
use lightning::routing::gossip::NetworkGraph;
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters};
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringDecayParameters};
use lightning::sign::{EntropySource, SignerProvider};
use lightning::util::logger::Logger;
use lightning::util::ser::{Readable, ReadableArgs, Writeable};

Expand Down Expand Up @@ -161,7 +161,7 @@ pub(crate) fn read_scorer<
where
L::Target: Logger,
{
let params = ProbabilisticScoringParameters::default();
let params = ProbabilisticScoringDecayParameters::default();
let mut reader = kv_store.read(SCORER_PERSISTENCE_NAMESPACE, SCORER_PERSISTENCE_KEY)?;
let args = (params, network_graph, logger.clone());
ProbabilisticScorer::read(&mut reader, args).map_err(|e| {
Expand Down
Loading