MCPcopy Index your code
hub / github.com/chainflip-io/chainflip-backend

github.com/chainflip-io/chainflip-backend @10.99.7

Chat with this repo
repository ↗ · DeepWiki ↗ · release 10.99.7 ↗ · + Follow
4,429 symbols 12,643 edges 514 files 694 documented · 16%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

codecov

Chainflip

This repo contains everything you need to run a validator node on the Chainflip network.

Getting started

The project is organised using rust workspaces. See the Cargo.toml in this directory for a list of contained workspaces. Each workspace should have its own README with instructions on how to get started. If not, please raise an issue!

Compile and run tests

To compile the code execute:

cargo build --release

To run the test suite execute:

cargo cf-test-ci

NOTE: ci-test-ci is an alias for cargo test with additional flags.

Contributing

Code style

The best way to ensure that your code is easy to merge, is to copy the project's pre-commit hook into your local .git/ directory. You can do this with:

cp .git-hooks/pre-commit .git/hooks/
chmod +x .git/hooks/pre-commit

Since much of the project is reliant on parity substrate, please take inspiration from parity's Substrate code style where possible. Please see this as a guideline rather than rigidly enforced rules. We will define and enforce formatting rules with rustfmt in due course. It should be straightforward to integrate this with your favourite editor for auto-formatting.

TODO: research and set up .rustfmt and/or .editorconfig settings, and enforce with CI. We may need to have separate settings files for each sub-project since substrate code has some funky settings by default and we may want to stick to a more common setup for our non-substrate components.

Branching and merging

Before making any changes:

  • create a new branch always.
  • give it a descriptive name: feature/my-awesome-feature

When your changes are ready, or you just want some feedback:

  • open a PR.
  • once the PR is open, avoid force-push, use git merge instead of git rebase to merge any upstream changes.

Useful commands

The following commands should be executed from the repo root directory.

  • Check formatting:

cargo fmt --check - Format code:

  • cargo fmt -- <filename>
  • cargo fmt --all (format all packages)
  • Check the state-chain and cfe compile:
  • cargo cf-clippy
  • cargo cf-clippy-ci (This is used by the CI, but you don't typically need it)
  • Run all unit tests:

cargo cf-test - Expand macros for a given part of the code. You'll need to pipe output to a file.

Requires cargo-expand (cargo install cargo-expand):

cargo expand <options> - Clean up old build objects (sometimes this will fix compile problems): - cargo clean - cargo clean -p <package> - Audit external dependencies (The CI runs this https://github.com/chainflip-io/chainflip-backend/issues/1175):

cargo audit

Localnet

You can run a local single-node testnet (Localnet), in Docker. This will allow you to quickly iterate on a particular commit.

Prerequisits

You will need to download Docker, docker-compose and the 1Password CLI 2.

Login to 1Password

The simplest way to login is to go via the 1Password app . Make sure you have v8 of 1Password installed.

Verify you can connect to 1Password with:

op vault ls

Login to Docker

The script will ask you to log in to our Docker container registry. You will need to create a Classic PAT for this.

You only need to enable the packages:read permission.

Creating a Localnet

Localnets use binaries built locally. To create a Localnet for your current branch, you will first need to build. You can use either release or debug builds.

From the repo root, run the following:

cargo cf-build # or cargo cf-build-ci
./localnet/manage.sh

If this is your first Localnet, the script will ask you to authenticate to Docker and 1Password. The script might fail if you haven't done this yet.

After set up completion, you will see the following:

❓ Would you like to build, recreate or destroy your Localnet? (Type 1, 2, 3, 4 or 5)
1) build-localnet
2) recreate
3) destroy
4) logs
5) yeet

Note: All chaindata and signing DBs will be under/tmp/chainflip

  • build - Create a new testnet using a path to the binaries you provide.
  • recreate - This will simply run destroy, followed by build. You have the option to change the path to the binaries.
  • destroy - Destroy your current Localnet and deletes chaindata.
  • logs - Tail the logs for your current Localnet.
  • yeet - Destroy your current Localnet, and remove all data including docker images. You should use this if you are getting some weird caching issues.

Log Filtering

These commands can be used to control which logs the engine outputs at runtime.

  • curl -X GET 127.0.0.1:36079/tracing (Returns the current filtering directives)
  • `curl --json '"debug,warp=off,hyper=off,jsonrpc=off,web3=off,reqwest=off"' (Sets the filter directives so the default is DEBUG, and the logging in modules warp, hyper, jsonrpc, web3, and reqwest is turned off)
  • curl -X POST -H 'Content-Type: application/json' -d '"debug,warp=off,hyper=off,jsonrpc=off,web3=off,reqwest=off"' 127.0.0.1:36079/tracing (Equivalent to the above, but without using the --sjon short-hand)

The RUST_LOG environment variable controls the initial filtering directives if specified at engine startup.

The syntax for specifying filtering directives is given here: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html

Testnet

To start a multi node testnet you can use the chainflip-testnet-tools. A multi-node testnet can be useful to test more complex test scenarios under more realistic conditions.

Extension points exported contracts — how you extend this code

Chain (Interface)
A trait representing all the types and constants that need to be implemented for supported blockchains. [6 implementers]
state-chain/chains/src/lib.rs
Broadcaster (Interface)
Something that is capable of encoding and broadcasting native blockchain api calls to external chains. [7 implementers]
state-chain/traits/src/lib.rs
CanonicalEncoding (Interface)
Defines the commonly agreed-upon byte-encoding used for public keys. [6 implementers]
engine/multisig/src/crypto/key_id.rs
WeightInfo (Interface)
Weight functions needed for pallet_cf_lp. [5 implementers]
state-chain/pallets/cf-lp/src/weights.rs
Config (Interface)
(no doc) [40 implementers]
state-chain/runtime-utilities/src/lib.rs
ExternalChainSource (Interface)
(no doc) [10 implementers]
engine/src/witness/common.rs
PalletInstanceAlias (Interface)
Allows a type to be used as an alias for a pallet `Instance`. [3 implementers]
state-chain/runtime/src/chainflip/chain_instances.rs
KeyUtils (Interface)
(no doc) [3 implementers]
state-chain/cf-integration-tests/src/threshold_signing.rs

Core symbols most depended-on inside this repo

clone
called by 956
engine/src/witness/common/epoch_source.rs
unwrap
called by 627
state-chain/traits/src/async_result.rs
default
called by 412
state-chain/cf-integration-tests/src/genesis.rs
map
called by 327
state-chain/amm/src/common.rs
new_test_ext
called by 263
state-chain/runtime/src/chainflip/missed_authorship_slots.rs
iter
called by 262
utilities/src/with_std/rle_bitmap.rs
into_iter
called by 165
state-chain/amm/src/common.rs
log
called by 148
engine/multisig/src/client/common/failure_reason.rs

Shape

Method 2,077
Function 1,311
Class 632
Interface 213
Enum 196

Languages

Rust96%
TypeScript4%

Modules by API surface

state-chain/traits/src/lib.rs80 symbols
state-chain/pallets/cf-validator/src/lib.rs70 symbols
state-chain/pallets/cf-pools/src/lib.rs64 symbols
state-chain/chains/src/btc.rs61 symbols
state-chain/custom-rpc/src/lib.rs55 symbols
state-chain/chains/src/dot.rs53 symbols
state-chain/pallets/cf-flip/src/lib.rs52 symbols
engine/src/settings.rs50 symbols
engine/multisig/src/client/helpers.rs49 symbols
state-chain/amm/src/range_orders.rs48 symbols
state-chain/runtime/src/chainflip.rs45 symbols
state-chain/chains/src/evm.rs45 symbols

For agents

$ claude mcp add chainflip-backend \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page