-
Notifications
You must be signed in to change notification settings - Fork 10
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
Segwit support plan #226
Comments
@oscarguindzberg May I throw in a few considerations/ideas/remarks? Regarding hardfork:I think we should only consider a hardfork if we are sure that there is no feasible alternative. A hardfork would require that existing offers are removed and created newly which is a usability penalty and causes loss of maker fee and tx fee. The lost maker fee could be reimbursed but that causes quite a bit of administrative overhead and again is a usability penalty. If users update when they have an open trade it would lead to failed trades. With the trade protocol v2 hard fork we have learned that telling people to not update in such cases is not sufficient as most do not read warnings....It was quite a support mess as a result to deal with all those failed trades. I would like to sketch out quickly the option for a non-hard fork solution: A user who has updated will create new offers with a BECH 32 address. Such offers get an extra data field to mark them and a taker who requests to take the offer has to send a flag to signal that he has segwit support, otherwise he will get a reject message from the maker. If we roll out early enough the flag in the offer, we can detect that also in the offerbook so an not-updated user sees such offers as deactivated (with a popup to tell the user to update), avoiding wait time for the response of the maker. Only users who have not updated for longer time would get the reject message. We have even the version number as part of the offer ID so we could even use that to detect if the offer was created after segwit activation.... Once most users have updated, most offers will be segwit enabled and thus there is more pressure on not-updated users. Additionally we could support an offer-renewal method to make it easier for users to switch their existing offers to segwit. The maker fee and tx fee would still be lost, but I assume some users would at least not care too much for smaller offers (fiat). As said we can support the transition with early shipping of options which will help us at segwit activation time. Tools for dealing with backward compatibility:We have several "tools" to deal with backward compatibility and its a quite complex field. I will list here a few I remember but there might be more...
Alternatives/BitcoinJ futureI have not followed BitcoinJ but a year back it seemed its a "dead horse" and we should be careful to invest too much to stick with it. The past investigations for alternatives ended negative but I think it might be useful to make an update for that investigation for alternatives. Also as Bitcoin Core has deactivated Bloom filters by default we are even more locked up with our federated Bitcoin Core nodes which makes the whole wallet infrastructure much more a "federated server model" as it was intended initially. I am wondering if a federated Electrum server model would be a feasible alternative? But I am aware that this is another huge multi-month project. So nothing we should take lightly and we have to consider the benefits/costs specially with out budget constraints now. How difficult and risky it would be to migrate the BSQ wallet would be another hard challenge. |
To add to what @chimp1984 said about handling backwards compatibility and migration under "Tools for dealing with backward compatibility", BitcoinJ 0.15.7 got service bit filtering for DnsDiscovery [0], (which is capabilities filtering you mentioned) letting you not connect to incompatible peers for example. Further, we can already check each peer's service bit and version in Bisq; it's only a matter of wiring that information through to where we need it. We can even disconnect a peer if we don't like its service bit (simulating the mentioned new feature in 0.15.7), but it's not as neat as doing it on DnsDiscovery's level. Even now BitcoinJ is still limited in how well it can discriminate peers (service bit filtering is not version filtering for example). We can expand BitcoinJ's facilities for our migration plans (and general robustness) if needed. I think that will often be preferable to doing something elaborate Bisq-side (like implementing parts of Bitcoin handshake on top of trade messages). |
Thanks for the info. But the capabilities I referred to is our own P2P network based capability feature. |
i´ll ask out of sheer ignorance, coulndt bisq just use the bitcoin daemon in localhost, if avaliable? |
@ricardosaurio |
@chimp1984 how about opt-in for users who do run such a full node with bloom filters activated? I am actually running such a setup in the same machine as my Bisq app. I dont know nothing about coding, im just spitballing. And I know running a full node is not what grandma would do. |
If you have a local full node Bisq is using it anyway (via BitcoinJ and bloom filters). I was thinking that you refer to use Bitcoin Core as replacement for BitcoinJ. |
yes i meant that, bitcoin core as replacement for BitcoinJ... I can see how it wouldnt help if someone without a node is sending from legacy to native segwit from bitcoinj, so that would be a problem. |
Closed as approved. |
@oscarguindzberg since this proposal was approved, many users are asking about the implementation timeline. i understand all the budget concerns have been addressed. do you have any ETA on when you can begin working on this project? |
@oscarguindzberg Offers: Open trades when one user has updated and the other not: Trade between not updated and updated users: The trade messages at creating the multisig need a new flag for indicating segwit support. If the flag on at user is missing P2SH multisig is used. Only if both users have updated they can use P2WSH. I am aware that handling both might be a bit more dev effort but if we dont support that we would run into lot of backward compatibility issues. Specially open trades cannot be handled by a hard fork (see comments above). For BSQ I do not see any issue as BTC inputs can be either segwit or legacy. By default segwit should be used. BTC change address would also be by default segwit (I think no option for user to change that is required). PS: Instead using flags for indicating segwit support we could also add a capability. But not sure if the capability is exchanged between the peers before the trade protocol starts. Probably more safe to add a flag. |
I had a call with @oscarguindzberg and we agreed that a enforced update (hardfork) is feasible and the intended strategy. If we find during development that support for a non-hardfork is feasible we might change that. |
I think making a hard fork is the better option. The issues we had going to the new trade protocol were quite broad and costly, both from a user experience perspective and definitely from a developer/support perspective. |
Summary
This is a plan to add segwit support to bisq. Bisq's custom bitcoinj has to be rebased on top of bitcoinj 0.15, bisq has to be adapted to use bitcoinj 0.15 and bisq has to use the segwit features present in bitcoinj 0.15. There are a couple of different places where segwit could be used in bisq, they are described as “phases” below. Migrating existing bisq users and data to segwit is one of the major challenges. Using segwit for BSQ txs is out of scope and could be subject to a future proposal.
Once a phase is implemented, it could be released to users and does not require the next phases to be implemented. I would recommend including phase 1 (and optionally phase 2) in one user release and phase 3 in another user release.
Goals
Context
Past work
Segwit BIPs
Related bisq open proposals
Done
Phases
Phase 1: Migrate to bitcoinj 0.15.8
Phase 2: Allow users to extract to native segwit addresses
org.bitcoinj.core.LegacyAddress.fromBase58()
and replace it withorg.bitcoinj.core.Address.fromString()
(which supports both legacy and native segwit addresses). Do it only when it makes sense (eg for btc addresses but not for bsq addresses)bisq.asset.coins.Bitcoin
should stop usingBase58BitcoinAddressValidator
that is based onLegacyAddress.fromBase58()
and use another validator that checksAddress.fromString()
. Keep in mindBase58BitcoinAddressValidator
is also used for many altcoins that don’t have segwit support.bisq.core.util.validation.BtcAddressValidator
.Phase 3: Segwit for bisq btc wallet and the Trade protocol
Segwit for bisq btc wallet
Wallet
has aKeyChainGroup
that has a list ofKeyChain
instances)org.bitcoinj.core.Address
andorg.bitcoinj.core.LegacyAddress
. Those are possible places where code needs to be adapted.WalletConfig
, thepreferredOutputScriptType
variable is currently set to P2PKH. Set to it to P2WPKH for the bisq btc wallet (make sure to keep P2PKH for the bsq wallet).Wallet
class provides a key/address from the active keychain. Once segwit is implemented, the active keychain for the btc wallet is native segwit. Bisq code that gets key/addresses from the btc wallet should be reviewed. If a legacy address is required, it should be obtained via one of theWallet
methods that accept aScriptType
parameter e.g.Wallet.freshReceiveAddress(Script.ScriptType.P2PKH)
. Maybe more methods for obtaining key/addresses with a Script.ScriptType parameter should need to be added to theWallet
class.Wallet.freshReceiveAddress(ScriptType)
or a newly created method that accepts aScriptType
.BisqKeyChainGroupStructure
andBisqKeyChainFactory
).Segwit for the Trade protocol
org.bitcoinj.core.Address
andorg.bitcoinj.core.LegacyAddress
. Those are possible places where code needs to be adapted. Also, code that signs transactions probably needs to be adapted.AddressEntry
boolean segwit
should be added to mark addresses as segwit or legacy.getAddress()
return type should remain asAddress
, but the actual instance returned should be either aSegwitAddress
orLegacyAddress
depending on the boolean value.pb.proto
.AddressEntry
records in the bisq db created before the bisq segwit upgrade have thesegwit
boolean flag set to false. Maybefalse
is the default value for a new attribute and no migration is required. If that is not the case, it should set tofalse
during migration.CreateMakerFeeTx
fundingAddress
,reservedForTradeAddress
andchangeAddress
make them a SegwitAddress.fundingAddress
,reservedForTradeAddress
andchangeAddress
make them a SegwitAddress.TakerSendInputsForDepositTxRequest
SellerAsMakerCreatesUnsignedDepositTx
BuyerAsMakerCreatesAndSignsDepositTx
DelayedPayoutTxValidation
BuyerSetupDepositTxListener
SetupPayoutTxListener
TradeWalletService
,WalletService
andBtcWalletService
have to be reviewed in detail and will require fixes in many places. I list some examples below.TradeWalletService
get2of2MultiSigRedeemScript()
andget2of2MultiSigOutputScript()
signInput()
createBtcTradingFeeTx()
sellerSignsAndFinalizesPayoutTx()
makerCreatesDepositTx()
WalletService
signTransactionInput()
BtcWalletService
getOrCreateAddressEntry()
andgetFreshAddressEntry()
AddressEntry
should mostly use segwit addresses unless a legacy address is needed.ScriptType
should be added.Wallet.freshReceiveKey()
usage should be replaced by a method that accepts aScriptType
.AddressEntry.segwit
boolean flag should be set depending on the script type.BsqWalletService
RawTransactionInput
.Phase 4: Use a segwit native address as the recipient of BTC trade fees
bisq.core.dao.governance.param.Param.RECIPIENT_BTC_ADDRESS
value should be changed the new address.DelayedPayoutTxValidation
and should be changed there too.Dictionary
bc1
.1
, and multisig over script hash addresses (P2SH) start with3
.Notes
The text was updated successfully, but these errors were encountered: