multi: add and use V1 constructor for models.ChannelEdgeInfo
This makes it clear what fields must/can be set for a V1 channel. Introduce NewV1Channel constructor to create v1 channel edges with proper initialization and validation. The constructor: - Takes required fields (chanID, chainHash, node keys) as parameters - Takes v1-specific fields (bitcoin keys, extra opaque data) via ChannelV1Fields struct - Accepts optional fields (capacity, channel point, features, proof) via functional options (WithCapacity, WithChannelPoint, etc.) - Validates that if an AuthProof is provided, its version matches the channel version This makes it clear which fields are required vs optional for v1 channels and prevents incorrectly initialized channel edges. All tests and production code updated to use the constructor.
This commit is contained in:
18 files changed
+853
-575
No files matched your search
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@@ -492,16 +493,20 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
||||
}
|
||||
|
||||
chanID := randChanID()
|
||||
edge := &models.ChannelEdgeInfo{
|
||||
Version: lnwire.GossipVersion1,
|
||||
ChannelID: chanID.ToUint64(),
|
||||
Capacity: capacity,
|
||||
Features: lnwire.EmptyFeatureVector(),
|
||||
nodeKey1 := route.NewVertex(lnNode1)
|
||||
nodeKey2 := route.NewVertex(lnNode2)
|
||||
btcKey1 := route.NewVertex(lnNode1)
|
||||
btcKey2 := route.NewVertex(lnNode2)
|
||||
edge, err := models.NewV1Channel(
|
||||
chanID.ToUint64(), chainhash.Hash{}, nodeKey1, nodeKey2,
|
||||
&models.ChannelV1Fields{
|
||||
BitcoinKey1Bytes: btcKey1,
|
||||
BitcoinKey2Bytes: btcKey2,
|
||||
}, models.WithCapacity(capacity),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
copy(edge.NodeKey1Bytes[:], lnNode1.SerializeCompressed())
|
||||
copy(edge.NodeKey2Bytes[:], lnNode2.SerializeCompressed())
|
||||
copy(edge.BitcoinKey1Bytes[:], lnNode1.SerializeCompressed())
|
||||
copy(edge.BitcoinKey2Bytes[:], lnNode2.SerializeCompressed())
|
||||
|
||||
if err := d.db.AddChannelEdge(ctx, edge); err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
Reference in new issue
Block a user