Skip to content

Commit

Permalink
Impl StateGetRandomnessDigestFromTickets
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-shashank committed Jul 18, 2024
1 parent 9d9b0af commit af26a3d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
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::V0;
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 af26a3d

Please sign in to comment.