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

Support top down query #331

Merged
merged 2 commits into from
Oct 6, 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
37 changes: 37 additions & 0 deletions ipc/provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -534,6 +535,33 @@ 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<ChainEpoch> {
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
}

/// Get the changes in subnet validators. This is fetched from parent.
pub async fn get_validator_changeset(
&self,
subnet: &SubnetID,
start: ChainEpoch,
end: ChainEpoch,
) -> anyhow::Result<Vec<StakingChangeRequest>> {
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this one implemented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the evm manager instance.

.await
}

pub async fn get_top_down_msgs(
&self,
subnet: &SubnetID,
Expand Down Expand Up @@ -572,6 +600,15 @@ impl IpcProvider {

conn.manager().get_chain_id().await
}

pub async fn get_chain_head_height(&self, subnet: &SubnetID) -> anyhow::Result<ChainEpoch> {
let conn = match self.connection(subnet) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the change set picked up from the parent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is get chain head height? Anyways, for change set, it's from the subnet actor in parent, so the address should be derived from the subnet directly.

None => return Err(anyhow!("target subnet not found")),
Some(conn) => conn,
};

conn.manager().chain_head_height().await
}
}

/// Lotus JSON keytype format
Expand Down
17 changes: 17 additions & 0 deletions ipc/provider/src/manager/evm/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ struct IPCContractInfo {

#[async_trait]
impl TopDownCheckpointQuery for EthSubnetManager {
async fn genesis_epoch(&self, subnet_id: &SubnetID) -> Result<ChainEpoch> {
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<ChainEpoch> {
let block = self
.ipc_contract_info
Expand Down
2 changes: 2 additions & 0 deletions ipc/provider/src/manager/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 genesis epoch that the subnet is created in parent network
async fn genesis_epoch(&self, subnet_id: &SubnetID) -> Result<ChainEpoch>;
/// Returns the chain head height
async fn chain_head_height(&self) -> Result<ChainEpoch>;
/// Returns the list of top down messages
Expand Down