From f3880126eeffb978f31059738112645f57612f3e Mon Sep 17 00:00:00 2001 From: Harry Kalodner Date: Mon, 29 Aug 2022 22:42:25 -0400 Subject: [PATCH] Support optional block num arg for estimate gas --- packages/arb-rpc-node/dev/fees_test.go | 2 +- packages/arb-rpc-node/web3/eth.go | 9 ++++++--- packages/arb-rpc-node/web3/ethclient.go | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/arb-rpc-node/dev/fees_test.go b/packages/arb-rpc-node/dev/fees_test.go index ea2ac440f8..19ac91653e 100644 --- a/packages/arb-rpc-node/dev/fees_test.go +++ b/packages/arb-rpc-node/dev/fees_test.go @@ -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) diff --git a/packages/arb-rpc-node/web3/eth.go b/packages/arb-rpc-node/web3/eth.go index 4a12b2c0f6..842360ef80 100644 --- a/packages/arb-rpc-node/web3/eth.go +++ b/packages/arb-rpc-node/web3/eth.go @@ -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 } diff --git a/packages/arb-rpc-node/web3/ethclient.go b/packages/arb-rpc-node/web3/ethclient.go index 663733ff44..ad4f8fd196 100644 --- a/packages/arb-rpc-node/web3/ethclient.go +++ b/packages/arb-rpc-node/web3/ethclient.go @@ -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 }