[![Crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
[![Build Status][build-image]][build-link]
[![Apache 2.0 Licensed][license-image]][license-link]
[![cargo-audit][cargo-audit-image]][cargo-audit-link]
<p align="center">
<a href="https://alephzero.org" target="_blank">
<img src="https://alephzero.org/wp-content/uploads/A0_logotype_bft_dark.jpg" />
</a>
</p>
### Overview
AlephBFT is an asynchronous and Byzantine fault tolerant consensus protocol aimed
at ordering arbitrary messages (transactions). It has been designed to operate
continuously under conditions where there is no bound on message-delivery delay
and under the assumption that there is a significant probability of malicious
behavior, making it an excellent fit for blockchain-related applications.
For more information, check [the white paper][paper-link].
This repository contains a Rust implementation of AlephBFT that offers a convenient
API enabling seamless application to various problems. The prime application of
the repository is the consensus engine (sometimes called the "finality gadget")
of the [Aleph Zero blockchain][aleph-node-link].
The code is split into several Rust packages, each having its own directory -
see the `Cargo.toml` file, which defines the layout of the whole workspace.
The main package, `aleph-bft`, is located in the `consensus` directory.
Additionally, every other package has a short README describing its role
in the AlephBFT toolset.
### Documentation
Every package is documented on [docs.rs][docs-link]. Comprehensive documentation
is available as a [mdBook][reference-link].
The book can be built locally (assuming you have installed `rustup`):
```
cargo install mdbook
cd docs
mdbook serve --open
```
### Implementation status
Highlights:
- The protocol is asynchronous, so it's driven by consensus events as opposed
to some clock ticks.
- The performance is still optimal in a partially synchronous environment.
- BFT - secure if less than one third of the committee is malicious.
- Secure against fork bombs.
- Lowered network overhead of sending DAG parent information.
- Thorough testing, including malicious scenarios, and high code coverage.
More details are available [in the book][reference-link-implementation-details].
### Using the crate
- Import AlephBFT in your crate
```toml
[dependencies]
aleph-bft = "^0.20"
```
- The main entry point is the `run_session` function, which returns a Future that runs the
consensus algorithm.
To call this function, you need to pass a configuration (defaults are available in the package),
and implement certain traits, which will provide all the necessary functionalities, such as networking
and message signing.
A comprehensive guide is available [in the documentation][reference-link-api].
### Examples
We provide two basic examples of running AlephBFT, both of which are not cryptographically secure, and assume honest, but possibly malfunctioning, participants.
The first one, `ordering`, implements a simple node that produces data items, and then waits for them to be finalized. It can also perform a simulated crash after creating a specified number of items.
For example, you may run the following command:
```
cd ./examples/ordering
./run.sh
```
that will launch 2 properly working nodes, and 2 nodes that will crash 3 times each.
The delay before relaunching a crashed node will be set to 1 second.
A faulty node will create 25 items before every crash, and another `25` in the end.
Every node will therefore create `100` items in total, and then wait for other nodes before finishing its run.
See:
```
./run.sh -h
```
for further details.
Note that if the number of properly working nodes is less or equal than two times the number of faulty nodes, they will be unable to advance the protocol on their own.
The script will try to start nodes at predefined IP addresses, `127.0.0.1:100XX`, where `XX` denotes the node id. If the port is unavailable, the node will log an error and keep trying to aquire it, waiting 10 seconds between consecutive attempts.
Running this script will result in generating log files `node0.log, node1.log, ...` corresponding to subsequent nodes.
A directory called `aleph-bft-examples-ordering-backup` will be created to store data required by the crash recovery mechanism, and the logs from subsequent runs will be appended to existing log files.
The cache and logs will be automatically cleared when launching the script again.
The second example, `blockchain`, is meant for benchmarking AlephBFT in the blockchain setting.
It implements a simple round-robin blockchain assuming honest participation.
The easiest way to run it is to use the provided script as follows (assuming we start in the root directory):
```
cd ./examples/blockchain
./run.sh 5
```
where, again, `5` denotes the number of nodes that will be started.
Here we only assume that the address `127.0.0.1:43000` is available, as the network implementation contains a simple node discovery mechanism.
The achieved transactions per second will be among the final log messages in these files.
For further details, see
```
cargo run -- --help
```
### Dependencies
The repository is mainly self-contained. It is implemented using Rust's async features and depends only on the
`futures` crate from the standard library. Moreover, it has some usual dependencies like
`log` and `rand` and one bigger for encoding, namely `parity-scale-codec`. In future work, we plan to get
rid of this dependency.
### Toolchain
This release was built and tested against the `nightly-2022-10-30` Rust toolchain.
If you want to use another version, edit the `rust-toolchain` file, or use an [override](https://rust-lang.github.io/rustup/overrides.html) with higher priority.
### Tests
There are many unit tests and several integration tests that may be run by standard command
`cargo test --lib` or `cargo test --lib --skip medium` if you want to run just small tests.
Alternatively, you may run the `run_local_pipeline.sh` script.
### Fuzzing
We provide fuzzing tests that try to crash the whole application by creating arbitrary data for the network layer
and feeding it into the `member` implementation. To run those tests you need to install `afl` and `cargo-fuzz`.
`cargo-fuzz` requires you to use a nightly Rust toolchain. `afl` differs from `cargo-fuzz` in that it requires
so called corpus data to operate, i.e. some non-empty data set that do not crash the application.
Both tools are using LLVM's instrumentation capabilities in order to guide the fuzzing process basing on code-coverage statistics.
```sh
cargo install cargo-fuzz
cargo install afl
```
#### cargo-fuzz/libfuzzer
```sh
cargo fuzz run --features="libfuzz" fuzz_target
```
#### afl
You will need to generate some `seed` data first in order to run it.
```sh
# create some random input containing network data from a locally executed test
mkdir afl_in
cargo build --bin gen_fuzz
./target/debug/gen_fuzz >./afl_in/seed
```
You might need to reconfigure your operating system in order to proceed -
in such a case follow the instructions printed by the afl tool in your terminal.
```sh
cargo afl build --features="afl-fuzz" --bin fuzz_target_afl
cargo afl fuzz -i afl_in -o afl_out target/debug/fuzz_target_afl
```
The `gen_fuzz` binary is also able to verify data for the afl tool.
```sh
cargo build --bin gen_fuzz
./target/debug/gen_fuzz | ./target/debug/gen_fuzz --check-fuzz
```
### Code Coverage
You may generate the code coverage summary using the `gen_cov_data.sh` script and then a detailed
raport for every file with `cov_report.sh`. Make sure to first install all the required
tools with `install_cov_tools.sh`.
### Resources
- Papers: [current version][paper-link], [old version][old-paper-link]
- docs: [crate documentation][docs-link], [reference][reference-link]
### Future work
- Asynchronous liveness is an important theoretical property and there is a lot of technical
sophisticatio
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Aleph协议的Rust实现_Rust_Shell_下载.zip (110个子文件)
.gitignore 106B
.gitignore 45B
.gitignore 10B
LICENSE 11KB
Cargo.lock 38KB
how_alephbft_does_it.md 22KB
aleph_bft_api.md 17KB
README.md 11KB
internals.md 5KB
reliable_broadcast.md 4KB
what_is_aleph_bft.md 4KB
differences.md 2KB
conventions.md 1024B
README.md 856B
README.md 701B
README.md 690B
README.md 688B
SUMMARY.md 291B
mod.rs 41KB
mod.rs 40KB
member.rs 30KB
signature.rs 22KB
collection.rs 21KB
lib.rs 21KB
alerts.rs 18KB
terminal.rs 17KB
backup.rs 16KB
lib.rs 15KB
network.rs 13KB
extender.rs 13KB
creator.rs 12KB
dag.rs 11KB
byzantine.rs 11KB
validator.rs 11KB
creation.rs 10KB
network.rs 10KB
node.rs 10KB
store.rs 9KB
terminator.rs 9KB
crash_recovery.rs 9KB
consensus.rs 8KB
packer.rs 8KB
mod.rs 8KB
network.rs 7KB
mod.rs 7KB
main.rs 6KB
config.rs 5KB
chain.rs 5KB
main.rs 5KB
data.rs 5KB
unreliable.rs 4KB
consensus.rs 4KB
mod.rs 3KB
network.rs 3KB
task_queue.rs 3KB
dataio.rs 3KB
crash.rs 3KB
network.rs 2KB
io.rs 2KB
keychain.rs 2KB
dataio.rs 2KB
wrappers.rs 2KB
testing.rs 2KB
lib.rs 1KB
lib.rs 1KB
dataio.rs 1KB
main.rs 1KB
spawner.rs 816B
tasks.rs 705B
signature.rs 562B
hasher.rs 554B
lib.rs 492B
lib.rs 383B
signable.rs 379B
afl_target.rs 276B
libfuzz_target.rs 260B
mod.rs 199B
rust-toolchain 19B
run.sh 3KB
readme-cargo-toml-versions-aligned-consensus.sh 1001B
gen_cov_data.sh 632B
run.sh 541B
cov_report.sh 326B
install_cov_tools.sh 138B
run_local_pipeline.sh 128B
Cargo.toml 1KB
Cargo.toml 984B
Cargo.toml 882B
Cargo.toml 835B
Cargo.toml 769B
Cargo.toml 738B
Cargo.toml 699B
Cargo.toml 597B
Cargo.toml 245B
book.toml 206B
rustfmt.toml 125B
ci.yml 2KB
gh-pages.yml 633B
readme-cargo-toml-versions-aligned-consensus.yml 625B
check-version-bumped-consensus.yml 569B
共 110 条
- 1
- 2
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9149
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功