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

Commit

Permalink
query event
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoAtwill committed Oct 27, 2023
1 parent 31a3be2 commit e65d9f1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
29 changes: 20 additions & 9 deletions ipc/provider/src/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,27 @@ impl<T: BottomUpCheckpointRelayer + Send + Sync + 'static> BottomUpCheckpointMan
return Ok(());
}

let bundle = self
.child_handler
.checkpoint_bundle_at(next_submission_height)
.await?;
log::debug!("bottom up bundle: {bundle:?}");
let prev_submission_height = next_submission_height - self.checkpoint_period();

self.parent_handler
.submit_checkpoint(submitter, bundle)
.await
.map_err(|e| anyhow!("cannot submit bottom up checkpoint due to: {e:}"))?;
for h in (prev_submission_height + 1)..=current_height {
let events = self.child_handler.quorum_reached_events(h).await?;
if events.is_empty() {
continue;
}

for event in events {
let bundle = self
.child_handler
.checkpoint_bundle_at(event.height)
.await?;
log::debug!("bottom up bundle: {bundle:?}");

self.parent_handler
.submit_checkpoint(submitter, bundle)
.await
.map_err(|e| anyhow!("cannot submit bottom up checkpoint due to: {e:}"))?;
}
}

Ok(())
}
Expand Down
28 changes: 25 additions & 3 deletions ipc/provider/src/manager/evm/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::time::Duration;

use ethers::types::H256;
use ipc_actors_abis::{
gateway_getter_facet, gateway_manager_facet, gateway_messenger_facet, lib_staking_change_log,
subnet_actor_getter_facet, subnet_actor_manager_facet, subnet_registry,
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,
};
use ipc_sdk::evm::{fil_to_eth_amount, payload_to_evm_address, subnet_id_to_evm_addresses};
use ipc_sdk::validator::from_contract_validators;
Expand All @@ -33,7 +33,7 @@ use ethers::types::{BlockId, Eip1559TransactionRequest, I256, U256};
use fvm_shared::clock::ChainEpoch;
use fvm_shared::{address::Address, econ::TokenAmount};
use ipc_identity::{EthKeyAddress, EvmKeyStore, PersistentKeyStore};
use ipc_sdk::checkpoint::{BottomUpCheckpoint, BottomUpCheckpointBundle};
use ipc_sdk::checkpoint::{BottomUpCheckpoint, BottomUpCheckpointBundle, QuorumReachedEvent};
use ipc_sdk::cross::CrossMsg;
use ipc_sdk::gateway::Status;
use ipc_sdk::staking::StakingChangeRequest;
Expand Down Expand Up @@ -965,6 +965,28 @@ impl BottomUpCheckpointRelayer for EthSubnetManager {
})
}

async fn quorum_reached_events(&self, height: ChainEpoch) -> Result<Vec<QuorumReachedEvent>> {
let contract = gateway_router_facet::GatewayRouterFacet::new(
self.ipc_contract_info.gateway_addr,
Arc::new(self.ipc_contract_info.provider.clone()),
);

let ev = contract
.event::<gateway_router_facet::QuorumReachedFilter>()
.from_block(height as u64)
.to_block(height as u64);

let mut events = vec![];
for (event, _meta) in ev.query_with_meta().await? {
events.push(QuorumReachedEvent {
height: event.height as ChainEpoch,
checkpoint: event.checkpoint.to_vec(),
quorum_weight: eth_to_fil_amount(&event.quorum_weight)?,
});
}

Ok(events)
}
async fn current_epoch(&self) -> Result<ChainEpoch> {
let epoch = self
.ipc_contract_info
Expand Down
4 changes: 3 additions & 1 deletion ipc/provider/src/manager/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anyhow::Result;
use async_trait::async_trait;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::{address::Address, econ::TokenAmount};
use ipc_sdk::checkpoint::BottomUpCheckpointBundle;
use ipc_sdk::checkpoint::{BottomUpCheckpointBundle, QuorumReachedEvent};
use ipc_sdk::cross::CrossMsg;
use ipc_sdk::staking::StakingChangeRequest;
use ipc_sdk::subnet::ConstructParams;
Expand Down Expand Up @@ -195,6 +195,8 @@ pub trait BottomUpCheckpointRelayer: Send + Sync {
async fn checkpoint_period(&self, subnet_id: &SubnetID) -> Result<ChainEpoch>;
/// Get the checkpoint bundle at a specific height. If it does not exist, it will through error.
async fn checkpoint_bundle_at(&self, height: ChainEpoch) -> Result<BottomUpCheckpointBundle>;
/// Queries the quorum reached events at target height.
async fn quorum_reached_events(&self, height: ChainEpoch) -> Result<Vec<QuorumReachedEvent>>;
/// Get the current epoch in the current subnet
async fn current_epoch(&self) -> Result<ChainEpoch>;
}
9 changes: 9 additions & 0 deletions ipc/sdk/src/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use cid::Cid;
use fvm_ipld_encoding::DAG_CBOR;
use fvm_shared::address::Address;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::econ::TokenAmount;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};

Expand All @@ -23,6 +24,14 @@ lazy_static! {

pub type Signature = Vec<u8>;

/// The event emitted
#[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)]
pub struct QuorumReachedEvent {
pub height: ChainEpoch,
pub checkpoint: Vec<u8>,
pub quorum_weight: TokenAmount,
}

/// The collection of items for the bottom up checkpoint submission
#[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)]
pub struct BottomUpCheckpointBundle {
Expand Down

0 comments on commit e65d9f1

Please sign in to comment.