Thank you for your interest in contributing to Malachite, a Byzantine Fault Tolerant (BFT) consensus engine written in Rust.
This document provides guidelines and instructions to help you set up your development environment and contribute to the project.
- Setup
- Building the Project
- Running Tests
- Code Style and Guidelines
- Pull Request Process
- Continuous Integration
To build and test Malachite, you need the following tools:
- Rust: Install the latest stable Rust toolchain using rustup
- Protocol Buffers Compiler (protoc): Required for Protobuf message serialization
- Node.js: Required for running Quint
- Quint: A formal specification language used for our model-based tests
- cargo-nextest: An improved test runner for Rust
-
Install Rust:
Via rustup.rs:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Install the Protocol Buffers Compiler:
protoc
is needed for compiling Protobuf definitions used in the test applications to Rust code.For Ubuntu/Debian:
sudo apt-get install protobuf-compiler
For macOS:
brew install protobuf
Please ensure that the version of
protoc
is at least v29.0. -
Install Node.js: (only required for running model-based tests)
Follow the instructions at nodejs.org or use a version manager:
# Using nvm curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash nvm install 21 nvm use 21
-
Install Quint: (only required for running model-based tests)
npm install -g @informalsystems/quint
-
Install cargo-nextest:
cargo install cargo-nextest
-
Fork and clone the repository:
git clone https://github.com/USERNAME/malachite.git cd malachite/code
Note
If you do not intend to contribute code and just want to play around with the codebase,
you can just clone the repository directly: git clone https://github.com/informalsystems/malachite.git
To build the project, run:
cargo build
We have several categories of tests that help ensure the quality and correctness of our code.
cargo all-tests
Or run specific integration tests:
-
Discovery:
cargo nextest run -p informalsystems-malachitebft-discovery-test
-
Starknet app:
cargo nextest run -p informalsystems-malachitebft-starknet-test
-
Test app:
cargo nextest run -p informalsystems-malachitebft-test
Important
For the integration tests to run successfully it is important to ensure that only one integration test is running at a time,
by supplying the --test-threads=1
flag to cargo-nextest
. This is done automatically via the code/.config/nextest.toml
configuration file,
but can be overridden from the command line if needed.
Tip
If you are on a Linux-based system, you can use cargo-maelstrom
to run each test in isolation, concurrently.
cargo install cargo-maelstrom
cargo maelstrom --slots 16
Model-based tests use formal specifications to generate test scenarios and validate system behavior against them.
To run model-based tests:
cargo mbt
We follow Rust's official style guidelines. Before submitting your code, please ensure:
-
Format your code using
rustfmt
:cargo fmt
-
Run Clippy to catch common mistakes and ensure code quality:
cargo lint
- Fork the repository and create your branch from
main
. - Make your changes and ensure all tests pass.
- Update documentation as needed.
- Submit a pull request with a clear description of the changes and any relevant issue numbers.
- Address any feedback from code reviewers.
When submitting a PR, our CI will automatically run all tests, Clippy checks, and formatting verification.
We use GitHub Actions for continuous integration. The following checks run on every PR:
- Unit Tests: Ensures individual components work correctly.
- Integration Tests: Validates component interactions.
- Model-Based Tests: Checks against formal specifications.
- Clippy: Catches common Rust mistakes and enforces best practices.
- Formatting: Ensures consistent code style with rustfmt.
Thank you for contributing to Malachite! If you have any questions, feel free to open an issue or ask the maintainers.