Pages:
Author

Topic: P2SH-P2WPKH (Segwit) change addresses in Bitcoin Core - how? (Read 3772 times)

staff
Activity: 3458
Merit: 6793
Just writing some code
Thanks a lot, will check this... any idea when 0.16.0 could be likely released?
0.16.0 will be released soon after PR #11403 is merged. When that will actually be, we don't know and cannot give a date.
hero member
Activity: 692
Merit: 569
Just wondering if there is native segwit change address support currently in Core (through any configuration). I can compile the source off master.

Have you tried compiling with the following, and then using -addresstype p2sh?: https://github.com/bitcoin/bitcoin/pull/11403

juscamarena said he's tested it on testnet, and with small amounts on mainnet, so maybe talk with him?: https://github.com/bitcoin/bitcoin/pull/11403#issuecomment-353809911

There are still some items to go before the 0.16.0 milestone, but it wouldn't hurt to test it out and report back.

Thanks a lot, will check this... any idea when 0.16.0 could be likely released?
legendary
Activity: 1762
Merit: 1011
Just wondering if there is native segwit change address support currently in Core (through any configuration). I can compile the source off master.

Have you tried compiling with the following, and then using -addresstype p2sh?: https://github.com/bitcoin/bitcoin/pull/11403

juscamarena said he's tested it on testnet, and with small amounts on mainnet, so maybe talk with him?: https://github.com/bitcoin/bitcoin/pull/11403#issuecomment-353809911

There are still some items to go before the 0.16.0 milestone, but it wouldn't hurt to test it out and report back.
hero member
Activity: 692
Merit: 569
Hi,

Just wondering if there is native segwit change address support currently in Core (through any configuration). I can compile the source off master. Please let me know , Tagging @achow

Thanks all
legendary
Activity: 1221
Merit: 1025
e-ducat.fr
P2SH-P2WPKH addresses are meant to allow users to create segwit utxos with their (BIP16-enabled) current wallet.
We should all aim for native (Bech32) P2WPKH addresses.
Only electrum 3.0 currently supports those.
I understand that the feature will be merged soon on Bitcoin Core.
jr. member
Activity: 45
Merit: 1
Hi,

I am running a service that accepts user deposits and sends withdrawals. I am using Bitcoin Core for the wallet.

I'd like to go full-Segwit with my service, but here's the problem: bitcoind wallet does not generate P2SH-P2WPKH (Segwit) change addresses by default. So even if I generate P2SH-P2WPKH addresses to accept deposits from my users via addwitnessaddress, whenever I send coins, the change is going to a P2PKH address.

I could manually create a P2SH-P2WPKH change address by (in pseudocode):

Code:
tx = createrawtransaction([], amounts)
chaddr = getrawchangeaddress()
chaddr = addwitnessaddress(chaddr) # this creates a P2SH-P2WPKH address from the P2PKH change address
# now fund the transaction
tx = fundrawtransaction(tx, changeAddress: chaddr)['hex']
tx = signrawtransaction(tx)['hex']
sendrawtransaction(tx)

No the thing is that addwitnessaddress(chaddr) breaks things a little since the resulting address is added to account addresses, and is NOT marked as a change address. Therefore it is used as a regular account address and generates send/receive transactions. It looks like it does not break anything except creating additional transactions returned by listtransactions and inaccurate "amount" fields.

So, a solution I'd really love to see is:

1. make the wallet generate segwit change addresses by itself so that we can just use sendtoaddress and other RPC calls without workarounds (maybe an option in config?),
2. somehow make the address resulting from addwitnessaddress(chaddr) as a change address,
3. or allow getrawchangeaddress to generate P2SH-P2WPH address in the first place.

Obviously (1) would be much better, but at this point I am looking for any solution that would "just work" and not break my workflow.

Cheers and thanks,
Ethan

Thanks for this code Ethan. Have you managed to do this with sendmany as well?

And something else. When you pay, the change is coming back to a Legacy Address (1...). What if you add with addwitnessaddress a SegWit address to this new Legacy change address? Will the balance on the newly created segwit address be the same as the Legacy change address? If yes, when paying again from wallet, will the wallet use the Legacy change address or the segwit address as input? Are there any risks with creating a segwit address for a legacy address that has a balance on it?
sr. member
Activity: 770
Merit: 305
I'm also waiting for support of different address types as change address
what about data-carrier (OP_RETURN) address type for a change?  Grin
full member
Activity: 209
Merit: 100
Radix-The Decentralized Finance Protocol
Hi Ethan,
Thanks for sharing this.  Would you suggest others follow in your footsteps or would you suggest waiting until core has the minor update that includes segwit change addresses?
I.e. is there any obvious risk to implementing it the way you've done?


I wont suggest to do such changes if you don't fully understand what you're doing.
I'm also waiting for support of different address types as change address ( prefered configurable and don't care much what the default is ).
s2
full member
Activity: 198
Merit: 123
Hi Ethan,
Thanks for sharing this.  Would you suggest others follow in your footsteps or would you suggest waiting until core has the minor update that includes segwit change addresses?
I.e. is there any obvious risk to implementing it the way you've done?
staff
Activity: 3458
Merit: 6793
Just writing some code
achow, do you have any idea on the timeline of this minor release? If it will take more than two months, I might as well use Ethan's solution (want to urgently reduce tx fee right)
There is no ETA for the minor release.
hero member
Activity: 692
Merit: 569
Hi Ethan,

can you give some links to these discussions?
 I would like to read/join Smiley
A lot of it happens in the #bitcoin-core-dev channel on IRC, usually during the weekly dev meetings (every Thursday at 19:00 UTC).

Are you sure about this? I've heard comments that this is not by default on 0.15
You still have to use the cli
That is correct. That's why I said "after 0.15.0" and "It will likely be a minor release" (hint: 0.15.0 is not a minor release).

achow, do you have any idea on the timeline of this minor release? If it will take more than two months, I might as well use Ethan's solution (want to urgently reduce tx fee right)
sr. member
Activity: 745
Merit: 471
Admin at YOLOdice.com - fast, fair, play/invest.
I have just enabled full Segwit support in YOLOdice. I am using the code from my first post to generate segwit change addresses and it seems to work fine. The only thing I added was a global lock so that no two processes create a withdrawal - this is to avoid race condition while using fundrawtransaction.

As I said earlier, this method has one disadvantage - it creates extra entries returned by "listtransactions" and an extra entry for "gettransaction" details because the change output is treated as a 1st class transfer now.

Anyway, it works find for me. My rationale to get early on the segwit bandwagon is mostly to reduce fees.

Cheers,
Ethan
hero member
Activity: 692
Merit: 569
Even I am looking forward to this. I thought segwit support in core meant this was already working.

It would make sense to enable it as config option.
changeAddressType = P2PKH,P2SH-P2PK,P2SH-P2WPKH
So users can choose what type of change address they want.

This makes sense , default can be P2SH-P2WPKH
full member
Activity: 209
Merit: 100
Radix-The Decentralized Finance Protocol
It would make sense to enable it as config option.
changeAddressType = P2PKH,P2SH-P2PK,P2SH-P2WPKH
So users can choose what type of change address they want.
staff
Activity: 3458
Merit: 6793
Just writing some code
can you give some links to these discussions?
 I would like to read/join Smiley
A lot of it happens in the #bitcoin-core-dev channel on IRC, usually during the weekly dev meetings (every Thursday at 19:00 UTC).

Are you sure about this? I've heard comments that this is not by default on 0.15
You still have to use the cli
That is correct. That's why I said "after 0.15.0" and "It will likely be a minor release" (hint: 0.15.0 is not a minor release).
hero member
Activity: 544
Merit: 507
1. make the wallet generate segwit change addresses by itself so that we can just use sendtoaddress and other RPC calls without workarounds (maybe an option in config?),
This is being worked on for the next version of Core (after 0.15.0). It will likely be a minor release.
Are you sure about this? I've heard comments that this is not by default on 0.15
You still have to use the cli
legendary
Activity: 954
Merit: 1003
any announces from Core?
No, not yet. This type of stuff isn't announced ahead of time, it just happens and goes into a release which is then announced. However we are actively discussing this in Github PRs and issues related to adding additional segwit wallet functionality and on IRC.

can you give some links to these discussions?
 I would like to read/join Smiley
staff
Activity: 3458
Merit: 6793
Just writing some code
any announces from Core?
No, not yet. This type of stuff isn't announced ahead of time, it just happens and goes into a release which is then announced. However we are actively discussing this in Github PRs and issues related to adding additional segwit wallet functionality and on IRC.
legendary
Activity: 954
Merit: 1003
1. make the wallet generate segwit change addresses by itself so that we can just use sendtoaddress and other RPC calls without workarounds (maybe an option in config?),
This is being worked on for the next version of Core (after 0.15.0). It will likely be a minor release.

any announces from Core?

of course, we can manually create raw transactions, but it's not a good solution
staff
Activity: 3458
Merit: 6793
Just writing some code
1. make the wallet generate segwit change addresses by itself so that we can just use sendtoaddress and other RPC calls without workarounds (maybe an option in config?),
This is being worked on for the next version of Core (after 0.15.0). It will likely be a minor release.
Pages:
Jump to: