diff --git a/src/rpc/methods/state.rs b/src/rpc/methods/state.rs index d28ca16cc00b..f73e6d321be1 100644 --- a/src/rpc/methods/state.rs +++ b/src/rpc/methods/state.rs @@ -1384,6 +1384,28 @@ impl RpcMethod<4> for StateGetRandomnessFromTickets { } } +pub enum StateGetRandomnessDigestFromTickets {} + +impl RpcMethod<2> for StateGetRandomnessDigestFromTickets { + const NAME: &'static str = "Filecoin.StateGetRandomnessDigestFromTickets"; + const PARAM_NAMES: [&'static str; 2] = ["rand_epoch", "tipset_key"]; + const API_PATHS: ApiPaths = ApiPaths::V0; + const PERMISSION: Permission = Permission::Read; + + type Params = (ChainEpoch, ApiTipsetKey); + type Ok = Vec; + + async fn handle( + ctx: Ctx, + (rand_epoch, ApiTipsetKey(tsk)): Self::Params, + ) -> Result { + let tipset = ctx.chain_store().load_required_tipset_or_heaviest(&tsk)?; + let chain_rand = ctx.state_manager.chain_rand(tipset); + let digest = chain_rand.get_chain_randomness(rand_epoch, false)?; + Ok(digest.to_vec()) + } +} + /// Get randomness from beacon pub enum StateGetRandomnessFromBeacon {} diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index 4302e2428340..8ca1fd715825 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -153,6 +153,7 @@ macro_rules! for_each_method { $callback!(crate::rpc::state::StateMinerInitialPledgeCollateral); $callback!(crate::rpc::state::StateGetReceipt); $callback!(crate::rpc::state::StateGetRandomnessFromTickets); + $callback!(crate::rpc::state::StateGetRandomnessDigestFromTickets); $callback!(crate::rpc::state::StateGetRandomnessFromBeacon); $callback!(crate::rpc::state::StateReadState); $callback!(crate::rpc::state::StateCirculatingSupply); diff --git a/src/tool/subcommands/api_cmd.rs b/src/tool/subcommands/api_cmd.rs index 7f4e269c3691..26d71610e06d 100644 --- a/src/tool/subcommands/api_cmd.rs +++ b/src/tool/subcommands/api_cmd.rs @@ -704,6 +704,10 @@ fn state_tests_with_tipset( "dead beef".as_bytes().to_vec(), tipset.key().into(), ))?), + RpcTest::identity(StateGetRandomnessDigestFromTickets::request(( + tipset.epoch(), + tipset.key().into(), + ))?), RpcTest::identity(StateGetRandomnessFromBeacon::request(( DomainSeparationTag::ElectionProofProduction as i64, tipset.epoch(),