testinprod-io / op-erigon

Optimism implementation on the efficiency frontier
https://op-erigon.testinprod.io
GNU Lesser General Public License v3.0
87 stars 15 forks source link

mismerge with erigon upstream causes crash in graphql code #203

Closed SLoeuillet closed 4 months ago

SLoeuillet commented 4 months ago

System information

Erigon version: 2.60.2-0.6.5

OS & Version: Ubuntu 24.04 amd64

Commit hash: 2f002f3e43403ee5df6c73db0fbf8158069038f6

Erigon Command (with flags/config): --graphql

Consensus Layer:

Consensus Layer Command (with flags/config):

Chain/Network: mainnet

Expected behaviour

http://127.0.0.1:8545/graphql/ui

specific block 1371681 returns JSON data, not error :

GraphQL query :


{   
                block(number: 1371681 ) {
                    number
                    difficulty
                    extraData
                    gasLimit
                    gasUsed
                    logsBloom
                    ommerHash
                    ommers{
                      hash
                    }
                    miner {
                      address
                    }
                    mixHash
                    nonce
                    hash
                    parent {
                      hash
                    }
                    receiptsRoot
                    stateRoot
                    timestamp
                    transactionsRoot
                    totalDifficulty
                    transactions {
                      createdContract {
                        address
                      }
                      cumulativeGasUsed
                      from {
                        address
                      }
                      gasUsed
                      gasPrice
                      inputData
                      nonce
                      index
                      value
                      logs {
                        account {
                          address
                        }
                        data
                        index
                        topics
                      }
                      hash
                      index
                      to {
                        address
                      }
                      status
                    }
                  }
                }

Expected result :

{
  "data": {
    "block": {
      "number": 1371681,
      "difficulty": "0x0",
      "extraData": "0x",
      "gasLimit": 30000000,
      "gasUsed": 46889,
      "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "ommerHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
      "ommers": [],
      "miner": {
        "address": "0x4200000000000000000000000000000000000011"
      },
      "mixHash": "0x1668a5dc05d8c4cc536bc8232552719e23951f254a2ff5f485271c2e83dadee9",
      "nonce": "0x0000000000000000",
      "hash": "0x0e1e5f7598a2e7e49c22a8530aedf7be5d5c8515cd742a2a1da2fa18283d49c5",
      "parent": {
        "hash": "0x45a5330b8955d0e0e50bb1de02da7f7a4ac87d6a7dc174eb83d980fd450a7130"
      },
      "receiptsRoot": "0x8f468282575b3a1ccef67b268423ac1c52e9b72ca3bda3cb187069dd45a8443b",
      "stateRoot": "0xd4657d3ea29320ebcbf2e0a8bec47442c735944bbcfa6ed1da0209282c62e513",
      "timestamp": "0x64b43925",
      "transactionsRoot": "0x5c1d9763fd836b7d89dfd1e32f0ec1130dd8c4e40dca6697ab19ecc756f24596",
      "totalDifficulty": "0x0",
      "transactions": [
        {
          "createdContract": null,
          "cumulativeGasUsed": 46889,
          "from": {
            "address": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001"
          },
          "gasUsed": 46889,
          "gasPrice": "0x33",
          "inputData": "0x015d8eb900000000000000000000000000000000000000000000000000000000010e329a0000000000000000000000000000000000000000000000000000000064b438d7000000000000000000000000000000000000000000000000000000030072ab10ecc39e9f39de6db900ce870965e4847ff40ec41cf19d591f979811dd8899f12700000000000000000000000000000000000000000000000000000000000000050000000000000000000000005050f69a9786f081509234f1a7f4684b5e5b76c900000000000000000000000000000000000000000000000000000000000000bc00000000000000000000000000000000000000000000000000000000000a6fe0",
          "nonce": "0x0",
          "index": 0,
          "value": "0x0",
          "logs": [],
          "hash": "0xaa339d29a0988aa5e71820186e9074ee25989dab3ddf3592bf49d1c69c87fd8c",
          "to": {
            "address": "0x4200000000000000000000000000000000000015"
          },
          "status": 1
        }
      ]
    }
  }
}

Actual behaviour

{
  "errors": [
    {
      "message": "internal system error",
      "path": [
        "block"
      ]
    }
  ],
  "data": {
    "block": null
  }
}

Steps to reproduce the behaviour

Go to local graphql UI, paste graphql query JSON

Backtrace

Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: runtime error: invalid memory address or nil pointer dereference
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: goroutine 264667282 [running]:
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: runtime/debug.Stack()
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         runtime/debug/stack.go:24 +0x5e
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: runtime/debug.PrintStack()
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         runtime/debug/stack.go:16 +0x13
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/99designs/gqlgen/graphql.DefaultRecover({0xc03651d700?, 0xc014d02800?}, {0x2518b20?, 0x501f600?})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/99designs/gqlgen@v0.17.40/graphql/recovery.go:17 +0x6b
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/99designs/gqlgen/graphql.(*OperationContext).Recover(0x0?, {0x3b04b88, 0xc016f4e8d0}, {0x2518b20?, 0x501f600?})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/99designs/gqlgen@v0.17.40/graphql/context_operation.go:124 +0x38
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph.(*executionContext)._Query_block.func1()
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph/generated.go:4320 +0x6e
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: panic({0x2518b20?, 0x501f600?})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         runtime/panic.go:914 +0x21f
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph.(*queryResolver).Block(0xc02a8b2eb0, {0x3b04b88, 0xc016f4e8d0}, 0xc03b344c50, 0x0?)
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph/schema.resolvers.go:108 +0x7cf
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph.(*executionContext)._Query_block.func2({0x3b04b88?, 0xc016f4e8d0})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph/generated.go:4326 +0x108
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/99designs/gqlgen/graphql/executor.processExtensions.func4({0x3b04b88?, 0xc016f4e8d0?}, 0xc01f220af0?)
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/99designs/gqlgen@v0.17.40/graphql/executor/extensions.go:72 +0x22
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph.(*executionContext)._Query_block(0xc019ea7900, {0x3b04b88, 0xc016f4e7e0}, {0xc03b78d7a0, {0xc018446c80, 0x13, 0x14}, 0x0})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph/generated.go:4324 +0x1ff
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph.(*executionContext)._Query.func1({0x3b04b88?, 0xc016f4e7e0?}, 0xc0181cecc0?)
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph/generated.go:8938 +0x95
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph.(*executionContext)._Query.func2.1({0x3b04b88?, 0xc016f4e7e0?})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph/generated.go:8944 +0x28
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/99designs/gqlgen/graphql/executor.processExtensions.func3({0x3b04b88?, 0xc016f4e7e0?}, 0x73e3306b5428?)
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/99designs/gqlgen@v0.17.40/graphql/executor/extensions.go:69 +0x22
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph.(*executionContext)._Query.func2({0x3b04b88, 0xc016f4e7e0})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph/generated.go:8943 +0xa2
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph.(*executionContext)._Query.func3({0x73e3b4d61e01?, 0x20?})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph/generated.go:8947 +0x22
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/99designs/gqlgen/graphql.(*FieldSet).Dispatch(0xc039b6e0f0, {0x3b04b88?, 0xc016f4e780?})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/99designs/gqlgen@v0.17.40/graphql/fieldset.go:41 +0xa2
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph.(*executionContext)._Query(0xc019ea7900, {0x3b04b88, 0xc016f4e720}, {0xc0228176a0, 0x1, 0x1})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph/generated.go:9130 +0x1ca9
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph.(*executableSchema).Exec.func1({0x3b04b88, 0xc016f4e6f0})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graph/generated.go:957 +0x234
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/99designs/gqlgen/graphql/executor.(*Executor).DispatchOperation.func1.1.1({0x3b04b88, 0xc016f4e6f0})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/99designs/gqlgen@v0.17.40/graphql/executor/executor.go:120 +0x25
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/99designs/gqlgen/graphql/executor.processExtensions.func2({0x3b04b88?, 0xc016f4e6f0?}, 0x23e5900?)
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/99designs/gqlgen@v0.17.40/graphql/executor/extensions.go:66 +0x22
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/99designs/gqlgen/graphql/executor.(*Executor).DispatchOperation.func1.1({0x3b04b88, 0xc016f4e630})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/99designs/gqlgen@v0.17.40/graphql/executor/executor.go:119 +0x104
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/99designs/gqlgen/graphql/handler/transport.POST.Do({0x3b04bc0?}, {0x3afd060?, 0xc01b707960}, 0xc028a7c600, {0x3b01590, 0xc00063f040})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/99designs/gqlgen@v0.17.40/graphql/handler/transport/http_post.go:91 +0x556
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/99designs/gqlgen/graphql/handler.(*Server).ServeHTTP(0xc01433a9e0, {0x3afd060?, 0xc01b707960}, 0xc028a7c600)
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/99designs/gqlgen@v0.17.40/graphql/handler/server.go:122 +0x278
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql.ProcessGraphQLcheckIfNeeded({0x3aec9a0, 0xc01433a9e0}, {0x3afd060, 0xc01b707960}, 0xc028a7c500)
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/ledgerwatch/erigon/cmd/rpcdaemon/graphql/graphql.go:45 +0x13d
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: github.com/ledgerwatch/erigon/cmd/rpcdaemon/cli.startRegularRpcServer.createHandler.func7({0x3afd060, 0xc01b707960}, 0xc016f4e4b0?)
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         github.com/ledgerwatch/erigon/cmd/rpcdaemon/cli/config.go:822 +0xbb
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: net/http.HandlerFunc.ServeHTTP(0xc19dc2c359d63486?, {0x3afd060?, 0xc01b707960?}, 0xc0080448f8?)
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         net/http/server.go:2141 +0x29
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: golang.org/x/net/http2/h2c.h2cHandler.ServeHTTP({{0x3ae76c0?, 0xc000b3ccb0?}, 0xc01433c550?}, {0x3afd060, 0xc01b707960}, 0xc028a7c500)
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         golang.org/x/net@v0.24.0/http2/h2c/h2c.go:125 +0x68e
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: net/http.serverHandler.ServeHTTP({0x3af4f60?}, {0x3afd060?, 0xc01b707960?}, 0x6?)
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         net/http/server.go:2943 +0x8e
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: net/http.(*conn).serve(0xc03beff170, {0x3b04b88, 0xc01434a420})
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         net/http/server.go:2014 +0x5f4
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]: created by net/http.(*Server).Serve in goroutine 2833
Jul 16 15:06:45 base00-mainnet-ovh erigon[124810]:         net/http/server.go:3091 +0x5cb
SLoeuillet commented 4 months ago

Comes from mismerge of cmd/rpcdaemon/graphql/graph/helpers.go

a block of code that was removed upstream in march 2023 is still there in op-erigon HEAD, not in erigon nor bsc-erigon :

diff --git a/cmd/rpcdaemon/graphql/graph/helpers.go b/cmd/rpcdaemon/graphql/graph/helpers.go
index 937f591ed..0a2901719 100644
--- a/cmd/rpcdaemon/graphql/graph/helpers.go
+++ b/cmd/rpcdaemon/graphql/graph/helpers.go
@@ -18,10 +19,6 @@ import (
 func convertDataToStringP(abstractMap map[string]interface{}, field string) *string {
        var result string

-       if reflect.ValueOf(abstractMap[field]).IsZero() {
-               return nil
-       }
-
        switch v := abstractMap[field].(type) {
        case int64:
                result = strconv.FormatInt(v, 10)
SLoeuillet commented 4 months ago

For that block (1371681) logBloom is an array of 00000, so helper returns nil, and as pointer is dereferenced afterward, it crashes in caller

SLoeuillet commented 4 months ago

That code was removed upstream on commit fd1a971384460039cb9efcbe437346af31b5685e on 2023-03-09

ImTei commented 4 months ago

@SLoeuillet The fix has been merged and released: https://github.com/testinprod-io/op-erigon/releases/tag/v2.60.2-0.6.6 Please let me know if the issue is resolved. Thank you for the contribution!

SLoeuillet commented 4 months ago

Issue is now fixed.

Thanks again