Bitcoin Forum
May 13, 2024, 11:48:43 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Electrum not using change addresses  (Read 1501 times)
DavidCWG (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
July 17, 2014, 08:48:37 PM
 #1

I recently made this transaction with Electrum 1.9.8:
https://blockchain.info/tx/7ba987f202323c302b7cc736436a1858579255b131e4f7332caced3a96d945ed

You'll notice that some change from the transaction went back to 1K2TZGCiP8F2sZHtZ73LtyMQJUygFxwUUH, which is also one of the source addresses.

Why is Electrum returning funds to the same address instead of to a change address?

"Use change addresses" is turned on in the Settings.
1715600923
Hero Member
*
Offline Offline

Posts: 1715600923

View Profile Personal Message (Offline)

Ignore
1715600923
Reply with quote  #2

1715600923
Report to moderator
"Your bitcoin is secured in a way that is physically impossible for others to access, no matter for what reason, no matter how good the excuse, no matter a majority of miners, no matter what." -- Greg Maxwell
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715600923
Hero Member
*
Offline Offline

Posts: 1715600923

View Profile Personal Message (Offline)

Ignore
1715600923
Reply with quote  #2

1715600923
Report to moderator
1715600923
Hero Member
*
Offline Offline

Posts: 1715600923

View Profile Personal Message (Offline)

Ignore
1715600923
Reply with quote  #2

1715600923
Report to moderator
Abdussamad
Legendary
*
Online Online

Activity: 3612
Merit: 1564



View Profile
July 19, 2014, 09:34:43 AM
 #2

Is 1K2 the address of an imported private key? I believe Electrum sends change back to an imported private key. If I'm wrong please correct me.
DavidCWG (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
July 25, 2014, 03:58:51 AM
 #3

No, it's not imported.
Abdussamad
Legendary
*
Online Online

Activity: 3612
Merit: 1564



View Profile
July 25, 2014, 07:07:47 PM
 #4

No, it's not imported.

This one is though isn't it?

https://blockchain.info/address/1DavidGAHiCiiSZgBrbteAkby5AUf6QR3o

DavidCWG (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
July 26, 2014, 12:55:22 AM
 #5

That one is, yes, though I did a regular "Send" transaction, not a custom one, so whether the source addresses are imported or not shouldn't matter to me. I would expect all change to go to a "Change" address - that is the whole point of them. It didn't even return the change to the imported address, just to one of my other regular addresses.

This seems like a bug to me.
dabura667
Sr. Member
****
Offline Offline

Activity: 475
Merit: 252


View Profile
July 26, 2014, 02:42:11 AM
 #6

I found the bug. (err... more like a good-intention feature gone wrong)

https://github.com/spesmilo/electrum/blob/f92b483942d3f8ee51506e0436d9b524db33a336/lib/wallet.py#L1142

The change selection method checks the first input, and if account == -1 (aka if the input is from imported keys) then it sets the change address as the address of the first input.
As your first input was from an imported address, it will send the change to your first input's imported address.

https://github.com/spesmilo/electrum/blob/master/lib/wallet.py#L602

It looks like this is how it still works with the current development HEAD as well.


My two cents: I think changing

Code:
if not self.use_change or account == -1:

to

Code:
if not self.use_change:

would be a good fix... as even if the input is from an imported key, if the user has change enabled, it shouldn't matter.



I assume this feature was created with this idea in mind:  "If the user imports a paper wallet into Electrum, then uses Electrum to send, then deletes Electrum... we want to make sure their paper wallet still has the change."


Another way to prevent your issue would be to add a loop that continues to check inputs as long as the inputs are from imported keys... if it finds even one input from a non-imported address, it should assume the user would like to follow the self.use_change option (the option you have set in the preferences)

If you have Electrum installed (using an installer) or are building it from source. Make the change I mentioned in "My two cents"... the line I mention is Line 1142 in the /lib/wallet.py file

My Tip Address:
1DXcHTJS2DJ3xDoxw22wCt11FeAsgfzdBU
dabura667
Sr. Member
****
Offline Offline

Activity: 475
Merit: 252


View Profile
July 26, 2014, 04:26:05 AM
 #7

Thanks for the issue report on Github:

Everyone else follow the issue here:

https://github.com/spesmilo/electrum/issues/769

My Tip Address:
1DXcHTJS2DJ3xDoxw22wCt11FeAsgfzdBU
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!