|
| 1 | +# Copilot Instructions for Fiber Network Node (FNN) |
| 2 | + |
| 3 | +## Build, test, and lint commands |
| 4 | + |
| 5 | +- Toolchain: Rust `1.93.0` (`rust-toolchain.toml`), default workspace members are `fnn` and `fiber-bin`. |
| 6 | +- Build: |
| 7 | + - `cargo build --locked` |
| 8 | + - `cargo build --release --locked` |
| 9 | + - `make check` (CI-style check matrix: debug/release/no-default-features + migrate crate check) |
| 10 | +- Tests (prefer `nextest`): |
| 11 | + - `cargo nextest run --no-fail-fast` |
| 12 | + - `RUST_TEST_THREADS=2 cargo nextest run --no-fail-fast` (matches CI and `.config/nextest.toml` expectations) |
| 13 | + - `cargo nextest run -p fnn -p fiber-bin` |
| 14 | + - Single test: `cargo nextest run test_name` |
| 15 | + - Single test pattern: `cargo nextest run 'tests::channel::test_name'` |
| 16 | + - Fallback when needed: `RUST_LOG=off cargo test -p fnn -p fiber-bin` |
| 17 | +- Lint/format: |
| 18 | + - `cargo fmt --all -- --check` |
| 19 | + - `cargo clippy --all-targets --all-features -p fnn -p fiber-bin -- -D warnings` |
| 20 | + - `make clippy` (also checks wasm crates) |
| 21 | + - `typos` |
| 22 | + |
| 23 | +## High-level architecture |
| 24 | + |
| 25 | +- Runtime bootstrap is in `crates/fiber-bin/src/main.rs`: |
| 26 | + 1. Parse config and open `Store`. |
| 27 | + 2. Start root actor/task tracking. |
| 28 | + 3. Start CKB chain actor and initialize contracts/chain hash. |
| 29 | + 4. Build `NetworkGraph` and start `NetworkActor` via `start_network`. |
| 30 | + 5. Start built-in watchtower actor (or standalone watchtower RPC client), depending on config. |
| 31 | + 6. Start JSON-RPC server (`rpc::server::start_rpc`) with enabled modules. |
| 32 | +- Core responsibilities in `crates/fiber-lib`: |
| 33 | + - `fiber/`: payment-channel protocol actors and flows (`network`, `channel`, `payment`, `gossip`, `graph`). |
| 34 | + - `ckb/`: CKB integration and on-chain transaction handling. |
| 35 | + - `rpc/`: jsonrpsee RPC modules (`info`, `peer`, `channel`, `payment`, `invoice`, `graph`, etc.). |
| 36 | + - `store/`: persistence traits/impl/schema. |
| 37 | +- Data compatibility flow: |
| 38 | + - Persistent key schema lives in `crates/fiber-lib/src/store/schema.rs`. |
| 39 | + - Storage migrations live in `migrate/src/migrations/` and are validated in CI. |
| 40 | + |
| 41 | +## Key conventions specific to this repository |
| 42 | + |
| 43 | +- Identity boundary: prefer `Pubkey` for business logic and RPC input/output; keep `PeerId` at p2p transport boundaries (multiaddr/session handling). |
| 44 | +- Actor-first design: cross-component interactions should go through actor message enums (`NetworkActorCommand`, `NetworkActorMessage`, service events) rather than direct shared-state mutation. |
| 45 | +- RPC documentation is generated and CI-checked: after RPC API/doc comment changes, run `make gen-rpc-doc` and ensure `make check-dirty-rpc-doc` passes. |
| 46 | +- Persistence changes require migration discipline: when storage structures/keys change, update migration code and run `make check-migrate`. |
| 47 | +- WASM is a first-class target for shared code paths; when touching cross-platform code in `fiber-lib`, keep `cfg` guards intact and run wasm-target clippy via `make clippy`. |
| 48 | +- Test execution is tuned by `.config/nextest.toml` overrides; prefer `nextest` over plain `cargo test` for reliability and CI parity. |
0 commit comments