EOSIO / demux-js

💫 Deterministic event-sourced state and side effect handling for blockchain applications
MIT License
307 stars 71 forks source link

The eos-transfers example crashes when started in replay mode and start at block -1 #171

Open olivierbeaulieu opened 5 years ago

olivierbeaulieu commented 5 years ago

When the eos-transfers example is run via yarn example eos-transfers, it works. However, is you start modifying values to see demux's difference behaviours, it crashes.

Changing startAtBlock from 50000000 to -1:

const actionReader = new NodeosActionReader({
  startAtBlock: -1,
  onlyIrreversible: false,
  nodeosEndpoint: "https://api.eosnewyork.io"
})

And changing watch to be in replay mode:

actionWatcher.watch(true)

Will crash on the first block with this error:

[2019-07-11T16:16:40.446Z] ERROR: demux/32914: Invalid array length
    RangeError: Invalid array length
        at ObjectActionHandler.rollbackTo (/Users/olivier/projects/demux-js-dfuse/node_modules/demux/examples/eos-transfers/ObjectActionHandler.js:68:26)
        at ObjectActionHandler.<anonymous> (/Users/olivier/projects/demux-js-dfuse/node_modules/demux/examples/eos-transfers/node_modules/demux/dist/AbstractActionHandler.js:187:28)
        at Generator.next (<anonymous>)
        at /Users/olivier/projects/demux-js-dfuse/node_modules/demux/examples/eos-transfers/node_modules/demux/dist/AbstractActionHandler.js:7:71
        at new Promise (<anonymous>)
        at __awaiter (/Users/olivier/projects/demux-js-dfuse/node_modules/demux/examples/eos-transfers/node_modules/demux/dist/AbstractActionHandler.js:3:12)
        at ObjectActionHandler.handleRollback (/Users/olivier/projects/demux-js-dfuse/node_modules/demux/examples/eos-transfers/node_modules/demux/dist/AbstractActionHandler.js:182:16)
        at ObjectActionHandler.<anonymous> (/Users/olivier/projects/demux-js-dfuse/node_modules/demux/examples/eos-transfers/node_modules/demux/dist/AbstractActionHandler.js:54:24)
        at Generator.next (<anonymous>)
        at fulfilled (/Users/olivier/projects/demux-js-dfuse/node_modules/demux/examples/eos-transfers/node_modules/demux/dist/AbstractActionHandler.js:4:58)

It is caused by ObjectActionHandler's rollbackTo trying to create an array with negative length, since latestBlockNumber is 0 (by default), and blockNumber will be something like 68149703.

I'm trying to understand why is a rollback attempted here, maybe you can shed some light on this.