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

FM: accept 0x address in --from, add bootstrap, subnet deploy and doc updates #344

Merged
merged 6 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ This repo is your entrypoint to the world of IPC. In this repo you will find:
>💡 **We've prepared a [quick start guide](/docs/quickstart-calibration.md) that will have you running and validating on your own subnet quickly, at the cost of detailed explanations.**

See:
- [docs/subnet.md](docs/subnet.md) for instructions on how to deploy a new subnet and the required architecture
- [docs/usage.md](docs/usage.md) for instructions on how to use the IPC Agent to interact with subnets
- [docs/deploying-hierarchy.md](docs/deploying-hierarchy.md) for instructions on how to deploy your own IPC root contract and hierarchy
- [docs/contracts.md](docs/contracts.md) for instructions on how to deploy FEVM actors on subnets
- [docs/troubleshooting.md](docs/troubleshooting.md) for answers to some common questions

For a detailed overview of the entire IPC stack design, please check the up-to-date **[IPC Design Reference](https://github.com/consensus-shipyard/IPC-design-reference-spec/blob/main/main.pdf)** doc.
- __NEEDS UPDATE/REMOVE:__ [docs/subnet.md](docs/subnet.md) for instructions on how to deploy a new subnet and the required architecture)
- __NEEDS UPDATE/REMOVE:__ [docs/usage.md](docs/usage.md) for instructions on how to use the IPC Agent to interact with subnets
- __NEEDS UPDATE/REMOVE:__ [docs/deploying-hierarchy.md](docs/deploying-hierarchy.md) for instructions on how to deploy your own IPC root contract and hierarchy
- __NEEDS UPDATE/REMOVE:__ [docs/troubleshooting.md](docs/troubleshooting.md) for answers to some common questions

## Branching Strategy

Expand Down
11 changes: 4 additions & 7 deletions docs/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ In order to connect the Ethereum tooling to your subnet, you'll need to get the

# Sample command
$ ./bin/ipc-agent subnet rpc --subnet /r31415926/t2xwzbdu7z5sam6hc57xxwkctciuaz7oe5omipwbq
[2023-05-17T15:10:57Z INFO ipc_agent::cli::commands::subnet::rpc] rpc endpoint for subnet /r31415926/t2xwzbdu7z5sam6hc57xxwkctciuaz7oe5omipwbq: http://127.0.0.1:1240/rpc/v1
[2023-05-17T15:10:57Z INFO ipc_agent::cli::commands::subnet::rpc] chainID for subnet /r31415926/t2xwzbdu7z5sam6hc57xxwkctciuaz7oe5omipwbq: 31415926
rpc: http://127.0.0.1:1240/rpc/v1
chainID: 31415926
```

You can also inspect the `json_rpcapi_http` field of your subnet on your config directly to get the RPC endpoint for your subnet.
This RPC endpoint and `chainID will be the ones needed to configure any EVM tooling to connect to your subnet.


### Example: Connect Metamask to your subnet

Expand Down Expand Up @@ -49,9 +46,9 @@ It is important to note that the IPC agent doesn't understand Ethereum addresses
./bin/ipc-agent util eth-to-f4-addr --addr <eth-adddress>

$ ./bin/ipc-agent util eth-to-f4-addr --addr 0x6BE1Ccf648c74800380d0520D797a170c808b624
[2023-05-17T13:37:37Z INFO ipc_agent::cli::commands::util::f4] f4 address: t410fnpq4z5siy5eaaoanauqnpf5bodearnren5fxyoi
t410fnpq4z5siy5eaaoanauqnpf5bodearnren5fxyoi
```

>💡 For more information about the relationship between `f4` and Ethereum addresses refer to [this page](https://docs.filecoin.io/smart-contracts/filecoin-evm-runtime/address-types/).

From there on, you should be able to follow the same steps currently used to deploy EVM contract in the Filecoin mainnet. You can find here the steps to [deploy an ERC20 contract using Remix](https://docs.filecoin.io/smart-contracts/fundamentals/erc-20-quickstart/).
From there on, you should be able to follow the same steps currently used to deploy EVM contract in the Filecoin mainnet. You can find here the steps to [deploy an ERC20 contract using Remix](https://docs.filecoin.io/smart-contracts/fundamentals/erc-20-quickstart/).
271 changes: 114 additions & 157 deletions docs/quickstart-calibration.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/subnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

>💡 For background and setup information, make sure to start with the [README](/README.md).

To spawn a new subnet, our IPC agent should be connected to the parent subnet (or rootnet) from which we plan to deploy a new subnet. Please refer to the [README](/README.md) for information on how to run or connect to a rootnet. This instructions will assume the deployment of a subnet from `/r31415926`, but the steps are equivalent for any other parent subnet.
To spawn a new subnet, we should configure our `ipc-cli` to point to the parent subnet (or rootnet) from which we plan to deploy a new subnet. Please refer to the [README](/README.md) for information on how to run or connect to a rootnet. This instructions will assume the deployment of a subnet from `/r314159` (i.e. Calibration), but the steps are equivalent for any other parent subnet.

We provide instructions for running both a [simple single-validator subnet](#running-a-simple-subnet-with-a-single-validator) and a more useful [multi-validator subnet](#running-a-subnet-with-several-validators). The two sets mostly overlap.

Expand Down
2 changes: 1 addition & 1 deletion ipc/cli/src/commands/crossmsg/fund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl CommandLineHandler for Fund {
let mut provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;
let from = match &arguments.from {
Some(address) => Some(Address::from_str(address)?),
Some(address) => Some(require_fil_addr_from_str(address)?),
None => None,
};
let to = match &arguments.to {
Expand Down
3 changes: 1 addition & 2 deletions ipc/cli/src/commands/crossmsg/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use async_trait::async_trait;
use clap::Args;
use fvm_shared::address::Address;
use ipc_sdk::subnet_id::SubnetID;
use std::{fmt::Debug, str::FromStr};

Expand All @@ -26,7 +25,7 @@ impl CommandLineHandler for Release {
let mut provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;
let from = match &arguments.from {
Some(address) => Some(Address::from_str(address)?),
Some(address) => Some(require_fil_addr_from_str(address)?),
None => None,
};
let to = match &arguments.to {
Expand Down
76 changes: 76 additions & 0 deletions ipc/cli/src/commands/subnet/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2022-2023 Protocol Labs
// SPDX-License-Identifier: MIT
//! Subnet bootstrap-related commands

use async_trait::async_trait;
use clap::Args;
use ipc_sdk::subnet_id::SubnetID;
use std::{fmt::Debug, str::FromStr};

use crate::{get_ipc_provider, require_fil_addr_from_str, CommandLineHandler, GlobalArguments};

/// The command to add a bootstrap subnet
pub struct AddBootstrap;

#[async_trait]
impl CommandLineHandler for AddBootstrap {
type Arguments = AddBootstrapArgs;

async fn handle(global: &GlobalArguments, arguments: &Self::Arguments) -> anyhow::Result<()> {
log::debug!("add subnet bootstrap with args: {:?}", arguments);

let mut provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;
let from = match &arguments.from {
Some(address) => Some(require_fil_addr_from_str(address)?),
None => None,
};

provider
.add_bootstrap(&subnet, from, arguments.endpoint.clone())
.await
}
}

#[derive(Debug, Args)]
#[command(name = "add-bootstrap", about = "Advertise bootstrap in the subnet")]
pub struct AddBootstrapArgs {
#[arg(
long,
short,
help = "The address of the validator adding the bootstrap"
)]
pub from: Option<String>,
#[arg(long, short, help = "The subnet to add the bootstrap to")]
pub subnet: String,
#[arg(long, short, help = "The bootstrap node's network endpoint")]
pub endpoint: String,
}

/// The command to list bootstrap nodes in a subnet
pub struct ListBootstraps;

#[async_trait]
impl CommandLineHandler for ListBootstraps {
type Arguments = ListBootstrapsArgs;

async fn handle(global: &GlobalArguments, arguments: &Self::Arguments) -> anyhow::Result<()> {
log::debug!("add subnet bootstrap with args: {:?}", arguments);

let provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;

for s in provider.list_bootstrap_nodes(&subnet).await? {
print!("{s},");
}
println!();
Ok(())
}
}

#[derive(Debug, Args)]
#[command(name = "list-bootstraps", about = "List bootstraps in the subnet")]
pub struct ListBootstrapsArgs {
#[arg(long, short, help = "The subnet to list bootstraps from")]
pub subnet: String,
}
6 changes: 3 additions & 3 deletions ipc/cli/src/commands/subnet/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

use async_trait::async_trait;
use clap::Args;
use fvm_shared::address::Address;
use fvm_shared::clock::ChainEpoch;
use ipc_sdk::subnet_id::SubnetID;
use std::fmt::Debug;
use std::str::FromStr;

use crate::commands::get_ipc_provider;
use crate::{f64_to_token_amount, CommandLineHandler, GlobalArguments};
use crate::{f64_to_token_amount, require_fil_addr_from_str, CommandLineHandler, GlobalArguments};

const DEFAULT_ACTIVE_VALIDATORS: u16 = 100;

Expand All @@ -25,8 +24,9 @@ impl CreateSubnet {
) -> anyhow::Result<String> {
let mut provider = get_ipc_provider(global)?;
let parent = SubnetID::from_str(&arguments.parent)?;

let from = match &arguments.from {
Some(address) => Some(Address::from_str(address)?),
Some(address) => Some(require_fil_addr_from_str(address)?),
None => None,
};

Expand Down
10 changes: 6 additions & 4 deletions ipc/cli/src/commands/subnet/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use async_trait::async_trait;
use clap::Args;
use fvm_shared::address::Address;
use ipc_sdk::subnet_id::SubnetID;
use std::{fmt::Debug, str::FromStr};

use crate::{f64_to_token_amount, get_ipc_provider, CommandLineHandler, GlobalArguments};
use crate::{
f64_to_token_amount, get_ipc_provider, require_fil_addr_from_str, CommandLineHandler,
GlobalArguments,
};

/// The command to join a subnet
pub struct JoinSubnet;
Expand All @@ -23,7 +25,7 @@ impl CommandLineHandler for JoinSubnet {
let mut provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;
let from = match &arguments.from {
Some(address) => Some(Address::from_str(address)?),
Some(address) => Some(require_fil_addr_from_str(address)?),
None => None,
};
let public_key = hex::decode(&arguments.public_key)?;
Expand Down Expand Up @@ -68,7 +70,7 @@ impl CommandLineHandler for StakeSubnet {
let mut provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;
let from = match &arguments.from {
Some(address) => Some(Address::from_str(address)?),
Some(address) => Some(require_fil_addr_from_str(address)?),
None => None,
};
provider
Expand Down
5 changes: 2 additions & 3 deletions ipc/cli/src/commands/subnet/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

use async_trait::async_trait;
use clap::Args;
use fvm_shared::address::Address;
use ipc_sdk::subnet_id::SubnetID;
use std::{fmt::Debug, str::FromStr};

use crate::{get_ipc_provider, CommandLineHandler, GlobalArguments};
use crate::{get_ipc_provider, require_fil_addr_from_str, CommandLineHandler, GlobalArguments};

/// The command to kill an existing subnet.
pub struct KillSubnet;
Expand All @@ -23,7 +22,7 @@ impl CommandLineHandler for KillSubnet {
let mut provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;
let from = match &arguments.from {
Some(address) => Some(Address::from_str(address)?),
Some(address) => Some(require_fil_addr_from_str(address)?),
None => None,
};

Expand Down
7 changes: 3 additions & 4 deletions ipc/cli/src/commands/subnet/leave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

use async_trait::async_trait;
use clap::Args;
use fvm_shared::address::Address;
use ipc_sdk::subnet_id::SubnetID;
use std::{fmt::Debug, str::FromStr};

use crate::{get_ipc_provider, CommandLineHandler, GlobalArguments};
use crate::{get_ipc_provider, require_fil_addr_from_str, CommandLineHandler, GlobalArguments};

/// The command to leave a new subnet.
pub struct LeaveSubnet;
Expand All @@ -23,7 +22,7 @@ impl CommandLineHandler for LeaveSubnet {
let mut provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;
let from = match &arguments.from {
Some(address) => Some(Address::from_str(address)?),
Some(address) => Some(require_fil_addr_from_str(address)?),
None => None,
};
provider.leave_subnet(subnet, from).await
Expand Down Expand Up @@ -52,7 +51,7 @@ impl CommandLineHandler for Claim {
let mut provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;
let from = match &arguments.from {
Some(address) => Some(Address::from_str(address)?),
Some(address) => Some(require_fil_addr_from_str(address)?),
None => None,
};
if !&arguments.rewards {
Expand Down
9 changes: 9 additions & 0 deletions ipc/cli/src/commands/subnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ use crate::commands::subnet::send_value::{SendValue, SendValueArgs};
use crate::{CommandLineHandler, GlobalArguments};
use clap::{Args, Subcommand};

use self::bootstrap::{AddBootstrap, AddBootstrapArgs, ListBootstraps, ListBootstrapsArgs};
use self::join::{StakeSubnet, StakeSubnetArgs};
use self::leave::{Claim, ClaimArgs};
use self::rpc::{ChainIdSubnet, ChainIdSubnetArgs};

pub mod bootstrap;
pub mod create;
pub mod join;
pub mod kill;
Expand All @@ -40,11 +43,14 @@ impl SubnetCommandsArgs {
Commands::List(args) => ListSubnets::handle(global, args).await,
Commands::Join(args) => JoinSubnet::handle(global, args).await,
Commands::Rpc(args) => RPCSubnet::handle(global, args).await,
Commands::ChainId(args) => ChainIdSubnet::handle(global, args).await,
Commands::Leave(args) => LeaveSubnet::handle(global, args).await,
Commands::Kill(args) => KillSubnet::handle(global, args).await,
Commands::SendValue(args) => SendValue::handle(global, args).await,
Commands::Stake(args) => StakeSubnet::handle(global, args).await,
Commands::Claim(args) => Claim::handle(global, args).await,
Commands::AddBootstrap(args) => AddBootstrap::handle(global, args).await,
Commands::ListBootstraps(args) => ListBootstraps::handle(global, args).await,
}
}
}
Expand All @@ -55,9 +61,12 @@ pub(crate) enum Commands {
List(ListSubnetsArgs),
Join(JoinSubnetArgs),
Rpc(RPCSubnetArgs),
ChainId(ChainIdSubnetArgs),
Leave(LeaveSubnetArgs),
Kill(KillSubnetArgs),
SendValue(SendValueArgs),
Stake(StakeSubnetArgs),
Claim(ClaimArgs),
AddBootstrap(AddBootstrapArgs),
ListBootstraps(ListBootstrapsArgs),
}
33 changes: 30 additions & 3 deletions ipc/cli/src/commands/subnet/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,35 @@ impl CommandLineHandler for RPCSubnet {
#[derive(Debug, Args)]
#[command(name = "rpc", about = "RPC endpoint for a subnet")]
pub struct RPCSubnetArgs {
#[arg(long, short, help = "The JSON RPC server url for ipc agent")]
pub ipc_agent_url: Option<String>,
#[arg(long, short, help = "The subnet to get the RPC from")]
#[arg(long, short, help = "The subnet to get the ChainId from")]
pub subnet: String,
}

/// The command to get the chain ID for a subnet
pub struct ChainIdSubnet;

#[async_trait]
impl CommandLineHandler for ChainIdSubnet {
type Arguments = ChainIdSubnetArgs;

async fn handle(global: &GlobalArguments, arguments: &Self::Arguments) -> anyhow::Result<()> {
log::debug!("get chain-id for subnet with args: {:?}", arguments);

let provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;
let conn = match provider.connection(&subnet) {
None => return Err(anyhow::anyhow!("target subnet not found")),
Some(conn) => conn,
};

println!("{:}", conn.manager().get_chain_id().await?);
Ok(())
}
}

#[derive(Debug, Args)]
#[command(name = "chain-id", about = "Chain ID endpoint for a subnet")]
pub struct ChainIdSubnetArgs {
#[arg(long, short, help = "The subnet to get the Chain ID from")]
pub subnet: String,
}
3 changes: 1 addition & 2 deletions ipc/cli/src/commands/subnet/send_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use async_trait::async_trait;
use clap::Args;
use fvm_shared::address::Address;
use ipc_sdk::subnet_id::SubnetID;
use std::{fmt::Debug, str::FromStr};

Expand All @@ -25,7 +24,7 @@ impl CommandLineHandler for SendValue {
let mut provider = get_ipc_provider(global)?;
let subnet = SubnetID::from_str(&arguments.subnet)?;
let from = match &arguments.from {
Some(address) => Some(Address::from_str(address)?),
Some(address) => Some(require_fil_addr_from_str(address)?),
None => None,
};

Expand Down
Loading