-
Notifications
You must be signed in to change notification settings - Fork 16
Refactor CCH order with FSM and actions #971
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
doitian
wants to merge
8
commits into
nervosnetwork:develop
Choose a base branch
from
doitian:feature/cch-order-fsm
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7c8f20b to
4d3c383
Compare
This was referenced Nov 28, 2025
4d3c383 to
f8089dd
Compare
Member
Author
|
363a0f5 to
36cf5ff
Compare
fbb132e to
a44401f
Compare
2 tasks
8ddd24e to
de0514e
Compare
Member
Author
|
It's recommended to review this PR by checking out locally and reviewing the whole cch folder. |
de0514e to
7e3d92b
Compare
- Implement a state machine for CCH orders to manage transitions based on incoming invoice and outgoing payment events. - Introduce action dispatchers for handling various order actions, such as sending payments and settling invoices. - Refactor existing code to improve modularity and maintainability, including the separation of event handling and order state management.
- For sending BTC from fiber to lnd, check the fiber payment has been settled successfully. - For receiving BTC from lnd to fiber, check the lnd payment has been settled successfully. Closes nervosnetwork#952
This change improves error handling in CCH (Cross-Chain Hub) actions by distinguishing between permanent and transient errors when sending payments or settling invoices. Permanent failures now result in order state transitions with detailed failure reasons, while transient errors are retried. Additionally, the `tonic` crate is added as a dependency to handle gRPC status codes from LND. The tracking events and state machine are updated to carry optional failure reasons, enabling better diagnostics and more precise order status management. Orders in final states now skip redundant tracking events to avoid unnecessary processing.
7e3d92b to
1eb0e35
Compare
Replaces the fixed 1-second retry delay with exponential backoff to reduce load during persistent failures and improve recovery behavior. Delays start at 1 second and double on each retry, capped at 10 minutes.
- Make cch order db operations synchronous - Added helper methods `get_order_or_none `and `get_active_order_or_none` to CchState to reduce code duplication and centralize the common pattern of handling NotFound errors vs other errors. This also eliminates redundant final status checks.
Introduce a 1-second delay after detecting successful payment receipt in end-to-end tests to ensure downstream processes have sufficient time to stabilize before proceeding.
1eb0e35 to
adb080f
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
This is a stacked PR:
Summary
cch/order/*and adds aCchOrderStateMachinethat translates tracker events into deterministic status transitions and follow-up actions.TrackingEvent/ExecuteActionmessages, and persists/retries FSM-emitted actions instead of relying on the previous ad-hoc settle/send handlers.