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

Commit

Permalink
fm-306: add method in provider to get genesis info
Browse files Browse the repository at this point in the history
  • Loading branch information
adlrocha committed Oct 16, 2023
1 parent 54dc974 commit fd2cecb
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ libipld = { version = "0.14", default-features = false, features = ["dag-cbor"]
ethers = "2.0.8"
ethers-contract = "2.0.8"

ipc_actors_abis = { git = "https://github.com/consensus-shipyard/ipc-solidity-actors.git", branch = "dev" }
ipc_actors_abis = { git = "https://github.com/consensus-shipyard/ipc-solidity-actors.git", branch = "fm-306-genesis-getters" }
ipc-sdk = { path = "./ipc/sdk" }

fvm_ipld_blockstore = "0.1.1"
Expand Down
8 changes: 8 additions & 0 deletions ipc/cli/src/commands/subnet/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl CreateSubnet {
arguments
.active_validators_limit
.unwrap_or(DEFAULT_ACTIVE_VALIDATORS),
f64_to_token_amount(arguments.min_cross_msg_fee)?,
)
.await?;

Expand Down Expand Up @@ -81,4 +82,11 @@ pub struct CreateSubnetArgs {
pub bottomup_check_period: ChainEpoch,
#[arg(long, help = "The max number of active validators in subnet")]
pub active_validators_limit: Option<u16>,
#[arg(
long,
short,
default_value = "0.000001",
help = "Minimum fee for cross-net messages in subnet (in whole FIL)"
)]
pub min_cross_msg_fee: f64,
}
15 changes: 14 additions & 1 deletion ipc/provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use ipc_sdk::{
subnet_id::SubnetID,
};
use lotus::message::wallet::WalletKeyType;
use manager::{EthSubnetManager, SubnetInfo, SubnetManager};
use manager::{EthSubnetManager, SubnetGenesisInfo, SubnetInfo, SubnetManager};
use num_traits::FromPrimitive;
use serde::{Deserialize, Serialize};
use std::{
Expand Down Expand Up @@ -232,6 +232,7 @@ impl IpcProvider {
min_validator_stake: TokenAmount,
bottomup_check_period: ChainEpoch,
active_validators_limit: u16,
min_cross_msg_fee: TokenAmount,
) -> anyhow::Result<Address> {
let conn = match self.connection(&parent) {
None => return Err(anyhow!("target parent subnet not found")),
Expand All @@ -249,6 +250,7 @@ impl IpcProvider {
min_validator_stake,
bottomup_check_period,
active_validators_limit,
min_cross_msg_fee,
};

conn.manager()
Expand Down Expand Up @@ -549,6 +551,17 @@ impl IpcProvider {
conn.manager().get_validator_changeset(subnet, epoch).await
}

/// Get genesis info for a child subnet. This can be used to deterministically
/// generate the genesis of the subnet
pub async fn get_genesis_info(&self, subnet: &SubnetID) -> anyhow::Result<SubnetGenesisInfo> {
let parent = subnet.parent().ok_or_else(|| anyhow!("no parent found"))?;
let conn = match self.connection(&parent) {
None => return Err(anyhow!("parent subnet config not found")),
Some(conn) => conn,
};
conn.manager().get_genesis_info(subnet).await
}

pub async fn get_top_down_msgs(
&self,
subnet: &SubnetID,
Expand Down
34 changes: 33 additions & 1 deletion ipc/provider/src/manager/evm/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use ipc_sdk::{eth_to_fil_amount, ethers_address_to_fil_address};
use crate::config::subnet::SubnetConfig;
use crate::config::Subnet;
use crate::lotus::message::ipc::SubnetInfo;
use crate::manager::subnet::{GetBlockHashResult, TopDownCheckpointQuery, TopDownQueryPayload};
use crate::manager::subnet::{
GetBlockHashResult, SubnetGenesisInfo, TopDownCheckpointQuery, TopDownQueryPayload,
};
use crate::manager::{EthManager, SubnetManager};
use anyhow::{anyhow, Context, Result};
use async_trait::async_trait;
Expand Down Expand Up @@ -207,6 +209,12 @@ impl SubnetManager for EthSubnetManager {
.to_u128()
.ok_or_else(|| anyhow!("invalid min validator stake"))?;

let min_cross_msg_fee = params
.min_cross_msg_fee
.atto()
.to_u128()
.ok_or_else(|| anyhow!("invalid min validator stake"))?;

log::debug!("calling create subnet for EVM manager");

let route = subnet_id_to_evm_addresses(&params.parent)?;
Expand All @@ -225,6 +233,7 @@ impl SubnetManager for EthSubnetManager {
majority_percentage: SUBNET_MAJORITY_PERCENTAGE,
active_validators_limit: params.active_validators_limit,
power_scale: 3,
min_cross_msg_fee: ethers::types::U256::from(min_cross_msg_fee),
};

log::info!("creating subnet on evm with params: {params:?}");
Expand Down Expand Up @@ -596,6 +605,29 @@ impl SubnetManager for EthSubnetManager {
.await?
.to_string())
}

async fn get_genesis_info(&self, subnet: &SubnetID) -> Result<SubnetGenesisInfo> {
let address = contract_address_from_subnet(subnet)?;
let contract = subnet_actor_getter_facet::SubnetActorGetterFacet::new(
address,
Arc::new(self.ipc_contract_info.provider.clone()),
);
Ok(SubnetGenesisInfo {
// Active validators limit set for the child subnet.
active_validators_limit: contract.active_validators_limit().call().await?,
// Bottom-up checkpoint period set in the subnet actor.
bottom_up_checkpoint_period: contract.bottom_up_check_period().call().await?,
// Genesis epoch when the subnet was bootstrapped in the parent.
genesis_epoch: self.genesis_epoch(subnet).await?,
// Majority percentage of
majority_percentage: contract.majority_percentage().call().await?,
// Minimum collateral required for subnets to register into the subnet
min_collateral: eth_to_fil_amount(&contract.min_activation_collateral().call().await?)?,
// Custom message fee that the child subnet wants to set for cross-net messages
msg_fee: eth_to_fil_amount(&contract.min_cross_msg_fee().call().await?)?,
validators: contract.genesis_validators().call().await?,
})
}
}

#[async_trait]
Expand Down
5 changes: 4 additions & 1 deletion ipc/provider/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// SPDX-License-Identifier: MIT
pub use crate::lotus::message::ipc::SubnetInfo;
pub use evm::{EthManager, EthSubnetManager};
pub use subnet::{GetBlockHashResult, SubnetManager, TopDownCheckpointQuery, TopDownQueryPayload};
pub use subnet::{
GetBlockHashResult, SubnetGenesisInfo, SubnetManager, TopDownCheckpointQuery,
TopDownQueryPayload,
};

pub mod evm;
mod subnet;
15 changes: 15 additions & 0 deletions ipc/provider/src/manager/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use anyhow::Result;
use async_trait::async_trait;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::{address::Address, econ::TokenAmount};
use ipc_actors_abis::subnet_actor_getter_facet;
use ipc_sdk::cross::CrossMsg;
use ipc_sdk::staking::StakingChangeRequest;
use ipc_sdk::subnet::ConstructParams;
Expand Down Expand Up @@ -111,6 +112,20 @@ pub trait SubnetManager: Send + Sync + TopDownCheckpointQuery {
/// Returning as a `String` because the maximum value for an EVM
/// networks is a `U256` that wouldn't fit in an integer type.
async fn get_chain_id(&self) -> Result<String>;

/// Gets the genesis information required to bootstrap a child subnet
async fn get_genesis_info(&self, subnet: &SubnetID) -> Result<SubnetGenesisInfo>;
}

#[derive(Debug)]
pub struct SubnetGenesisInfo {
pub bottom_up_checkpoint_period: u64,
pub msg_fee: TokenAmount,
pub majority_percentage: u8,
pub active_validators_limit: u16,
pub min_collateral: TokenAmount,
pub genesis_epoch: ChainEpoch,
pub validators: Vec<subnet_actor_getter_facet::Validator>,
}

/// The generic payload that returns the block hash of the data returning block with the actual
Expand Down
1 change: 1 addition & 0 deletions ipc/sdk/src/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct ConstructParams {
pub min_validators: u64,
pub bottomup_check_period: ChainEpoch,
pub active_validators_limit: u16,
pub min_cross_msg_fee: TokenAmount,
}

/// Consensus types supported by hierarchical consensus
Expand Down

0 comments on commit fd2cecb

Please sign in to comment.