[bisq-network/bisq] [WIP] Segwit for the trade protocol (#4612)

chimp1984 notifications at github.com
Thu Oct 22 00:40:49 UTC 2020


@chimp1984 requested changes on this pull request.



> @@ -957,7 +1013,15 @@ public Transaction traderSignAndFinalizeDisputedPayoutTx(byte[] depositTxSeriali
 
         // take care of sorting!
         Script redeemScript = get2of3MultiSigRedeemScript(buyerPubKey, sellerPubKey, arbitratorPubKey);
-        Sha256Hash sigHash = payoutTx.hashForSignature(0, redeemScript, Transaction.SigHash.ALL, false);
+        Sha256Hash sigHash;
+        boolean hashedMultiSigOutputIsSegwit = !ScriptPattern.isP2SH(hashedMultiSigOutput.getScriptPubKey());

Maybe better to use "hashedMultiSigOutputIsLegacy" to avoid the 2x negation. Makes it easier to read...

> @@ -1181,6 +1181,11 @@ private RawTransactionInput getRawInputFromTransactionInput(@NotNull Transaction
                 "input.getConnectedOutput().getParentTransaction() must not be null");
         checkNotNull(input.getValue(), "input.getValue() must not be null");
 
+        // If we would be sure all bisq nodes migrated to bitcoinj 0.15, bitcoinSerialize(true) can be used.
+        // Since there is no way to check migration to bitcoinj 0.15,
+        // Config.SEGWIT_TRADE_PROTOCOL_ACTIVE could be checked instead.
+        // Actually, given the serialized tx is used just as the connected tx of an input,
+        // we don't need the the connected tx's witness data.

duplicate "the the"

>      // VERSION = 0.5.0 -> TRADE_PROTOCOL_VERSION = 1
     // Version 1.2.2 -> TRADE_PROTOCOL_VERSION = 2
-    public static final int TRADE_PROTOCOL_VERSION = 2;
+    // Version 1.4.1 -> TRADE_PROTOCOL_VERSION = 3

We will be on 1.4.2 or more likely 1.5.0

> @@ -1193,10 +1196,6 @@ private RawTransactionInput getRawInputFromTransactionInput(@NotNull Transaction
 
     private byte[] getMakersScriptSigProgram(TransactionInput transactionInput) throws TransactionVerificationException {
         byte[] scriptProgram = transactionInput.getScriptSig().getProgram();
-        if (scriptProgram.length == 0) {
-            throw new TransactionVerificationException("Inputs from maker not signed.");
-        }
-
         return scriptProgram;

Variable is redundant now. Also does not throw exception anymore

> @@ -1286,11 +1286,7 @@ private void signInput(Transaction transaction, TransactionInput input, int inpu
                 input.setScriptSig(ScriptBuilder.createInputScript(txSig, sigKey));
             }
         } else if (ScriptPattern.isP2WPKH(scriptPubKey)) {
-            // TODO: Consider using this alternative way to build the scriptCode (taken from bitcoinj master)
-            // Script scriptCode = ScriptBuilder.createP2PKHOutputScript(sigKey)
-            Script scriptCode = new ScriptBuilder().data(
-                    ScriptBuilder.createOutputScript(LegacyAddress.fromKey(transaction.getParams(), sigKey)).getProgram())
-                    .build();
+            Script scriptCode = ScriptBuilder.createP2PKHOutputScript(sigKey);

Is createP2PKHOutputScript correct? Would expect a segwit method...

>              BtcWalletService btcWalletService = processModel.getBtcWalletService();
+            NetworkParameters params = btcWalletService.getParams();
+            Transaction preparedDepositTx = new Transaction(params, processModel.getPreparedDepositTx());
+            Coin delayedPayoutTxInputValue = preparedDepositTx.getOutput(0).getValue();
+

Why not take the input from preparedDelayedPayoutTx? If that is not possible, I would prefer to pass over the deposit tx to the signDelayedPayoutTx method and do the deail work in the TradeWalletService to keep the transaction domain more isolated there.

> @@ -1181,6 +1181,11 @@ private RawTransactionInput getRawInputFromTransactionInput(@NotNull Transaction
                 "input.getConnectedOutput().getParentTransaction() must not be null");
         checkNotNull(input.getValue(), "input.getValue() must not be null");
 
+        // If we would be sure all bisq nodes migrated to bitcoinj 0.15, bitcoinSerialize(true) can be used.
+        // Since there is no way to check migration to bitcoinj 0.15,
+        // Config.SEGWIT_TRADE_PROTOCOL_ACTIVE could be checked instead.
+        // Actually, given the serialized tx is used just as the connected tx of an input,
+        // we don't need the the connected tx's witness data.

Isn't the input always from the users own wallet (not the peers input)? If so I don't understand the above comment. Then this code is only execute anyway if the user runs the new version and segwit could be used. 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/bisq-network/bisq/pull/4612#pullrequestreview-514264778
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20201021/065deb24/attachment.html>


More information about the bisq-github mailing list