Skip to content

Commit

Permalink
Implemented Filecoin.StateMinerDeadlines API (#3761)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-shashank authored Nov 30, 2023
1 parent c35e21e commit 0152318
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ where
.with_method(STATE_MINER_ACTIVE_SECTORS, state_miner_active_sectors::<DB>)
.with_method(STATE_MINER_FAULTS, state_miner_faults::<DB>)
.with_method(STATE_MINER_POWER, state_miner_power::<DB>)
.with_method(STATE_MINER_DEADLINES, state_miner_deadlines::<DB>)
.with_method(STATE_GET_RECEIPT, state_get_receipt::<DB>)
.with_method(STATE_WAIT_MSG, state_wait_msg::<DB>)
.with_method(STATE_FETCH_ROOT, state_fetch_root::<DB>)
Expand Down
26 changes: 25 additions & 1 deletion src/rpc/state_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::cid_collections::CidHashSet;
use crate::libp2p::NetworkMessage;
use crate::lotus_json::LotusJson;
use crate::rpc_api::data_types::{
ApiActorState, ApiInvocResult, MarketDeal, MessageLookup, RPCState, SectorOnChainInfo,
ApiActorState, ApiDeadline, ApiInvocResult, MarketDeal, MessageLookup, RPCState,
SectorOnChainInfo,
};
use crate::shim::{
address::Address, clock::ChainEpoch, executor::Receipt, message::Message,
Expand Down Expand Up @@ -244,6 +245,29 @@ pub(in crate::rpc) async fn state_miner_power<DB: Blockstore + Send + Sync + 'st
.map_err(|e| e.into())
}

pub(in crate::rpc) async fn state_miner_deadlines<DB: Blockstore + Send + Sync + 'static>(
data: Data<RPCState<DB>>,
Params(LotusJson((addr, tsk))): Params<LotusJson<(Address, TipsetKeys)>>,
) -> Result<LotusJson<Vec<ApiDeadline>>, JsonRpcError> {
let ts = data.chain_store.load_required_tipset(&tsk)?;
let policy = &data.state_manager.chain_config().policy;
let actor = data
.state_manager
.get_actor(&addr, *ts.parent_state())?
.ok_or("Miner actor address could not be resolved")?;
let store = data.state_manager.blockstore();
let state = miner::State::load(store, actor.code, actor.state)?;
let mut res = Vec::new();
state.for_each_deadline(policy, store, |_idx, deadline| {
res.push(ApiDeadline {
post_submissions: deadline.partitions_posted(),
disputable_proof_count: deadline.disputable_proof_count(store)?,
});
Ok(())
})?;
Ok(LotusJson(res))
}

/// looks up the miner power of the given address.
pub(in crate::rpc) async fn state_miner_faults<DB: Blockstore + Send + Sync + 'static>(
data: Data<RPCState<DB>>,
Expand Down
11 changes: 11 additions & 0 deletions src/rpc_api/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use fil_actor_interface::{
power::Claim,
};
use fil_actor_miner_state::v12::{BeneficiaryTerm, PendingBeneficiaryChange};
use fil_actors_shared::fvm_ipld_bitfield::BitField;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::{BytesDe, RawBytes};
use jsonrpc_v2::{MapRouter as JsonRpcMapRouter, Server as JsonRpcServer};
Expand Down Expand Up @@ -626,6 +627,16 @@ impl From<fil_actor_interface::miner::SectorOnChainInfo> for SectorOnChainInfo {

lotus_json_with_self!(SectorOnChainInfo);

#[derive(Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct ApiDeadline {
#[serde(with = "crate::lotus_json")]
pub post_submissions: BitField,
#[serde(with = "crate::lotus_json")]
pub disputable_proof_count: u64,
}

lotus_json_with_self!(ApiDeadline);
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ApiInvocResult {
Expand Down
2 changes: 2 additions & 0 deletions src/rpc_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub static ACCESS_MAP: Lazy<HashMap<&str, Access>> = Lazy::new(|| {
access.insert(state_api::STATE_MINER_ACTIVE_SECTORS, Access::Read);
access.insert(state_api::STATE_MINER_FAULTS, Access::Read);
access.insert(state_api::STATE_MINER_POWER, Access::Read);
access.insert(state_api::STATE_MINER_DEADLINES, Access::Read);
access.insert(state_api::STATE_GET_RECEIPT, Access::Read);
access.insert(state_api::STATE_WAIT_MSG, Access::Read);
access.insert(state_api::STATE_NETWORK_NAME, Access::Read);
Expand Down Expand Up @@ -241,6 +242,7 @@ pub mod state_api {
pub const STATE_MINER_INFO: &str = "Filecoin.StateMinerInfo";
pub const STATE_MINER_FAULTS: &str = "Filecoin.StateMinerFaults";
pub const STATE_MINER_POWER: &str = "Filecoin.StateMinerPower";
pub const STATE_MINER_DEADLINES: &str = "Filecoin.StateMinerDeadlines";
pub const STATE_GET_RECEIPT: &str = "Filecoin.StateGetReceipt";
pub const STATE_WAIT_MSG: &str = "Filecoin.StateWaitMsg";
pub const STATE_FETCH_ROOT: &str = "Filecoin.StateFetchRoot";
Expand Down
11 changes: 10 additions & 1 deletion src/rpc_client/state_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use std::path::PathBuf;
use crate::{
blocks::TipsetKeys,
rpc_api::{
data_types::{ApiActorState, ApiInvocResult, MessageLookup, SectorOnChainInfo},
data_types::{
ApiActorState, ApiDeadline, ApiInvocResult, MessageLookup, SectorOnChainInfo,
},
state_api::*,
},
shim::{
Expand Down Expand Up @@ -74,6 +76,13 @@ impl ApiInfo {
RpcRequest::new(STATE_MINER_POWER, (miner, tsk))
}

pub fn state_miner_deadlines_req(
miner: Address,
tsk: TipsetKeys,
) -> RpcRequest<Vec<ApiDeadline>> {
RpcRequest::new(STATE_MINER_DEADLINES, (miner, tsk))
}

pub fn state_get_randomness_from_tickets_req(
tsk: TipsetKeys,
personalization: DomainSeparationTag,
Expand Down
4 changes: 4 additions & 0 deletions src/tool/subcommands/api_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ fn snapshot_tests(store: &ManyCar, n_tipsets: usize) -> anyhow::Result<Vec<RpcTe
*block.miner_address(),
tipset.key().clone(),
)));
tests.push(RpcTest::identity(ApiInfo::state_miner_deadlines_req(
*block.miner_address(),
tipset.key().clone(),
)));
tests.push(RpcTest::identity(ApiInfo::state_miner_faults_req(
*block.miner_address(),
tipset.key().clone(),
Expand Down

0 comments on commit 0152318

Please sign in to comment.