lnwire: directly embed the wire.OutPoint in all commitment update msgs
This commit is contained in:
parent
5330513c7b
commit
ccbbcf389b
@ -19,7 +19,7 @@ import (
|
||||
// inputs/outputs.
|
||||
type CloseComplete struct {
|
||||
// ChannelPoint serves to identify which channel is to be closed.
|
||||
ChannelPoint *wire.OutPoint
|
||||
ChannelPoint wire.OutPoint
|
||||
|
||||
// ResponderCloseSig is the signature of the responder for the
|
||||
// transaction which closes the previously active channel.
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
|
||||
func TestCloseCompleteEncodeDecode(t *testing.T) {
|
||||
cc := &CloseComplete{
|
||||
ChannelPoint: outpoint1,
|
||||
ChannelPoint: *outpoint1,
|
||||
ResponderCloseSig: commitSig,
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
// know the order of the inputs/outputs.
|
||||
type CloseRequest struct {
|
||||
// ChannelPoint serves to identify which channel is to be closed.
|
||||
ChannelPoint *wire.OutPoint
|
||||
ChannelPoint wire.OutPoint
|
||||
|
||||
// RequesterCloseSig is the signature of the requester for the fully
|
||||
// assembled closing transaction.
|
||||
@ -36,7 +36,7 @@ type CloseRequest struct {
|
||||
}
|
||||
|
||||
// NewCloseRequest creates a new CloseRequest.
|
||||
func NewCloseRequest(cp *wire.OutPoint, sig *btcec.Signature) *CloseRequest {
|
||||
func NewCloseRequest(cp wire.OutPoint, sig *btcec.Signature) *CloseRequest {
|
||||
// TODO(roasbeef): update once fees aren't hardcoded
|
||||
return &CloseRequest{
|
||||
ChannelPoint: cp,
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func TestCloseRequestEncodeDecode(t *testing.T) {
|
||||
cr := &CloseRequest{
|
||||
ChannelPoint: outpoint1,
|
||||
ChannelPoint: *outpoint1,
|
||||
RequesterCloseSig: commitSig,
|
||||
Fee: btcutil.Amount(10000),
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ type ErrorGeneric struct {
|
||||
// ChannelPoint references the active channel in which the error
|
||||
// occurred within. A ChannelPoint of zeroHash:0 denotes this error
|
||||
// applies to the entire established connection.
|
||||
ChannelPoint *wire.OutPoint
|
||||
ChannelPoint wire.OutPoint
|
||||
|
||||
// PendingChannelID allows peers communicate errors in the context of a
|
||||
// particular pending channel. With this field, once a peer reads an
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
|
||||
func TestErrorGenericEncodeDecode(t *testing.T) {
|
||||
eg := &ErrorGeneric{
|
||||
ChannelPoint: outpoint1,
|
||||
ChannelPoint: *outpoint1,
|
||||
PendingChannelID: 1,
|
||||
Code: 99,
|
||||
Problem: "Hello world!",
|
||||
|
@ -230,7 +230,8 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
if err := e.Encode(w); err != nil {
|
||||
return err
|
||||
}
|
||||
case *wire.OutPoint:
|
||||
|
||||
case wire.OutPoint:
|
||||
// TODO(roasbeef): consolidate with above
|
||||
// First write out the previous txid.
|
||||
var h [32]byte
|
||||
@ -514,7 +515,7 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
}
|
||||
(*e).PreviousOutPoint.Index = binary.BigEndian.Uint32(idxBytes[:])
|
||||
return nil
|
||||
case **wire.OutPoint:
|
||||
case *wire.OutPoint:
|
||||
// TODO(roasbeef): consolidate with above
|
||||
var h [32]byte
|
||||
if _, err = io.ReadFull(r, h[:]); err != nil {
|
||||
@ -532,7 +533,7 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
}
|
||||
index := binary.BigEndian.Uint32(idxBytes[:])
|
||||
|
||||
*e = wire.NewOutPoint(hash, index)
|
||||
*e = wire.OutPoint{Hash: *hash, Index: index}
|
||||
case *int64, *float64:
|
||||
err := binary.Read(r, binary.BigEndian, e)
|
||||
if err != nil {
|
||||
|
@ -2,7 +2,6 @@ package lnwire
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"net"
|
||||
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
@ -12,7 +11,6 @@ import (
|
||||
)
|
||||
|
||||
// Common variables and functions for the message tests
|
||||
|
||||
var (
|
||||
revHash = [32]byte{
|
||||
0xb7, 0x94, 0x38, 0x5f, 0x2d, 0x1e, 0xf7, 0xab,
|
||||
@ -21,66 +19,25 @@ var (
|
||||
0x6a, 0x49, 0x18, 0x83, 0x31, 0x98, 0x47, 0x53,
|
||||
}
|
||||
|
||||
maxUint32 uint32 = (1 << 32) - 1
|
||||
maxUint24 uint32 = (1 << 24) - 1
|
||||
maxUint16 uint16 = (1 << 16) - 1
|
||||
|
||||
// For debugging, writes to /dev/shm/
|
||||
// Maybe in the future do it if you do "go test -v"
|
||||
WRITE_FILE = false
|
||||
filename = "/dev/shm/serialized.raw"
|
||||
|
||||
// preimage: 9a2cbd088763db88dd8ba79e5726daa6aba4aa7e
|
||||
// echo -n | openssl sha256 | openssl ripemd160 | openssl sha256 | openssl ripemd160
|
||||
revocationHashBytes, _ = hex.DecodeString("4132b6b48371f7b022a16eacb9b2b0ebee134d41")
|
||||
revocationHash [20]byte
|
||||
|
||||
// preimage: "hello world"
|
||||
redemptionHashBytes, _ = hex.DecodeString("5b315ebabb0d8c0d94281caa2dfee69a1a00436e")
|
||||
redemptionHash [20]byte
|
||||
|
||||
// preimage: "next hop"
|
||||
nextHopBytes, _ = hex.DecodeString("94a9ded5a30fc5944cb1e2cbcd980f30616a1440")
|
||||
nextHop [20]byte
|
||||
shaHash1Bytes, _ = hex.DecodeString("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
|
||||
shaHash1, _ = chainhash.NewHash(shaHash1Bytes)
|
||||
outpoint1 = wire.NewOutPoint(shaHash1, 0)
|
||||
|
||||
privKeyBytes, _ = hex.DecodeString("9fa1d55217f57019a3c37f49465896b15836f54cb8ef6963870a52926420a2dd")
|
||||
privKey, pubKey = btcec.PrivKeyFromBytes(btcec.S256(), privKeyBytes)
|
||||
address = pubKey
|
||||
|
||||
// Delivery PkScript
|
||||
// Privkey: f2c00ead9cbcfec63098dc0a5f152c0165aff40a2ab92feb4e24869a284c32a7
|
||||
// PKhash: n2fkWVphUzw3zSigzPsv9GuDyg9mohzKpz
|
||||
deliveryPkScript, _ = hex.DecodeString("76a914e8048c0fb75bdecc91ebfb99c174f4ece29ffbd488ac")
|
||||
|
||||
// Change PkScript
|
||||
// Privkey: 5b18f5049efd9d3aff1fb9a06506c0b809fb71562b6ecd02f6c5b3ab298f3b0f
|
||||
// PKhash: miky84cHvLuk6jcT6GsSbgHR8d7eZCu9Qc
|
||||
changePkScript, _ = hex.DecodeString("76a914238ee44bb5c8c1314dd03974a17ec6c406fdcb8388ac")
|
||||
|
||||
// echo -n | openssl sha256
|
||||
// This stuff gets reversed!!!
|
||||
shaHash1Bytes, _ = hex.DecodeString("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
|
||||
shaHash1, _ = chainhash.NewHash(shaHash1Bytes)
|
||||
outpoint1 = wire.NewOutPoint(shaHash1, 0)
|
||||
// echo | openssl sha256
|
||||
// This stuff gets reversed!!!
|
||||
shaHash2Bytes, _ = hex.DecodeString("01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b")
|
||||
shaHash2, _ = chainhash.NewHash(shaHash2Bytes)
|
||||
outpoint2 = wire.NewOutPoint(shaHash2, 1)
|
||||
// create inputs from outpoint1 and outpoint2
|
||||
inputs = []*wire.TxIn{wire.NewTxIn(outpoint1, nil, nil), wire.NewTxIn(outpoint2, nil, nil)}
|
||||
|
||||
// Commitment Signature
|
||||
tx = wire.NewMsgTx(1)
|
||||
emptybytes = new([]byte)
|
||||
sigStr, _ = txscript.RawTxInSignature(tx, 0, *emptybytes, txscript.SigHashAll, privKey)
|
||||
commitSig, _ = btcec.ParseSignature(sigStr, btcec.S256())
|
||||
|
||||
// Funding TX Sig 1
|
||||
sig1privKeyBytes, _ = hex.DecodeString("927f5827d75dd2addeb532c0fa5ac9277565f981dd6d0d037b422be5f60bdbef")
|
||||
sig1privKey, _ = btcec.PrivKeyFromBytes(btcec.S256(), sig1privKeyBytes)
|
||||
sigStr1, _ = txscript.RawTxInSignature(tx, 0, *emptybytes, txscript.SigHashAll, sig1privKey)
|
||||
commitSig1, _ = btcec.ParseSignature(sigStr1, btcec.S256())
|
||||
|
||||
// Funding TX Sig 2
|
||||
sig2privKeyBytes, _ = hex.DecodeString("8a4ad188f6f4000495b765cfb6ffa591133a73019c45428ddd28f53bab551847")
|
||||
sig2privKey, _ = btcec.PrivKeyFromBytes(btcec.S256(), sig2privKeyBytes)
|
||||
@ -101,6 +58,10 @@ var (
|
||||
|
||||
someAddress = &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8333}
|
||||
|
||||
maxUint32 uint32 = (1 << 32) - 1
|
||||
maxUint24 uint32 = (1 << 24) - 1
|
||||
maxUint16 uint16 = (1 << 16) - 1
|
||||
|
||||
someChannelID = ChannelID{
|
||||
BlockHeight: maxUint24,
|
||||
TxIndex: maxUint24,
|
||||
|
@ -23,7 +23,7 @@ type SingleFundingComplete struct {
|
||||
// FundingOutPoint is the outpoint (txid:index) of the funding
|
||||
// transaction. With this value, Bob will be able to generate a
|
||||
// signature for Alice's version of the commitment transaction.
|
||||
FundingOutPoint *wire.OutPoint
|
||||
FundingOutPoint wire.OutPoint
|
||||
|
||||
// CommitSignature is Alice's signature for Bob's version of the
|
||||
// commitment transaction.
|
||||
@ -46,7 +46,7 @@ type SingleFundingComplete struct {
|
||||
|
||||
// NewSingleFundingComplete creates, and returns a new empty
|
||||
// SingleFundingResponse.
|
||||
func NewSingleFundingComplete(chanID uint64, fundingPoint *wire.OutPoint,
|
||||
func NewSingleFundingComplete(chanID uint64, fundingPoint wire.OutPoint,
|
||||
commitSig *btcec.Signature, revokeKey *btcec.PublicKey,
|
||||
obsfucator [4]byte) *SingleFundingComplete {
|
||||
|
||||
@ -74,7 +74,7 @@ func (s *SingleFundingComplete) Decode(r io.Reader, pver uint32) error {
|
||||
&s.FundingOutPoint,
|
||||
&s.CommitSignature,
|
||||
&s.RevocationKey,
|
||||
&s.StateHintObsfucator)
|
||||
s.StateHintObsfucator[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -97,7 +97,7 @@ func (s *SingleFundingComplete) Encode(w io.Writer, pver uint32) error {
|
||||
s.FundingOutPoint,
|
||||
s.CommitSignature,
|
||||
s.RevocationKey,
|
||||
s.StateHintObsfucator)
|
||||
s.StateHintObsfucator[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ func TestSingleFundingCompleteWire(t *testing.T) {
|
||||
copy(obsfucator[:], bytes.Repeat([]byte("k"), 4))
|
||||
|
||||
// First create a new SFC message.
|
||||
sfc := NewSingleFundingComplete(22, outpoint1, commitSig1, pubKey,
|
||||
sfc := NewSingleFundingComplete(22, *outpoint1, commitSig1, pubKey,
|
||||
obsfucator)
|
||||
|
||||
// Next encode the SFC message into an empty bytes buffer.
|
||||
|
Loading…
Reference in New Issue
Block a user