mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 15:11:09 +02:00
lnwire: add new ChannelType field as TLV record to Open/AcceptChannel
In this commit, we add a new ChannelType field as a new TLV record to the OpenChannel message. During this change, we make a few tweaks to the generic TLV encode/decode methods for the ExtraOpaqueData struct to have it work on the level of tlv.RecordProducer instead of tlv.Record, as this reduces line noise a bit. We also partially undo existing logic that would attempt to "prepend" any new TLV records to the end of the ExtraOpaqueData if one was already present within the struct. This is based on the assumption that if we've read a message from disk to order to re-send/transmit it, then the ExtraOpaqueData is fully populated so we'll write that as is. Otherwise, a message is being encoded for the first time, and we expect all fields that are known TLV fields to be specified within the struct itself. This change required the unit tests to be modified slightly, as we'll always encode a fresh set of TLV records if none was already specified within the struct.
This commit is contained in:
@@ -18,8 +18,8 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/lightningnetwork/lnd/tor"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -284,9 +284,7 @@ func TestLightningWireProtocol(t *testing.T) {
|
||||
t.Fatalf("unable to read msg: %v", err)
|
||||
return false
|
||||
}
|
||||
if !reflect.DeepEqual(msg, newMsg) {
|
||||
t.Fatalf("messages don't match after re-encoding: %v "+
|
||||
"vs %v", spew.Sdump(msg), spew.Sdump(newMsg))
|
||||
if !assert.Equalf(t, msg, newMsg, "message mismatch") {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -369,17 +367,16 @@ func TestLightningWireProtocol(t *testing.T) {
|
||||
t.Fatalf("unable to generate delivery address: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
req.ChannelType = new(ChannelType)
|
||||
*req.ChannelType = ChannelType(*randRawFeatureVector(r))
|
||||
} else {
|
||||
req.UpfrontShutdownScript = []byte{}
|
||||
}
|
||||
|
||||
// 1/2 chance how having more TLV data after the
|
||||
// shutdown script.
|
||||
// 1/2 chance additional TLV data.
|
||||
if r.Intn(2) == 0 {
|
||||
// TLV type 1 of length 2.
|
||||
req.ExtraData = []byte{1, 2, 0xff, 0xff}
|
||||
} else {
|
||||
req.ExtraData = []byte{}
|
||||
req.ExtraData = []byte{0xfd, 0x00, 0xff, 0x00}
|
||||
}
|
||||
|
||||
v[0] = reflect.ValueOf(req)
|
||||
@@ -439,16 +436,16 @@ func TestLightningWireProtocol(t *testing.T) {
|
||||
t.Fatalf("unable to generate delivery address: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
req.ChannelType = new(ChannelType)
|
||||
*req.ChannelType = ChannelType(*randRawFeatureVector(r))
|
||||
} else {
|
||||
req.UpfrontShutdownScript = []byte{}
|
||||
}
|
||||
// 1/2 chance how having more TLV data after the
|
||||
// shutdown script.
|
||||
|
||||
// 1/2 chance additional TLV data.
|
||||
if r.Intn(2) == 0 {
|
||||
// TLV type 1 of length 2.
|
||||
req.ExtraData = []byte{1, 2, 0xff, 0xff}
|
||||
} else {
|
||||
req.ExtraData = []byte{}
|
||||
req.ExtraData = []byte{0xfd, 0x00, 0xff, 0x00}
|
||||
}
|
||||
|
||||
v[0] = reflect.ValueOf(req)
|
||||
|
Reference in New Issue
Block a user