EOSIO / demux-js-eos

Demux-js Action Reader implementations for EOSIO blockchains
MIT License
39 stars 17 forks source link

Does not find actions if "producer_block_id" is null in "action_traces" for MongoDB #36

Closed ryanleecode closed 5 years ago

ryanleecode commented 5 years ago

The Mongo Action Reader does not find any actions if the producer_block_id is null. All my action traces come up with producer_block_id as null. I'm not sure why it comes up as null, could be something wrong with my setup. Either way, its preventing all of my handlers from executing because it will filter out all the actions.

We should definately put in a warning of some sort, since this caused me a couple hours tracing why my updaters weren't firing. And if theres not something wrong with my setup, probably will need a way to disable it.

I'm happy to open a PR for this but just wanna check if my setup is bugged first.

The code related to this is from demux-js-eos/src/MongoActionReader.ts in getBlock.

        const rawActions = await this.mongodb!.collection("action_traces")
          .find({
            block_num: blockNumber,
            producer_block_id: blockState.block_id,
          })
          .sort({ "receipt.global_sequence": 1 })
          .toArray()

Example Block image

demux version: 3.1.3 demux-eos version: 3.0.1 eos-dev version: 1.5.2 eos cdt version: 1.4.1

flux627 commented 5 years ago

The problem is that you need to have your Nodeos set with the following modes:

read-only = true
mongodb-update-via-block-num = true

Since read-only is required, this means that if you are producing your own blocks, the Nodeos node that runs the MongoDB plugin needs to be a separate instance. the mongodb-update-via-block-num option will, instead of adding a new block with the same number during micro-forks, replace the orphaned block with updated information. This will not be a problem in a local test environment when you are creating your own blocks, but it will be in production.

I've added documenting this to the back-log. I'll leave this issue open until that's updated.

ryanleecode commented 5 years ago

Yep that worked. Thanks!