Skip to content

Commit

Permalink
fix(rpc): update StateSectorPreCommitInfo against v1 spec (#4443)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanabi1224 authored Jun 26, 2024
1 parent 42964f8 commit 247c311
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

- [#4352](https://github.com/ChainSafe/forest/pull/4352) Add support for the
`Filecoin.StateGetClaim` RPC method.

- [#4356](https://github.com/ChainSafe/forest/pull/4356) Add support for the
`Filecoin.NetProtectAdd` RPC method.

Expand All @@ -49,6 +50,9 @@
- [#4359](https://github.com/ChainSafe/forest/issues/4359) Add support for the
`EIP-1898` object scheme.

- [#4443](https://github.com/ChainSafe/forest/issues/4443) Update
`Filecoin.StateSectorPreCommitInfo` RPC method to be API-V1-compatible

- [#4444](https://github.com/ChainSafe/forest/issues/4444) Update
`Filecoin.StateWaitMsg` RPC method to be API-V1-compatible

Expand Down
57 changes: 34 additions & 23 deletions src/rpc/methods/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1585,16 +1585,47 @@ impl RpcMethod<1> for StateGetBeaconEntry {
}
}

pub enum StateSectorPreCommitInfoV0 {}

impl RpcMethod<3> for StateSectorPreCommitInfoV0 {
// TODO(forest): https://github.com/ChainSafe/forest/issues/3960
// point v0 implementation back to this one
const NAME: &'static str = "Filecoin.StateSectorPreCommitInfoV0";
const PARAM_NAMES: [&'static str; 3] = ["miner_address", "sector_number", "tipset_key"];
const API_VERSION: ApiVersion = ApiVersion::V0;
const PERMISSION: Permission = Permission::Read;

type Params = (Address, u64, ApiTipsetKey);
type Ok = SectorPreCommitOnChainInfo;

async fn handle(
ctx: Ctx<impl Blockstore>,
(miner_address, sector_number, ApiTipsetKey(tsk)): Self::Params,
) -> Result<Self::Ok, ServerError> {
let ts = ctx
.state_manager
.chain_store()
.load_required_tipset_or_heaviest(&tsk)?;
let actor = ctx
.state_manager
.get_required_actor(&miner_address, *ts.parent_state())?;
let state = miner::State::load(ctx.store(), actor.code, actor.state)?;
Ok(state
.load_precommit_on_chain_info(ctx.store(), sector_number)?
.context("precommit info does not exist")?)
}
}

pub enum StateSectorPreCommitInfo {}

impl RpcMethod<3> for StateSectorPreCommitInfo {
const NAME: &'static str = "Filecoin.StateSectorPreCommitInfo";
const PARAM_NAMES: [&'static str; 3] = ["miner_address", "sector_number", "tipset_key"];
const API_VERSION: ApiVersion = ApiVersion::V0;
const API_VERSION: ApiVersion = ApiVersion::V1;
const PERMISSION: Permission = Permission::Read;

type Params = (Address, u64, ApiTipsetKey);
type Ok = SectorPreCommitOnChainInfo;
type Ok = Option<SectorPreCommitOnChainInfo>;

async fn handle(
ctx: Ctx<impl Blockstore>,
Expand All @@ -1608,27 +1639,7 @@ impl RpcMethod<3> for StateSectorPreCommitInfo {
.state_manager
.get_required_actor(&miner_address, *ts.parent_state())?;
let state = miner::State::load(ctx.store(), actor.code, actor.state)?;
Ok(match state {
miner::State::V8(s) => s
.get_precommitted_sector(ctx.store(), sector_number)?
.map(SectorPreCommitOnChainInfo::from),
miner::State::V9(s) => s
.get_precommitted_sector(ctx.store(), sector_number)?
.map(SectorPreCommitOnChainInfo::from),
miner::State::V10(s) => s
.get_precommitted_sector(ctx.store(), sector_number)?
.map(SectorPreCommitOnChainInfo::from),
miner::State::V11(s) => s
.get_precommitted_sector(ctx.store(), sector_number)?
.map(SectorPreCommitOnChainInfo::from),
miner::State::V12(s) => s
.get_precommitted_sector(ctx.store(), sector_number)?
.map(SectorPreCommitOnChainInfo::from),
miner::State::V13(s) => s
.get_precommitted_sector(ctx.store(), sector_number)?
.map(SectorPreCommitOnChainInfo::from),
}
.context("precommit info does not exist")?)
Ok(state.load_precommit_on_chain_info(ctx.store(), sector_number)?)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ macro_rules! for_each_method {
$callback!(crate::rpc::state::StateNetworkName);
$callback!(crate::rpc::state::StateReplay);
$callback!(crate::rpc::state::StateSectorGetInfo);
$callback!(crate::rpc::state::StateSectorPreCommitInfoV0);
$callback!(crate::rpc::state::StateSectorPreCommitInfo);
$callback!(crate::rpc::state::StateAccountKey);
$callback!(crate::rpc::state::StateLookupID);
Expand Down
9 changes: 8 additions & 1 deletion src/shim/actors/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use fil_actor_interface::miner::State;
use fil_actors_shared::fvm_ipld_bitfield::BitField;
use fvm_ipld_blockstore::Blockstore;

use crate::rpc::types::SectorOnChainInfo;
use crate::rpc::types::{SectorOnChainInfo, SectorPreCommitOnChainInfo};
use crate::utils::db::CborStoreExt as _;

pub trait MinerStateExt {
Expand All @@ -24,6 +24,13 @@ pub trait MinerStateExt {
/// Loads the allocated sector numbers
fn load_allocated_sector_numbers<BS: Blockstore>(&self, store: &BS)
-> anyhow::Result<BitField>;

/// Loads the precommit-on-chain info
fn load_precommit_on_chain_info<BS: Blockstore>(
&self,
store: &BS,
sector_number: u64,
) -> anyhow::Result<Option<SectorPreCommitOnChainInfo>>;
}

pub trait PartitionExt {
Expand Down
27 changes: 27 additions & 0 deletions src/shim/actors/miner/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,31 @@ impl MinerStateExt for State {
};
store.get_cbor_required(&allocated_sectors)
}

fn load_precommit_on_chain_info<BS: Blockstore>(
&self,
store: &BS,
sector_number: u64,
) -> anyhow::Result<Option<SectorPreCommitOnChainInfo>> {
Ok(match self {
Self::V8(s) => s
.get_precommitted_sector(store, sector_number)?
.map(SectorPreCommitOnChainInfo::from),
Self::V9(s) => s
.get_precommitted_sector(store, sector_number)?
.map(SectorPreCommitOnChainInfo::from),
Self::V10(s) => s
.get_precommitted_sector(store, sector_number)?
.map(SectorPreCommitOnChainInfo::from),
Self::V11(s) => s
.get_precommitted_sector(store, sector_number)?
.map(SectorPreCommitOnChainInfo::from),
Self::V12(s) => s
.get_precommitted_sector(store, sector_number)?
.map(SectorPreCommitOnChainInfo::from),
Self::V13(s) => s
.get_precommitted_sector(store, sector_number)?
.map(SectorPreCommitOnChainInfo::from),
})
}
}

0 comments on commit 247c311

Please sign in to comment.