From f94fffa7698929736f0991748f4c2103b4e6e30a Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Thu, 18 Jul 2024 15:39:50 +0800 Subject: [PATCH 1/2] feat(rpc): implement Filecoin.StateVerifiedRegistryRootKey --- src/rpc/methods/state.rs | 25 +++++++++++++++++++++++++ src/rpc/mod.rs | 1 + src/shim/actors/verifreg.rs | 2 ++ src/shim/actors/verifreg/state.rs | 12 ++++++++++++ src/tool/subcommands/api_cmd.rs | 3 +++ 5 files changed, 43 insertions(+) diff --git a/src/rpc/methods/state.rs b/src/rpc/methods/state.rs index 7420b3b4a608..476e926982db 100644 --- a/src/rpc/methods/state.rs +++ b/src/rpc/methods/state.rs @@ -199,6 +199,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, + (ApiTipsetKey(tsk),): Self::Params, + ) -> Result { + 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 {} diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index 7621842c9600..656301713482 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -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); diff --git a/src/shim/actors/verifreg.rs b/src/shim/actors/verifreg.rs index 0a1bd52e0d2e..7e9be729adb8 100644 --- a/src/shim/actors/verifreg.rs +++ b/src/shim/actors/verifreg.rs @@ -29,4 +29,6 @@ pub trait VerifiedRegistryStateExt { fn get_all_claims(&self, store: &BS) -> anyhow::Result>; + + fn root_key(&self) -> Address; } diff --git a/src/shim/actors/verifreg/state.rs b/src/shim/actors/verifreg/state.rs index 36db43be9002..dc15775ce49b 100644 --- a/src/shim/actors/verifreg/state.rs +++ b/src/shim/actors/verifreg/state.rs @@ -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(), + } + } } diff --git a/src/tool/subcommands/api_cmd.rs b/src/tool/subcommands/api_cmd.rs index 9e9d844bafa8..93fd8f353922 100644 --- a/src/tool/subcommands/api_cmd.rs +++ b/src/tool/subcommands/api_cmd.rs @@ -723,6 +723,9 @@ fn state_tests_with_tipset( 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(), From f87fc971f0a9e2816855b9d23eb652b9b44fde11 Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Thu, 18 Jul 2024 15:48:50 +0800 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffdde30f60be..9d443c0f7e16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`.