Skip to content

Conversation

sdaftuar
Copy link
Member

@sdaftuar sdaftuar commented Sep 3, 2017

Replace witness-stripped wallet transactions with full transactions;
this can happen when upgrading from a pre-segwit wallet to a segwit-
aware wallet.

Replace witness-stripped wallet transactions with full transactions;
this can happen when upgrading from a pre-segwit wallet to a segwit-
aware wallet.
@fanquake fanquake added the Wallet label Sep 3, 2017
@jonasschnelli
Copy link
Contributor

utACK 617c459.
Makes sense.
Ideally we should add a test for this.

@sipa
Copy link
Member

sipa commented Sep 3, 2017

utACK d01a968

This should be backported to 0.15(.1), I think.

@@ -914,6 +914,15 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
wtx.fFromMe = wtxIn.fFromMe;
fUpdated = true;
}
// If we have a witness-stripped version of this transaction, and we
// see a new version with a witness, then we must be upgrading a pre-segwit
// wallet. Store the new version of the transaction with the witness,
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove extra space.

// wallet. Store the new version of the transaction with the witness,
// as the stripped-version must be invalid.
// TODO: Store all versions of the transaction, instead of just one.
if (wtxIn.tx->HasWitness() && !wtx.tx->HasWitness()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

First check stored transaction:

if (!wtx.tx->HasWitness() && wtxIn.tx->HasWitness()) {

@promag
Copy link
Contributor

promag commented Sep 4, 2017

BTW, remove TODO comment and create an issue since it requires a significant change/discussion?

@sdaftuar
Copy link
Member Author

sdaftuar commented Sep 5, 2017

@promag I opened #11240 to expand on the issue mentioned in the TODO.

@maflcko maflcko added this to the 0.15.1 milestone Sep 5, 2017
@TheBlueMatt
Copy link
Contributor

Wait, do we want to also update if the witness was malleated on its way into a block?

@sdaftuar
Copy link
Member Author

@TheBlueMatt I considered that issue, and decided it was more conservative (at least for now) to not do that, because:
a) You can always figure out what version of the transaction got mined if you need to (just go look it up in the block file -- ok not great if you're pruning, but in theory this is possible)
b) It's conceivable that the mined version is invalid-to-you (ie violates policy), and throwing away a known-good signature you made, which you might be able to reproduce, is scary, say in the event of a reorg that causes the malleated-version of the transaction to no longer be confirmed.

b) is pretty edge-case, to be sure, but since the only benefit to storing the actually-confirmed-witness is recordkeeping, which doesn't affect our wallet's behavior, I figure why risk it. IMO we should eventually store both the original version of the transaction and any malleated versions that get confirmed.

@TheBlueMatt
Copy link
Contributor

Yea, ok, more complexity than I figured, this is clearly better than nothing as-is and anything more looks like it'll take some real rewriting of our malleability handling.
utACK d01a968 +/- outstanding nits.

@laanwj laanwj merged commit d01a968 into bitcoin:master Sep 26, 2017
laanwj added a commit that referenced this pull request Sep 26, 2017
d01a968 wallet: update stored witness in AddToWallet (Suhas Daftuar)

Pull request description:

  Replace witness-stripped wallet transactions with full transactions;
  this can happen when upgrading from a pre-segwit wallet to a segwit-
  aware wallet.

Tree-SHA512: a348b16b38ae738fa75cf7d3ff50ebd0d0071d5d6061c9a10dc3325fc34f6bc96a67aea21fde460ca20f6178768ee0af04d6d8785b35647f436a9083c4270b07
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 4, 2017
Replace witness-stripped wallet transactions with full transactions;
this can happen when upgrading from a pre-segwit wallet to a segwit-
aware wallet.

Github-Pull: bitcoin#11225
Rebased-From: d01a968
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants