Skip to content

Commit

Permalink
Keep gasLimit in RPC response if in block header
Browse files Browse the repository at this point in the history
  • Loading branch information
karlb committed May 30, 2023
1 parent 6089665 commit 7f15bbc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
3 changes: 1 addition & 2 deletions e2e_test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,7 @@ func TestEthersJSCompatibilityDisable(t *testing.T) {
err = network[0].WsClient.GetRPCClient().CallContext(ctx, &result, "eth_getBlockByNumber", "latest", true)
require.NoError(t, err)

_, ok = result["gasLimit"]
assert.False(t, ok, "gasLimit field should not be present on RPC block")
// gasLimit can be in the response, depending on whether it is in the block header or not
_, ok = result["baseFeePerGas"]
assert.False(t, ok, "baseFeePerGas field should not be present on RPC block")
}
18 changes: 6 additions & 12 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,17 +709,13 @@ func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.B
if block != nil && err == nil {
response, err := s.rpcMarshalBlock(ctx, block, true, fullTx)

if err == nil {
if s.b.RPCEthCompatibility() {
addEthCompatibilityFields(ctx, response, s.b, block.Header())
if number == rpc.PendingBlockNumber {
// Pending blocks need to nil out a few fields
for _, field := range []string{"hash", "nonce", "miner"} {
response[field] = nil
}
if err == nil && s.b.RPCEthCompatibility() {
addEthCompatibilityFields(ctx, response, s.b, block.Header())
if number == rpc.PendingBlockNumber {
// Pending blocks need to nil out a few fields
for _, field := range []string{"hash", "nonce", "miner"} {
response[field] = nil
}
} else {
delete(response, "gasLimit")
}
}
return response, err
Expand All @@ -738,8 +734,6 @@ func (s *PublicBlockChainAPI) GetBlockByHash(ctx context.Context, hash common.Ha
}
if s.b.RPCEthCompatibility() {
addEthCompatibilityFields(ctx, result, s.b, block.Header())
} else {
delete(result, "gasLimit")
}
return result, nil
}
Expand Down

0 comments on commit 7f15bbc

Please sign in to comment.