Skip to content

Commit

Permalink
Support optional block num arg for estimate gas
Browse files Browse the repository at this point in the history
  • Loading branch information
hkalodner committed Aug 30, 2022
1 parent aeb2076 commit f388012
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/arb-rpc-node/dev/fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func TestNonAggregatorFee(t *testing.T) {
To: &simpleAddr,
Data: (*hexutil.Bytes)(&data),
Aggregator: &emptyAgg,
})
}, nil)
test.FailIfError(t, err)
userOpts.GasLimit = uint64(estimatedGas)
t.Log("estimate:", userOpts.GasLimit)
Expand Down
9 changes: 6 additions & 3 deletions packages/arb-rpc-node/web3/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,16 @@ func (s *Server) Call(ctx context.Context, callArgs CallTxArgs, blockNum rpc.Blo
return res.ReturnData, nil
}

func (s *Server) EstimateGas(ctx context.Context, args CallTxArgs) (hexutil.Uint64, error) {
func (s *Server) EstimateGas(ctx context.Context, args CallTxArgs, optBlockNum *rpc.BlockNumberOrHash) (hexutil.Uint64, error) {
if args.To != nil && *args.To == arbos.ARB_NODE_INTERFACE_ADDRESS {
// Fake gas for call
return hexutil.Uint64(21000), nil
}
blockNum := rpc.PendingBlockNumber
snap, err := s.getSnapshot(ctx, &blockNum)
blockNum := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
if optBlockNum != nil {
blockNum = *optBlockNum
}
snap, err := s.getSnapshotForNumberOrHash(ctx, blockNum)
if err != nil {
return 0, err
}
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-rpc-node/web3/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (c *EthClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uin
Value: (*hexutil.Big)(call.Value),
Data: (*hexutil.Bytes)(&call.Data),
}
gas, err := c.srv.EstimateGas(ctx, args)
gas, err := c.srv.EstimateGas(ctx, args, nil)
if err != nil {
return 0, err
}
Expand Down

0 comments on commit f388012

Please sign in to comment.