bob-wallet icon indicating copy to clipboard operation
bob-wallet copied to clipboard

Network synchronization stalled after adding the same Ledger wallet twice

Open CorpulentBrony opened this issue 2 years ago • 1 comments

Expected Behavior

Wallet should maintain synchronization with the network.

Current Behavior

Wallet goes out of sync. Upon restart, Bob will resynchronize up to the point where txns were issued after duplicate wallet was removed.

Steps to Reproduce

  1. In a fresh Bob instance, create new Ledger-backed wallet
  2. Issue txns on that wallet
  3. Create another wallet using the same Ledger key (a duplicate wallet)
  4. Rescan the new wallet so now both wallets are equivalent
  5. Delete the new wallet
  6. Create new txns on your existing wallet
  7. Wait a period of time (took me overnight)
  8. The new txns will remain in pending status, restart Bob wallet
  9. Synchronization progress will now stall

Logs

For each pending txn, I see the following error message:

[I:2022-09-14T17:56:46Z] (wallet) Incoming transaction for 2 wallets in WalletDB (9617...).
[E:2022-09-14T17:56:46Z] (node) Assertion failed.
    at WalletDB._addTX (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\wallet\walletdb.js:2432:7)
    at async WalletDB._addBlock (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\wallet\walletdb.js:2267:13)
    at async WalletDB.rescanBlock (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\wallet\walletdb.js:2378:7)
    at async C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\wallet\walletdb.js:154:9
    at async NodeClient._emitAsync (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\bevent\lib\asyncemitter.js:377:11)
    at async NodeClient.emitAsync (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\bevent\lib\asyncemitter.js:318:7)
    at async ChainDB.scan (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\blockchain\chaindb.js:1610:7)
    at async Chain.scan (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\blockchain\chain.js:2228:14)
    at async WalletDB.scan (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\wallet\walletdb.js:509:7)
    at async WalletDB.syncNode (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\wallet\walletdb.js:408:7)
[E:2022-09-14T17:56:46Z] (node) Assertion failed.
    at WalletDB._addTX (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\wallet\walletdb.js:2432:7)
    at async WalletDB._addBlock (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\wallet\walletdb.js:2267:13)
    at async WalletDB.rescanBlock (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\wallet\walletdb.js:2378:7)
    at async C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\wallet\walletdb.js:154:9
    at async NodeClient._emitAsync (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\bevent\lib\asyncemitter.js:377:11)
    at async NodeClient.emitAsync (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\bevent\lib\asyncemitter.js:318:7)
    at async ChainDB.scan (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\blockchain\chaindb.js:1610:7)
    at async Chain.scan (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\blockchain\chain.js:2228:14)
    at async WalletDB.scan (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\wallet\walletdb.js:509:7)
    at async WalletDB.syncNode (C:\Users\account\AppData\Local\Programs\bob-wallet\resources\app.asar\node_modules\hsd\lib\wallet\walletdb.js:408:7)

Fix

Moved existing wallet directory to wallet_old, re-imported wallet from Ledger, rescanned wallet. No more pending txns, everything synchronizing fine.

CorpulentBrony avatar Sep 14 '22 18:09 CorpulentBrony

Delete the new wallet

I didn't realize this is something Bob users can do, it's not normally exposed in the hsd API so I wouldn't be surprised that there's an edge case like this. I'm looking at walletdb.getWalletsByTX() and it retrieves WIDs based on outpointMap, pathMap, and nameMap -- all three of which seem to be cleared appropriately in walletdb.remove().

this log line is maybe a clue:

[I:2022-09-14T17:56:46Z] (wallet) Incoming transaction for 2 wallets in WalletDB (9617...).

It says 2 wallets -- but only one of the matching wallets was actually retrievable. Maybe we should ensure that removing a wallet doesn't have any race conditions?

pinheadmz avatar Sep 15 '22 15:09 pinheadmz