EOSIO / EOSIO/demux-js

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

Open
#171 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
298
Forks
69
PR merge metrics
No merged PRs in 30d

Description

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:

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

And changing watch to be in replay mode:
```js
actionWatcher.watch(true)
```

Will crash on the first block with this error:

```sh
[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. (/Users/olivier/projects/demux-js-dfuse/node_modules/demux/examples/eos-transfers/node_modules/demux/dist/AbstractActionHandler.js:187:28)
at Generator.next ()
at /Users/olivier/projects/demux-js-dfuse/node_modules/demux/examples/eos-transfers/node_modules/demux/dist/AbstractActionHandler.js:7:71
at new Promise ()
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. (/Users/olivier/projects/demux-js-dfuse/node_modules/demux/examples/eos-transfers/node_modules/demux/dist/AbstractActionHandler.js:54:24)
at Generator.next ()
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](https://github.com/EOSIO/demux-js/blob/develop/examples/eos-transfers/ObjectActionHandler.js#L68) 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](https://github.com/EOSIO/demux-js/blob/develop/src/AbstractActionHandler.ts#L298), maybe you can shed some light on this.

Contributor guide

Open the contributing guide

Research direction

Reproduce with `yarn example eos-transfers`, `startAtBlock: -1`, and `actionWatcher.watch(true)`. Read `examples/eos-transfers/ObjectActionHandler.js` at `rollbackTo` alongside `src/AbstractActionHandler.ts` around line 298 to trace the first-block rollback. Done means replay mode no longer crashes with `RangeError: Invalid array length`, with rollback behavior covered or clearly accounted for.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
blockchain
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.