Merge branch 'master' of github.com:lightningnetwork/lnd into uspvdev
This commit is contained in:
commit
2cbe605221
@ -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
|
||||
// ensure the signatures appear on the Script Virual Machine stack in
|
||||
// the correct order.
|
||||
// TODO(roasbeef): func
|
||||
redeemScript := channelState.FundingRedeemScript
|
||||
ourKey := channelState.OurCommitKey.PubKey().SerializeCompressed()
|
||||
theirKey := channelState.TheirCommitKey.SerializeCompressed()
|
||||
if bytes.Compare(ourKey, theirKey) == -1 {
|
||||
scriptSig, err = spendMultiSig(redeemScript, theirSig, ourSig)
|
||||
} else {
|
||||
scriptSig, err = spendMultiSig(redeemScript, ourSig, theirSig)
|
||||
}
|
||||
|
||||
scriptSig, err = spendMultiSig(redeemScript, ourKey, ourSig, theirKey, theirSig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -595,30 +589,8 @@ func createCommitTx(fundingOutput *wire.TxIn, selfKey, theirKey *btcec.PublicKey
|
||||
commitTx := wire.NewMsgTx()
|
||||
commitTx.Version = 2
|
||||
commitTx.AddTxIn(fundingOutput)
|
||||
// TODO(roasbeef): we default to blocks, make configurable as part of
|
||||
// channel reservation.
|
||||
commitTx.TxIn[0].Sequence = lockTimeToSequence(false, csvTimeout)
|
||||
commitTx.AddTxOut(wire.NewTxOut(int64(amountToSelf), payToUsScriptHash))
|
||||
commitTx.AddTxOut(wire.NewTxOut(int64(amountToThem), payToThemScriptHash))
|
||||
|
||||
return commitTx, nil
|
||||
}
|
||||
|
||||
// lockTimeToSequence converts the passed relative locktime to a sequence
|
||||
// number in accordance to BIP-68.
|
||||
// See: https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki
|
||||
// * (Compatibility)
|
||||
func lockTimeToSequence(isSeconds bool, locktime uint32) uint32 {
|
||||
if !isSeconds {
|
||||
// The locktime is to be expressed in confirmations. Apply the
|
||||
// mask to restrict the number of confirmations to 65,535 or
|
||||
// 1.25 years.
|
||||
return SequenceLockTimeMask & locktime
|
||||
}
|
||||
|
||||
// Set the 22nd bit which indicates the lock time is in seconds, then
|
||||
// shift the locktime over by 9 since the time granularity is in
|
||||
// 512-second intervals (2^9). This results in a max lock-time of
|
||||
// 33,554,431 seconds, or 1.06 years.
|
||||
return SequenceLockTimeSeconds | (locktime >> 9)
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ func fundMultiSigOut(aPub, bPub []byte, amt int64) ([]byte, *wire.TxOut, error)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
pkScript, err := scriptHashPkScript(redeemScript)
|
||||
if err != nil {
|
||||
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
|
||||
// multi-sig output.
|
||||
func spendMultiSig(redeemScript, sigA, sigB []byte) ([]byte, error) {
|
||||
func spendMultiSig(redeemScript, pubA, sigA, pubB, sigB []byte) ([]byte, error) {
|
||||
bldr := txscript.NewScriptBuilder()
|
||||
|
||||
// add a 0 for some multisig fun
|
||||
bldr.AddOp(txscript.OP_0)
|
||||
|
||||
// add sigA
|
||||
bldr.AddData(sigA)
|
||||
// add sigB
|
||||
bldr.AddData(sigB)
|
||||
// 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.
|
||||
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
|
||||
bldr.AddData(redeemScript)
|
||||
@ -204,6 +212,25 @@ func receiverHTLCScript(absoluteTimeout, relativeTimeout uint32, senderKey,
|
||||
return builder.Script()
|
||||
}
|
||||
|
||||
// lockTimeToSequence converts the passed relative locktime to a sequence
|
||||
// number in accordance to BIP-68.
|
||||
// See: https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki
|
||||
// * (Compatibility)
|
||||
func lockTimeToSequence(isSeconds bool, locktime uint32) uint32 {
|
||||
if !isSeconds {
|
||||
// The locktime is to be expressed in confirmations. Apply the
|
||||
// mask to restrict the number of confirmations to 65,535 or
|
||||
// 1.25 years.
|
||||
return SequenceLockTimeMask & locktime
|
||||
}
|
||||
|
||||
// Set the 22nd bit which indicates the lock time is in seconds, then
|
||||
// shift the locktime over by 9 since the time granularity is in
|
||||
// 512-second intervals (2^9). This results in a max lock-time of
|
||||
// 33,554,431 seconds, or 1.06 years.
|
||||
return SequenceLockTimeSeconds | (locktime >> 9)
|
||||
}
|
||||
|
||||
// commitScriptToSelf constructs the public key script for the output on the
|
||||
// commitment transaction paying to the "owner" of said commitment transaction.
|
||||
// If the other party learns of the pre-image to the revocation hash, then they
|
||||
|
@ -1,7 +1,6 @@
|
||||
package lnwallet
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -934,18 +933,12 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
|
||||
|
||||
// Next, create the spending scriptSig, and then verify that the script
|
||||
// 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
|
||||
if bytes.Compare(ourKey.PubKey().SerializeCompressed(), theirKey.SerializeCompressed()) == -1 {
|
||||
scriptSig, err = spendMultiSig(redeemScript, theirCommitSig, ourCommitSig)
|
||||
} else {
|
||||
scriptSig, err = spendMultiSig(redeemScript, ourCommitSig, theirCommitSig)
|
||||
}
|
||||
ourKeySer := ourKey.PubKey().SerializeCompressed()
|
||||
theirKeySer := theirKey.SerializeCompressed()
|
||||
scriptSig, err := spendMultiSig(redeemScript, ourKeySer, ourCommitSig,
|
||||
theirKeySer,
|
||||
theirCommitSig)
|
||||
if err != nil {
|
||||
msg.err <- err
|
||||
return
|
||||
|
@ -573,13 +573,13 @@ func TestLightningWallet(t *testing.T) {
|
||||
// up this node with a chain length of 125, so we have plentyyy of BTC
|
||||
// to play around with.
|
||||
miningNode, err := rpctest.New(netParams, nil, nil)
|
||||
defer miningNode.TearDown()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create mining node: %v", err)
|
||||
}
|
||||
if err := miningNode.SetUp(true, 25); err != nil {
|
||||
t.Fatalf("unable to set up mining node: %v", err)
|
||||
}
|
||||
defer miningNode.TearDown()
|
||||
|
||||
// Funding via 5 outputs with 4BTC each.
|
||||
testDir, lnwallet, err := createTestWallet(miningNode, netParams)
|
||||
|
Loading…
Reference in New Issue
Block a user