Skip to content

add test for handling failed RGB forward swaps#121

Open
Arshia-r-m wants to merge 1 commit intoRGB-Tools:masterfrom
Arshia-r-m:test/htlc_failure_handling
Open

add test for handling failed RGB forward swaps#121
Arshia-r-m wants to merge 1 commit intoRGB-Tools:masterfrom
Arshia-r-m:test/htlc_failure_handling

Conversation

@Arshia-r-m
Copy link
Copy Markdown
Contributor

prove the problem on #119

Copilot AI review requested due to automatic review settings April 17, 2026 09:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a regression test intended to reproduce Issue #119 (“swaps stuck in PENDING”) by simulating a failed RGB forward during an intercepted swap, plus a small test-only fault-injection hook in the LDK event handler to trigger the failure path deterministically.

Changes:

  • Add a new swap roundtrip test that expects the taker swap to be marked Failed when RGB forwarding fails.
  • Introduce a #[cfg(test)] global flag to force the next intercepted swap RGB forward to fail by altering the outbound RGB payment amount.
  • Register the new test module in src/test/mod.rs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/test/swap_roundtrip_fail_forward.rs New test that reproduces the stuck-Pending behavior by forcing an RGB forward failure and asserting swaps reach Failed.
src/test/mod.rs Adds the new test module to the test suite.
src/ldk.rs Adds a test-only failure injection flag and uses it to mutate outbound RGB payment during Event::HTLCIntercepted forwarding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +91 to +98
// This assertion documents the expected behavior and currently fails because the
// HTLCHandlingFailed event is ignored, leaving the taker swap stuck as Pending.
wait_for_swap_status(
taker_addr,
&maker_init_response.payment_hash,
SwapStatus::Failed,
)
.await;
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test currently asserts taker reaches SwapStatus::Failed, but the comment indicates this is known to fail (taker stays Pending). As written it will make cargo test hang up to 70s and then fail CI. If the fix isn’t included in this PR, mark the test #[ignore] (or otherwise gate it) so the suite stays green; alternatively, include the production fix so the assertion can pass reliably.

Copilot uses AI. Check for mistakes.
Comment on lines +72 to +74
crate::ldk::FORCE_NEXT_INTERCEPTED_SWAP_RGB_FORWARD_FAILURE
.store(true, std::sync::atomic::Ordering::SeqCst);

Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global FORCE_NEXT_INTERCEPTED_SWAP_RGB_FORWARD_FAILURE flag is set here but only reset when an intercepted HTLC is processed (via swap(false, ...)). If this test fails/panics before that event occurs, the flag can remain true and potentially affect later tests in the same run. Consider resetting it back to false with a small RAII drop-guard (or an explicit cleanup in a finally-style block) to prevent cross-test contamination.

Copilot uses AI. Check for mistakes.
Comment thread src/ldk.rs Outdated
@Arshia-r-m Arshia-r-m force-pushed the test/htlc_failure_handling branch from f9407d7 to 0c05618 Compare April 17, 2026 10:53
@Arshia-r-m Arshia-r-m force-pushed the test/htlc_failure_handling branch from 0c05618 to 8689530 Compare April 17, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants