Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

### Changed

- [#6897](https://github.com/ChainSafe/forest/pull/6897): Integrated EC finality into Eth RPC methods.

- [#6821](https://github.com/ChainSafe/forest/pull/6821): Added message receipt size and event size to `forest-tool archive info` output.

- [#6830](https://github.com/ChainSafe/forest/pull/6830): Make base fee FIP-0115 activation configurable via `FOREST_FEES_FIP0115HEIGHT` environment variable. The FIP will NOT be automatically activated on the next network upgrade with this change, for now.
Expand Down
23 changes: 4 additions & 19 deletions src/rpc/methods/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,28 +1070,13 @@ impl ChainGetTipSetV2 {
pub async fn get_latest_finalized_tipset(
ctx: &Ctx<impl Blockstore + Send + Sync + 'static>,
) -> anyhow::Result<Tipset> {
let Some(f3_finalized_head) = ctx.chain_store().f3_finalized_tipset() else {
return Self::get_ec_finalized_tipset(ctx);
};
let head = ctx.chain_store().heaviest_tipset();
// Latest F3 finalized tipset is older than EC finality, falling back to EC finality
if head.epoch() > f3_finalized_head.epoch() + ctx.chain_config().policy.chain_finality {
Self::get_ec_finalized_tipset(ctx)
if let Some(ts) = ChainGetTipSetFinalityStatus::get_finality_status(ctx).finalized_tip_set {
Ok(ts)
} else {
Ok(f3_finalized_head)
crate::rpc::eth::tipset_resolver::get_fallback_ec_finalized_tipset(ctx.chain_store())
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}
}

pub fn get_ec_finalized_tipset(ctx: &Ctx<impl Blockstore>) -> anyhow::Result<Tipset> {
let head = ctx.chain_store().heaviest_tipset();
let ec_finality_epoch = (head.epoch() - ctx.chain_config().policy.chain_finality).max(0);
Ok(ctx.chain_index().tipset_by_height(
ec_finality_epoch,
head,
ResolveNullTipset::TakeOlder,
)?)
}

pub async fn get_tipset(
ctx: &Ctx<impl Blockstore + Send + Sync + 'static>,
selector: &TipsetSelector,
Expand Down Expand Up @@ -1169,7 +1154,7 @@ impl ChainGetTipSetFinalityStatus {
}
}

fn get_ec_finality_threshold_depth_and_tipset_with_cache(
pub fn get_ec_finality_threshold_depth_and_tipset_with_cache(
ctx: &Ctx<impl Blockstore>,
head: Tipset,
) -> (i64, Option<Tipset>) {
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod eth_tx;
pub mod filter;
pub mod pubsub;
pub(crate) mod pubsub_trait;
mod tipset_resolver;
pub(crate) mod tipset_resolver;
pub(crate) mod trace;
pub mod types;
mod utils;
Expand Down
37 changes: 26 additions & 11 deletions src/rpc/methods/eth/tipset_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use super::*;
use crate::rpc::chain::SAFE_HEIGHT_DISTANCE;
use crate::rpc::chain::{ChainGetTipSetFinalityStatus, SAFE_HEIGHT_DISTANCE};

pub struct TipsetResolver<'a, DB>
where
Expand Down Expand Up @@ -167,17 +167,32 @@ where
)?)
}

/// Returns the tipset considered finalized by expected-consensus finality.
///
/// The finalized epoch is computed as head.epoch() minus the chain's `policy.chain_finality`, clamped to zero. The tipset at that epoch is returned; when the exact height is unavailable, an older tipset is selected.
/// Returns the tipset considered finalized by the expected-consensus finality calculator(`FRC-0089`).
pub fn get_ec_finalized_tipset(&self) -> anyhow::Result<Tipset> {
let head = self.ctx.chain_store().heaviest_tipset();
let ec_finality_epoch =
(head.epoch() - self.ctx.chain_config().policy.chain_finality).max(0);
Ok(self.ctx.chain_index().tipset_by_height(
ec_finality_epoch,
head,
ResolveNullTipset::TakeOlder,
)?)
let (_, ec_finalized_tipset) =
ChainGetTipSetFinalityStatus::get_ec_finality_threshold_depth_and_tipset_with_cache(
self.ctx,
head.clone(),
);
if let Some(ts) = ec_finalized_tipset {
Ok(ts)
} else {
get_fallback_ec_finalized_tipset(self.ctx.chain_store())
}
}
}

/// Returns the tipset considered finalized by the fallback expected-consensus finality.
///
/// The finalized epoch is computed as head.epoch() minus the chain's `policy.chain_finality`, clamped to zero.
/// The tipset at that epoch is returned; when the exact height is unavailable, an older tipset is selected.
pub fn get_fallback_ec_finalized_tipset<DB: Blockstore>(
cs: &ChainStore<DB>,
) -> anyhow::Result<Tipset> {
let head = cs.heaviest_tipset();
let ec_finality_epoch = (head.epoch() - cs.chain_config().policy.chain_finality).max(0);
Ok(cs
.chain_index()
.tipset_by_height(ec_finality_epoch, head, ResolveNullTipset::TakeOlder)?)
}
2 changes: 1 addition & 1 deletion src/tool/subcommands/api_cmd/api_compare_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ fn chain_tests(offline: bool) -> Vec<RpcTest> {
} else {
RpcTest::identity(ChainGetTipSetFinalityStatus::request(()).unwrap())
},
RpcTest::basic(ChainGetFinalizedTipset::request(()).unwrap()),
]
}

Expand Down Expand Up @@ -567,7 +568,6 @@ fn chain_tests_with_tipset<DB: Blockstore>(
.clone()
.into(),))?),
RpcTest::identity(ChainTipSetWeight::request((tipset.key().into(),))?),
RpcTest::basic(ChainGetFinalizedTipset::request(())?),
];

if !offline {
Expand Down
4 changes: 2 additions & 2 deletions src/tool/subcommands/api_cmd/test_snapshots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ filecoin_chaingetevents_1764864316078100.rpcsnap.json.zst
filecoin_chaingetevents_1765289237680041.rpcsnap.json.zst
filecoin_chaingetevents_1765289237680294.rpcsnap.json.zst
filecoin_chaingetevents_1765289237681455.rpcsnap.json.zst
filecoin_chaingetfinalizedtipset_1759828121342574.rpcsnap.json.zst
filecoin_chaingetfinalizedtipset_1776082510830037.rpcsnap.json.zst
filecoin_chaingetgenesis_1736937286915866.rpcsnap.json.zst
filecoin_chaingetmessage_1758734340836824.rpcsnap.json.zst
filecoin_chaingetmessagesintipset_1758734696116136.rpcsnap.json.zst
Expand Down Expand Up @@ -108,7 +108,7 @@ filecoin_ethgettransactionbyhash_1741272955520821.rpcsnap.json.zst
filecoin_ethgettransactionbyhashlimited_1741272955509708.rpcsnap.json.zst
filecoin_ethgettransactioncount_1740132538183426.rpcsnap.json.zst
filecoin_ethgettransactioncount_v1_unknown_addr_1770288294132251.rpcsnap.json.zst
filecoin_ethgettransactioncount_v2_1767847407595348.rpcsnap.json.zst
filecoin_ethgettransactioncount_v2_1776080971678636.rpcsnap.json.zst
filecoin_ethgettransactioncount_v2_unknown_addr_1770288294132366.rpcsnap.json.zst
filecoin_ethgettransactionhashbycid_1737446676698540.rpcsnap.json.zst
filecoin_ethgettransactionreceipt_1741272955712904.rpcsnap.json.zst
Expand Down
Loading