Skip to content

Commit

Permalink
feat(rpc) Implement Filecoin.StateGetRandomnessDigestFromBeacon (#4565)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-shashank authored Jul 18, 2024
1 parent a79de25 commit 896ea13
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
- [#4474](https://github.com/ChainSafe/forest/pull/4474) Add new subcommand
`forest-cli healthcheck ready`.

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

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

Expand Down
22 changes: 22 additions & 0 deletions src/rpc/methods/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,28 @@ impl RpcMethod<4> for StateGetRandomnessFromBeacon {
}
}

pub enum StateGetRandomnessDigestFromBeacon {}

impl RpcMethod<2> for StateGetRandomnessDigestFromBeacon {
const NAME: &'static str = "Filecoin.StateGetRandomnessDigestFromBeacon";
const PARAM_NAMES: [&'static str; 2] = ["rand_epoch", "tipset_key"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

type Params = (ChainEpoch, ApiTipsetKey);
type Ok = Vec<u8>;

async fn handle(
ctx: Ctx<impl Blockstore>,
(rand_epoch, ApiTipsetKey(tsk)): Self::Params,
) -> Result<Self::Ok, ServerError> {
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_beacon_randomness_v3(rand_epoch)?;
Ok(digest.to_vec())
}
}

/// Get read state
pub enum StateReadState {}

Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ macro_rules! for_each_method {
$callback!(crate::rpc::state::StateGetRandomnessFromTickets);
$callback!(crate::rpc::state::StateGetRandomnessDigestFromTickets);
$callback!(crate::rpc::state::StateGetRandomnessFromBeacon);
$callback!(crate::rpc::state::StateGetRandomnessDigestFromBeacon);
$callback!(crate::rpc::state::StateReadState);
$callback!(crate::rpc::state::StateCirculatingSupply);
$callback!(crate::rpc::state::StateVerifiedClientStatus);
Expand Down
4 changes: 4 additions & 0 deletions src/tool/subcommands/api_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,10 @@ fn state_tests_with_tipset<DB: Blockstore>(
"dead beef".as_bytes().to_vec(),
tipset.key().into(),
))?),
RpcTest::identity(StateGetRandomnessDigestFromBeacon::request((
tipset.epoch(),
tipset.key().into(),
))?),
RpcTest::identity(StateReadState::request((
Address::SYSTEM_ACTOR,
tipset.key().into(),
Expand Down

0 comments on commit 896ea13

Please sign in to comment.