lnwire: introduce message types for dynamic commitment negotiation

lnwire: add tests for dynamic commitment wire serialization
This commit is contained in:
Keagan McClelland
2023-09-22 19:26:52 -07:00
committed by Olaoluwa Osuntokun
parent b298c84d21
commit e5f7ed8ba1
6 changed files with 575 additions and 0 deletions

View File

@@ -20,6 +20,8 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/tor"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -708,6 +710,96 @@ func TestLightningWireProtocol(t *testing.T) {
v[0] = reflect.ValueOf(req)
},
MsgDynPropose: func(v []reflect.Value, r *rand.Rand) {
var dp DynPropose
rand.Read(dp.ChanID[:])
if rand.Uint32()%2 == 0 {
v := btcutil.Amount(rand.Uint32())
dp.DustLimit = fn.Some(v)
}
if rand.Uint32()%2 == 0 {
v := MilliSatoshi(rand.Uint32())
dp.MaxValueInFlight = fn.Some(v)
}
if rand.Uint32()%2 == 0 {
v := btcutil.Amount(rand.Uint32())
dp.ChannelReserve = fn.Some(v)
}
if rand.Uint32()%2 == 0 {
v := uint16(rand.Uint32())
dp.CsvDelay = fn.Some(v)
}
if rand.Uint32()%2 == 0 {
v := uint16(rand.Uint32())
dp.MaxAcceptedHTLCs = fn.Some(v)
}
if rand.Uint32()%2 == 0 {
v, _ := btcec.NewPrivateKey()
dp.FundingKey = fn.Some(*v.PubKey())
}
if rand.Uint32()%2 == 0 {
v := ChannelType(*NewRawFeatureVector())
dp.ChannelType = fn.Some(v)
}
if rand.Uint32()%2 == 0 {
v := chainfee.SatPerKWeight(rand.Uint32())
dp.KickoffFeerate = fn.Some(v)
}
v[0] = reflect.ValueOf(dp)
},
MsgDynReject: func(v []reflect.Value, r *rand.Rand) {
var dr DynReject
rand.Read(dr.ChanID[:])
features := NewRawFeatureVector()
if rand.Uint32()%2 == 0 {
features.Set(FeatureBit(DPDustLimitSatoshis))
}
if rand.Uint32()%2 == 0 {
features.Set(
FeatureBit(DPMaxHtlcValueInFlightMsat),
)
}
if rand.Uint32()%2 == 0 {
features.Set(
FeatureBit(DPChannelReserveSatoshis),
)
}
if rand.Uint32()%2 == 0 {
features.Set(FeatureBit(DPToSelfDelay))
}
if rand.Uint32()%2 == 0 {
features.Set(FeatureBit(DPMaxAcceptedHtlcs))
}
if rand.Uint32()%2 == 0 {
features.Set(FeatureBit(DPFundingPubkey))
}
if rand.Uint32()%2 == 0 {
features.Set(FeatureBit(DPChannelType))
}
if rand.Uint32()%2 == 0 {
features.Set(FeatureBit(DPKickoffFeerate))
}
dr.UpdateRejections = *features
v[0] = reflect.ValueOf(dr)
},
MsgCommitSig: func(v []reflect.Value, r *rand.Rand) {
req := NewCommitSig()
if _, err := r.Read(req.ChanID[:]); err != nil {
@@ -1153,6 +1245,18 @@ func TestLightningWireProtocol(t *testing.T) {
return mainScenario(&m)
},
},
{
msgType: MsgDynPropose,
scenario: func(m DynPropose) bool {
return mainScenario(&m)
},
},
{
msgType: MsgDynReject,
scenario: func(m DynReject) bool {
return mainScenario(&m)
},
},
{
msgType: MsgUpdateAddHTLC,
scenario: func(m UpdateAddHTLC) bool {