lnwallet: move pubKey comparison for funding output spend into spendMultiSig func
* This change makes the spendMultiSig function testable independent of the reservation workflow.
This commit is contained in:
parent
4632894562
commit
fa05ee9a22
@ -189,16 +189,10 @@ func (c *ChannelUpdate) VerifyNewCommitmentSigs(ourSig, theirSig []byte) error {
|
|||||||
// public keys in descending order. So we do a quick comparison in order
|
// public keys in descending order. So we do a quick comparison in order
|
||||||
// ensure the signatures appear on the Script Virual Machine stack in
|
// ensure the signatures appear on the Script Virual Machine stack in
|
||||||
// the correct order.
|
// the correct order.
|
||||||
// TODO(roasbeef): func
|
|
||||||
redeemScript := channelState.FundingRedeemScript
|
redeemScript := channelState.FundingRedeemScript
|
||||||
ourKey := channelState.OurCommitKey.PubKey().SerializeCompressed()
|
ourKey := channelState.OurCommitKey.PubKey().SerializeCompressed()
|
||||||
theirKey := channelState.TheirCommitKey.SerializeCompressed()
|
theirKey := channelState.TheirCommitKey.SerializeCompressed()
|
||||||
if bytes.Compare(ourKey, theirKey) == -1 {
|
scriptSig, err = spendMultiSig(redeemScript, ourKey, ourSig, theirKey, theirSig)
|
||||||
scriptSig, err = spendMultiSig(redeemScript, theirSig, ourSig)
|
|
||||||
} else {
|
|
||||||
scriptSig, err = spendMultiSig(redeemScript, ourSig, theirSig)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ func fundMultiSigOut(aPub, bPub []byte, amt int64) ([]byte, *wire.TxOut, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pkScript, err := scriptHashPkScript(redeemScript)
|
pkScript, err := scriptHashPkScript(redeemScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -77,16 +78,23 @@ func fundMultiSigOut(aPub, bPub []byte, amt int64) ([]byte, *wire.TxOut, error)
|
|||||||
|
|
||||||
// spendMultiSig generates the scriptSig required to redeem the 2-of-2 p2sh
|
// spendMultiSig generates the scriptSig required to redeem the 2-of-2 p2sh
|
||||||
// multi-sig output.
|
// multi-sig output.
|
||||||
func spendMultiSig(redeemScript, sigA, sigB []byte) ([]byte, error) {
|
func spendMultiSig(redeemScript, pubA, sigA, pubB, sigB []byte) ([]byte, error) {
|
||||||
bldr := txscript.NewScriptBuilder()
|
bldr := txscript.NewScriptBuilder()
|
||||||
|
|
||||||
// add a 0 for some multisig fun
|
// add a 0 for some multisig fun
|
||||||
bldr.AddOp(txscript.OP_0)
|
bldr.AddOp(txscript.OP_0)
|
||||||
|
|
||||||
// add sigA
|
// When initially generating the redeemScript, we sorted the serialized
|
||||||
bldr.AddData(sigA)
|
// public keys in descending order. So we do a quick comparison in order
|
||||||
// add sigB
|
// ensure the signatures appear on the Script Virual Machine stack in
|
||||||
bldr.AddData(sigB)
|
// the correct order.
|
||||||
|
if bytes.Compare(pubA, pubB) == -1 {
|
||||||
|
bldr.AddData(sigB)
|
||||||
|
bldr.AddData(sigA)
|
||||||
|
} else {
|
||||||
|
bldr.AddData(sigA)
|
||||||
|
bldr.AddData(sigB)
|
||||||
|
}
|
||||||
|
|
||||||
// preimage goes on AT THE ENDDDD
|
// preimage goes on AT THE ENDDDD
|
||||||
bldr.AddData(redeemScript)
|
bldr.AddData(redeemScript)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package lnwallet
|
package lnwallet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -934,18 +933,12 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
|
|||||||
|
|
||||||
// Next, create the spending scriptSig, and then verify that the script
|
// Next, create the spending scriptSig, and then verify that the script
|
||||||
// is complete, allowing us to spend from the funding transaction.
|
// is complete, allowing us to spend from the funding transaction.
|
||||||
//
|
|
||||||
// When initially generating the redeemScript, we sorted the serialized
|
|
||||||
// public keys in descending order. So we do a quick comparison in order
|
|
||||||
// ensure the signatures appear on the Script Virual Machine stack in
|
|
||||||
// the correct order.
|
|
||||||
var scriptSig []byte
|
|
||||||
theirCommitSig := msg.theirCommitmentSig
|
theirCommitSig := msg.theirCommitmentSig
|
||||||
if bytes.Compare(ourKey.PubKey().SerializeCompressed(), theirKey.SerializeCompressed()) == -1 {
|
ourKeySer := ourKey.PubKey().SerializeCompressed()
|
||||||
scriptSig, err = spendMultiSig(redeemScript, theirCommitSig, ourCommitSig)
|
theirKeySer := theirKey.SerializeCompressed()
|
||||||
} else {
|
scriptSig, err := spendMultiSig(redeemScript, ourKeySer, ourCommitSig,
|
||||||
scriptSig, err = spendMultiSig(redeemScript, ourCommitSig, theirCommitSig)
|
theirKeySer,
|
||||||
}
|
theirCommitSig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg.err <- err
|
msg.err <- err
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user