Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Update balance for only existing assets on tip change #2763

Merged
merged 1 commit into from
May 18, 2024

Conversation

ukane-philemon
Copy link
Contributor

@ukane-philemon ukane-philemon commented May 5, 2024

Closes #2757

I was able to reproduce and debug the issue. The problem was that asset.TipChangeNote notification might be received by core before the wallet exists.

There are just two such notifications asset.TipChangeNote and asset.BalanceChangeNote and we already check for an existing wallet for asset.BalanceChangeNote before proceeding.

@JoeGruffins please confirm if you can still reproduce with this PR. I got a log when debugging the issue.

2024-05-05 21:47:36.369 [INF] DEXC: dexc version 0.7.0-pre+522d86aaa (Go version go1.22.2)
...
2024-05-05 21:47:57.750 [INF] CORE: notify: |SUCCESS| (security) Don't forget to back up your application seed - A new application seed has been created. Make a back up now in the settings view.
2024-05-05 21:48:00.774 [DBG] CORE: notify: |POKE| (conn) Server connected - 127.0.0.1:17273 is connected
2024-05-05 21:48:00.777 [INF] CORE: Server 127.0.0.1:17273 supports API version 1.
2024-05-05 21:48:00.777 [DBG] CORE: Server 127.0.0.1:17273 broadcast timeout 1m0s. Tick interval 7.5s
2024-05-05 21:48:00.777 [INF] CORE: Connected to DEX server at 127.0.0.1:17273 and listening for messages.
2024-05-05 21:48:01.455 [INF] CORE: Initializing a dcr wallet
2024-05-05 21:48:01.475 [INF] CORE: Initializing a ltc wallet
2024-05-05 21:48:01.561 [INF] CORE: Initializing a bch wallet
2024-05-05 21:48:01.595 [INF] CORE: Initializing a polygon wallet
2024-05-05 21:48:01.602 [INF] CORE: Initializing a btc wallet
2024-05-05 21:48:01.604 [INF] CORE: Initializing a eth wallet
...

**2024-05-05 21:48:04.034 [CRT] CORE: Wallet with asset ID 42  does not exits // Debug log**

2024-05-05 21:48:04.776 [INF] CORE: Created dcr wallet. Balance available = 0 / locked = 0 / locked in contracts = 0, Deposit address = SspcFYfHYA1APEPjQ1acMf7KZrxminqEFcp
2024-05-05 21:48:08.806 [DBG] CORE[ltc][SPV]: Starting native LTC wallet...
2024-05-05 21:48:09.310 [DBG] CORE[btc][SPV]: Starting native BTC wallet...
2024-05-05 21:48:11.401 [DBG] CORE[ltc][SPV]: Starting neutrino chain service...
2024-05-05 21:48:11.474 [INF] CORE[ltc][SPV]: Synchronizing wallet with network...
2024-05-05 21:48:11.477 [INF] CORE[ltc]: Connected wallet with current best block 530827f38f93b43ed12af0b3ad25a288dc02ed74d6d7857862df51fc56c416f9 (0)
2024-05-05 21:48:11.529 [DBG] CORE[ltc]: Using tx history db at /Users/philemon/Desktop/testsim/simnet/assetdb/ltc/regtest/txhistorydb-rltc1qkqs9eg5rkx3tw4d84qzmk8ezmj07zc67ghhm22
2024-05-05 21:48:11.608 [DBG] CORE[btc][SPV]: Starting neutrino chain service...
2024-05-05 21:48:11.682 [INF] CORE[btc][SPV]: Synchronizing wallet with network...
2024-05-05 21:48:11.683 [INF] CORE[btc]: Connected wallet with current best block 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 (0)
2024-05-05 21:48:11.685 [DBG] CORE[btc]: Using tx history db at /Users/philemon/Desktop/testsim/simnet/assetdb/btc/regtest/txhistorydb-ce8d8e8c5c0f060aec5693218589a4e61b69ac2c
2024-05-05 21:48:11.752 [DBG] CORE[btc]: tip change: 0 (0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206) => 0 (0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206)

**2024-05-05 21:48:11.753 [CRT] CORE: Wallet with asset ID 0  does not exits  // Debug log**

2024-05-05 21:48:11.892 [DBG] CORE[bch][SPV]: Starting native BCH wallet...
2024-05-05 21:48:12.507 [INF] CORE: Wallet synced for asset dcr
2024-05-05 21:48:13.205 [INF] CORE: Created ltc wallet. Balance available = 0 / locked = 0 / locked in contracts = 0, Deposit address = rltc1qxzz95jed0snv3fq4e3x0lqnxmkdc73sguhnqlr
2024-05-05 21:48:13.378 [INF] CORE: Created btc wallet. Balance available = 0 / locked = 0 / locked in contracts = 0, Deposit address = bcrt1q4j7wkck4syfkfyss39epd829njn2h2kw0gqswd
2024-05-05 21:48:13.445 [DBG] CORE[bch][SPV]: Starting neutrino chain service...
2024-05-05 21:48:13.528 [INF] CORE[bch][SPV]: Synchronizing wallet with network...
2024-05-05 21:48:13.530 [INF] CORE[bch]: Connected wallet with current best block 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 (0)
2024-05-05 21:48:13.544 [DBG] CORE[bch]: Using tx history db at ***/txhistorydb-bchreg:qqg0dldu4vwe2maq8ug0kw48c6u3ktnnlszv0d2ect
2024-05-05 21:48:14.666 [INF] CORE: Created bch wallet. Balance available = 0 / locked = 0 / locked in contracts = 0, Deposit address = bchreg:qzxpaz0t4nr9gf7ekrwm5x9wudksj8qsaywxzdqjfu
2024-05-05 21:48:14.784 [INF] CORE: Wallet synced for asset btc
2024-05-05 21:48:15.038 [DBG] CORE[dcr]: tip change: 734 (eb9ce4a61114475c023a6e8607018fc623d5ef12eed19bf3c773ad8878569a63) => 735 (2b763512621c82046e18b1201a59d713eceb13a5580eeb0839690e258b1fa5c5)
......
^C2024-05-05 21:49:48.396 [INF] DEXC: Attempting to logout...
2024-05-05 21:49:48.397 [INF] DEXC: Shutting down...
....

Signed-off-by: Philemon Ukane <ukanephilemon@gmail.com>
@ukane-philemon
Copy link
Contributor Author

We can still leave the log message, but it should never show up in the logs if this PR gets merged.

@buck54321
Copy link
Member

It looks like this can only happen in createWalletOrToken because that's the only place we connectWallet before we call updateWallet. I wonder if we can just call updateWallet earlier?

@ukane-philemon
Copy link
Contributor Author

ukane-philemon commented May 7, 2024

It looks like this can only happen in createWalletOrToken because that's the only place we connectWallet before we call updateWallet. I wonder if we can just call updateWallet earlier?

Hmm, will look into this.

EDIT:

It looks like this can only happen in createWalletOrToken

You're right. The Connect wallet method kicks off the emitter and we might receive notes before the wallet is added to core.

I wonder if we can just call updateWallet earlier?

I think we should ensure notes that could be emitted before the wallet is ready are ignored. There are just two of that nature asset.TipChangeNote and asset.BalanceChangeNote. We already check for asset.BalanceChangeNote and return early.

If we call updateWallet early, the user might see the wallet has been created and maybe we encounter an error in connectWallet, or another error path below, we'd have to undo updateWallet.

Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah don't see it anymore. Change looks fine to me.

@buck54321 buck54321 merged commit f8bfd38 into decred:master May 18, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CORE: non-existent 42 wallet should exist
3 participants