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

Wrong block hash returned by ethclient.Client.HeaderByNumber #23463

Closed
tclemos opened this issue Aug 25, 2021 · 0 comments · Fixed by #23466
Closed

Wrong block hash returned by ethclient.Client.HeaderByNumber #23463

tclemos opened this issue Aug 25, 2021 · 0 comments · Fixed by #23466
Labels

Comments

@tclemos
Copy link

tclemos commented Aug 25, 2021

System information

Geth version: 1.10.8
OS & Version: Linux

Expected behaviour

When calling ethclient.Client.HeaderByNumber should return the correct block hash

Actual behaviour

Invalid block hash is returned when Geth version on the server is v1.10.8 and the call is made using the ethclient.Client.HeaderByNumber. The problem also happens when calling the ethclient.Client.BlockByNumber.

I've tried calling the method using the client library with versions v1.10.4, v1.10.5, v1.10.6, v1.10.7 and v1.10.8, the behavior is the same, it seems to be something related to the server response instead of something in the client.

The behaviour is the same independently of the network, we tested it in Goerli and Rinkeby

When making the jsonRPC request directly via HTTP, the hash is correct:

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x504174", false],"id":1}' -H "Content-Type: application/json" --dump-header - <<geth address>>

output:

HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Wed, 25 Aug 2021 11:40:59 GMT
Content-Type: application/json
Content-Length: 1910
Connection: keep-alive
Vary: Origin

{"jsonrpc":"2.0","id":1,"result":{"baseFeePerGas":"0x7","difficulty":"0x1","extraData":"0x000000000000436f6e73656e5379732048797065726c65646765722042657375c646a88f9833b01f1bdb897db5890c15c04d932b70cd7eba1d0cab041a0a597c537e7f529e499e759e8205979e9d152a958aede503fa65e12ed7132bb8b869f901","gasLimit":"0x1c9c380","gasUsed":"0x2958c2","hash":"0x3705a71830dab88c25ca3b5765ffba738bea10339d629b4fb225679b5d8be9de","logsBloom":"0x000000008000000040000000100000004000100200000042100000000002020202000406088080400000008010000081000100000400000002800001802020000000010010200002000043080000000280800040100800a002200000080000000408000102000800000002000000080010000002000000001000001480000001000001c0000040600000000800000000000c00000100000002040000800002000200000000400000000000200000000000000100012000000008a00001000000080000020000000000000000000000000000000000090000001000000000224000100000001000008000000010000001000820000000000000008c0010000004","miner":"0x22ea9f6b28db76a7162054c05ed812deb2f519cd","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x504174","parentHash":"0x029c7181addbed120ada15160cb8022641f035ffb5d2d6e08714227122bd30a8","receiptsRoot":"0x63cee320c5f2708a08c9e2d2f67780edbabc01a0b560ba6ababbb9d1188c7766","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0xc665","stateRoot":"0x93f5316da7fc3351f57ed5dc030e28cfaefef59d18300ada9a019964b1ded065","timestamp":"0x610a4f50","totalDifficulty":"0x754af2","transactions":["0xdb758e501a9701c65d7522084f83f6e4e3bd2105de90647ca08425727dddf9bf","0x0409bb7eaec02f593ed345ad6df9b835a0c2435e33faad57ae94d433314e4b3a","0x1957dde4c3912da6c9cb22c1e236f40dd8fc652cab15450dff2f4e53081ac13b","0x0d8f5a3c3b9e4b408bbb4150fe7f435cc84b09fa0641423d7173ce1962088a98"],"transactionsRoot":"0xb63e1a997f37e896811c01415bacdc4ee052d9744e0fd6b4d3cbe5cbf86cd08f","uncles":[]}}

it also works properly via when querying via GraphQL:

query {
  block(number:5259636) {
    number
    hash
  }
}

response:

{
  "data": {
    "block": {
      "number": 5259636,
      "hash": "0x3705a71830dab88c25ca3b5765ffba738bea10339d629b4fb225679b5d8be9de"
    }
  }
}

Steps to reproduce the behaviour

Ref block: https://goerli.etherscan.io/block/5259636

package main

import (
	"context"
	"fmt"
	"math/big"

	"github.com/ethereum/go-ethereum/ethclient"
)

const (
	geth_1_10_7_url = ""
	geth_1_10_8_url = ""

	block = 5259636
)

func main() {

	ctx := context.Background()

	client_1_10_7, err := ethclient.Dial(geth_1_10_7_url)
	panicErr(err)

	client_1_10_8, err := ethclient.Dial(geth_1_10_8_url)
	panicErr(err)

	b_1_10_7, err := client_1_10_7.HeaderByNumber(ctx, big.NewInt(block))
	panicErr(err)

	b_1_10_8, err := client_1_10_8.HeaderByNumber(ctx, big.NewInt(block))
	panicErr(err)

	fmt.Printf("Number - b_1_10_7: %v b_1_10_8: %v\n", b_1_10_7.Number, b_1_10_8.Number)
	fmt.Printf("Hash - b_1_10_7: %v b_1_10_8: %v\n", b_1_10_7.Hash(), b_1_10_8.Hash())
	fmt.Printf("Hash Hex - b_1_10_7: %v b_1_10_8: %v\n", b_1_10_7.Hash().Hex(), b_1_10_8.Hash().Hex())

	if b_1_10_7.Number.Cmp(b_1_10_8.Number) != 0 {
		panic("hold on, wait a minute, different block number")
	}

	if b_1_10_7.Hash() != b_1_10_8.Hash() {
		panic("hold on, wait a minute, different block hash")
	}

	if b_1_10_7.Hash().Hex() != b_1_10_8.Hash().Hex() {
		panic("hold on, wait a minute, diffferent block hash hex")
	}
}

func panicErr(err error) {
	if err != nil {
		panic(err)
	}
}

output:

Number - b_1_10_7: 5259636 b_1_10_8: 5259636
Hash - b_1_10_7: 0x3705a71830dab88c25ca3b5765ffba738bea10339d629b4fb225679b5d8be9de b_1_10_8: 0xc7c6eee418abf033c0d1247598dc73ad39e047573fe703c8e995716534725cee
Hash Hex - b_1_10_7: 0x3705a71830dab88c25ca3b5765ffba738bea10339d629b4fb225679b5d8be9de b_1_10_8: 0xc7c6eee418abf033c0d1247598dc73ad39e047573fe703c8e995716534725cee
panic: hold on, wait a minute, different block hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant