Skip to content

Commit

Permalink
Add block param to EthEstimateGas
Browse files Browse the repository at this point in the history
  • Loading branch information
fridrik01 committed Nov 28, 2023
1 parent 3d5bebc commit 717d2a0
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- feat: metric: export Mpool message count ([filecoin-project/lotus#11361](https://github.com/filecoin-project/lotus/pull/11361))
- feat: sealing: load SectorsSummary from sealing SectorStats instead of calling API each time ([filecoin-project/lotus#11353](https://github.com/filecoin-project/lotus/pull/11353))
- fix: miner info: Show correct sector state counts ([filecoin-project/lotus#11456](https://github.com/filecoin-project/lotus/pull/11456))
- feat: add support for specifying block number when calling `eth_estimateGas` RPC number which s

## Improvements
- fix: Add time slicing to splitstore purging step during compaction to reduce lock congestion [filecoin-project/lotus#11269](https://github.com/filecoin-project/lotus/pull/11269)
Expand Down
6 changes: 3 additions & 3 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,9 @@ type FullNode interface {
EthGasPrice(ctx context.Context) (ethtypes.EthBigInt, error) //perm:read
EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (ethtypes.EthFeeHistory, error) //perm:read

EthMaxPriorityFeePerGas(ctx context.Context) (ethtypes.EthBigInt, error) //perm:read
EthEstimateGas(ctx context.Context, tx ethtypes.EthCall) (ethtypes.EthUint64, error) //perm:read
EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error) //perm:read
EthMaxPriorityFeePerGas(ctx context.Context) (ethtypes.EthBigInt, error) //perm:read
EthEstimateGas(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthUint64, error) //perm:read
EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error) //perm:read

EthSendRawTransaction(ctx context.Context, rawTx ethtypes.EthBytes) (ethtypes.EthHash, error) //perm:read

Expand Down
2 changes: 1 addition & 1 deletion api/api_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type Gateway interface {
EthGasPrice(ctx context.Context) (ethtypes.EthBigInt, error)
EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (ethtypes.EthFeeHistory, error)
EthMaxPriorityFeePerGas(ctx context.Context) (ethtypes.EthBigInt, error)
EthEstimateGas(ctx context.Context, tx ethtypes.EthCall) (ethtypes.EthUint64, error)
EthEstimateGas(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthUint64, error)
EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error)
EthSendRawTransaction(ctx context.Context, rawTx ethtypes.EthBytes) (ethtypes.EthHash, error)
EthGetLogs(ctx context.Context, filter *ethtypes.EthFilterSpec) (*ethtypes.EthFilterResult, error)
Expand Down
8 changes: 4 additions & 4 deletions api/mocks/mock_full.go

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

16 changes: 8 additions & 8 deletions api/proxy_gen.go

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

Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/gateway.json.gz
Binary file not shown.
3 changes: 2 additions & 1 deletion documentation/en/api-v1-unstable-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -2409,7 +2409,8 @@ Inputs:
"gasPrice": "0x0",
"value": "0x0",
"data": "0x07"
}
},
"string value"
]
```

Expand Down
2 changes: 1 addition & 1 deletion gateway/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type TargetAPI interface {
EthGasPrice(ctx context.Context) (ethtypes.EthBigInt, error)
EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (ethtypes.EthFeeHistory, error)
EthMaxPriorityFeePerGas(ctx context.Context) (ethtypes.EthBigInt, error)
EthEstimateGas(ctx context.Context, tx ethtypes.EthCall) (ethtypes.EthUint64, error)
EthEstimateGas(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthUint64, error)
EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error)
EthSendRawTransaction(ctx context.Context, rawTx ethtypes.EthBytes) (ethtypes.EthHash, error)
EthGetLogs(ctx context.Context, filter *ethtypes.EthFilterSpec) (*ethtypes.EthFilterResult, error)
Expand Down
4 changes: 2 additions & 2 deletions gateway/proxy_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,13 @@ func (gw *Node) EthMaxPriorityFeePerGas(ctx context.Context) (ethtypes.EthBigInt
return gw.target.EthMaxPriorityFeePerGas(ctx)
}

func (gw *Node) EthEstimateGas(ctx context.Context, tx ethtypes.EthCall) (ethtypes.EthUint64, error) {
func (gw *Node) EthEstimateGas(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthUint64, error) {
if err := gw.limit(ctx, stateRateLimitTokens); err != nil {
return 0, err
}

// todo limit gas? to what?
return gw.target.EthEstimateGas(ctx, tx)
return gw.target.EthEstimateGas(ctx, tx, blkParam)
}

func (gw *Node) EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error) {
Expand Down
2 changes: 1 addition & 1 deletion itests/eth_account_abstraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func TestEthAccountAbstractionFailsFromEvmActor(t *testing.T) {
gaslimit, err := client.EthEstimateGas(ctx, ethtypes.EthCall{
From: &ethAddr,
Data: contract,
})
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
require.NoError(t, err)

maxPriorityFeePerGas, err := client.EthMaxPriorityFeePerGas(ctx)
Expand Down
6 changes: 3 additions & 3 deletions itests/eth_conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ethAPIRaw struct {
EthBlockNumber func(context.Context) (json.RawMessage, error)
EthCall func(context.Context, ethtypes.EthCall, ethtypes.EthBlockNumberOrHash) (json.RawMessage, error)
EthChainId func(context.Context) (json.RawMessage, error)
EthEstimateGas func(context.Context, ethtypes.EthCall) (json.RawMessage, error)
EthEstimateGas func(context.Context, ethtypes.EthCall, ethtypes.EthBlockNumberOrHash) (json.RawMessage, error)
EthFeeHistory func(context.Context, ethtypes.EthUint64, string, []float64) (json.RawMessage, error)
EthGasPrice func(context.Context) (json.RawMessage, error)
EthGetBalance func(context.Context, ethtypes.EthAddress, ethtypes.EthBlockNumberOrHash) (json.RawMessage, error)
Expand Down Expand Up @@ -185,7 +185,7 @@ func TestEthOpenRPCConformance(t *testing.T) {
return ethapi.EthEstimateGas(context.Background(), ethtypes.EthCall{
From: &senderEthAddr,
Data: contractBin,
})
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
},
},

Expand Down Expand Up @@ -451,7 +451,7 @@ func createRawSignedEthTx(ctx context.Context, t *testing.T, client *kit.TestFul
gaslimit, err := client.EthEstimateGas(ctx, ethtypes.EthCall{
From: &senderEthAddr,
Data: contractBin,
})
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
require.NoError(t, err)

maxPriorityFeePerGas, err := client.EthMaxPriorityFeePerGas(ctx)
Expand Down
2 changes: 1 addition & 1 deletion itests/eth_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestDeployment(t *testing.T) {
gaslimit, err := client.EthEstimateGas(ctx, ethtypes.EthCall{
From: &ethAddr,
Data: contract,
})
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
require.NoError(t, err)

maxPriorityFeePerGas, err := client.EthMaxPriorityFeePerGas(ctx)
Expand Down
4 changes: 2 additions & 2 deletions itests/eth_hash_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestTransactionHashLookup(t *testing.T) {
gaslimit, err := client.EthEstimateGas(ctx, ethtypes.EthCall{
From: &ethAddr,
Data: contract,
})
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
require.NoError(t, err)

maxPriorityFeePerGas, err := client.EthMaxPriorityFeePerGas(ctx)
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestEthGetMessageCidByTransactionHashEthTx(t *testing.T) {
gaslimit, err := client.EthEstimateGas(ctx, ethtypes.EthCall{
From: &ethAddr,
Data: contract,
})
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
require.NoError(t, err)

maxPriorityFeePerGas, err := client.EthMaxPriorityFeePerGas(ctx)
Expand Down
6 changes: 3 additions & 3 deletions itests/eth_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestValueTransferValidSignature(t *testing.T) {
gaslimit, err := client.EthEstimateGas(ctx, ethtypes.EthCall{
From: &ethAddr,
Data: contract,
})
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
require.NoError(t, err)

maxPriorityFeePerGas, err := client.EthMaxPriorityFeePerGas(ctx)
Expand Down Expand Up @@ -235,7 +235,7 @@ func TestContractInvocation(t *testing.T) {
From: &ethAddr,
To: &contractAddr,
Data: params,
})
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
require.NoError(t, err)

maxPriorityFeePerGas, err := client.EthMaxPriorityFeePerGas(ctx)
Expand Down Expand Up @@ -353,7 +353,7 @@ func deployContractTx(ctx context.Context, client *kit.TestFullNode, ethAddr eth
gaslimit, err := client.EthEstimateGas(ctx, ethtypes.EthCall{
From: &ethAddr,
Data: contract,
})
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions itests/fevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func TestFEVMRecursiveActorCallEstimate(t *testing.T) {
From: &ethAddr,
To: &contractAddr,
Data: params,
})
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
require.NoError(t, err)
require.LessOrEqual(t, int64(gaslimit), build.BlockGasLimit)

Expand Down Expand Up @@ -820,7 +820,7 @@ func TestFEVMBareTransferTriggersSmartContractLogic(t *testing.T) {
From: &accntEth,
To: &contractEth,
Value: ethtypes.EthBigInt(big.NewInt(100)),
})
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
require.NoError(t, err)

maxPriorityFeePerGas, err := client.EthMaxPriorityFeePerGas(ctx)
Expand Down Expand Up @@ -1037,7 +1037,7 @@ func TestFEVMErrorParsing(t *testing.T) {
_, err := e.EthEstimateGas(ctx, ethtypes.EthCall{
To: &contractAddrEth,
Data: entryPoint,
})
}, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
require.ErrorContains(t, err, expected)
})
})
Expand Down
2 changes: 1 addition & 1 deletion node/impl/full/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (e *EthModuleDummy) EthGasPrice(ctx context.Context) (ethtypes.EthBigInt, e
return ethtypes.EthBigIntZero, ErrModuleDisabled
}

func (e *EthModuleDummy) EthEstimateGas(ctx context.Context, tx ethtypes.EthCall) (ethtypes.EthUint64, error) {
func (e *EthModuleDummy) EthEstimateGas(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthUint64, error) {
return 0, ErrModuleDisabled
}

Expand Down
10 changes: 7 additions & 3 deletions node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type EthModuleAPI interface {
NetListening(ctx context.Context) (bool, error)
EthProtocolVersion(ctx context.Context) (ethtypes.EthUint64, error)
EthGasPrice(ctx context.Context) (ethtypes.EthBigInt, error)
EthEstimateGas(ctx context.Context, tx ethtypes.EthCall) (ethtypes.EthUint64, error)
EthEstimateGas(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthUint64, error)
EthCall(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthBytes, error)
EthMaxPriorityFeePerGas(ctx context.Context) (ethtypes.EthBigInt, error)
EthSendRawTransaction(ctx context.Context, rawTx ethtypes.EthBytes) (ethtypes.EthHash, error)
Expand Down Expand Up @@ -1007,7 +1007,7 @@ func (a *EthModule) applyMessage(ctx context.Context, msg *types.Message, tsk ty
return res, nil
}

func (a *EthModule) EthEstimateGas(ctx context.Context, tx ethtypes.EthCall) (ethtypes.EthUint64, error) {
func (a *EthModule) EthEstimateGas(ctx context.Context, tx ethtypes.EthCall, blkParam ethtypes.EthBlockNumberOrHash) (ethtypes.EthUint64, error) {
msg, err := ethCallToFilecoinMessage(ctx, tx)
if err != nil {
return ethtypes.EthUint64(0), err
Expand All @@ -1017,7 +1017,11 @@ func (a *EthModule) EthEstimateGas(ctx context.Context, tx ethtypes.EthCall) (et
// gas estimation actually run.
msg.GasLimit = 0

ts := a.Chain.GetHeaviestTipSet()
ts, err := getTipsetByEthBlockNumberOrHash(ctx, a.Chain, blkParam)
if err != nil {
return ethtypes.EthUint64(0), xerrors.Errorf("failed to process block param: %v; %w", blkParam, err)
}

gassedMsg, err := a.GasAPI.GasEstimateMessageGas(ctx, msg, nil, ts.Key())
if err != nil {
// On failure, GasEstimateMessageGas doesn't actually return the invocation result,
Expand Down

0 comments on commit 717d2a0

Please sign in to comment.