Skip to content
Merged
Show file tree
Hide file tree
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
59 changes: 47 additions & 12 deletions src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,23 @@ impl RpcMethod<0> for EthAccounts {
}

pub enum EthBaseFee {}

impl EthBaseFee {
fn get_base_fee(ctx: &Ctx, ts: &Tipset) -> anyhow::Result<TokenAmount> {
let heights = &ctx.chain_config().height_infos;
let smoke_height = heights
.get(&Height::Smoke)
.context("Missing Smoke height")?
.epoch;
let firehorse_height = heights
.get(&Height::FireHorse)
.context("Missing FireHorse height")?
.epoch;
compute_base_fee(ctx.db(), ts, smoke_height, firehorse_height)
.context("failed to compute base fee for eth_baseFee")
}
}

impl RpcMethod<0> for EthBaseFee {
const NAME: &'static str = "Filecoin.EthBaseFee";
const NAME_ALIAS: Option<&'static str> = Some("eth_baseFee");
Expand All @@ -852,18 +869,36 @@ impl RpcMethod<0> for EthBaseFee {
(): Self::Params,
_: &http::Extensions,
) -> Result<Self::Ok, ServerError> {
let ts = ctx.chain_store().heaviest_tipset();
let heights = &ctx.chain_config().height_infos;
let smoke_height = heights
.get(&Height::Smoke)
.context("Missing Smoke height")?
.epoch;
let firehorse_height = heights
.get(&Height::FireHorse)
.context("Missing FireHorse height")?
.epoch;
let base_fee = compute_base_fee(ctx.db(), &ts, smoke_height, firehorse_height)
.context("failed to compute base fee for eth_baseFee")?;
let base_fee = Self::get_base_fee(&ctx, &ctx.chain_store().heaviest_tipset())?;
Ok(EthBigInt(base_fee.atto().clone()))
}
}

pub enum BaseFeeByHeight {}
impl RpcMethod<1> for BaseFeeByHeight {
const NAME: &'static str = "Forest.BaseFeeByHeight";
const NAME_ALIAS: Option<&'static str> = None;
const PARAM_NAMES: [&'static str; 1] = ["height"];
const API_PATHS: BitFlags<ApiPaths> = ApiPaths::all_with_v2();
const PERMISSION: Permission = Permission::Read;
const DESCRIPTION: Option<&'static str> = Some(
"Returns the calculated upcoming base fee of the tipset at the given height in attoFIL",
);

type Params = (ChainEpoch,);
type Ok = EthBigInt;

async fn handle(
ctx: Ctx,
(height,): Self::Params,
_: &http::Extensions,
) -> Result<Self::Ok, ServerError> {
let ts = ctx.chain_index().load_required_tipset_by_height(
height,
ctx.chain_store().heaviest_tipset(),
ResolveNullTipset::TakeOlder,
)?;
Comment thread
hanabi1224 marked this conversation as resolved.
let base_fee = EthBaseFee::get_base_fee(&ctx, &ts)?;
Ok(EthBigInt(base_fee.atto().clone()))
}
}
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ macro_rules! for_each_rpc_method {
$callback!($crate::rpc::eth::EthAddressToFilecoinAddress);
$callback!($crate::rpc::eth::FilecoinAddressToEthAddress);
$callback!($crate::rpc::eth::EthBaseFee);
$callback!($crate::rpc::eth::BaseFeeByHeight);
$callback!($crate::rpc::eth::EthBlockNumber);
$callback!($crate::rpc::eth::EthCall);
$callback!($crate::rpc::eth::EthChainId);
Expand Down
14 changes: 14 additions & 0 deletions src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/rpc/snapshots/forest__rpc__tests__rpc__v2.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/tool/subcommands/api_cmd/test_snapshots_ignored.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Filecoin.WalletSetDefault
Filecoin.WalletSign
Filecoin.WalletSignMessage
Filecoin.Web3ClientVersion
Forest.BaseFeeByHeight
Forest.ChainExport
Forest.ChainExportCancel
Forest.ChainExportDiff
Expand Down
Loading