Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impl EthGasPrice RPC API #3806

Merged
merged 9 commits into from
Dec 8, 2023
Merged

feat: impl EthGasPrice RPC API #3806

merged 9 commits into from
Dec 8, 2023

Conversation

hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Dec 7, 2023

Summary of changes

As part of #3640

Changes introduced in this pull request:

  • Implement Filecoin.EthGasPrice RPC API
  • Test coverage in forest-tool api compare
     Running `target/debug/forest-tool api compare /home/me/fr/snapshots/calibnet/forest_snapshot_calibnet_2023-12-07_height_1153690.forest.car.zst --filter EthGas`
| RPC Method           | Forest | Lotus |
|----------------------|--------|-------|
| Filecoin.EthGasPrice | Valid  | Valid |

Lotus code

func (a *EthModule) EthGasPrice(ctx context.Context) (ethtypes.EthBigInt, error) {
	// According to Geth's implementation, eth_gasPrice should return base + tip
	// Ref: https://github.com/ethereum/pm/issues/328#issuecomment-853234014

	ts := a.Chain.GetHeaviestTipSet()
	baseFee := ts.Blocks()[0].ParentBaseFee
	premium, err := a.EthMaxPriorityFeePerGas(ctx)
	if err != nil {
		return ethtypes.EthBigInt(big.Zero()), nil
	}
	gasPrice := big.Add(baseFee, big.Int(premium))
	return ethtypes.EthBigInt(gasPrice), nil
}

func (a *EthModule) EthMaxPriorityFeePerGas(ctx context.Context) (ethtypes.EthBigInt, error) {
	gasPremium, err := a.GasAPI.GasEstimateGasPremium(ctx, 0, builtinactors.SystemActorAddr, 10000, types.EmptyTSK)
	if err != nil {
		return ethtypes.EthBigInt(big.Zero()), err
	}
	return ethtypes.EthBigInt(gasPremium), nil
}

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@hanabi1224 hanabi1224 marked this pull request as ready for review December 7, 2023 10:44
@hanabi1224 hanabi1224 requested a review from a team as a code owner December 7, 2023 10:44
@hanabi1224 hanabi1224 requested review from ruseinov and sudo-shashank and removed request for a team December 7, 2023 10:44
#[derive(Debug, Deserialize, Serialize, Default)]
pub struct GasPriceResult(#[serde(with = "stringify")] pub BigInt);

pub mod stringify {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be hexify? And it should probably live in lotus_json/mod.rs. It'll definitely be used by other RPC methods as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@elmattic elmattic added this pull request to the merge queue Dec 8, 2023
Merged via the queue into main with commit a185cbf Dec 8, 2023
26 checks passed
@elmattic elmattic deleted the hm/eth-gas-price-rpc-api branch December 8, 2023 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants