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 changes for Segwit BSQ implementation #5109

Merged

Conversation

stejbac
Copy link
Contributor

@stejbac stejbac commented Jan 23, 2021

This is a continuation from #5000, which replaces Bisq's Json RPC client to allow Segwit data ("txinwitness" fields) to be retrieved by DAO full nodes, in order to fill in the pubkeys of BSQ tx Segwit inputs (as necessary to support fully Segwit compensation and proof-of-burn txs).

This PR makes the necessary changes to the user's wallet and address formatting + validation to support Segwit BSQ, migrating the wallet upon startup in an analogous way to the Segwit BTC wallet upgrade (#4568). With these changes, newly generated BSQ addresses are native Segwit (p2wpkh) and take the form 'B' + <bech32-address>, e.g.

Bbc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq (mainnet)
Bbcrt1qj4t04q4mpssfv9uzpm6w2n8rlhs7es47ktqx8x (regtest)

They should be valid everywhere the old base58 (p2pkh) BSQ addresses are, which continue to be supported (just never selected as new change or recipient addresses).

--

Note that this PR probably shouldn't be merged into master until the technical hard fork introduced by #5000 activates on mainnet, as otherwise upgraded users will have difficultly generating valid compensation requests or proof-of-burn txs. This is because native Segwit BSQ coins from their wallet may be arbitrarily selected as tx inputs.

@boring-cyborg boring-cyborg bot added in:altcoins is:no-priority PR or issue marked with this label is not up for compensation right now labels Jan 23, 2021
chimp1984
chimp1984 previously approved these changes Jan 28, 2021
Copy link
Contributor

@chimp1984 chimp1984 left a comment

Choose a reason for hiding this comment

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

utACK

Looks all good to me.

The Base58AddressValidator is still used in MockTestnetCoin. I think that can be replaced with BitcoinAddressValidator now.

Copy link
Contributor

@chimp1984 chimp1984 left a comment

Choose a reason for hiding this comment

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

utACK

@chimp1984
Copy link
Contributor

Maybe it would be more safe to convert the 2 segwit PRs to draft until we are ready for merging it? (on the right side GH added a feature recently to convert a PR to draft)

@stejbac stejbac marked this pull request as draft January 30, 2021 22:14
@cd2357 cd2357 added in:dao in:trade-process and removed in:altcoins is:no-priority PR or issue marked with this label is not up for compensation right now labels Mar 1, 2021
@chimp1984
Copy link
Contributor

@stejbac Is that PR ready for the upcomig release?

@chimp1984
Copy link
Contributor

I just checked the ACTIVATE_HARD_FORK_2_HEIGHT_MAINNET is at block 680300 which was 3 days ago (2021-04-23 11:33).
https://mempool.space/block/00000000000000000009267fac0111c0e2feef71d001229e11e88c0c77e4d9a3

Proposal phase ends May 12th, so if we release soon we do not risk to fall into the voting period which carries a bit more risk.
DAO partizipants (proposal, voting) should update before posting proposal and doing voting, so reduce risks as well.

@stejbac
Copy link
Contributor Author

stejbac commented Apr 27, 2021

I just tried merging with master and there are some slightly nontrivial conflicts in CoreWalletsService and a few other places. As the draft changes haven't been touched for a while, I'll try rebasing onto master as it stood a few weeks ago, which should address all the conflicts I saw. (That way it will be easier to cherry pick into the 1.6.3 release if there's time.)

@ripcurlx
Copy link
Contributor

I just tried merging with master and there are some slightly nontrivial conflicts in CoreWalletsService and a few other places. As the draft changes haven't been touched for a while, I'll try rebasing onto master as it stood a few weeks ago, which should address all the conflicts I saw. (That way it will be easier to cherry pick into the 1.6.3 release if there's time.)

Hi Steven! Just let me know when it is ready to be merged and tested. Please point the PR directly to the v1.6.3 release branch so we can test it there a bit before it is merged into master. Thanks!

stejbac added 3 commits April 27, 2021 10:39
Use flatMap(Optional::stream) instead of filter(..isPresent).map(..get)
and avoid a redundantly nested Optional in OpReturnType.

Also replace some unnecessary stream().forEach(..) invocations on lists
in BtcWalletService, as forEach is already part of the List interface.
Remove the restriction to base58 (P2SH & P2PKH) addresses when parsing,
formatting & validating BSQ addresses, by replacing o.b.c.LegacyAddress
with its superclass o.b.c.Address throughout. Also remove restriction to
LegacyAddress in BsqTxListItem and BsqTransfer(Service|Model).

The bech32 BSQ addresses follow the same format as the old base58 BSQ
addresses, namely 'B' + <btc-address>.
Uncomment & enable the m/44'/142'/1' native segwit BSQ account path and
add code to migrate the user's BSQ wallet to segwit upon startup, along
the same lines as the existing BTC wallet segwit migration logic. That
is, set P2WPKH as the default output type, add a native segwit key chain
(set to active) to the BSQ wallet and back up the old 'bisq_BSQ.wallet'
file to 'pre_segwit_bisq_BSQ.wallet.backup'.

Also filter out legacy addresses coming from the original keychain from
BsqWalletService.get(Unused|Change)Address.
@stejbac stejbac force-pushed the implement-segwit-for-bsq-wallet branch from cf9d162 to c8e847c Compare April 27, 2021 10:40
@boring-cyborg boring-cyborg bot added in:altcoins is:no-priority PR or issue marked with this label is not up for compensation right now labels Apr 27, 2021
@stejbac
Copy link
Contributor Author

stejbac commented Apr 27, 2021

I've rebased onto de8213a (2021/04/20 - shared by master and release/1.6.3).

Move consecutive maybeAddSegwitKeychain(..) calls for the BTC & BSQ
wallets from BisqSetup to WalletsManager, as the latter class is used
for operations which should be applied to both wallets and this moves
the logic closer to the wallet domain.

Also migrate a BSQ address validator in one of the test mock classes
from Base58AddressValidator to BitcoinAddressValidator (missed earlier).
@stejbac stejbac force-pushed the implement-segwit-for-bsq-wallet branch from c8e847c to 9760526 Compare April 27, 2021 10:46
@stejbac
Copy link
Contributor Author

stejbac commented Apr 27, 2021

(Amended the last commit of the rebase to remove a missed unused constructor parameter from CoreWalletsService.)

@stejbac stejbac marked this pull request as ready for review April 27, 2021 10:56
@stejbac stejbac changed the base branch from master to release/v1.6.3 April 27, 2021 10:57
@ghubstan
Copy link
Contributor

Some important changes in CoreWalletsService will be lost if this PR is successfully merged.

I cannot attend to the details until later today, but I the current master's CoreWalletsService should be included in this PR if possible (with the additional changes you require).

@stejbac
Copy link
Contributor Author

stejbac commented Apr 27, 2021

It appears the only difference between CoreWalletService on current master and the de8213a version I rebased off is a few lines calling feeService.getMinFeePerVByte(), in place of the hard coded fee BTC_DAO_REGTEST.getDefaultMinFeePerVbyte(). But I don't think those lines conflict (textually or otherwise) with the changes from this PR, so they shouldn't be inadvertently reverted as a result of merging this PR.

@ghubstan
Copy link
Contributor

ghubstan commented Apr 27, 2021

It appears the only difference between CoreWalletService on current master and the de8213a version I rebased off is a few lines calling feeService.getMinFeePerVByte(), in place of the hard coded fee BTC_DAO_REGTEST.getDefaultMinFeePerVbyte(). But I don't think those lines conflict (textually or otherwise) with the changes from this PR, so they shouldn't be inadvertently reverted as a result of merging this PR.

That CoreWalletService diff is related to other changes in grpc.proto , TxFeeRateInfo (a proto wrapper), etc. If you can successfully merge, I think I can easily re-add those changes. I am concerned about other recent api changes to master being overwritten; I can review after a successful merging of this PR. [EDIT This is a false alarm, grpc.proto , TxFeeRateInfo
should be unchanged after the merge.]

@chimp1984
Copy link
Contributor

chimp1984 commented Apr 27, 2021

I had locally merged yesterday and my branch matches exactly the rebased one. But would be good if @ghubstan can double check the changes in CoreWalletService.

The walletsManager.maybeAddSegwitKeychains(aesKey); is used instead only applying it on the btc keychain.

@ghubstan
Copy link
Contributor

But would be good if @ghubstan can double check the changes in CoreWalletService.

Looks OK. (I just checked the diff between this PR's CoreWalletService and current master's. )

Copy link
Contributor

@ripcurlx ripcurlx left a comment

Choose a reason for hiding this comment

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

utACK based on reviews from @chimp1984. I'll test it as part of release testing for v1.6.3.

@ripcurlx ripcurlx merged commit c615d5d into bisq-network:release/v1.6.3 Apr 27, 2021
@ripcurlx ripcurlx added this to the v1.6.3 milestone Apr 29, 2021
stejbac added a commit to stejbac/bisq that referenced this pull request Mar 11, 2023
Add the new account path "44'/142'/1'" for segwit BSQ to the wallet info
view, which was missed from PR bisq-network#5109 making the wallet & UI changes to
implement segwit BSQ. Also format the paths from the constants defined
in 'BisqKeyChainGroupStructure', instead of using string literals, so
that they are only defined in one place. (Though it is extremely
unlikely the paths would ever change.)
helixx87 pushed a commit to helixx87/bisq that referenced this pull request May 6, 2023
Add the new account path "44'/142'/1'" for segwit BSQ to the wallet info
view, which was missed from PR bisq-network#5109 making the wallet & UI changes to
implement segwit BSQ. Also format the paths from the constants defined
in 'BisqKeyChainGroupStructure', instead of using string literals, so
that they are only defined in one place. (Though it is extremely
unlikely the paths would ever change.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in:altcoins in:dao in:trade-process is:no-priority PR or issue marked with this label is not up for compensation right now
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants