Skip to content

Let BackgroundProcessor drive HTLC forwarding #3891

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

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
61348b1
Add copyright header to `lightning-background-processor/src/lib.rs`
tnull Jun 25, 2025
d0cb0d6
Drop forwarding/holding-cell related `rustfmt::skip`s
tnull Jun 24, 2025
9223399
Post-`rustfmt` cleanup
tnull Jun 24, 2025
d672df7
f Address Val's comments
tnull Jul 4, 2025
82f8a59
Prefactor: Switch `TIMER`s to be `Duration`s
tnull Jun 25, 2025
03f052d
Let `BackgroundProcessor` drive HTLC forwarding
tnull Jun 24, 2025
18c8ed3
f No need for interior mutability
tnull Jul 3, 2025
29b13ad
f Change comment
tnull Jul 4, 2025
fa60ba7
Randomly draw forwarding delays
tnull Jun 24, 2025
9e9510c
f Fix clippy lint
tnull Jun 26, 2025
eaa76a6
f Account for `usize` not always being 8 bytes
tnull Jul 2, 2025
a235a0b
Drop `PendingHTLCsForwardable` event
tnull Jun 25, 2025
051b504
f Fix length check in `expect_payment_failed_condition_event`
tnull Jul 2, 2025
ebf8a4d
f Drop `expect_pending_htlcs_forwardable`
tnull Jun 26, 2025
b09f7b8
f Drop `expect_pending_htlcs_forwardable_conditions` macro
tnull Jun 26, 2025
e9fd301
f Drop `expect_pending_htlcs_forwardable_.._ignore` macro
tnull Jun 26, 2025
bb75d79
f Drop `expect_pending_htlcs_forwardable_ignore` macro
tnull Jun 26, 2025
6a3081f
f Rename `expect..and_htlc_handling_failed` macro
tnull Jun 27, 2025
66da430
f Rename `expect_pending_htlcs_forwardable_conditions`
tnull Jun 27, 2025
e309c4e
f Adjust helper docs
tnull Jun 27, 2025
4740d01
f Try fix fuzzer
tnull Jun 27, 2025
0236418
Use `optionally_notify` in `process_pending_htlc_forwards`
tnull Jul 3, 2025
7758838
Skip unnecessary persists in `process_pending_htlc_forwards`
tnull Jul 3, 2025
eb83451
Add reenatrancy guard for `process_pending_htlc_forwards`
tnull Jul 3, 2025
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
31 changes: 3 additions & 28 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ use bitcoin::secp256k1::{self, Message, PublicKey, Scalar, Secp256k1, SecretKey}
use lightning::util::dyn_signer::DynSigner;

use std::cell::RefCell;
use std::cmp::{self, Ordering};
use std::cmp;
use std::mem;
use std::sync::atomic;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -1304,28 +1304,6 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
// deduplicate the calls here.
let mut claim_set = new_hash_map();
let mut events = nodes[$node].get_and_clear_pending_events();
// Sort events so that PendingHTLCsForwardable get processed last. This avoids a
// case where we first process a PendingHTLCsForwardable, then claim/fail on a
// PaymentClaimable, claiming/failing two HTLCs, but leaving a just-generated
// PaymentClaimable event for the second HTLC in our pending_events (and breaking
// our claim_set deduplication).
events.sort_by(|a, b| {
if let events::Event::PaymentClaimable { .. } = a {
if let events::Event::PendingHTLCsForwardable { .. } = b {
Ordering::Less
} else {
Ordering::Equal
}
} else if let events::Event::PendingHTLCsForwardable { .. } = a {
if let events::Event::PaymentClaimable { .. } = b {
Ordering::Greater
} else {
Ordering::Equal
}
} else {
Ordering::Equal
}
});
let had_events = !events.is_empty();
for event in events.drain(..) {
match event {
Expand All @@ -1352,9 +1330,6 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
},
events::Event::PaymentForwarded { .. } if $node == 1 => {},
events::Event::ChannelReady { .. } => {},
events::Event::PendingHTLCsForwardable { .. } => {
nodes[$node].process_pending_htlc_forwards();
},
events::Event::HTLCHandlingFailed { .. } => {},
_ => {
if out.may_fail.load(atomic::Ordering::Acquire) {
Expand All @@ -1365,6 +1340,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
},
}
}
nodes[$node].process_pending_htlc_forwards();
had_events
}};
}
Expand Down Expand Up @@ -1806,8 +1782,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
last_pass_no_updates = false;
continue;
}
// ...making sure any pending PendingHTLCsForwardable events are handled and
// payments claimed.
// ...making sure any payments are claimed.
if process_events!(0, false) {
last_pass_no_updates = false;
continue;
Expand Down
9 changes: 1 addition & 8 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
let mut loss_detector =
MoneyLossDetector::new(&peers, channelmanager.clone(), monitor.clone(), peer_manager);

let mut should_forward = false;
let mut payments_received: Vec<PaymentHash> = Vec::new();
let mut intercepted_htlcs: Vec<InterceptId> = Vec::new();
let mut payments_sent: u16 = 0;
Expand Down Expand Up @@ -785,10 +784,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
}
},
7 => {
if should_forward {
channelmanager.process_pending_htlc_forwards();
should_forward = false;
}
channelmanager.process_pending_htlc_forwards();
},
8 => {
for payment in payments_received.drain(..) {
Expand Down Expand Up @@ -1004,9 +1000,6 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
//TODO: enhance by fetching random amounts from fuzz input?
payments_received.push(payment_hash);
},
Event::PendingHTLCsForwardable { .. } => {
should_forward = true;
},
Event::HTLCIntercepted { intercept_id, .. } => {
if !intercepted_htlcs.contains(&intercept_id) {
intercepted_htlcs.push(intercept_id);
Expand Down
1 change: 1 addition & 0 deletions lightning-background-processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bitcoin-io = { version = "0.1.2", default-features = false }
lightning = { version = "0.2.0", path = "../lightning", default-features = false }
lightning-rapid-gossip-sync = { version = "0.2.0", path = "../lightning-rapid-gossip-sync", default-features = false }
lightning-liquidity = { version = "0.2.0", path = "../lightning-liquidity", default-features = false }
possiblyrandom = { version = "0.2", path = "../possiblyrandom", default-features = false }

[dev-dependencies]
tokio = { version = "1.35", features = [ "macros", "rt", "rt-multi-thread", "sync", "time" ] }
Expand Down
485 changes: 485 additions & 0 deletions lightning-background-processor/src/fwd_batch.rs

Large diffs are not rendered by default.

Loading
Loading