dashevo / wallet-lib

DEPRECATED A pure and extensible JavaScript Wallet Library for Dash
https://dashevo.github.io/platform/Wallet-library/
MIT License
12 stars 15 forks source link

TransactionSyncStreamWorker failed onStart: 3 INVALID_ARGUMENT: count is too big, could not fetch more than blockchain length #190

Closed ganthern closed 3 years ago

ganthern commented 4 years ago

trying to create a wallet from a fixed mnemonic, the TransactionSyncStreamWorker first tries to sync from the first block, then from some block in the chain, but without updating the count of synced blocks.

Possible Solution

Looks like it syncs up to the gap limit, updates the last synced block hash but not the height, therefore trying to sync more blocks than are on the chain on the next sync call.

https://github.com/dashevo/wallet-lib/blob/7722d817373ae332d15641d0b3b73b9556e48a6c/src/plugins/Workers/TransactionSyncStreamWorker/methods/startHistoricalSync.js#L19-L23

syncUpToTheGapLimit should probably update the height as well.

Steps to Reproduce (for bugs)

wallet.js:

const Dash = require('dash');

async function createWallet() {
    const clientOpts = {
        network: 'evonet',
        wallet: {
            mnemonic: "fade slot island promote tower drama tomato lonely elbow pact allow use"
        }
    }
    const client = new Dash.Client(clientOpts)
    await client.wallet.getAccount()
}

createWallet().catch(e => console.log(e.message))

run with LOG_LEVEL=debug node wallet.js

Output:

verbose: Logger uses "debug" level { level: 'debug' }
warn: Running on a NodeJS env without any specified adapter. Data will not persist.
debug: Account.injectPlugin(chainplugin) - starting injection
debug: ChainPlugin - Setting up starting blockHeight 22156
debug: Account.injectPlugin(chainplugin) - successfully injected
debug: Account.injectPlugin(transactionsyncstreamworker) - starting injection
debug: {"eventTypeStarting":"WORKER/TRANSACTIONSYNCSTREAMWORKER/STARTING","result":null}
debug: ChainPlugin - setting chain blockheight 22156
debug: TransactionSyncStreamWorker - HistoricalSync - Started from 1, count: 22155
debug: syncing up to the gap limit: - from block: 1 Count: 22155
debug: Options: {"count":22155,"fromBlockHeight":1}
debug: TransactionSyncStreamWorker - HistoricalSync - Restarting the stream
debug: TransactionSyncStreamWorker - HistoricalSync - Started from 0000021e209dd7938b42646fc350631e9d5a6cc2e526fbebcfacf905b784d9e7, count: 22155
debug: syncing up to the gap limit: - from block: 0000021e209dd7938b42646fc350631e9d5a6cc2e526fbebcfacf905b784d9e7 Count: 22155
debug: Options: {"count":22155,"fromBlockHash":"0000021e209dd7938b42646fc350631e9d5a6cc2e526fbebcfacf905b784d9e7"}
debug: {"eventType":"WORKER/TRANSACTIONSYNCSTREAMWORKER/STOPPED"}
Failed to perform standard injections with reason: Worker TransactionSyncStreamWorker failed onStart: 3 INVALID_ARGUMENT: count is too big, could not fetch more than blockchain length

Your Environment

antouhou commented 4 years ago

Thank you for the report! We'll investigate the issue 👍

ganthern commented 4 years ago

@antouhou I had a fiddle with this and at least got it syncing correctly, but it's probably not ready for a pull request since I started looking at dashevo literally yesterday and don't really know yet what I'm doing. Should I still open a PR so someone can have a look?

Alex-Werner commented 4 years ago

@ganthern We will look at it even if not ready. When creating a PR, you can setup to a be a draft PR instead, that looks suitable :) Thank you !

cloudwheels commented 4 years ago

@ganthern nice one for putting this PR together - I had the same issue myself a couple of days ago but didn't have a chance to investigate further. If you're just getting into Dash Platform ("evo") devolpment, are you aware of the developer discord? http://chat.dashdevs.org/ We're actually running a bounty program there which includes some small incentives to help with bug spotting & swatting just like this, amongst other things. Would be great to see you there!

ganthern commented 4 years ago

@cloudwheels I actually found the discord already, and have seen that you seem to have encountered this issue at almost the same time. Thanks for the invitation!

antouhou commented 4 years ago

Hey @cloudwheels @ganthern! I've deployed a new version of DAPI yesterday to the evonet. It fixes the issue. Sorry for the long wait! Eventually, we ended up just removing the error message from the DAPI in the https://github.com/dashevo/dapi/pull/315. Please check when you have time! Thanks!

dalibran commented 3 years ago

This has been in a previous release.