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

BTC that are send to change addresses don't show up in walletbalance or coins #498

Closed
gnorbsl opened this issue Jun 20, 2018 · 5 comments
Closed

Comments

@gnorbsl
Copy link

gnorbsl commented Jun 20, 2018

Hi,

I use var changeAddress = await wallet.createChange('default'); to generate change addresses that I use for raw transactions. It seems that sometimes those addresses are not recognized by the wallet and the funds that are send to the change address are not usable anymore.

One example of my console output:

2018-06-20 13:15:28 debug: 	Available coins: [
    {
        "version": 1,
        "height": 1325925,
        "value": 10000000,
        "script": "76a91419805aa25009f8d53162b3f52e9b3069080754a788ac",
        "address": "mhqnx3Ys4YwntzVxvoCcJHe7FHztvwfo8L",
        "coinbase": false,
        "hash": "c719ff164c4cae127af1be147162b452d1c0fdf5b12d17f3e9af604f15147d01",
        "index": 1
    },
    {
        "version": 1,
        "height": 1325925,
        "value": 8796800,
        "script": "76a914a358e45f74bcd5f33a03a3d119629f7f63d7207688ac",
        "address": "mvQeveoCzrGfqY81kQ6WxNRE7jtx24ecQW",
        "coinbase": false,
        "hash": "e8bb94089f31d78e92b72291a8efb23fb296a9add426d8e69c76db5ed314b56c",
        "index": 2
    },
    {
        "version": 1,
        "height": 1325925,
        "value": 160000000,
        "script": "76a914efc4573c912ded06a712136e8dba651f5cc3640588ac",
        "address": "n3NiztzTbCM8KajoSsuoNwX6KNrwEjfVbj",
        "coinbase": false,
        "hash": "5cbb93154c67f0f1d425263a4df0546d79fc08f472c2537d0d9f717d6a0fc2ae",
        "index": 0
    },
    {
        "version": 1,
        "height": 1325925,
        "value": 3242161,
        "script": "76a914efc4573c912ded06a712136e8dba651f5cc3640588ac",
        "address": "n3NiztzTbCM8KajoSsuoNwX6KNrwEjfVbj",
        "coinbase": false,
        "hash": "76f4ab505f41ef64e703ba43bf406f5926fdec0fd6d8aafe29c9be0cfa6d4bd8",
        "index": 0
    }
] 
2018-06-20 13:15:28 debug: 	Available coins: 1.82038961 
2018-06-20 13:15:28 debug: 	Changeaddress: n2i8bQDNLtbRZWfLmdNXRyxQwHMLh6xppJ 
2018-06-20 13:15:28 debug: 	Size: 798 fee: 0.001596 
2018-06-20 13:15:28 debug: 	Change: 1.8177936100000003 
2018-06-20 13:15:28 debug: 	SendTo: {
    "data": "",
    "n3QP8AaZoVa2YmtKhKm7ekJrg3vKrKbz3Y": 0.001,
    "n2i8bQDNLtbRZWfLmdNXRyxQwHMLh6xppJ": 1.8177936100000003
} 

The Transaction is created and signed successfully, the transaction in the chain:

https://live.blockcypher.com/btc-testnet/tx/3283380520b41eaf2e7a62e15801bfb0ba2372890a0cf304823e4f9996d148ed/

The output of the default account of this wallet after the transaction was made:

{
  "name": "default",
  "initialized": true,
  "witness": false,
  "watchOnly": true,
  "type": "pubkeyhash",
  "m": 1,
  "n": 1,
  "accountIndex": 0,
  "receiveDepth": 7,
  "changeDepth": 12,
  "nestedDepth": 0,
  "lookahead": 10,
  "receiveAddress": "n2hqx7GCthbGXUmVzHd2TAnQsYLyQABXpk",
  "changeAddress": "n2i8bQDNLtbRZWfLmdNXRyxQwHMLh6xppJ",
  "nestedAddress": null,
  "accountKey": "tpubDCxeiTyxA4wKXmD49y6K5TZqyHNVeVjGgP2u1jAfBUqsTmsoLXkCjQjuNaSHpyfF5UYKQj7n8dfrVwZE3J1xGne2NyXRpkJS8szPVybeLKU",
  "keys": [],
  "balance": {
    "tx": 7,
    "coin": 0,
    "unconfirmed": 0,
    "confirmed": 0
  }
}

The Node is fully synced and previous transactions with the same method worked too, a rescan of the block with the transactions and previous blocks didn't change the balance.

Thread on Slack for more information:
https://bcoin-dev.slack.com/archives/C4VSMQNFJ/p1529502702000257

@gnorbsl
Copy link
Author

gnorbsl commented Jun 20, 2018

debug.log after a rescan:

https://gist.github.com/gnorbsl/e3a2a33d7b6ae49d671eef5158b6932d

I created a new account and imported the public key from the broken account:

{
  "name": "test2",
  "initialized": true,
  "witness": false,
  "watchOnly": true,
  "type": "pubkeyhash",
  "m": 1,
  "n": 1,
  "accountIndex": 2,
  "receiveDepth": 7,
  "changeDepth": 11,
  "nestedDepth": 0,
  "lookahead": 10,
  "receiveAddress": "n2hqx7GCthbGXUmVzHd2TAnQsYLyQABXpk",
  "changeAddress": "mjv6VsFnLfot5KBAMktC5KKoXoj4QPVdxq",
  "nestedAddress": null,
  "accountKey": "tpubDCxeiTyxA4wKXmD49y6K5TZqyHNVeVjGgP2u1jAfBUqsTmsoLXkCjQjuNaSHpyfF5UYKQj7n8dfrVwZE3J1xGne2NyXRpkJS8szPVybeLKU",
  "keys": [],
  "balance": {
    "tx": 0,
    "coin": 0,
    "unconfirmed": 0,
    "confirmed": 182038961
  }
}

I noticed that the changeDepth is one less than on the original account but I assume it has to be higher or at least the same? Also it shows the funds as confirmed but they are unusable because I cant access the coins

@gnorbsl
Copy link
Author

gnorbsl commented Jun 21, 2018

I found that the bug is reproducible. I first create a wallet and then I create a second watch only wallet with the public key from the first one. then I create raw transactions with a receiver and the generated changeAddress in the sendTo array and sign/send it. As soon as the changeDepth reaches 12 the change becomes unusable.

@gnorbsl
Copy link
Author

gnorbsl commented Jun 23, 2018

This should be fixed with these changes:

https://github.com/bcoin-org/bcoin/pull/503/files

Thanks to @nodar-chkuaselidze for fixing it so fast.

@tuxcanfly
Copy link
Member

@gnorbsl Are you still seeing an issue with the fix?

@gnorbsl
Copy link
Author

gnorbsl commented Jun 26, 2018

@tuxcanfly No this fix solved the problem described in my issue.

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