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

Commit

Permalink
FM-148: Deploy IPC actors in genesis (#159)
Browse files Browse the repository at this point in the history
* FM-148: Change genesis initialisation to allow message execution

* FM-148: Wait before starting the Eth API

* FM-148: Add contracts_dir to config and interpreter

* FM-148: Trying to deploy the Gateway

* FM-148: Link the bytecode references

* FM-148: Copy the entire contract directory

* FM-148: Topo sorted dependencies

* FM-148: Deploy libraries during genesis

* FM-148: Move Hardhat to own crate

* FM-148: Make topo_sort generic

* FM-148: Compile Solidity for testing

* FM-148: Fix copying of contracts in docker build

* FM-148: Trying to add ethereum libraries to the init actor map

* FM-148: Deterministic ordering in toposort

* FM-148: Hash the masked ID for delegation

* FM-148: Fix initcode encoding

* FM-148: Unit test constructor param encoding (fails)

* FM-148: Fix passing the constructor argument.

* FM-148: Use ID address in library map but log both

* FM-148: Helper method to deploy top level Eth contracts

* FM-148: Factor out deployment

* FM-148: Fix FVM version

* FM-148: Use a known version of actors

* FM-148: Try to print container logs on e2e error

* FM-148: Only ask for IDs

* FM-148: Try printing logs after setup

* FM-148: Print cometbft logs as well.

* FM-148: Increase wait time on CI

* FM-148: Fix deploy logs

* Update fendermint/vm/actor_interface/src/ipc.rs

Co-authored-by: adlrocha <6717133+adlrocha@users.noreply.github.com>

* Update fendermint/vm/actor_interface/src/ipc.rs

Co-authored-by: adlrocha <6717133+adlrocha@users.noreply.github.com>

---------

Co-authored-by: adlrocha <6717133+adlrocha@users.noreply.github.com>
  • Loading branch information
aakoshh and adlrocha authored Aug 1, 2023
1 parent 01fc7a3 commit 3e0fc95
Show file tree
Hide file tree
Showing 25 changed files with 1,166 additions and 268 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
docker/.artifacts
cometbft
test-network
48 changes: 31 additions & 17 deletions Cargo.lock

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

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = [
"fendermint/abci",
"fendermint/app",
"fendermint/eth/api",
"fendermint/eth/*",
"fendermint/rocksdb",
"fendermint/rpc",
"fendermint/storage",
Expand Down Expand Up @@ -63,6 +63,7 @@ tracing-subscriber = "0.3"


# Stable FVM dependencies from crates.io

# Using the 3.3 version of the FVM because the newer ones update the IPLD dependencies
# to version which are different than the ones in the builtin-actors project, and since
# they are 0.x cargo cannot upgrade them automatically, which leads to version conflicts.
Expand All @@ -74,6 +75,14 @@ fvm_ipld_encoding = "0.3"
fvm_ipld_car = "0.6"
fvm_ipld_hamt = "0.6"

# Local FVM debugging
# fvm = { path = "../ref-fvm/fvm", default-features = false }
# fvm_ipld_blockstore = { path = "../ref-fvm/ipld/blockstore" }
# fvm_ipld_encoding = { path = "../ref-fvm/ipld/encoding" }
# fvm_ipld_car = { path = "../ref-fvm/ipld/car" }
# fvm_ipld_hamt = { path = "../ref-fvm/ipld/hamt" }
# fvm_shared = { path = "../ref-fvm/shared", features = ["crypto"] }

# Using 0.8 because of ref-fvm.
# 0.9 would be better because of its updated quickcheck dependency.
# 0.10 breaks some API.
Expand Down
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ BUILTIN_ACTORS_BUNDLE:=$(shell pwd)/$(BUILTIN_ACTORS_DIR)/output/bundle.car
IPC_ACTORS_DIR:=$(shell pwd)/../ipc-solidity-actors
IPC_ACTORS_CODE:=$(shell find $(IPC_ACTORS_DIR) -type f -name "*.sol")
IPC_ACTORS_BUILD:=fendermint/vm/ipc_actors/build.rs
IPC_ACTORS_ABI:=$(IPC_ACTORS_DIR)/out/.compile.abi
IPC_ACTORS_OUT:=$(IPC_ACTORS_DIR)/out
IPC_ACTORS_ABI:=$(IPC_ACTORS_OUT)/.compile.abi

FENDERMINT_CODE:=$(shell find . -type f \( -name "*.rs" -o -name "Cargo.toml" \) | grep -v target)

Expand All @@ -21,8 +22,10 @@ build:
cargo build --release

# Using --release for testing because wasm can otherwise be slow.
test: $(BUILTIN_ACTORS_BUNDLE)
FM_BUILTIN_ACTORS_BUNDLE=$(BUILTIN_ACTORS_BUNDLE) cargo test --release --workspace --exclude smoke-test
test: $(BUILTIN_ACTORS_BUNDLE) $(IPC_ACTORS_ABI)
FM_BUILTIN_ACTORS_BUNDLE=$(BUILTIN_ACTORS_BUNDLE) \
FM_CONTRACTS_DIR=$(IPC_ACTORS_OUT) \
cargo test --release --workspace --exclude smoke-test

e2e: docker-build
cd fendermint/testing/smoke-test && cargo make --profile $(PROFILE)
Expand Down Expand Up @@ -51,7 +54,7 @@ docker-build: $(BUILTIN_ACTORS_BUNDLE) $(FENDERMINT_CODE) $(IPC_ACTORS_ABI)
mkdir -p docker/.artifacts/contracts

cp $(BUILTIN_ACTORS_BUNDLE) docker/.artifacts
cp $(IPC_ACTORS_DIR)/out/*.json docker/.artifacts/contracts
cp -r $(IPC_ACTORS_OUT)/* docker/.artifacts/contracts

if [ "$(PROFILE)" = "ci" ]; then \
$(MAKE) --no-print-directory build && \
Expand Down Expand Up @@ -96,8 +99,8 @@ $(IPC_ACTORS_ABI): $(IPC_ACTORS_CODE) | forge
git clone https://github.com/consensus-shipyard/ipc-solidity-actors.git; \
fi
cd $(IPC_ACTORS_DIR) && \
git checkout fm-156-ipc-solidity-actors && \
git pull
git fetch origin && \
git checkout origin/fm-156-ipc-solidity-actors
make -C $(IPC_ACTORS_DIR) compile-abi
touch $@

Expand Down
4 changes: 3 additions & 1 deletion fendermint/app/config/default.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Data directory relative to the `--home-dir`, unless given as an absolute path.
data_dir = "data"
# Builtin actor bunlde path relative to the `--home-dir`, unless given as an absolute path.
# Contract directory relative to the `--home-dir`, unless given as an absolute path.
contracts_dir = "contracts"
# Builtin actor bundle path relative to the `--home-dir`, unless given as an absolute path.
builtin_actors_bundle = "bundle.car"

[abci]
Expand Down
21 changes: 11 additions & 10 deletions fendermint/app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ where
/// Path to the Wasm bundle.
///
/// Only loaded once during genesis; later comes from the [`StateTree`].
actor_bundle_path: PathBuf,
builtin_actors_bundle: PathBuf,
/// Namespace to store app state.
namespace: S::Namespace,
/// Collection of past state parameters.
Expand Down Expand Up @@ -140,7 +140,7 @@ where
pub fn new(
db: DB,
state_store: SS,
actor_bundle_path: PathBuf,
builtin_actors_bundle: PathBuf,
app_namespace: S::Namespace,
state_hist_namespace: S::Namespace,
state_hist_size: u64,
Expand All @@ -150,7 +150,7 @@ where
db: Arc::new(db),
state_store: Arc::new(state_store),
multi_engine: Arc::new(MultiEngine::new(1)),
actor_bundle_path,
builtin_actors_bundle,
namespace: app_namespace,
state_hist: KVCollection::new(state_hist_namespace),
state_hist_size,
Expand Down Expand Up @@ -350,13 +350,14 @@ where

/// Called once upon genesis.
async fn init_chain(&self, request: request::InitChain) -> AbciResult<response::InitChain> {
let bundle_path = &self.actor_bundle_path;
let bundle = std::fs::read(bundle_path)
.map_err(|e| anyhow!("failed to load bundle CAR from {bundle_path:?}: {e}"))?;

let state = FvmGenesisState::new(self.state_store_clone(), &bundle)
.await
.context("failed to create genesis state")?;
let bundle = &self.builtin_actors_bundle;
let bundle = std::fs::read(bundle)
.map_err(|e| anyhow!("failed to load bundle CAR from {bundle:?}: {e}"))?;

let state =
FvmGenesisState::new(self.state_store_clone(), self.multi_engine.clone(), &bundle)
.await
.context("failed to create genesis state")?;

tracing::info!(
manifest_root = format!("{}", state.manifest_data_cid),
Expand Down
2 changes: 1 addition & 1 deletion fendermint/app/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cmd! {
}

async fn run(settings: Settings) -> anyhow::Result<()> {
let interpreter = FvmMessageInterpreter::<NamespaceBlockstore>::new();
let interpreter = FvmMessageInterpreter::<NamespaceBlockstore>::new(settings.contracts_dir());
let interpreter = SignedMessageInterpreter::new(interpreter);
let interpreter = ChainMessageInterpreter::new(interpreter);
let interpreter = BytesMessageInterpreter::new(interpreter);
Expand Down
19 changes: 12 additions & 7 deletions fendermint/app/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@ pub struct Settings {
/// Home directory configured on the CLI, to which all paths in settings can be set relative.
home_dir: PathBuf,
data_dir: PathBuf,
contracts_dir: PathBuf,
builtin_actors_bundle: PathBuf,
pub abci: AbciSettings,
pub db: DbSettings,
pub eth: EthSettings,
}

macro_rules! home_relative {
($name:ident) => {
pub fn $name(&self) -> PathBuf {
self.expand_path(&self.$name)
}
};
}

impl Settings {
/// Load the default configuration from a directory,
/// then potential overrides specific to the run mode,
Expand Down Expand Up @@ -96,13 +105,9 @@ impl Settings {
expand_tilde(self.home_dir.join(path))
}

pub fn data_dir(&self) -> PathBuf {
self.expand_path(&self.data_dir)
}

pub fn builtin_actors_bundle(&self) -> PathBuf {
self.expand_path(&self.builtin_actors_bundle)
}
home_relative!(data_dir);
home_relative!(contracts_dir);
home_relative!(builtin_actors_bundle);
}

/// Expand paths that begin with "~" to `$HOME`.
Expand Down
4 changes: 2 additions & 2 deletions fendermint/eth/api/examples/ethers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ abigen!(
#[derive(Parser, Debug)]
pub struct Options {
/// The host of the Fendermint Ethereum API endpoint.
#[arg(long, default_value = "127.0.0.1", env = "FM_ETH__HTTP__HOST")]
#[arg(long, default_value = "127.0.0.1", env = "FM_ETH__LISTEN__HOST")]
pub http_host: String,

/// The port of the Fendermint Ethereum API endpoint.
#[arg(long, default_value = "8545", env = "FM_ETH__HTTP__PORT")]
#[arg(long, default_value = "8545", env = "FM_ETH__LISTEN__PORT")]
pub http_port: u32,

/// Secret key used to send funds, expected to be in Base64 format.
Expand Down
16 changes: 16 additions & 0 deletions fendermint/eth/hardhat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "fendermint_eth_hardhat"
description = "Utilities to deal with Hardhat build artifacts"
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]
anyhow = { workspace = true }
ethers-core = { workspace = true }
hex = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Loading

0 comments on commit 3e0fc95

Please sign in to comment.