Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): implement Filecoin.StateVerifiedRegistryRootKey #4558

Merged
merged 3 commits into from
Jul 18, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
- [#4515](https://github.com/ChainSafe/forest/pull/4515) Add support for the
`Filecoin.StateLookupRobustAddress` RPC method.

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

- [#4474](https://github.com/ChainSafe/forest/pull/4474) Add new subcommand
`forest-cli healthcheck ready`.

Expand Down
25 changes: 25 additions & 0 deletions src/rpc/methods/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,31 @@ impl RpcMethod<2> for StateLookupID {
}
}

/// `StateVerifiedRegistryRootKey` returns the address of the Verified Registry's root key
pub enum StateVerifiedRegistryRootKey {}

impl RpcMethod<1> for StateVerifiedRegistryRootKey {
const NAME: &'static str = "Filecoin.StateVerifiedRegistryRootKey";
const PARAM_NAMES: [&'static str; 1] = ["tipset_key"];
const API_PATHS: ApiPaths = ApiPaths::V0;
const PERMISSION: Permission = Permission::Read;

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

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(ApiTipsetKey(tsk),): Self::Params,
) -> Result<Self::Ok, ServerError> {
let ts = ctx.chain_store().load_required_tipset_or_heaviest(&tsk)?;
let actor = ctx
.state_manager
.get_required_actor(&Address::VERIFIED_REGISTRY_ACTOR, *ts.parent_state())?;
let state = verifreg::State::load(ctx.store(), actor.code, actor.state)?;
Ok(state.root_key())
}
}

// StateVerifiedClientStatus returns the data cap for the given address.
// Returns zero if there is no entry in the data cap table for the address.
pub enum StateVerifierStatus {}
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ macro_rules! for_each_method {
$callback!(crate::rpc::state::StateFetchRoot);
$callback!(crate::rpc::state::StateCompute);
$callback!(crate::rpc::state::StateMinerPreCommitDepositForPower);
$callback!(crate::rpc::state::StateVerifiedRegistryRootKey);
$callback!(crate::rpc::state::StateVerifierStatus);
$callback!(crate::rpc::state::StateGetClaim);
$callback!(crate::rpc::state::StateGetClaims);
Expand Down
2 changes: 2 additions & 0 deletions src/shim/actors/verifreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ pub trait VerifiedRegistryStateExt {

fn get_all_claims<BS: Blockstore>(&self, store: &BS)
-> anyhow::Result<HashMap<ClaimID, Claim>>;

fn root_key(&self) -> Address;
}
12 changes: 12 additions & 0 deletions src/shim/actors/verifreg/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,16 @@ impl VerifiedRegistryStateExt for State {
};
Ok(result)
}

fn root_key(&self) -> Address {
match self {
State::V8(s) => s.root_key.into(),
State::V9(s) => s.root_key.into(),
State::V10(s) => s.root_key.into(),
State::V11(s) => s.root_key.into(),
State::V12(s) => s.root_key.into(),
State::V13(s) => s.root_key.into(),
State::V14(s) => s.root_key.into(),
}
}
}
3 changes: 3 additions & 0 deletions src/tool/subcommands/api_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ fn state_tests_with_tipset<DB: Blockstore>(
Address::new_id(0xdeadbeef),
tipset.key().into(),
))?),
RpcTest::identity(StateVerifiedRegistryRootKey::request((tipset
.key()
.into(),))?),
RpcTest::identity(StateVerifierStatus::request((
Address::VERIFIED_REGISTRY_ACTOR,
tipset.key().into(),
Expand Down
Loading