lnwire: add ChannelUpdate2

Add the new ChannelUpdate2 message and ensure that it implements the
ChannelUpdate interface.
This commit is contained in:
Elle Mouton
2023-09-29 11:37:39 +02:00
parent 21c9ef8904
commit 580c10477f
4 changed files with 568 additions and 0 deletions

View File

@@ -1590,6 +1590,83 @@ func TestLightningWireProtocol(t *testing.T) {
require.NoError(t, err)
}
v[0] = reflect.ValueOf(req)
},
MsgChannelUpdate2: func(v []reflect.Value, r *rand.Rand) {
req := ChannelUpdate2{
Signature: testSchnorrSig,
ExtraOpaqueData: make([]byte, 0),
}
req.ShortChannelID.Val = NewShortChanIDFromInt(
uint64(r.Int63()),
)
req.BlockHeight.Val = r.Uint32()
req.HTLCMaximumMsat.Val = MilliSatoshi(r.Uint64())
// Sometimes set chain hash to bitcoin mainnet genesis
// hash.
req.ChainHash.Val = *chaincfg.MainNetParams.GenesisHash
if r.Int31()%2 == 0 {
_, err := r.Read(req.ChainHash.Val[:])
require.NoError(t, err)
}
// Sometimes use default htlc min msat.
req.HTLCMinimumMsat.Val = defaultHtlcMinMsat
if r.Int31()%2 == 0 {
req.HTLCMinimumMsat.Val = MilliSatoshi(
r.Uint64(),
)
}
// Sometimes set the cltv expiry delta to the default.
req.CLTVExpiryDelta.Val = defaultCltvExpiryDelta
if r.Int31()%2 == 0 {
req.CLTVExpiryDelta.Val = uint16(r.Int31())
}
// Sometimes use default fee base.
req.FeeBaseMsat.Val = defaultFeeBaseMsat
if r.Int31()%2 == 0 {
req.FeeBaseMsat.Val = r.Uint32()
}
// Sometimes use default proportional fee.
req.FeeProportionalMillionths.Val =
defaultFeeProportionalMillionths
if r.Int31()%2 == 0 {
req.FeeProportionalMillionths.Val = r.Uint32()
}
// Alternate between the two direction possibilities.
if r.Int31()%2 == 0 {
req.SecondPeer = tlv.SomeRecordT(
tlv.ZeroRecordT[tlv.TlvType8, TrueBoolean](), //nolint:lll
)
}
// Sometimes set the incoming disabled flag.
if r.Int31()%2 == 0 {
req.DisabledFlags.Val |=
ChanUpdateDisableIncoming
}
// Sometimes set the outgoing disabled flag.
if r.Int31()%2 == 0 {
req.DisabledFlags.Val |=
ChanUpdateDisableOutgoing
}
numExtraBytes := r.Int31n(1000)
if numExtraBytes > 0 {
req.ExtraOpaqueData = make(
[]byte, numExtraBytes,
)
_, err := r.Read(req.ExtraOpaqueData[:])
require.NoError(t, err)
}
v[0] = reflect.ValueOf(req)
},
}
@@ -1832,6 +1909,12 @@ func TestLightningWireProtocol(t *testing.T) {
return mainScenario(&m)
},
},
{
msgType: MsgChannelUpdate2,
scenario: func(m ChannelUpdate2) bool {
return mainScenario(&m)
},
},
}
for _, test := range tests {
var config *quick.Config