From 60f2d7d44e9badae90327e6afac2ddd162051476 Mon Sep 17 00:00:00 2001 From: cryptoAtwill Date: Thu, 5 Oct 2023 17:14:32 +0800 Subject: [PATCH 1/2] support top down query --- ipc/provider/src/lib.rs | 45 +++++++++++++++++++++++++ ipc/provider/src/manager/evm/manager.rs | 17 ++++++++++ ipc/provider/src/manager/subnet.rs | 2 ++ 3 files changed, 64 insertions(+) diff --git a/ipc/provider/src/lib.rs b/ipc/provider/src/lib.rs index f2b54653..9895934c 100644 --- a/ipc/provider/src/lib.rs +++ b/ipc/provider/src/lib.rs @@ -14,6 +14,7 @@ use fvm_shared::{ use ipc_identity::{ EthKeyAddress, EvmKeyStore, KeyStore, KeyStoreConfig, PersistentKeyStore, Wallet, }; +use ipc_sdk::staking::StakingChangeRequest; use ipc_sdk::{ cross::CrossMsg, subnet::{ConsensusType, ConstructParams}, @@ -534,6 +535,31 @@ impl IpcProvider { conn.manager().chain_head_height().await } + pub async fn genesis_epoch(&self, subnet: &SubnetID) -> anyhow::Result { + 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().genesis_epoch(subnet).await + } + + pub async fn get_validator_changeset( + &self, + subnet: &SubnetID, + start: ChainEpoch, + end: ChainEpoch, + ) -> anyhow::Result> { + let conn = match self.connection(subnet) { + None => return Err(anyhow!("target subnet not found")), + Some(conn) => conn, + }; + + conn.manager() + .get_validator_changeset(subnet, start, end) + .await + } + pub async fn get_top_down_msgs( &self, subnet: &SubnetID, @@ -572,6 +598,25 @@ impl IpcProvider { conn.manager().get_chain_id().await } + + pub async fn get_chain_head_height(&self, subnet: &SubnetID) -> anyhow::Result { + let conn = match self.connection(subnet) { + None => return Err(anyhow!("target subnet not found")), + Some(conn) => conn, + }; + + conn.manager().chain_head_height().await + } + + pub async fn get_genesis_epoch(&self, subnet: &SubnetID) -> anyhow::Result { + let parent = subnet.parent().ok_or_else(|| anyhow!("no parent found"))?; + let conn = match self.connection(&parent) { + None => return Err(anyhow!("parent subnet not found")), + Some(conn) => conn, + }; + + conn.manager().chain_head_height().await + } } /// Lotus JSON keytype format diff --git a/ipc/provider/src/manager/evm/manager.rs b/ipc/provider/src/manager/evm/manager.rs index 125b48b1..e95d240f 100644 --- a/ipc/provider/src/manager/evm/manager.rs +++ b/ipc/provider/src/manager/evm/manager.rs @@ -70,6 +70,23 @@ struct IPCContractInfo { #[async_trait] impl TopDownCheckpointQuery for EthSubnetManager { + async fn genesis_epoch(&self, subnet_id: &SubnetID) -> Result { + let address = contract_address_from_subnet(subnet_id)?; + log::info!("querying genesis epoch in evm subnet contract: {address:}"); + + let evm_subnet_id = gateway_getter_facet::SubnetID::try_from(subnet_id)?; + + let contract = gateway_getter_facet::GatewayGetterFacet::new( + self.ipc_contract_info.gateway_addr, + Arc::new(self.ipc_contract_info.provider.clone()), + ); + let (exists, subnet) = contract.get_subnet(evm_subnet_id).call().await?; + if !exists { + return Err(anyhow!("subnet: {} does not exists", subnet_id)); + } + Ok(subnet.genesis_epoch.as_u64() as ChainEpoch) + } + async fn chain_head_height(&self) -> Result { let block = self .ipc_contract_info diff --git a/ipc/provider/src/manager/subnet.rs b/ipc/provider/src/manager/subnet.rs index ee160c83..cf261306 100644 --- a/ipc/provider/src/manager/subnet.rs +++ b/ipc/provider/src/manager/subnet.rs @@ -128,6 +128,8 @@ pub trait SubnetManager: Send + Sync + TopDownCheckpointQuery { /// Trait to interact with a subnet to query the necessary information for top down checkpoint. #[async_trait] pub trait TopDownCheckpointQuery: Send + Sync { + /// Returns the chain head height + async fn genesis_epoch(&self, subnet_id: &SubnetID) -> Result; /// Returns the chain head height async fn chain_head_height(&self) -> Result; /// Returns the list of top down messages From 1a0ac5481acfafe46f3159f148a94abd0f7aaa8f Mon Sep 17 00:00:00 2001 From: cryptoAtwill Date: Thu, 5 Oct 2023 19:16:14 +0800 Subject: [PATCH 2/2] review feedbacks --- ipc/provider/src/lib.rs | 12 ++---------- ipc/provider/src/manager/subnet.rs | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/ipc/provider/src/lib.rs b/ipc/provider/src/lib.rs index 9895934c..dc854c67 100644 --- a/ipc/provider/src/lib.rs +++ b/ipc/provider/src/lib.rs @@ -535,6 +535,7 @@ impl IpcProvider { conn.manager().chain_head_height().await } + /// Obtain the genesis epoch of the input subnet. pub async fn genesis_epoch(&self, subnet: &SubnetID) -> anyhow::Result { let parent = subnet.parent().ok_or_else(|| anyhow!("no parent found"))?; let conn = match self.connection(&parent) { @@ -544,6 +545,7 @@ impl IpcProvider { conn.manager().genesis_epoch(subnet).await } + /// Get the changes in subnet validators. This is fetched from parent. pub async fn get_validator_changeset( &self, subnet: &SubnetID, @@ -607,16 +609,6 @@ impl IpcProvider { conn.manager().chain_head_height().await } - - pub async fn get_genesis_epoch(&self, subnet: &SubnetID) -> anyhow::Result { - let parent = subnet.parent().ok_or_else(|| anyhow!("no parent found"))?; - let conn = match self.connection(&parent) { - None => return Err(anyhow!("parent subnet not found")), - Some(conn) => conn, - }; - - conn.manager().chain_head_height().await - } } /// Lotus JSON keytype format diff --git a/ipc/provider/src/manager/subnet.rs b/ipc/provider/src/manager/subnet.rs index cf261306..7957679a 100644 --- a/ipc/provider/src/manager/subnet.rs +++ b/ipc/provider/src/manager/subnet.rs @@ -128,7 +128,7 @@ pub trait SubnetManager: Send + Sync + TopDownCheckpointQuery { /// Trait to interact with a subnet to query the necessary information for top down checkpoint. #[async_trait] pub trait TopDownCheckpointQuery: Send + Sync { - /// Returns the chain head height + /// Returns the genesis epoch that the subnet is created in parent network async fn genesis_epoch(&self, subnet_id: &SubnetID) -> Result; /// Returns the chain head height async fn chain_head_height(&self) -> Result;