Skip to content

Commit

Permalink
feat(rpc) Implement Filecoin.StateGetRandomnessDigestFromTickets (#4566)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-shashank authored Jul 18, 2024
1 parent 9d9b0af commit a79de25
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 @@ -66,6 +66,9 @@
- [#4547](https://github.com/ChainSafe/forest/pull/4547) Add support for the
`Filecoin.MpoolPushUntrusted` RPC method.

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

### Changed

### Removed
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 @@ -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::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_chain_randomness(rand_epoch, false)?;
Ok(digest.to_vec())
}
}

/// Get randomness from beacon
pub enum StateGetRandomnessFromBeacon {}

Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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 @@ -704,6 +704,10 @@ fn state_tests_with_tipset<DB: Blockstore>(
"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(),
Expand Down

0 comments on commit a79de25

Please sign in to comment.