Skip to content

Commit aa1635c

Browse files
committed
Upgrade LDK to 0.0.118
1 parent 7ef8932 commit aa1635c

File tree

5 files changed

+57
-25
lines changed

5 files changed

+57
-25
lines changed

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ edition = "2018"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
lightning = { version = "0.0.117", features = ["max_level_trace"] }
12-
lightning-block-sync = { version = "0.0.117", features = [ "rpc-client", "tokio" ] }
13-
lightning-invoice = { version = "0.25.0" }
14-
lightning-net-tokio = { version = "0.0.117" }
15-
lightning-persister = { version = "0.0.117" }
16-
lightning-background-processor = { version = "0.0.117", features = [ "futures" ] }
17-
lightning-rapid-gossip-sync = { version = "0.0.117" }
11+
lightning = { version = "0.0.118", features = ["max_level_trace"] }
12+
lightning-block-sync = { version = "0.0.118", features = [ "rpc-client", "tokio" ] }
13+
lightning-invoice = { version = "0.26.0" }
14+
lightning-net-tokio = { version = "0.0.118" }
15+
lightning-persister = { version = "0.0.118" }
16+
lightning-background-processor = { version = "0.0.118", features = [ "futures" ] }
17+
lightning-rapid-gossip-sync = { version = "0.0.118" }
1818

1919
base64 = "0.13.0"
2020
bitcoin = "0.29.0"

src/bitcoind_client.rs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,23 @@ impl BitcoindClient {
7575
"Failed to make initial call to bitcoind - please check your RPC user/password and access settings")
7676
})?;
7777
let mut fees: HashMap<ConfirmationTarget, AtomicU32> = HashMap::new();
78-
fees.insert(ConfirmationTarget::MempoolMinimum, AtomicU32::new(MIN_FEERATE));
79-
fees.insert(ConfirmationTarget::Background, AtomicU32::new(MIN_FEERATE));
80-
fees.insert(ConfirmationTarget::Normal, AtomicU32::new(2000));
81-
fees.insert(ConfirmationTarget::HighPriority, AtomicU32::new(5000));
78+
fees.insert(ConfirmationTarget::OnChainSweep, AtomicU32::new(5000));
79+
fees.insert(
80+
ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee,
81+
AtomicU32::new(25 * 250),
82+
);
83+
fees.insert(
84+
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
85+
AtomicU32::new(MIN_FEERATE),
86+
);
87+
fees.insert(
88+
ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee,
89+
AtomicU32::new(MIN_FEERATE),
90+
);
91+
fees.insert(ConfirmationTarget::AnchorChannelFee, AtomicU32::new(MIN_FEERATE));
92+
fees.insert(ConfirmationTarget::NonAnchorChannelFee, AtomicU32::new(2000));
93+
fees.insert(ConfirmationTarget::ChannelCloseMinimum, AtomicU32::new(MIN_FEERATE));
94+
8295
let client = Self {
8396
bitcoind_rpc_client: Arc::new(bitcoind_rpc_client),
8497
host,
@@ -162,18 +175,28 @@ impl BitcoindClient {
162175
}
163176
};
164177

165-
fees.get(&ConfirmationTarget::MempoolMinimum)
178+
fees.get(&ConfirmationTarget::OnChainSweep)
179+
.unwrap()
180+
.store(high_prio_estimate, Ordering::Release);
181+
fees.get(&ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee)
182+
.unwrap()
183+
.store(std::cmp::max(25 * 250, high_prio_estimate * 10), Ordering::Release);
184+
fees.get(&ConfirmationTarget::MinAllowedAnchorChannelRemoteFee)
166185
.unwrap()
167186
.store(mempoolmin_estimate, Ordering::Release);
168-
fees.get(&ConfirmationTarget::Background)
187+
fees.get(&ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee)
188+
.unwrap()
189+
.store(background_estimate - 250, Ordering::Release);
190+
fees.get(&ConfirmationTarget::AnchorChannelFee)
169191
.unwrap()
170192
.store(background_estimate, Ordering::Release);
171-
fees.get(&ConfirmationTarget::Normal)
193+
fees.get(&ConfirmationTarget::NonAnchorChannelFee)
172194
.unwrap()
173195
.store(normal_estimate, Ordering::Release);
174-
fees.get(&ConfirmationTarget::HighPriority)
196+
fees.get(&ConfirmationTarget::ChannelCloseMinimum)
175197
.unwrap()
176-
.store(high_prio_estimate, Ordering::Release);
198+
.store(background_estimate, Ordering::Release);
199+
177200
tokio::time::sleep(Duration::from_secs(60)).await;
178201
}
179202
});
@@ -203,7 +226,8 @@ impl BitcoindClient {
203226
// LDK gives us feerates in satoshis per KW but Bitcoin Core here expects fees
204227
// denominated in satoshis per vB. First we need to multiply by 4 to convert weight
205228
// units to virtual bytes, then divide by 1000 to convert KvB to vB.
206-
"fee_rate": self.get_est_sat_per_1000_weight(ConfirmationTarget::Normal) as f64 / 250.0,
229+
"fee_rate": self
230+
.get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee) as f64 / 250.0,
207231
// While users could "cancel" a channel open by RBF-bumping and paying back to
208232
// themselves, we don't allow it here as its easy to have users accidentally RBF bump
209233
// and pay to the channel funding address, which results in loss of funds. Real

src/cli.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use lightning::ln::channelmanager::{PaymentId, RecipientOnionFields, Retry};
1212
use lightning::ln::msgs::SocketAddress;
1313
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage};
1414
use lightning::onion_message::OnionMessagePath;
15-
use lightning::onion_message::{CustomOnionMessageContents, Destination, OnionMessageContents};
15+
use lightning::onion_message::{Destination, OnionMessageContents};
1616
use lightning::routing::gossip::NodeId;
1717
use lightning::routing::router::{PaymentParameters, RouteParameters};
1818
use lightning::sign::{EntropySource, KeysManager};
@@ -48,7 +48,7 @@ struct UserOnionMessageContents {
4848
data: Vec<u8>,
4949
}
5050

51-
impl CustomOnionMessageContents for UserOnionMessageContents {
51+
impl OnionMessageContents for UserOnionMessageContents {
5252
fn tlv_type(&self) -> u64 {
5353
self.tlv_type
5454
}
@@ -445,7 +445,7 @@ pub(crate) fn poll_for_user_input(
445445
let message_path = OnionMessagePath { intermediate_nodes, destination };
446446
match onion_messenger.send_onion_message(
447447
message_path,
448-
OnionMessageContents::Custom(UserOnionMessageContents { tlv_type, data }),
448+
UserOnionMessageContents { tlv_type, data },
449449
None,
450450
) {
451451
Ok(()) => println!("SUCCESS: forwarded onion message to first hop"),

src/main.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub(crate) type GossipVerifier = lightning_block_sync::gossip::GossipVerifier<
139139
Arc<FilesystemLogger>,
140140
SocketDescriptor,
141141
Arc<ChannelManager>,
142-
Arc<SimpleArcOnionMessenger<FilesystemLogger>>,
142+
Arc<OnionMessenger>,
143143
IgnoringMessageHandler,
144144
Arc<KeysManager>,
145145
>;
@@ -158,7 +158,8 @@ pub(crate) type ChannelManager =
158158

159159
pub(crate) type NetworkGraph = gossip::NetworkGraph<Arc<FilesystemLogger>>;
160160

161-
type OnionMessenger = SimpleArcOnionMessenger<FilesystemLogger>;
161+
type OnionMessenger =
162+
SimpleArcOnionMessenger<ChainMonitor, BitcoindClient, BitcoindClient, FilesystemLogger>;
162163

163164
pub(crate) type BumpTxEventHandler = BumpTransactionEventHandler<
164165
Arc<BitcoindClient>,
@@ -358,6 +359,13 @@ async fn handle_ldk_events(
358359
}
359360
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap();
360361
}
362+
Event::InvoiceRequestFailed { payment_id } => {
363+
print!("\nEVENT: Failed to request invoice to send payment with id {}", payment_id);
364+
print!("> ");
365+
io::stdout().flush().unwrap();
366+
367+
// TODO: mark the payment as failed
368+
}
361369
Event::PaymentForwarded {
362370
prev_channel_id,
363371
next_channel_id,
@@ -754,7 +762,7 @@ async fn start_ldk() {
754762
Arc::clone(&keys_manager),
755763
Arc::clone(&logger),
756764
Arc::new(DefaultMessageRouter {}),
757-
IgnoringMessageHandler {},
765+
Arc::clone(&channel_manager),
758766
IgnoringMessageHandler {},
759767
));
760768
let mut ephemeral_bytes = [0; 32];

src/sweep.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ pub(crate) async fn periodic_sweep(
109109
}
110110
let destination_address = bitcoind_client.get_new_address().await;
111111
let output_descriptors = &outputs.iter().map(|a| a).collect::<Vec<_>>();
112-
let tx_feerate =
113-
bitcoind_client.get_est_sat_per_1000_weight(ConfirmationTarget::Background);
112+
let tx_feerate = bitcoind_client
113+
.get_est_sat_per_1000_weight(ConfirmationTarget::ChannelCloseMinimum);
114114

115115
// We set nLockTime to the current height to discourage fee sniping.
116116
// Occasionally randomly pick a nLockTime even further back, so

0 commit comments

Comments
 (0)