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

Wallet: clone transaction before committing #38

Closed
wants to merge 2 commits into from

Conversation

sqrrm
Copy link
Member

@sqrrm sqrrm commented Sep 22, 2021

Problem: A transaction received from the network is added to all wallets
that find it relevant. If two wallets find the same transaction relevant
the same Transaction instance is added to both wallets.

Spending the outputs from this transaction can cause consistiency
issues, in particular if the outputs are spent in the same transaction,
as shown in WalletTest.oneTxTwoWallets. There are probably more issues
with having the same Transaction instance handled by two different
wallets.

Fix: Clone the transaction before adding it to the wallet.

Problem: A transaction received from the network is added to all wallets
that find it relevant. If two wallets find the same transaction relevant
the same Transaction instance is added to both wallets.

Spending the outputs from this transaction can cause consistiency
issues, in particular if the outputs are spent in the same transaction,
as shown in WalletTest.oneTxTwoWallets. There are probably more issues
with having the same Transaction instance handled by two different
wallets.

Fix: Clone the transaction before adding it to the wallet.
Copy link

@chimp1984 chimp1984 left a comment

Choose a reason for hiding this comment

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

utACK
Take my utACK with caution. Not familiar much with BitcoinJ and not sure if there would be a better way to make sure deleting would work on Windows. But I guess its acceptable to get the test on windows ok.

// two wallets depend on the same transaction.
Transaction cloneTx = tx.getParams().getDefaultSerializer().makeTransaction(tx.bitcoinSerialize());
cloneTx.setPurpose(tx.getPurpose());
cloneTx.setUpdateTime(tx.getUpdateTime());

Choose a reason for hiding this comment

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

Are there any other properties we need to move over to the cloneTx?
Maybe avoid code duplication at line 1913 and use a method for getting the clone from the tx?

@ripcurlx
Copy link

ripcurlx commented Feb 1, 2022

Closing as already integrated with 033c195

@ripcurlx ripcurlx closed this Feb 1, 2022
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.

None yet

4 participants