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
|
// 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
|
||||||
}
|
}
|
||||||
@ -595,30 +589,8 @@ func createCommitTx(fundingOutput *wire.TxIn, selfKey, theirKey *btcec.PublicKey
|
|||||||
commitTx := wire.NewMsgTx()
|
commitTx := wire.NewMsgTx()
|
||||||
commitTx.Version = 2
|
commitTx.Version = 2
|
||||||
commitTx.AddTxIn(fundingOutput)
|
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(amountToSelf), payToUsScriptHash))
|
||||||
commitTx.AddTxOut(wire.NewTxOut(int64(amountToThem), payToThemScriptHash))
|
commitTx.AddTxOut(wire.NewTxOut(int64(amountToThem), payToThemScriptHash))
|
||||||
|
|
||||||
return commitTx, nil
|
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 {
|
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)
|
||||||
@ -204,6 +212,25 @@ func receiverHTLCScript(absoluteTimeout, relativeTimeout uint32, senderKey,
|
|||||||
return builder.Script()
|
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
|
// commitScriptToSelf constructs the public key script for the output on the
|
||||||
// commitment transaction paying to the "owner" of said commitment transaction.
|
// 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
|
// If the other party learns of the pre-image to the revocation hash, then they
|
||||||
|
@ -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
|
||||||
|
@ -573,13 +573,13 @@ func TestLightningWallet(t *testing.T) {
|
|||||||
// up this node with a chain length of 125, so we have plentyyy of BTC
|
// up this node with a chain length of 125, so we have plentyyy of BTC
|
||||||
// to play around with.
|
// to play around with.
|
||||||
miningNode, err := rpctest.New(netParams, nil, nil)
|
miningNode, err := rpctest.New(netParams, nil, nil)
|
||||||
|
defer miningNode.TearDown()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create mining node: %v", err)
|
t.Fatalf("unable to create mining node: %v", err)
|
||||||
}
|
}
|
||||||
if err := miningNode.SetUp(true, 25); err != nil {
|
if err := miningNode.SetUp(true, 25); err != nil {
|
||||||
t.Fatalf("unable to set up mining node: %v", err)
|
t.Fatalf("unable to set up mining node: %v", err)
|
||||||
}
|
}
|
||||||
defer miningNode.TearDown()
|
|
||||||
|
|
||||||
// Funding via 5 outputs with 4BTC each.
|
// Funding via 5 outputs with 4BTC each.
|
||||||
testDir, lnwallet, err := createTestWallet(miningNode, netParams)
|
testDir, lnwallet, err := createTestWallet(miningNode, netParams)
|
||||||
|
Loading…
Reference in New Issue
Block a user