go-substrate-rpc-client icon indicating copy to clipboard operation
go-substrate-rpc-client copied to clipboard

ChainBridge substrate error "expected more bytes, but could not decode any more"

Open DmitriyMolch opened this issue 2 years ago • 3 comments

How to reproduce: 1)git pull [email protected]:ChainSafe/ChainBridge.git 2)go get -u -v -f all 3)cd ./cmd/chainbridge 4)./chainbridge accounts import --privateKey 0x4c9cc36d8e528d1e2c41f5eb2f8dea9b79c7d717c4f1668aa9355665f0e1e13d --sr25519

Enter the requested password in the console: YDMKUCkf8TT4k27 5) touch config.json Update config.json content:

{
    "chains": [
      {
        "name": "sub",
        "type": "substrate",
        "id": "1",
        "endpoint": "wss://archive.mainnet.cere.network:9945",
        "from": "5GvRKPpQmMHcKNrxUqHYYGWMudKMKfdmAwQvvbBJghddDnyV",
        "scan": true,
        "nativeTokenSymbol": "CERE",
        "chainbridgePalletName": "chainBridge",
        "bridgeFeeValue": 0,
        "transferPalletName": "erc20",
        "transferFunctionName": "transferNative",
        "opts": {
          "startBlock": "4233319"
        }
      }
    ]
  }

6)go build -o ./ 7)./chainbridge --config ./config.json --fresh --verbosity trce

Expected result: Process all substrate network blocks successfully.

Actual result: Got an console error in file ./chains/substrate/listener.go ( line 201) Failed to process events in block chain=sub block=4233320 err="unable to decode field 1 event #2 with EventID [0 2], field System_CodeUpdated: expected more bytes, but could not decode any more"

Full log example:

ChainBridge/cmd/chainbridge$ ./chainbridge --config ./config.json --fresh --verbosity trce
INFO[03-23|12:03:33] Starting ChainBridge... 
DBUG[03-23|12:03:33] Config on initialization...              config="{Chains:[{Name:sub Type:substrate Id:1 Endpoint:wss://archive.mainnet.cere.network:9945 From:5FbgtZmcqnWzJS9Tx9jBSi7Fiw18nXx31bfPg9TPJu9kpD59 Opts:map[startBlock:4233319]}] KeystorePath:./keys}"
Enter password for key ./keys/5FbgtZmcqnWzJS9Tx9jBSi7Fiw18nXx31bfPg9TPJu9kpD59.key:
> 
INFO[03-23|12:03:36] Connecting to substrate chain...         chain=sub url=wss://archive.mainnet.cere.network:9945
2022/03/23 12:03:36 Connecting to wss://archive.mainnet.cere.network:9945...
DBUG[03-23|12:03:37] Fetched substrate metadata               chain=sub
DBUG[03-23|12:03:37] Fetched substrate genesis hash           chain=sub hash=0x81443836a9a24caaa23f1241897d1235717535711d1d3fe24eae4fdc942c092c
DBUG[03-23|12:03:37] Registering new chain in router          system=router id=1
DBUG[03-23|12:03:37] Successfully started chain               chain=sub chainId=1
INFO[03-23|12:03:37] Started sub chain                        system=core
TRCE[03-23|12:03:38] Fetching block for events                chain=sub hash=0xee95aaa4d866e64eff1446acd85db84930dc8ec7d58f214d0f56bbed950bce89
TRCE[03-23|12:03:38] Finished processing events               chain=sub block=0xee95aaa4d866e64eff1446acd85db84930dc8ec7d58f214d0f56bbed950bce89
TRCE[03-23|12:03:38] Fetching block for events                chain=sub hash=0xa14fc31897ce537121c0d605a9cc5be59efbf257115643e9020208c3b1b568cb
EROR[03-23|12:03:38] Failed to process events in block        chain=sub block=4233320 err="unable to decode field 1 event #2 with EventID [0 2], field System_CodeUpdated: expected more bytes, but could not decode any more"
TRCE[03-23|12:03:39] Fetching block for events                chain=sub hash=0xa14fc31897ce537121c0d605a9cc5be59efbf257115643e9020208c3b1b568cb
EROR[03-23|12:03:39] Failed to process events in block        chain=sub block=4233320 err="unable to decode field 1 event #2 with EventID [0 2], field System_CodeUpdated: expected more bytes, but could not decode any more"
TRCE[03-23|12:03:39] Fetching block for events                chain=sub hash=0xa14fc31897ce537121c0d605a9cc5be59efbf257115643e9020208c3b1b568cb

EROR[03-23|12:03:39] Failed to process events in block        chain=sub block=4233320 err="unable to decode field 1 event #2 with EventID [0 2], field System_CodeUpdated: expected more bytes, but could not decode any more"
TRCE[03-23|12:03:39] Fetching block for events                chain=sub hash=0xa14fc31897ce537121c0d605a9cc5be59efbf257115643e9020208c3b1b568cb
EROR[03-23|12:03:40] Failed to process events in block        chain=sub block=4233320 err="unable to decode field 1 event #2 with EventID [0 2], field System_CodeUpdated: expected more bytes, but could not decode any more"
TRCE[03-23|12:03:40] Fetching block for events                chain=sub hash=0xa14fc31897ce537121c0d605a9cc5be59efbf257115643e9020208c3b1b568cb
EROR[03-23|12:03:40] Failed to process events in block        chain=sub block=4233320 err="unable to decode field 1 event #2 with EventID [0 2], field System_CodeUpdated: expected more bytes, but could not decode any more"
EROR[03-23|12:03:40] FATAL ERROR. Shutting down.              system=core err="event polling retries exceeded (chain=1, name=sub)"

Notes:

  1. I was trying to debug the code and see that the received field is not empty and at the first glance seems like incorrect data format or its type interpretation.

DmitriyMolch avatar Mar 23 '22 10:03 DmitriyMolch

@Dmitriy1984Molchanov We are pushing in the next few days new substrate events that changed since the last time we upgraded them. This one will be fixed.

mikiquantum avatar Mar 23 '22 17:03 mikiquantum

@mikiquantum , did you have a chance to fix this issue?

DmitriyMolch avatar Apr 12 '22 08:04 DmitriyMolch

@Dmitriy1984Molchanov Looking a bit deeper, found a few things:

  • That version of ChainBridge uses an older version of GSRPC (v2.0.0)
  • Your substrate chain uses metadata V12 (a few versions old) and therefore the types defined in the events.go file are already different compare to what your chain produces.

For that block in the test there are two event types that are already different:

  • offences.Offence
  • staking.StakingElection

If you want to use chainbridge, you will need to fork it and override these event types with your own. Just create two different structs with the attributes that your chain generates. This is the code you need to tweak: https://github.com/ChainSafe/ChainBridge/blob/8cee3ff157224d18ccc214002548aa5bd75f52ef/shared/substrate/events.go#L172 Here are the events that are causing the issue: https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Farchive.mainnet.cere.network%3A9945#/explorer/query/4233320

mikiquantum avatar Apr 14 '22 00:04 mikiquantum

Please let us know if you still need help here.

cdamian avatar Dec 05 '23 11:12 cdamian