Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
FM-150: Subnet deployment scripts (#222)
Browse files Browse the repository at this point in the history
* Add scripts to deploy testnet nodes

Co-authored-by: Denis Kolegov <[email protected]>
Co-authored-by: Akosh Farkash <[email protected]>
  • Loading branch information
3 people authored Sep 26, 2023
1 parent 67db31f commit f28efaa
Show file tree
Hide file tree
Showing 18 changed files with 853 additions and 24 deletions.
86 changes: 74 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ cid = { version = "0.8", features = ["serde-codec", "std"] }
# Using the same tendermint-rs dependency as tower-abci. From both we are interested in v037 modules.
tower-abci = { version = "0.7" }
tendermint = { version = "0.31", features = ["secp256k1"] }
tendermint-config = "0.33.0"
tendermint-rpc = { version = "0.31", features = ["secp256k1", "http-client", "websocket-client"] }
tendermint-proto = { version = "0.31" }

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Fendermint is an effort to implement [IPC with Tendermint Core](https://docs.google.com/document/d/1cFoTdoRuYgxmWJia6K-b5vmEj-4MvyHCNvShZpyconU/edit#). There is a preliminary [roadmap](https://docs.google.com/spreadsheets/d/1eVwkHEPGNg0js8DKRDIX7sugf5JqbI9zRBddIqzJFfI/edit#gid=0) that lays out the tasks towards implementing subnets that run IPLD and FVM under the Filecoin rootnet, sharing components with the Lotus/Eudico based implementation.

## Quick Start
- [Local testnets](./docs/localnet.md)

## Docs

Expand Down
61 changes: 61 additions & 0 deletions docs/localnet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Local Testnets

Prerequisites:
```bash
make build docker-build
```

## Single node deployment

To run IPC in the local rootnet just perform the following :
```bash
cargo make --makefile ./infra/Makefile.toml node

```

It will create three docker containers (cometbft, fendermint, and eth-api).

To stop run the following:
```bash
cargo make --makefile ./infra/Makefile.toml node-down
```

## Local 4-nodes deployment
To run IPC in the local rootnet with 4 nodes perform the following command :
```bash
cargo make --makefile ./infra/Makefile.toml testnet

```

To stop the network:
```bash
cargo make --makefile ./infra/Makefile.toml testnet-down
```

The testnet contains four logical nodes. Each node consists of cometbft, fendermint, and ethapi containers.
The Docker internal network is `192.167.10.0/24`.

ETH-API is accessible on the following interfaces on the Docker internal network:
- `192.167.10.10:8545` or `ethapi-node0:8545`
- `192.167.10.11:8545` or `ethapi-node1:8545`
- `192.167.10.12:8545` or `ethapi-node2:8545`
- `192.167.10.13:8545` or `ethapi-node3:8545`

and on the following interfaces from the host machine:
- `127.0.0.1:8545`
- `127.0.0.1:8546`
- `127.0.0.1:8547`
- `127.0.0.1:8548`

## Deployment process

The deployment process is as follows:
- Remove all docker containers, files, networks, etc. from the previous deployment
- Create all necessary directories
- Initialize CometBFT testnet by creating `config` and `data` directories using `cometbft` tools
- Read cometbft nodes private keys,derive node IDs and store in `config.toml` for each node
- Create the `genesis` file for Fendermint
- Share the genesis among all Fendermint nodes
- Run Fendermint application in 4 containers
- Run CometBFT in 4 containers
- Run Eth API in 4 containers
1 change: 1 addition & 0 deletions fendermint/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ serde = { workspace = true }
serde_json = { workspace = true }
serde_with = { workspace = true }
tendermint = { workspace = true }
tendermint-config = { workspace = true }
tendermint-rpc = { workspace = true }
tendermint-proto = { workspace = true }
tokio = { workspace = true }
Expand Down
17 changes: 17 additions & 0 deletions fendermint/app/options/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub enum KeyCommands {
IntoTendermint(KeyIntoTendermintArgs),
/// Convert a public key file from base64 into an f1 Address format an print it to STDOUT.
Address(KeyAddressArgs),
/// Get the peer ID corresponding to a node ID and its network address and print it to a local file.
AddPeer(AddPeer),
}

#[derive(Args, Debug)]
Expand All @@ -21,6 +23,21 @@ pub struct KeyArgs {
pub command: KeyCommands,
}

#[derive(Args, Debug)]
pub struct AddPeer {
/// The path to a CometBFT node key file.
#[arg(long, short = 'n')]
pub node_key_file: PathBuf,
/// The path to a temporal local file where the peer IDs will be added.
/// The file will be created if it doesn't exist.
#[arg(long, short)]
pub local_peers_file: PathBuf,
/// The target CometBFT node network interface in the following format `IP:Port`.
/// For example: `192.168.10.7:26656`.
#[arg(long, short)]
pub network_addr: String,
}

#[derive(Args, Debug)]
pub struct KeyGenArgs {
/// Name used to distinguish the files from other exported keys.
Expand Down
46 changes: 34 additions & 12 deletions fendermint/app/src/cmd/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ use fvm_shared::address::Address;
use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng};
use serde_json::json;
use std::path::{Path, PathBuf};
use tendermint_config::NodeKey;

use super::{from_b64, to_b64};
use crate::{
cmd,
options::key::{KeyAddressArgs, KeyArgs, KeyCommands, KeyGenArgs, KeyIntoTendermintArgs},
options::key::{
AddPeer, KeyAddressArgs, KeyArgs, KeyCommands, KeyGenArgs, KeyIntoTendermintArgs,
},
};

cmd! {
KeyArgs(self) {
match &self.command {
KeyCommands::Gen(args) => args.exec(()).await,
KeyCommands::IntoTendermint(args) => args.exec(()).await,
KeyCommands::Address(args) => args.exec(()).await,
KeyArgs(self) {
match &self.command {
KeyCommands::Gen(args) => args.exec(()).await,
KeyCommands::IntoTendermint(args) => args.exec(()).await,
KeyCommands::AddPeer(args) => args.exec(()).await,
KeyCommands::Address(args) => args.exec(()).await,
}
}
}
}

cmd! {
Expand Down Expand Up @@ -67,14 +71,32 @@ cmd! {
}

cmd! {
KeyAddressArgs(self) {
let pk = read_public_key(&self.public_key)?;
let addr = Address::new_secp256k1(&pk.serialize())?;
println!("{}", addr);
Ok(())
AddPeer(self) {
let node_key = NodeKey::load_json_file(&self.node_key_file).context("failed to read node key file")?;
let peer_id = format!("{}@{}", node_key.node_id(), self.network_addr);
let mut peers = std::fs::read_to_string(&self.local_peers_file).unwrap_or_default();

if peers.is_empty() {
peers.push_str(&peer_id);
} else {
peers.push(',');
peers.push_str(peer_id.as_str());
}

std::fs::write(&self.local_peers_file, peers).context("failed to write to the peers file")?;
Ok(())
}
}

cmd! {
KeyAddressArgs(self) {
let pk = read_public_key(&self.public_key)?;
let addr = Address::new_secp256k1(&pk.serialize())?;
println!("{}", addr);
Ok(())
}
}

fn secret_to_b64(sk: &SecretKey) -> String {
to_b64(sk.serialize().as_ref())
}
Expand Down
1 change: 1 addition & 0 deletions infra/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMETBFT_VERSION=v0.37.x
11 changes: 11 additions & 0 deletions infra/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "fendermint_infra"
description = "Workflows for the deployment of Fendermint infrastructure"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
license.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Loading

0 comments on commit f28efaa

Please sign in to comment.