Skip to content

Commit

Permalink
fix(rpc): verify and adjust common node API parameter names 1/4 (#5290)
Browse files Browse the repository at this point in the history
  • Loading branch information
elmattic authored Feb 13, 2025
1 parent e28fe8f commit 8134b37
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 63 deletions.
68 changes: 39 additions & 29 deletions src/rpc/methods/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use tokio::sync::{
pub enum ChainGetMessage {}
impl RpcMethod<1> for ChainGetMessage {
const NAME: &'static str = "Filecoin.ChainGetMessage";
const PARAM_NAMES: [&'static str; 1] = ["msg_cid"];
const PARAM_NAMES: [&'static str; 1] = ["messageCid"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

Expand All @@ -54,12 +54,12 @@ impl RpcMethod<1> for ChainGetMessage {

async fn handle(
ctx: Ctx<impl Blockstore>,
(msg_cid,): Self::Params,
(message_cid,): Self::Params,
) -> Result<Self::Ok, ServerError> {
let chain_message: ChainMessage = ctx
.store()
.get_cbor(&msg_cid)?
.with_context(|| format!("can't find message with cid {msg_cid}"))?;
.get_cbor(&message_cid)?
.with_context(|| format!("can't find message with cid {message_cid}"))?;
Ok(match chain_message {
ChainMessage::Signed(m) => m.into_message(),
ChainMessage::Unsigned(m) => m,
Expand All @@ -70,7 +70,7 @@ impl RpcMethod<1> for ChainGetMessage {
pub enum ChainGetEvents {}
impl RpcMethod<1> for ChainGetEvents {
const NAME: &'static str = "Filecoin.ChainGetEvents";
const PARAM_NAMES: [&'static str; 1] = ["cid"];
const PARAM_NAMES: [&'static str; 1] = ["rootCid"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;
type Params = (Cid,);
Expand All @@ -83,7 +83,7 @@ impl RpcMethod<1> for ChainGetEvents {
pub enum ChainGetParentMessages {}
impl RpcMethod<1> for ChainGetParentMessages {
const NAME: &'static str = "Filecoin.ChainGetParentMessages";
const PARAM_NAMES: [&'static str; 1] = ["block_cid"];
const PARAM_NAMES: [&'static str; 1] = ["blockCid"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

Expand All @@ -110,7 +110,7 @@ impl RpcMethod<1> for ChainGetParentMessages {
pub enum ChainGetParentReceipts {}
impl RpcMethod<1> for ChainGetParentReceipts {
const NAME: &'static str = "Filecoin.ChainGetParentReceipts";
const PARAM_NAMES: [&'static str; 1] = ["block_cid"];
const PARAM_NAMES: [&'static str; 1] = ["blockCid"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

Expand Down Expand Up @@ -155,7 +155,7 @@ impl RpcMethod<1> for ChainGetParentReceipts {
pub enum ChainGetMessagesInTipset {}
impl RpcMethod<1> for ChainGetMessagesInTipset {
const NAME: &'static str = "Filecoin.ChainGetMessagesInTipset";
const PARAM_NAMES: [&'static str; 1] = ["tsk"];
const PARAM_NAMES: [&'static str; 1] = ["tipsetKey"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

Expand All @@ -164,9 +164,11 @@ impl RpcMethod<1> for ChainGetMessagesInTipset {

async fn handle(
ctx: Ctx<impl Blockstore>,
(ApiTipsetKey(tsk),): Self::Params,
(ApiTipsetKey(tipset_key),): Self::Params,
) -> Result<Self::Ok, ServerError> {
let tipset = ctx.chain_store().load_required_tipset_or_heaviest(&tsk)?;
let tipset = ctx
.chain_store()
.load_required_tipset_or_heaviest(&tipset_key)?;
load_api_messages_from_tipset(ctx.store(), &tipset)
}
}
Expand Down Expand Up @@ -339,7 +341,7 @@ impl RpcMethod<2> for ChainStatObj {
pub enum ChainGetBlockMessages {}
impl RpcMethod<1> for ChainGetBlockMessages {
const NAME: &'static str = "Filecoin.ChainGetBlockMessages";
const PARAM_NAMES: [&'static str; 1] = ["cid"];
const PARAM_NAMES: [&'static str; 1] = ["blockCid"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

Expand All @@ -348,9 +350,9 @@ impl RpcMethod<1> for ChainGetBlockMessages {

async fn handle(
ctx: Ctx<impl Blockstore>,
(cid,): Self::Params,
(block_cid,): Self::Params,
) -> Result<Self::Ok, ServerError> {
let blk: CachingBlockHeader = ctx.store().get_cbor_required(&cid)?;
let blk: CachingBlockHeader = ctx.store().get_cbor_required(&block_cid)?;
let blk_msgs = &blk.messages;
let (unsigned_cids, signed_cids) = crate::chain::read_msg_cids(ctx.store(), blk_msgs)?;
let (bls_msg, secp_msg) =
Expand Down Expand Up @@ -446,7 +448,7 @@ fn impl_chain_get_path(
pub enum ChainGetTipSetByHeight {}
impl RpcMethod<2> for ChainGetTipSetByHeight {
const NAME: &'static str = "Filecoin.ChainGetTipSetByHeight";
const PARAM_NAMES: [&'static str; 2] = ["height", "tsk"];
const PARAM_NAMES: [&'static str; 2] = ["height", "tipsetKey"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

Expand All @@ -455,9 +457,11 @@ impl RpcMethod<2> for ChainGetTipSetByHeight {

async fn handle(
ctx: Ctx<impl Blockstore>,
(height, ApiTipsetKey(tsk)): Self::Params,
(height, ApiTipsetKey(tipset_key)): Self::Params,
) -> Result<Self::Ok, ServerError> {
let ts = ctx.chain_store().load_required_tipset_or_heaviest(&tsk)?;
let ts = ctx
.chain_store()
.load_required_tipset_or_heaviest(&tipset_key)?;
let tss = ctx
.chain_index()
.tipset_by_height(height, ts, ResolveNullTipset::TakeOlder)?;
Expand All @@ -468,7 +472,7 @@ impl RpcMethod<2> for ChainGetTipSetByHeight {
pub enum ChainGetTipSetAfterHeight {}
impl RpcMethod<2> for ChainGetTipSetAfterHeight {
const NAME: &'static str = "Filecoin.ChainGetTipSetAfterHeight";
const PARAM_NAMES: [&'static str; 2] = ["height", "tsk"];
const PARAM_NAMES: [&'static str; 2] = ["height", "tipsetKey"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

Expand All @@ -477,9 +481,11 @@ impl RpcMethod<2> for ChainGetTipSetAfterHeight {

async fn handle(
ctx: Ctx<impl Blockstore>,
(height, ApiTipsetKey(tsk)): Self::Params,
(height, ApiTipsetKey(tipset_key)): Self::Params,
) -> Result<Self::Ok, ServerError> {
let ts = ctx.chain_store().load_required_tipset_or_heaviest(&tsk)?;
let ts = ctx
.chain_store()
.load_required_tipset_or_heaviest(&tipset_key)?;
let tss = ctx
.chain_index()
.tipset_by_height(height, ts, ResolveNullTipset::TakeNewer)?;
Expand Down Expand Up @@ -522,7 +528,7 @@ impl RpcMethod<0> for ChainHead {
pub enum ChainGetBlock {}
impl RpcMethod<1> for ChainGetBlock {
const NAME: &'static str = "Filecoin.ChainGetBlock";
const PARAM_NAMES: [&'static str; 1] = ["cid"];
const PARAM_NAMES: [&'static str; 1] = ["blockCid"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

Expand All @@ -531,17 +537,17 @@ impl RpcMethod<1> for ChainGetBlock {

async fn handle(
ctx: Ctx<impl Blockstore>,
(cid,): Self::Params,
(block_cid,): Self::Params,
) -> Result<Self::Ok, ServerError> {
let blk: CachingBlockHeader = ctx.store().get_cbor_required(&cid)?;
let blk: CachingBlockHeader = ctx.store().get_cbor_required(&block_cid)?;
Ok(blk)
}
}

pub enum ChainGetTipSet {}
impl RpcMethod<1> for ChainGetTipSet {
const NAME: &'static str = "Filecoin.ChainGetTipSet";
const PARAM_NAMES: [&'static str; 1] = ["tsk"];
const PARAM_NAMES: [&'static str; 1] = ["tipsetKey"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

Expand All @@ -550,9 +556,11 @@ impl RpcMethod<1> for ChainGetTipSet {

async fn handle(
ctx: Ctx<impl Blockstore>,
(ApiTipsetKey(tsk),): Self::Params,
(ApiTipsetKey(tipset_key),): Self::Params,
) -> Result<Self::Ok, ServerError> {
let ts = ctx.chain_store().load_required_tipset_or_heaviest(&tsk)?;
let ts = ctx
.chain_store()
.load_required_tipset_or_heaviest(&tipset_key)?;
Ok((*ts).clone())
}
}
Expand Down Expand Up @@ -621,7 +629,7 @@ impl RpcMethod<1> for ChainGetMinBaseFee {
pub enum ChainTipSetWeight {}
impl RpcMethod<1> for ChainTipSetWeight {
const NAME: &'static str = "Filecoin.ChainTipSetWeight";
const PARAM_NAMES: [&'static str; 1] = ["tsk"];
const PARAM_NAMES: [&'static str; 1] = ["tipsetKey"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

Expand All @@ -630,10 +638,12 @@ impl RpcMethod<1> for ChainTipSetWeight {

async fn handle(
ctx: Ctx<impl Blockstore>,
(ApiTipsetKey(tsk),): Self::Params,
(ApiTipsetKey(tipset_key),): Self::Params,
) -> Result<Self::Ok, ServerError> {
let tsk = ctx.chain_store().load_required_tipset_or_heaviest(&tsk)?;
let weight = crate::fil_cns::weight(ctx.store(), &tsk)?;
let ts = ctx
.chain_store()
.load_required_tipset_or_heaviest(&tipset_key)?;
let weight = crate::fil_cns::weight(ctx.store(), &ts)?;
Ok(weight)
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/rpc/methods/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct MessageMeta {
pub enum MinerCreateBlock {}
impl RpcMethod<1> for MinerCreateBlock {
const NAME: &'static str = "Filecoin.MinerCreateBlock";
const PARAM_NAMES: [&'static str; 1] = ["block_template"];
const PARAM_NAMES: [&'static str; 1] = ["blockTemplate"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Write;

Expand Down Expand Up @@ -270,7 +270,7 @@ fn aggregate_from_bls_signatures(bls_sigs: Vec<Signature>) -> anyhow::Result<Sig
pub enum MinerGetBaseInfo {}
impl RpcMethod<3> for MinerGetBaseInfo {
const NAME: &'static str = "Filecoin.MinerGetBaseInfo";
const PARAM_NAMES: [&'static str; 3] = ["address", "epoch", "tsk"];
const PARAM_NAMES: [&'static str; 3] = ["minerAddress", "epoch", "tipsetKey"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;

Expand All @@ -279,13 +279,15 @@ impl RpcMethod<3> for MinerGetBaseInfo {

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(address, epoch, ApiTipsetKey(tsk)): Self::Params,
(miner_address, epoch, ApiTipsetKey(tipset_key)): Self::Params,
) -> Result<Self::Ok, ServerError> {
let ts = ctx.chain_store().load_required_tipset_or_heaviest(&tsk)?;
let tipset = ctx
.chain_store()
.load_required_tipset_or_heaviest(&tipset_key)?;

Ok(ctx
.state_manager
.miner_get_base_info(ctx.beacon(), ts, address, epoch)
.miner_get_base_info(ctx.beacon(), tipset, miner_address, epoch)
.await?)
}
}
2 changes: 1 addition & 1 deletion src/rpc/methods/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
pub enum GetActorEventsRaw {}
impl RpcMethod<1> for GetActorEventsRaw {
const NAME: &'static str = "Filecoin.GetActorEventsRaw";
const PARAM_NAMES: [&'static str; 1] = ["filter"];
const PARAM_NAMES: [&'static str; 1] = ["eventFilter"];
const API_PATHS: ApiPaths = ApiPaths::V1;
const PERMISSION: Permission = Permission::Read;
type Params = (Option<ActorEventFilter>,);
Expand Down
Loading

0 comments on commit 8134b37

Please sign in to comment.