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

Default to native segwit change addresses for testnet #837

Closed
wants to merge 3 commits into from

Conversation

murchandamus
Copy link
Contributor

Default to p2wsh change addresses on tbtc/tltc

If the `addressType` is not specified explicitly by the user, we will
default to native segwit (p2wsh) addresses for change outputs on tbtc
and tltc. After a period of testing, we will enable the same for btc and
ltc.

Ticket: BG-23508

@@ -1625,9 +1625,16 @@ export class Wallet {
const self = this;
return co<PrebuildTransactionResult>(function *() {
// Whitelist params to build tx
const whitelistedParams = _.pick(params, self.prebuildWhitelistedParams());
let whitelistedParams = _.pick(params, self.prebuildWhitelistedParams());
Copy link
Contributor

Choose a reason for hiding this comment

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

should the default be set in prebuildWhitelistedParams() perhaps? we leak coin-specific code here that could be avoided

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a good idea, but I think this just returns the property names to take from the params object and can't actually set any defaults. Would be good to not have coin specific code in here, but it would require a bit of refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah yes of course

weird that we made it this far without having a func providing coin-specific defaults here

let's not refactor in this PR imo

Copy link
Contributor

@tylerlevine tylerlevine left a comment

Choose a reason for hiding this comment

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

Concept ack, have a couple ideas for improvements

@@ -1625,9 +1625,16 @@ export class Wallet {
const self = this;
return co<PrebuildTransactionResult>(function *() {
// Whitelist params to build tx
const whitelistedParams = _.pick(params, self.prebuildWhitelistedParams());
let whitelistedParams = _.pick(params, self.prebuildWhitelistedParams());
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a good idea, but I think this just returns the property names to take from the params object and can't actually set any defaults. Would be good to not have coin specific code in here, but it would require a bit of refactoring.

* Indicates whether a coin defaults to native segwit change outputs
* @returns {boolean}
*/
defaultsToP2wshChange() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe call this defaultChangeAddressType() which returns an element of some UtxoAddressType enum? I'm not sure if we already have an enum like that, but if not I'd be fine with defining one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer to only send an addressType parameter in the case that the SDK requests a different format than the general address default. In other cases, I would like to continue to leave it up to platform.

Mark Erhardt added 3 commits August 5, 2020 18:47
If the `addressType` is not specified explicitly by the user, we will
default to native segwit (p2wsh) addresses for change outputs on tbtc
and tltc. After a period of testing, we will enable the same for btc and
ltc.

Ticket: BG-23508
@murchandamus murchandamus force-pushed the BG-23508.defaultToNativeSegwitChange branch from ed0e690 to 64d2a15 Compare August 6, 2020 01:47
Copy link
Contributor Author

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

Maybe call this defaultChangeAddressType() which returns an element of some UtxoAddressType enum? I'm not sure if we already have an enum like that, but if not I'd be fine with defining one.

Renamed to defaultChangeAddressType(). I have not introduced a UtxoAddressType enum, yet. I would tend to use the types already defined in bitgo-utxo-lib to that end, would that be good?

I want to only send an addressType parameter in the case that the SDK requests a different format than the general address default. In other cases, I would like to continue to leave it up to platform, hence I'm not always setting the value defined in defaultChangeAddressType(). This was why I previously went with defaultsToP2wshChange() to make that more explicit. In the long run, I'd hope native segwit (or p2tr) would be the default, but I guess stuff like that always takes longer than expected. What's a good enough approach for a long-term temporary override? ;)

* Indicates whether a coin defaults to native segwit change outputs
* @returns {boolean}
*/
defaultsToP2wshChange() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer to only send an addressType parameter in the case that the SDK requests a different format than the general address default. In other cases, I would like to continue to leave it up to platform.

@OttoAllmendinger
Copy link
Contributor

I would tend to use the types already defined in bitgo-utxo-lib to that end, would that be good?

I don't think so, bitgo-utxo-lib should move towards bitcoinjs-lib not away from it. We already have this enum in @bitgo/unspents though: https://github.com/BitGo/unspents/blob/master/src/codes.ts#L11-L19

@@ -22,4 +22,8 @@ export class Tbtc extends Btc {
getFullName() {
return 'Testnet Bitcoin';
}

defaultChangeAddressType() {
return this.supportsP2wsh() ? `p2wsh` : this.supportsP2shP2wsh() ? `p2shP2wsh` : `p2sh`;
Copy link
Contributor

Choose a reason for hiding this comment

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

return "p2wsh"; would be cleaner here (the commit message suggests that it is equivalent)

@murchandamus
Copy link
Contributor Author

Upon further conferring with Tyler, we are moving the default native segwit change address functionality to platform. We will gate per SDK version there.

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

Successfully merging this pull request may close these issues.

3 participants