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

Propagate nov changes to main #399

Merged
merged 11 commits into from
Nov 20, 2023
28 changes: 10 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
# syntax=docker/dockerfile:1

# Build stage
FROM rust:1.68 as builder
FROM rust:bookworm as builder

RUN <<EOF
set -e

apt-get update
apt-get install -y build-essential

rm -rf /var/lib/apt/lists/*
EOF
RUN apt update && \
apt install -y build-essential libssl-dev mesa-opencl-icd ocl-icd-opencl-dev gcc git bzr jq pkg-config curl clang hwloc libhwloc-dev wget ca-certificates gnupg

WORKDIR /app

COPY . .

RUN --mount=type=cache,target=$RUSTUP_HOME,from=rust,source=$RUSTUP_HOME \
--mount=type=cache,target=$CARGO_HOME,from=rust,source=$CARGO_HOME \
--mount=type=cache,target=target \
cargo install --root output --path .

RUN make build

# Main stage
FROM debian:bullseye-slim
FROM debian:bookworm-slim

COPY --from=builder /app/output/bin/ipc-agent /usr/local/bin/ipc-agent
RUN apt update && \
apt install -y build-essential libssl-dev curl ca-certificates && \
rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["ipc-agent"]
COPY --from=builder /app/bin/ipc-cli /usr/local/bin/ipc-cli

EXPOSE 3030
ENTRYPOINT ["/usr/local/bin/ipc-cli"]
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,27 @@ If it is the first time that you use your `ipc-cli`, to initialize cli configura
The suggested configuration for the `ipc-cli` is:

```
# Default configuration for Filecoin Calibration
keystore_path = "~/.ipc"

# Filecoin Calibration
[[subnets]]
id = "/r314159"

[subnets.config]
gateway_addr = "0x0341fA160C66aBB112195192aE359a6D61df45cd"
network_type = "fevm"
provider_http = "https://api.calibration.node.glif.io/rpc/v1"
gateway_addr = "0x0341fA160C66aBB112195192aE359a6D61df45cd"
registry_addr = "0xc7068Cea947035560128a6a6F4c8913523A5A44C"

# Mycelium Calibration
[[subnets]]
id = "/r314159/t410fnotsxwgnxcjp5phjmgp6n3lnhxvrf3pncnm3oxq"

[subnets.config]
network_type = "fevm"
provider_http = "https://api.mycelium.calibration.node.glif.io/"
gateway_addr = "0x77aa40b105843728088c0132e43fc44348881da8"
registry_addr = "0x74539671a1d2f1c8f200826baba665179f53a1b7"
```

To be able to interact with Calibration and run new subnets, some FIL should be provided to, at least, the wallet that will be used by the `ipc-cli` to interact with IPC. You can request some tFIL for your address through the [Calibration Faucet](https://faucet.calibration.fildev.network/funds.html).
Expand Down
16 changes: 13 additions & 3 deletions docs/quickstart-calibration.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,17 @@ Before running our validators, at least one bootstrap needs to be deployed and a

* We can deploy a new bootstrap node in the subnet by running:
```bash
cargo make --makefile bin/ipc-infra/Makefile.toml -e CMT_P2P_HOST_PORT=26650 bootstrap
cargo make --makefile infra/Makefile.toml \
-e PRIVATE_KEY_PATH=<VALIDATOR_PRIV_KEY> \
-e SUBNET_ID=<SUBNET_ID> \
-e CMT_P2P_HOST_PORT=<COMETBFT_P2P_PORT> \
-e CMT_RPC_HOST_PORT=<COMETBFT_RPC_PORT> \
-e ETHAPI_HOST_PORT=<ETH_RPC_PORT> \
-e BOOTSTRAPS=<BOOTSTRAP_ENDPOINT>
-e PARENT_REGISTRY=<PARENT_REGISTRY_CONTRACT_ADDR> \
-e PARENT_GATEWAY=<GATEWAY_REGISTRY_CONTRACT_ADDR> \
-e CMT_EXTERNAL_ADDR=<COMETBFT_EXTERNAL_ENDPOINT> \
bootstrap
```

At the end of the output, this command should return the ID of your new bootstrap node:
Expand All @@ -160,11 +170,11 @@ At the end of the output, this command should return the ID of your new bootstra
[email protected]:26650
[cargo-make] INFO - Build Done in 13.38 seconds.
```
Remember the address of your bootstrap for the next step. This address has the following format `id@ip:port`, and by default shows the public IP of your network interface. Feel free to adjust the `ip` to use a reachable IP for your deployment so other nodes can contact it (in our case our localhost IP, `127.0.0.1`).
Remember the address of your bootstrap for the next step. This address has the following format `id@ip:port`. Feel free to adjust the `ip` to use a reachable IP for your deployment so other nodes can contact it (in our case our localhost IP, `127.0.0.1`) and to use as `CMT_EXTERNAL_ADDR` a reachable IP by other peers, and the port configured in `CMT_EXTERNAL_ADDR`.

* We can get the address of the deployed bootstrap node by running:
```bash
cargo make --makefile bin/ipc-infra/Makefile.toml bootstrap-id
cargo make --makefile bin/ipc-infra/Makefile.toml bootstrap-node-id
```

* To shut down the bootstrap node run:
Expand Down
2 changes: 1 addition & 1 deletion ipc/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ enum Commands {
about = "The IPC agent command line tool",
version = "v0.0.1"
)]
#[command(propagate_version = true)]
#[command(propagate_version = true, arg_required_else_help = true)]
struct IPCAgentCliCommands {
// If provided, outputs the completion file for given shell
#[arg(long = "cli-autocomplete-gen", value_enum)]
Expand Down
15 changes: 13 additions & 2 deletions ipc/cli/src/commands/wallet/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Wallet import cli handler

use async_trait::async_trait;
use clap::Args;
use clap::{ArgGroup, Args};
use ipc_identity::WalletType;
use std::fmt::Debug;
use std::str::FromStr;
Expand Down Expand Up @@ -57,14 +57,25 @@ impl CommandLineHandler for WalletImport {

#[derive(Debug, Args)]
#[command(about = "Import a key into the agent's wallet")]
#[clap(group(ArgGroup::new("key_source")
.required(true)
.multiple(false)
.args(&["path", "private_key"]),
))]
pub(crate) struct WalletImportArgs {
#[arg(long, short, help = "The type of the wallet, i.e. fvm, evm")]
pub wallet_type: String,
#[arg(long, short, help = "Path of key info file for the key to import")]
#[arg(
long,
short,
group = "key_source",
help = "Path of key info file for the key to import"
)]
pub path: Option<String>,
#[arg(
long,
short,
group = "key_source",
help = "The evm private key to import if path is not specified"
)]
pub private_key: Option<String>,
Expand Down
13 changes: 12 additions & 1 deletion ipc/provider/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub const JSON_RPC_VERSION: &str = "2.0";
pub const DEFAULT_CONFIG_TEMPLATE: &str = r#"
keystore_path = "~/.ipc"

# Filecoin Calibration
[[subnets]]
id = "/r314159"

Expand All @@ -40,13 +41,23 @@ provider_http = "https://api.calibration.node.glif.io/rpc/v1"
gateway_addr = "0x0341fA160C66aBB112195192aE359a6D61df45cd"
registry_addr = "0xc7068Cea947035560128a6a6F4c8913523A5A44C"

# Mycelium Calibration
[[subnets]]
id = "/r314159/t410fnotsxwgnxcjp5phjmgp6n3lnhxvrf3pncnm3oxq"

[subnets.config]
network_type = "fevm"
provider_http = "https://api.mycelium.calibration.node.glif.io/"
gateway_addr = "0x77aa40b105843728088c0132e43fc44348881da8"
registry_addr = "0x74539671a1d2f1c8f200826baba665179f53a1b7"

# Subnet template - uncomment and adjust before using
# [[subnets]]
# id = "/r314159/<SUBNET_ID>"

# [subnets.config]
# network_type = "fevm"
# provider_http = "https://api.calibration.node.glif.io/rpc/v1"
# provider_http = "https://<RPC_ADDR>/"
# gateway_addr = "0x77aa40b105843728088c0132e43fc44348881da8"
# registry_addr = "0x74539671a1d2f1c8f200826baba665179f53a1b7"
"#;
Expand Down
43 changes: 38 additions & 5 deletions ipc/provider/src/manager/evm/manager.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright 2022-2023 Protocol Labs
// SPDX-License-Identifier: MIT

use std::collections::HashMap;
use std::borrow::Borrow;
use std::collections::{BTreeMap, HashMap};
use std::sync::{Arc, RwLock};
use std::time::Duration;

use ethers::types::H256;
use ethers_contract::{ContractError, EthLogDecode, LogMeta};
use ipc_actors_abis::{
gateway_getter_facet, gateway_manager_facet, gateway_messenger_facet, gateway_router_facet,
lib_staking_change_log, subnet_actor_getter_facet, subnet_actor_manager_facet, subnet_registry,
Expand Down Expand Up @@ -179,7 +181,7 @@ impl TopDownFinalityQuery for EthSubnetManager {

let mut changes = vec![];
let mut hash = None;
for (event, meta) in ev.query_with_meta().await? {
for (event, meta) in query_with_meta(ev, contract.client()).await? {
if let Some(h) = hash {
if h != meta.block_hash {
return Err(anyhow!("block hash not equal"));
Expand Down Expand Up @@ -1098,7 +1100,7 @@ impl BottomUpCheckpointRelayer for EthSubnetManager {
.to_block(height as u64);

let mut events = vec![];
for (event, _meta) in ev.query_with_meta().await? {
for (event, _meta) in query_with_meta(ev, contract.client()).await? {
events.push(QuorumReachedEvent {
height: event.height as ChainEpoch,
checkpoint: event.checkpoint.to_vec(),
Expand Down Expand Up @@ -1269,11 +1271,42 @@ fn is_valid_bootstrap_addr(input: &str) -> Option<(String, IpAddr, u16)> {
None
}

/// This is a replacement for `Event::query_with_meta` in `ethers-contract`
/// because in that one we don't get access to the `reverted` field, which
/// we need to filteron in the currently deployed `1.25-rc4` version of Lotus.
async fn query_with_meta<B, M, D>(
event: ethers::contract::Event<B, M, D>,
client: B,
) -> Result<Vec<(D, LogMeta)>, ContractError<M>>
where
B: Borrow<M>,
M: Middleware,
D: EthLogDecode,
{
let logs = client
.borrow()
.get_logs(&event.filter)
.await
.map_err(ContractError::from_middleware_error)?;

let events = logs
.into_iter()
.filter(|l| !l.removed.unwrap_or_default())
.map(|log| {
let meta = LogMeta::from(&log);
let event = ethers::contract::parse_log::<D>(log)?;
Ok((event, meta))
})
.collect::<Result<_, ContractError<M>>>()?;

Ok(events)
}

fn into_genesis_balance_map(
addrs: Vec<ethers::types::Address>,
balances: Vec<ethers::types::U256>,
) -> Result<HashMap<Address, TokenAmount>> {
let mut map = HashMap::new();
) -> Result<BTreeMap<Address, TokenAmount>> {
let mut map = BTreeMap::new();
for (a, b) in addrs.into_iter().zip(balances) {
map.insert(ethers_address_to_fil_address(&a)?, eth_to_fil_amount(&b)?);
}
Expand Down
4 changes: 2 additions & 2 deletions ipc/provider/src/manager/subnet.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022-2023 Protocol Labs
// SPDX-License-Identifier: MIT

use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};

use anyhow::Result;
use async_trait::async_trait;
Expand Down Expand Up @@ -157,7 +157,7 @@ pub struct SubnetGenesisInfo {
pub min_collateral: TokenAmount,
pub genesis_epoch: ChainEpoch,
pub validators: Vec<Validator>,
pub genesis_balances: HashMap<Address, TokenAmount>,
pub genesis_balances: BTreeMap<Address, TokenAmount>,
}

/// The generic payload that returns the block hash of the data returning block with the actual
Expand Down
Loading