Skip to content

Commit e2fc9d2

Browse files
authored
feat(rpc): add Forest.ChainGetTipsetByParentState for trouble shooting state tree missing issues. (#6352)
1 parent 74a5f0c commit e2fc9d2

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/rpc/methods/chain.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,29 @@ impl RpcMethod<1> for ChainTipSetWeight {
12451245
}
12461246
}
12471247

1248+
pub enum ChainGetTipsetByParentState {}
1249+
impl RpcMethod<1> for ChainGetTipsetByParentState {
1250+
const NAME: &'static str = "Forest.ChainGetTipsetByParentState";
1251+
const PARAM_NAMES: [&'static str; 1] = ["parentState"];
1252+
const API_PATHS: BitFlags<ApiPaths> = ApiPaths::all();
1253+
const PERMISSION: Permission = Permission::Read;
1254+
1255+
type Params = (Cid,);
1256+
type Ok = Option<Tipset>;
1257+
1258+
async fn handle(
1259+
ctx: Ctx<impl Blockstore>,
1260+
(parent_state,): Self::Params,
1261+
) -> Result<Self::Ok, ServerError> {
1262+
Ok(ctx
1263+
.chain_store()
1264+
.heaviest_tipset()
1265+
.chain(ctx.store())
1266+
.find(|ts| ts.parent_state() == &parent_state)
1267+
.clone())
1268+
}
1269+
}
1270+
12481271
pub const CHAIN_NOTIFY: &str = "Filecoin.ChainNotify";
12491272
pub(crate) fn chain_notify<DB: Blockstore>(
12501273
_params: Params<'_>,

src/rpc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ macro_rules! for_each_rpc_method {
8888
$callback!($crate::rpc::chain::ForestChainExportDiff);
8989
$callback!($crate::rpc::chain::ForestChainExportStatus);
9090
$callback!($crate::rpc::chain::ForestChainExportCancel);
91+
$callback!($crate::rpc::chain::ChainGetTipsetByParentState);
9192

9293
// common vertical
9394
$callback!($crate::rpc::common::Session);

src/tool/subcommands/api_cmd/test_snapshots_ignored.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Forest.ChainExportCancel
8181
Forest.ChainExportDiff
8282
Forest.ChainExportStatus
8383
Forest.ChainGetMinBaseFee
84+
Forest.ChainGetTipsetByParentState
8485
Forest.NetInfo
8586
Forest.SnapshotGC
8687
Forest.StateActorInfo

0 commit comments

Comments
 (0)