Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 1 addition & 49 deletions src/rpc/methods/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,58 +167,10 @@ impl RpcMethod<0> for ChainGetFinalizedTipset {
(): Self::Params,
_: &http::Extensions,
) -> Result<Self::Ok, ServerError> {
let head = ctx.chain_store().heaviest_tipset();
let ec_finality_epoch = (head.epoch() - ctx.chain_config().policy.chain_finality).max(0);

// Either get the f3 finalized tipset or the ec finalized tipset
match get_f3_finality_tipset(&ctx, ec_finality_epoch).await {
Ok(f3_tipset) => {
tracing::debug!("Using F3 finalized tipset at epoch {}", f3_tipset.epoch());
Ok(f3_tipset)
}
Err(_) => {
// fallback to ec finality
tracing::warn!("F3 finalization unavailable, falling back to EC finality");
let ec_tipset = ctx.chain_index().tipset_by_height(
ec_finality_epoch,
head,
ResolveNullTipset::TakeOlder,
)?;
Ok(ec_tipset)
}
}
Ok(ChainGetTipSetV2::get_latest_finalized_tipset(&ctx).await?)
}
}

// get f3 finalized tipset based on ec finality epoch
async fn get_f3_finality_tipset<DB: Blockstore + Sync + Send + 'static>(
ctx: &Ctx<DB>,
ec_finality_epoch: ChainEpoch,
) -> Result<Tipset> {
let f3_finalized_cert = crate::rpc::f3::F3GetLatestCertificate::get()
.await
.map_err(|e| anyhow::anyhow!("Failed to get F3 certificate: {}", e))?;

let f3_finalized_head = f3_finalized_cert.chain_head();
if f3_finalized_head.epoch < ec_finality_epoch {
return Err(anyhow::anyhow!(
"F3 finalized tipset epoch {} is further back than EC finalized tipset epoch {}",
f3_finalized_head.epoch,
ec_finality_epoch
));
}

ctx.chain_index()
.load_required_tipset(&f3_finalized_head.key)
.map_err(|e| {
anyhow::anyhow!(
"Failed to load F3 finalized tipset at epoch {}: {}",
f3_finalized_head.epoch,
e
)
})
}

pub enum ChainGetMessage {}
impl RpcMethod<1> for ChainGetMessage {
const NAME: &'static str = "Filecoin.ChainGetMessage";
Expand Down
Loading