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 Protobuf serialization failure when sending coins between 2 listening wallets #1582

Open
jd1318 opened this issue May 21, 2018 · 1 comment

Comments

@jd1318
Copy link

jd1318 commented May 21, 2018

when you have 2 or more listening wallets, and you send coins from 1 wallet to another, then out to a third party, if you try to deserialize the wallets it will fail due to an error.

I have only tested this with full pruned block store, never with spv. I believe this is only relevant to fullpruned stores

the error on deserialization:

org.bitcoinj.wallet.UnreadableWalletException: Could not connect 66a13920c7e9a637da523266e0a9fe43c65347933220f60d2579f807b1c32341 to e698caadfcd95be72658289e85f57ca9662be8369aed01552c0578f7a5021d2d
at org.bitcoinj.wallet.WalletProtobufSerializer.connectTransactionOutputs(WalletProtobufSerializer.java:704)
at org.bitcoinj.wallet.WalletProtobufSerializer.readWallet(WalletProtobufSerializer.java:508)
at org.bitcoinj.wallet.WalletProtobufSerializer.readWallet(WalletProtobufSerializer.java:417)
at org.bitcoinj.wallet.WalletProtobufSerializer.readWallet(WalletProtobufSerializer.java:391)
at org.bitcoinj.wallet.Wallet.loadFromFileStream(Wallet.java:1602)
at org.bitcoinj.wallet.Wallet.loadFromFile(Wallet.java:1508)

The cause of this seems to be related to how Transaction objects are committed to the wallets, and when Wallet.UpdateForSpends() is ran on the TX, it will set the spentBy value for all wallets because the "root" transaction object is altered. UpdateForSpends is only run on the relevant wallet but all listening wallets are effected that contain the transaction with outputs being spent by the new outgoing transaction.

input ->[tx #1] -> wallet #1 ->[tx #2] -> wallet #2 ->[tx #3] -> third party

The third transaction is not relevant to the first wallet in the chain so it is not committed (as it should be), however transaction #2 in wallet #1 still has a spent by that can not be avoided without restructuring the way broadcast transactions are handled from what i have found. updateforspends is never called on wallet#1 for tx#3 but that does not matter.

The commit 943a139 does not solve the issue. I am running 0.14.7 with this commit manually added.

My solution was to ignore transaction connection failure in org.bitcoinj.wallet.WalletProtobufSerializer.connectTransactionOutputs
if the transaction we are trying to connect from (by using spent by) has no value sent FROM us. could this have any effect with other aspects of the code? ideally a change to how spentBy is set would be ideal but its a lot of heavy lifting for something that may be intended functionality. so basically my question is, is my solution viable or would it be better to stop spentby from being set on wallet #1?

i may be way off here on the cause, but the solution does work regardless, it just doesn't solve the real issue.

Thank you for reading!

@schildbach
Copy link
Member

This issue has a thread on the mailing list titled "unreadable wallet corruption after crash".

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

No branches or pull requests

2 participants