-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
RGB state is not updated on blockchain re-orgs or RBFs #124
Comments
You haven't specified whether the witness tx for the transfers is mined. If it is, than we have the expected behavior |
In this rgb-sandbox branch I create the recipient UTXO before saving the blockchain state, which lets the wallet see it after restoring the previous state. In addition to that, I no more save wallet 1 (issuer) data and sync both wallets before attempting the 2nd transfer. With this updated scenario, I expect:
To further clarify, I added a 3rd transfer, where the recipient (of the first 2 transfers) tries to spend both allocations (of which one should not be visible) to a new wallet. I expect the validation to fail and indeed when the new wallet tries to validate the transfer it fails with:
|
I tried to read through it 3 times and got lost each time. Can we distil a specific bug out of this or this is the actual task we still need to do? |
IMO the bug here is that the wallet doesn't update his view of the contract allocations based on changes in the blockchain. Specifically, if a witness tx disappears (e.g. because of a reorg) then the wallet will still show the allocation that was anchored to the disappeared tx. Trying to spend that allocation will result in a validation error. The solution here might be to add the possibility to remove/hide a transition (that is, the wallet should not show the resulting allocations anymore), or the possibility to check all transitions and remove/hide the ones that don't have a valid anchor anymore. |
The whole wallet functionality here is in a command-line tool. Thus, it can't track the blockchain state unless said so. Did you use |
Yes, the rgb-sandbox script syncs both sender and recipient wallet after restoring the chain data, using the |
Tested with an updated rgb-sandbox branch that uses the current |
Can you please re-test with the all-new and shiny |
Re-tested on branch The recipient wallet still sees no UTXOs at the end of the 2nd transfer and its asset balance is thus 0. |
I've added a test called |
Some updates from rgb-sandbox:
|
Need to think.. Thank you for figuring out the scenario... |
Ok, the problem is in |
With BP-WG/bp-wallet#49 the test now passes and RBFs work. My changes for integration tests can be found in https://github.com/zoedberg/rgb-integration-tests/pull/1/files |
I confirm test now passes, PR ACKed
This contains changes that I already did locally, sorry, next time I'll push updates everytime RGB master branches get updates |
I did the PR to showcase (1) how to use new wallet apis and (2) to ensure the test now passes. Feel free to close it. Just make sure that we use the new wallet apis the same way (like you do not need to call any store/save methods anymore since everything happens automatically now) |
I can confirm the RBF issue is not showing up anymore also in rgb-sandbox. @dr-orlovsky please re-open this issue so we keep tracking the other half of the problem. |
How I can reproduce the re-org issue to investigate it? |
You can reproduce it using this ./demo.sh -v -s 124 The idea is the same as in the original issue report, but using an updated Here's what the test scenario now does:
I expect the balance for wallet_1 to be 100 (the amount transferred) both after the 1st and 2nd transfer, as the chain status has been restored to the initial state (no transfer) between the two transfers. What I get instead is that wallet_1 sees a balance of 200 after the 2nd transfer or, in other words, it still sees the amount from the 1st transfer even though the witness tx is no more included in the chain. |
From what I see after running
|
My bad, I inadvertently dropped a fix while preparing the branch for publication. The state that you're seeing is the one before the 2nd transfer. The test stops because of a wrong check (the computed final balance doesn't match the one provided at command invocation). I have now updated the branch, correctly specifying 0 as the initial balance for the recipient wallet (wallet_1) and skipping the initial balance check (it would fail because the expected initial balance is 0 but the wallet reports 100). This way the test continues and the 2nd transfer completes. Now the reported failure is the correct one, where at the end of the 2nd transfer the balance should be 100 but is instead 200. Checking the state once the test exits you should see a situation like:
|
The problems comes to the fact that somehow both witness transaction ids are known to the wallet. In sandbox, how I can query Bitcoin Core - or better Electrum/Esplora for a specific txid to check whether it is still known to it and what information is returned? |
Ok, I found the source of the problem. We do not filter witness transactions - nowhere in the wallet code we attest whether a specific witness transaction is mined or in a mempool. Witness transactions may not belong to the wallet descriptor and thus are not a part of wallet-basing filtering. They require a specially-designed APIs. I am thinking on the best way of doing it. The main problem - a lot of requests to the indexer which must be handled on update (much more than for usual wallet stuff) - basically we need to check each witness transaction id in the history... |
I have tested the After restoring the chain data (simulating a re-org) and syncing, the recipient wallet still sees the previous allocation, even though the witness transaction is no more available from the blockchain. I have updated the rgb-sandbox branch to check the recipient balance before re-trying the transfer (previously disabled as it was expected to be wrong) and also added a check for the witness transaction on bitcoind to make sure it isn't returned after the restore (it isn't). |
I find this log a bit strange:
It misses the part it must have from here: https://github.com/RGB-WG/rgb/pull/227/files#diff-e5535881c50a9e6adb6c634e4756823e8ca0a816452748017426d349a1ae7504R119-R134 which should read |
Ok, I see the commit is correct:
Strange that the piece of code I quoted is never reached and executed... |
Ok, I have finally got it: you provide |
Ok, adding diff --git a/demo.sh b/demo.sh
index 06eae60..1e5bf46 100755
--- a/demo.sh
+++ b/demo.sh
@@ -197,7 +197,7 @@ _show_state() {
schema=${CONTRACT_SCHEMA_MAP[$contract_name]}
iface=${IFACE_MAP[$schema]}
_trace "${RGB[@]}" -d "data${wallet_id}" \
- state -w "$wallet" -a "$contract_id" "$iface"
+ state --sync -w "$wallet" -a "$contract_id" "$iface"
} However somehow I see from the debug dumps that the removed after re-org tx now is returned by an indexer as a mempool tx, and thus the state is still invalid. Investigating for indexer bug |
Ok, the problem was bug in the indexers - they never ever returned that the tx is non-existent and classified all unknown txes as mempool. With this change the tests do work: 8563b58 |
I have switched to commit |
So should we close this issue? I expect I can merge the bunch of PRs from |
Let's resolve the discussion on telegram before we go ahead and merge those PRs. I'd close the issue once the PRs have been merged. |
Closing since RGB-WG/rgb-std#247 is merged into the master |
Using this branch of rgb-sandbox I get zero balance after accepting a transfer twice.
Here's what the test run does:
The 2nd transfer re-uses the same invoice as the 1st one and overrides the expected final balance, as it's supposed to be the same once all is done.
Before the 2nd transfer, the recipient sees one UTXO and the asset balance from the 1st transfer, as expected. The transfer is successful, including the recipient accepting it into the stash.
The problem is that, after the 2nd transfer, the recipient sees no UTXOs and therefore the asset balance is 0. The expected outcome is that the same UTXO and asset balance as before the 2nd transfer should be visible.
This happens with both opret and tapret.
The text was updated successfully, but these errors were encountered: