@@ -68,7 +68,7 @@ const HEAD_CHANNEL_CAPACITY: usize = 10;
6868/// Discussion on this current value and a tracking item to document the
6969/// probabilistic impact of various values is in
7070/// https://github.com/filecoin-project/go-f3/issues/944
71- const SAFE_HEIGHT_DISTANCE : ChainEpoch = 200 ;
71+ pub const SAFE_HEIGHT_DISTANCE : ChainEpoch = 200 ;
7272
7373static CHAIN_EXPORT_LOCK : LazyLock < Mutex < Option < CancellationToken > > > =
7474 LazyLock :: new ( || Mutex :: new ( None ) ) ;
@@ -988,6 +988,7 @@ impl RpcMethod<1> for ChainGetBlock {
988988}
989989
990990pub enum ChainGetTipSet { }
991+
991992impl RpcMethod < 1 > for ChainGetTipSet {
992993 const NAME : & ' static str = "Filecoin.ChainGetTipSet" ;
993994 const PARAM_NAMES : [ & ' static str ; 1 ] = [ "tipsetKey" ] ;
@@ -1045,7 +1046,7 @@ impl ChainGetTipSetV2 {
10451046 ) -> anyhow:: Result < Option < Tipset > > {
10461047 match tag {
10471048 TipsetTag :: Latest => Ok ( Some ( ctx. state_manager . heaviest_tipset ( ) ) ) ,
1048- TipsetTag :: Finalized => Self :: get_latest_finalized_tipset ( ctx) . await ,
1049+ TipsetTag :: Finalized => Some ( Self :: get_latest_finalized_tipset ( ctx) . await ) . transpose ( ) ,
10491050 TipsetTag :: Safe => Some ( Self :: get_latest_safe_tipset ( ctx) . await ) . transpose ( ) ,
10501051 }
10511052 }
@@ -1056,9 +1057,7 @@ impl ChainGetTipSetV2 {
10561057 let finalized = Self :: get_latest_finalized_tipset ( ctx) . await ?;
10571058 let head = ctx. chain_store ( ) . heaviest_tipset ( ) ;
10581059 let safe_height = ( head. epoch ( ) - SAFE_HEIGHT_DISTANCE ) . max ( 0 ) ;
1059- if let Some ( finalized) = finalized
1060- && finalized. epoch ( ) >= safe_height
1061- {
1060+ if finalized. epoch ( ) >= safe_height {
10621061 Ok ( finalized)
10631062 } else {
10641063 Ok ( ctx. chain_index ( ) . tipset_by_height (
@@ -1069,9 +1068,17 @@ impl ChainGetTipSetV2 {
10691068 }
10701069 }
10711070
1071+ pub fn get_ec_safe_tipset ( ctx : & Ctx < impl Blockstore > ) -> anyhow:: Result < Tipset > {
1072+ let head = ctx. chain_store ( ) . heaviest_tipset ( ) ;
1073+ let safe_height = ( head. epoch ( ) - SAFE_HEIGHT_DISTANCE ) . max ( 0 ) ;
1074+ Ok ( ctx
1075+ . chain_index ( )
1076+ . tipset_by_height ( safe_height, head, ResolveNullTipset :: TakeOlder ) ?)
1077+ }
1078+
10721079 pub async fn get_latest_finalized_tipset (
10731080 ctx : & Ctx < impl Blockstore + Send + Sync + ' static > ,
1074- ) -> anyhow:: Result < Option < Tipset > > {
1081+ ) -> anyhow:: Result < Tipset > {
10751082 let Ok ( f3_finalized_cert) =
10761083 crate :: rpc:: f3:: F3GetLatestCertificate :: handle ( ctx. clone ( ) , ( ) ) . await
10771084 else {
@@ -1095,22 +1102,17 @@ impl ChainGetTipSetV2 {
10951102 f3_finalized_head. key,
10961103 )
10971104 } ) ?;
1098- Ok ( Some ( ts ) )
1105+ Ok ( ts )
10991106 }
11001107
1101- pub fn get_ec_finalized_tipset ( ctx : & Ctx < impl Blockstore > ) -> anyhow:: Result < Option < Tipset > > {
1108+ pub fn get_ec_finalized_tipset ( ctx : & Ctx < impl Blockstore > ) -> anyhow:: Result < Tipset > {
11021109 let head = ctx. chain_store ( ) . heaviest_tipset ( ) ;
1103- let ec_finality_epoch = head. epoch ( ) - ctx. chain_config ( ) . policy . chain_finality ;
1104- if ec_finality_epoch >= 0 {
1105- let ts = ctx. chain_index ( ) . tipset_by_height (
1106- ec_finality_epoch,
1107- head,
1108- ResolveNullTipset :: TakeOlder ,
1109- ) ?;
1110- Ok ( Some ( ts) )
1111- } else {
1112- Ok ( None )
1113- }
1110+ let ec_finality_epoch = ( head. epoch ( ) - ctx. chain_config ( ) . policy . chain_finality ) . max ( 0 ) ;
1111+ Ok ( ctx. chain_index ( ) . tipset_by_height (
1112+ ec_finality_epoch,
1113+ head,
1114+ ResolveNullTipset :: TakeOlder ,
1115+ ) ?)
11141116 }
11151117
11161118 pub async fn get_tipset (
0 commit comments