The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
hyperlane-monorepo/rust
Nam Chu Hoai cee9a2d8ef
Add more tracing information (#362)
3 years ago
..
abacus-base Add more tracing information (#362) 3 years ago
abacus-core Remove Outbox nonce and checkpointedRoot from dispatch event (#341) 3 years ago
abacus-test Remove Outbox nonce and checkpointedRoot from dispatch event (#341) 3 years ago
agents Add more tracing information (#362) 3 years ago
chains Add more tracing information (#362) 3 years ago
config Support agents with AWS keys (#361) 3 years ago
helm/abacus-agent Support agents with AWS keys (#361) 3 years ago
tools Support multiple inboxes per domain (#349) 3 years ago
.dockerignore Add rust .dockerignore (#14) 3 years ago
.gitignore Remove docs & all optics-related rust (#322) 3 years ago
Cargo.lock Remove docs & all optics-related rust (#322) 3 years ago
Cargo.toml Remove docs & all optics-related rust (#322) 3 years ago
Dockerfile Dev environment & updated infrastructure (#352) 3 years ago
README.md Rename rust packages (#128) 3 years ago
build.sh Dev environment & updated infrastructure (#352) 3 years ago
release.sh initial dockerfile implementation 4 years ago

README.md

Abacus Rust implementations

Setup

  • install rustup
  • setup pre-commit hooks: cp ../pre-commit.sh ../.git/hooks/pre-commit
    • Note: To bypass pre-commit hooks, pass --no-verify after commit message

Note: You should be running >= version 1.52.1 of the rustc compiler, you can see that version with this command and should see similar output:

$ rustup --version
rustup 1.24.2 (755e2b07e 2021-05-12)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.52.1 (9bc8c42bb 2021-05-09)`

Useful cargo commands

  • cargo doc --open
    • generate documentation and open it in a web browser
  • cargo build
    • compile the project
  • cargo run --example example
    • run the default executable for the current project
  • cargo test
    • run the tests

Useful cargo extensions

  • tree
    • show the dependency tree. Allows searching for specific packages
    • install: cargo install cargo-tree
    • invoke: cargo tree
  • clippy
    • search the codebase for a large number of lints and bad patterns
    • install: rustup component add clippy
    • invoke: cargo clippy
  • expand
    • expand macros and procedural macros. Show the code generated by the preprocessor
    • useful for debugging #[macros] and macros!()
    • install: cargo install cargo-expand
    • invoke cargo expand path::to::module

Architecture

The on-chain portions of Abacus are written in Solidity. The rust portions are exclusively off-chain. Later, there may be on-chain rust for Near/Solana/ Polkadot.

Abacus will be managed by a number of small off-chain programs ("agents"). Each of these will have a specific role. We want these roles to be simple, and easily described. Each of these agents will connect to a home chain and any number of replicas. They need to be configured with chain connection details and have access to a reliable node for each chain.

Some agent sketches:

  • updater
    • Needs only a connection to the home chain
    • Signs upate attestations and submits them to the home chain
  • watcher
    • Observe the home chain
    • Observe as many replicas as possible
    • Cache updates
    • Check for fraud
    • Submit fraud to the home chain
    • if configured, issue emergency stop transactions
  • relayer
    • Relays signed updates from the home to the replica
  • processor
    • retrieve leaves from home chain
    • observe >=1 replica
    • generate proofs for the messages
    • submit messages and proofs to the replica for processing
    • config option: gas params

For Ethereum and Celo connections we use ethers-rs. Please see the docs here.

We use the tokio async runtime environment. Please see the docs here.

Repo layout

  • abacus-core
    • contains implementations of core primitives
    • this includes
      • traits (interfaces) for the on-chain contracts
      • model implementations of the contracts in rust
      • merkle tree implementations (for provers)
  • abacus-base
    • contains shared utilities for building off-chain agents
    • this includes
      • trait implementations for different chains
      • shared configuration file formats
      • basic setup for an off-chain agent
  • chains/abacus-ethereum
    • interfaces to the ethereum contracts
  • agents
    • each of the off-chain agents implemented thus far

High-level guide to building an agent

  • cargo new $AGENT_NAME
  • add the new directory name to the workspace Cargo.toml
  • add dependencies to the new directory's Cargo.toml
    • copy most of the dependencies from abacus-base
  • create a new module in src/$AGENT_NAME.rs
    • add a new struct
    • implement abacus_base::AbacusAgent for your struct
    • your run function is the business logic of your agent
  • create a new settings module src/settings.rs
    • reuse the Settings objects from abacus_base::settings
    • make sure to read the docs :)
    • add your own new settings
  • in $AGENT_NAME/src/main.rs
    • add mod _____ declarations for your agent and settings modules
    • create main and setup functions
    • follow the pattern in abacus-base/src/main.rs
  • make a config folder and a toml file
    • Make sure to include your own settings from above