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.StateGetRandomnessDigestFromBeacon #4565

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 @@ -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 @@ -1414,6 +1414,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 @@ -154,6 +154,7 @@ macro_rules! for_each_method {
$callback!(crate::rpc::state::StateGetReceipt);
$callback!(crate::rpc::state::StateGetRandomnessFromTickets);
$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 @@ -710,6 +710,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
Loading