-
Notifications
You must be signed in to change notification settings - Fork 27
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
Clone transaction before adding to wallet #18
Clone transaction before adding to wallet #18
Conversation
Since PeerGroup can have multiple wallets that all might depend on the same transaction it was adding the same transaction to multiple wallets. By cloning the transaction each wallet is guaranteed to have its own, non shared transactions
There were a couple of commits with a workaround to the "same tx shared by multiple wallet" issue: Have you found a new bug not solved by these workarounds? |
I don't think any of those fixes would solve the issue I found. The problem I encountered was that when txA (a tx sending some BTC from BTC wallet to BSQ wallet) was broadcast it was first added in the BTC wallet and on broadcast completion the same txA was added to the BSQ wallet. When spending from the BSQ wallet the spend txB is committed to first the BTC wallet and then to the BSQ wallet. In the commit to the BTC wallet, a txA output used by txB will be tagged as spent and when the BSQ wallet tries to do the same thing the txA output is no longer spendable and the wallet ends up in a bad state. |
Then, I have 2 suggestions:
|
|
@oscarguindzberg I leave that review for you. I will do do a final review as well. |
I had a closer look. bitcoinj was not built to work with multiple wallet instances. So,
|
@sqrrm I think your last commits are wrong (reverts). See @oscarguindzberg's last comment. |
Cloning a transaction does not clone the connected outputs from the transaction inputs. Not sure if that can become an issue here, btu maybe worth to consider. @sqrrm Is the only use case where this leads to a problem the one when a user sends BTC from his Bisq BTC wallet to the BSQ wallet? This is not a valid use-case (not possible even as the prefix "B" in the address would not allow sending BTC. |
@ManfredKarrer The cloning of every incoming tx will ensure that each wallet has unique txs and thus the connected outputs will be unique to that wallet. The current problem is that transactions published by the BTC side of bisq are not cloned if they're relevant to the BSQ wallet. The BSQ transactions are all cloned before being committed and then published inside WalletsManager.publishAndCommitBsqTx(). This proposed change is to make sure we do that from the BTC side as well, and we could also get rid of the explicit cloning in publishAndCommitBsqTx(). I can't think of any current use case but I don't have a complete picture of how the BTC wallet is used. It's possible that this case is the only current issue, but even if it is I think it's worth fixing to make sure we don't get trouble further down the line when we get at atomic BTC/BSQ transactions or something similar. @oscarguindzberg Good point, better to avoid unnecessary cloning. I will make a new PR without all the reverted commits. I think we should refrain from too much refactoring right now but rather look at doing things slowly and only get this fix in if it's acceptable. |
@sqrrm Ah ok, that explains why we don't encounted any issues as all BSQ txs are broadcasted by the BSQ wallet and cloned at that step. Also the trade fee txs are cloning the tx for the btc wallet. I agree we should fix that even if it is not a real risk atm. But would prefer to make it at a later point to not add risk now and focus on other more concrete issues. @sqrrm Is it ok to close that PR? |
See #21 for new PR |
Since PeerGroup can have multiple wallets that all might depend on the
same transaction it was adding the same transaction to multiple wallets.
By cloning the transaction each wallet is guaranteed to have its own,
non shared transactions