Skip to content

Conversation

@doitian
Copy link
Member

@doitian doitian commented Nov 28, 2025

Summary

  • Compared to feature/cch-monitor-store-changes, this branch moves all CCH order types and DB helpers into cch/order/* and adds a CchOrderStateMachine that translates tracker events into deterministic status transitions and follow-up actions.
  • The CCH actor now handles TrackingEvent/ExecuteAction messages, and persists/retries FSM-emitted actions instead of relying on the previous ad-hoc settle/send handlers.
  • Added action dispatchers/executors for tracking invoices/payments, sending outgoing payments via Fiber or LND, and settling incoming invoices so backend-specific effects stay encapsulated.

@doitian doitian force-pushed the feature/cch-order-fsm branch 2 times, most recently from 7c8f20b to 4d3c383 Compare November 28, 2025 11:26
@doitian doitian changed the title Refactor CCH order FSM and actions Refactor CCH order with FSM and actions Nov 28, 2025
@doitian doitian force-pushed the feature/cch-order-fsm branch from 4d3c383 to f8089dd Compare November 28, 2025 11:36
@doitian doitian linked an issue Nov 28, 2025 that may be closed by this pull request
@doitian doitian marked this pull request as draft December 2, 2025 10:35
@doitian
Copy link
Member Author

doitian commented Dec 2, 2025

@doitian doitian force-pushed the feature/cch-order-fsm branch 9 times, most recently from 363a0f5 to 36cf5ff Compare December 5, 2025 04:34
@doitian doitian marked this pull request as ready for review December 5, 2025 04:36
@doitian doitian force-pushed the feature/cch-order-fsm branch 2 times, most recently from fbb132e to a44401f Compare December 5, 2025 14:03
@doitian doitian linked an issue Dec 8, 2025 that may be closed by this pull request
2 tasks
@doitian doitian force-pushed the feature/cch-order-fsm branch from 8ddd24e to de0514e Compare December 15, 2025 04:31
@doitian
Copy link
Member Author

doitian commented Dec 15, 2025

It's recommended to review this PR by checking out locally and reviewing the whole cch folder.

@doitian doitian mentioned this pull request Dec 17, 2025
9 tasks
@doitian doitian force-pushed the feature/cch-order-fsm branch from de0514e to 7e3d92b Compare December 24, 2025 08:30
- 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.
@doitian doitian force-pushed the feature/cch-order-fsm branch from 7e3d92b to 1eb0e35 Compare December 27, 2025 17:42
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.
@doitian doitian force-pushed the feature/cch-order-fsm branch from 1eb0e35 to adb080f Compare December 29, 2025 03:47
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.

Add more checks in cross-chain-hub e2e test Avoid cch actor name conflicts in tests

1 participant