Skip to content

Commit

Permalink
move MinerGetBaseInfo to miner module (#4294)
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs authored May 8, 2024
1 parent bb4f5c7 commit dd44a8a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 59 deletions.
28 changes: 28 additions & 0 deletions src/rpc/methods/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::message::SignedMessage;
use crate::networks::Height;

use crate::rpc::reflect::Permission;
use crate::rpc::types::{ApiTipsetKey, MiningBaseInfo};
use crate::rpc::{ApiVersion, Ctx, RpcMethod, ServerError};
use crate::shim::address::Address;
use crate::shim::clock::ChainEpoch;
Expand Down Expand Up @@ -44,6 +45,7 @@ use std::sync::Arc;
macro_rules! for_each_method {
($callback:ident) => {
$callback!(crate::rpc::miner::MinerCreateBlock);
$callback!(crate::rpc::miner::MinerGetBaseInfo);
};
}
pub(crate) use for_each_method;
Expand Down Expand Up @@ -277,3 +279,29 @@ fn aggregate_from_bls_signatures(bls_sigs: Vec<Signature>) -> anyhow::Result<Sig
})
}
}

pub enum MinerGetBaseInfo {}
impl RpcMethod<3> for MinerGetBaseInfo {
const NAME: &'static str = "Filecoin.MinerGetBaseInfo";
const PARAM_NAMES: [&'static str; 3] = ["address", "epoch", "tsk"];
const API_VERSION: ApiVersion = ApiVersion::V0;
const PERMISSION: Permission = Permission::Read;

type Params = (Address, i64, ApiTipsetKey);
type Ok = Option<MiningBaseInfo>;

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(address, epoch, ApiTipsetKey(tsk)): Self::Params,
) -> Result<Self::Ok, ServerError> {
let ts = ctx
.state_manager
.chain_store()
.load_required_tipset_or_heaviest(&tsk)?;

Ok(ctx
.state_manager
.miner_get_base_info(ctx.state_manager.beacon_schedule(), ts, address, epoch)
.await?)
}
}
27 changes: 0 additions & 27 deletions src/rpc/methods/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ use tokio::task::JoinSet;

macro_rules! for_each_method {
($callback:ident) => {
$callback!(crate::rpc::state::MinerGetBaseInfo);
$callback!(crate::rpc::state::StateCall);
$callback!(crate::rpc::state::StateGetBeaconEntry);
$callback!(crate::rpc::state::StateListMessages);
Expand Down Expand Up @@ -104,32 +103,6 @@ pub(crate) use for_each_method;
const INITIAL_PLEDGE_NUM: u64 = 110;
const INITIAL_PLEDGE_DEN: u64 = 100;

pub enum MinerGetBaseInfo {}
impl RpcMethod<3> for MinerGetBaseInfo {
const NAME: &'static str = "Filecoin.MinerGetBaseInfo";
const PARAM_NAMES: [&'static str; 3] = ["address", "epoch", "tsk"];
const API_VERSION: ApiVersion = ApiVersion::V0;
const PERMISSION: Permission = Permission::Read;

type Params = (Address, i64, ApiTipsetKey);
type Ok = Option<MiningBaseInfo>;

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(address, epoch, ApiTipsetKey(tsk)): Self::Params,
) -> Result<Self::Ok, ServerError> {
let ts = ctx
.state_manager
.chain_store()
.load_required_tipset_or_heaviest(&tsk)?;

Ok(ctx
.state_manager
.miner_get_base_info(ctx.state_manager.beacon_schedule(), ts, address, epoch)
.await?)
}
}

pub enum StateCall {}
impl RpcMethod<2> for StateCall {
const NAME: &'static str = "Filecoin.StateCall";
Expand Down
30 changes: 0 additions & 30 deletions src/rpc/methods/state/types.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Copyright 2019-2024 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::beacon::BeaconEntry;
use crate::lotus_json::{lotus_json_with_self, LotusJson};
use crate::shim::{
address::Address,
econ::TokenAmount,
error::ExitCode,
executor::Receipt,
message::Message,
sector::{SectorInfo, StoragePower},
state_tree::{ActorID, ActorState},
};
use cid::Cid;
Expand Down Expand Up @@ -164,34 +162,6 @@ impl PartialEq for GasTrace {
}
}

#[derive(Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct MiningBaseInfo {
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<StoragePower>")]
pub miner_power: StoragePower,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<StoragePower>")]
pub network_power: StoragePower,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Vec<SectorInfo>>")]
pub sectors: Vec<SectorInfo>,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Address>")]
pub worker_key: Address,
#[schemars(with = "u64")]
pub sector_size: fvm_shared2::sector::SectorSize,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<BeaconEntry>")]
pub prev_beacon_entry: BeaconEntry,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Vec<BeaconEntry>>")]
pub beacon_entries: Vec<BeaconEntry>,
pub eligible_for_mining: bool,
}

lotus_json_with_self!(MiningBaseInfo);

#[derive(PartialEq, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct InvocResult {
Expand Down
31 changes: 30 additions & 1 deletion src/rpc/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod tsk_impl;
#[cfg(test)]
mod tests;

use crate::beacon::BeaconEntry;
use crate::blocks::TipsetKey;
use crate::libp2p::Multihash;
use crate::lotus_json::{lotus_json_with_self, HasLotusJson, LotusJson};
Expand All @@ -26,7 +27,7 @@ use crate::shim::{
executor::Receipt,
fvm_shared_latest::MethodNum,
message::Message,
sector::{RegisteredSealProof, SectorNumber},
sector::{RegisteredSealProof, SectorInfo, SectorNumber, StoragePower},
};
use cid::Cid;
use fil_actor_interface::market::AllocationID;
Expand Down Expand Up @@ -535,3 +536,31 @@ pub struct DealCollateralBounds {
}

lotus_json_with_self!(DealCollateralBounds);

#[derive(Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct MiningBaseInfo {
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<StoragePower>")]
pub miner_power: StoragePower,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<StoragePower>")]
pub network_power: StoragePower,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Vec<SectorInfo>>")]
pub sectors: Vec<SectorInfo>,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Address>")]
pub worker_key: Address,
#[schemars(with = "u64")]
pub sector_size: fvm_shared2::sector::SectorSize,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<BeaconEntry>")]
pub prev_beacon_entry: BeaconEntry,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Vec<BeaconEntry>>")]
pub beacon_entries: Vec<BeaconEntry>,
pub eligible_for_mining: bool,
}

lotus_json_with_self!(MiningBaseInfo);
3 changes: 2 additions & 1 deletion src/state_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use crate::lotus_json::{lotus_json_with_self, LotusJson};
use crate::message::{ChainMessage, Message as MessageTrait};
use crate::metrics::HistogramTimerExt;
use crate::networks::ChainConfig;
use crate::rpc::state::{ApiInvocResult, InvocResult, MessageGasCost, MiningBaseInfo};
use crate::rpc::state::{ApiInvocResult, InvocResult, MessageGasCost};
use crate::rpc::types::MiningBaseInfo;
use crate::shim::{
address::{Address, Payload, Protocol},
clock::ChainEpoch,
Expand Down

0 comments on commit dd44a8a

Please sign in to comment.