AcalaNetwork / chopsticks

Create parallel reality of your Substrate network.
Apache License 2.0
138 stars 84 forks source link

Getting Method not found: chain_getHead from a subsquid indexer #434

Closed Tbaut closed 1 year ago

Tbaut commented 1 year ago

Hey there,

I'm forking Rococo and I'd like to run a Subsquid indexer along side Chopsticks.

Running Chopsticks with

endpoint: wss://rococo-rpc.polkadot.io
mock-signature-host: true
block: 7437969
db: ./db.sqlite

import-storage:
  System:
    Account:
      - - - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
        - providers: 1
          data:
            free: '10000000000000000000'
  Council:
    Members: [5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY]
  PhragmenElection:
    Members:
      - who: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
        stake: 1000000000000
        deposit: 1000000000000
  TechnicalCommittee:
    Members: [5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY]
  TechnicalMembership:
    Members: [5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY]

When I run the indexer pointing at the ws://localhost:8000 I get the following:

Error handling request: ResponseError: Method not found: chain_getHead 'ResponseError: Method not found: chain_getHead

This is a method that exists on public RPCs:

curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "chain_getHead"}' https://rococo-rpc.polkadot.io
# {"jsonrpc":"2.0","result":"0xc7b638d962eab30042ac50f94c57ebe342ec34db68588c50ac6905054b7dd134","id":1}
xlc commented 1 year ago

chain_getHead is alias of chain_getBlockHash. We can add an alias here https://github.com/AcalaNetwork/chopsticks/blob/4a5e41e5d9c7a142e8174a237680754307ce6379/packages/chopsticks/src/rpc/substrate/chain.ts#L106

Tbaut commented 1 year ago

Thanks for the pointer. I added

export const chain_getHead =  chain_getBlockHash

But since it expects a blockNumber as argument, I get

Error handling request: TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))

So I added some more logic to fetch the latest block number if no argument was given (see my branch https://github.com/AcalaNetwork/chopsticks/compare/master...Tbaut:chopsticks:tbaut-subsquid-support?expand=1). But then things fail later, e.g when I submit an extrinsic. Not sure what's the culprit.. That's the error on the processor side

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

                               (0, assert_1.default)((0, util_internal_1.last)(chain).height === head.height)

While Chopsticks shows no error or relevant log (even in trace) and built a block.

[00:34:51.065] INFO (block-builder/174246): Block built
    number: 7437970
    hash: "0xe786b54466eb089a6c96f7d6849ecb5d2fc21ff03bd9e301887d5bef72d0b200"
    extrinsics: [
      "0x11038400d43593c715fdd31c61141abd…4433cf13001e04000000000000000000"
    ]
    pendingExtrinsicsCount: 0
    ump: {}

Also I'd expect the node to emit some events such as InBlock now it only emits the isFinalized one which is not realistic and breaks the UI I'm testing :)

ermalkaleci commented 1 year ago

@Tbaut I've pushed a fix on master. Give it a try and let me know. Also chopsticks will emit tx events, what exactly not working?

Tbaut commented 1 year ago

Thanks a lot @ermalkaleci this doesn't work unfortunately, probably because the type isn't null but undefined. Take a look at my branch posted above. https://github.com/AcalaNetwork/chopsticks/compare/master...Tbaut:chopsticks:tbaut-subsquid-support?expand=1 I get:

Error handling request: TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) 'TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) at chain_getBlockHash (/home/thib/Github/Tbaut/chopsticks/packages/chopsticks/src/rpc/substrate/chain.ts:18:113)

Regarding the Tx events, when I have a code that looks like

api.tx.balances
  .transfer(recipient, 123)
  .signAndSend(sender, ({ status, events }) => {
    console.log(status)
 })

It goes from isReady, to isFinalized without the isInBlock.

ermalkaleci commented 1 year ago

@Tbaut I have pushed a fix that handles both null and undefined. Make sure to pull master

ermalkaleci commented 1 year ago

It goes from isReady, to isFinalized without the isInBlock.

Chopsticks will emit inBlock and then immediately finalized. I don't know how why you're not getting it

ermalkaleci commented 1 year ago
Screenshot 2023-10-14 at 5 25 51 PM

@Tbaut event is sent but because they're sent too quickly somehow inblock is skipped

442 might fix it

Tbaut commented 1 year ago

@Tbaut I have pushed a fix that handles both null and undefined. Make sure to pull master

I can't see that fix. I still get the same issue on master and the code doesn't have undefined unless I missed something.

https://github.com/AcalaNetwork/chopsticks/blob/master/packages/chopsticks/src/rpc/substrate/chain.ts#L18

ermalkaleci commented 1 year ago

undefined is handle by getBlockAt. please post more details

Tbaut commented 1 year ago

There's not much I can post more but to repeat what I've posted...

Error handling request: TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) 'TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) at chain_getBlockHash (/home/thib/Github/Tbaut/chopsticks/packages/chopsticks/src/rpc/substrate/chain.ts:18:113) at /home/thib/Github/Tbaut/chopsticks/packages/chopsticks/src/rpc/index.ts:35:12

This is pointing at line 18, which is chain_getBlockHash which is the alias and gets called without params. Looking at this line, it's not handling undefined and is trying to destructure an array with [blockNumber], although this param is undefined, that's I guess the culprit.

ermalkaleci commented 1 year ago

Ok got it. So it's a call without params. I thought a request without params is invalid. What tool is sending this request?

ermalkaleci commented 1 year ago

@Tbaut another fix is merged into master

Tbaut commented 1 year ago

Thanks a lot, this particular error is now solved and the events are fired as well :rocket: This tool is Subsquid which is an indexer.

I'm hitting some new issues now, but I'll create another issue on Github for it.