diff --git a/channeldb/graph.go b/channeldb/graph.go index fa7b35f2..b53933e1 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -1108,6 +1108,10 @@ func (p *ChannelAuthProof) IsEmpty() bool { // information concerning fees, and minimum time-lock information which is // utilized during path finding. type ChannelEdgePolicy struct { + // Signature is a channel announcement signature, which is needed for + // proper edge policy announcement. + Signature *btcec.Signature + // ChannelID is the unique channel ID for the channel. The first 3 // bytes are the block height, the next 3 the index within the block, // and the last 2 bytes are the output index for the channel. @@ -1361,6 +1365,11 @@ func putLightningNode(nodeBucket *bolt.Bucket, aliasBucket *bolt.Bucket, node *L } } + err := wire.WriteVarBytes(&b, 0, node.AuthSig.Serialize()) + if err != nil { + return err + } + return nodeBucket.Put(nodePub, b.Bytes()) } @@ -1462,6 +1471,16 @@ func deserializeLightningNode(r io.Reader) (*LightningNode, error) { } node.Addresses = addresses + sigBytes, err := wire.ReadVarBytes(r, 0, 80, "sig") + if err != nil { + return nil, err + } + + node.AuthSig, err = btcec.ParseSignature(sigBytes, btcec.S256()) + if err != nil { + return nil, err + } + return node, nil } @@ -1626,6 +1645,11 @@ func putChanEdgePolicy(edges *bolt.Bucket, edge *ChannelEdgePolicy, from, to []b var b bytes.Buffer + err := wire.WriteVarBytes(&b, 0, edge.Signature.Serialize()) + if err != nil { + return err + } + if err := binary.Write(&b, byteOrder, edge.ChannelID); err != nil { return err } @@ -1723,6 +1747,16 @@ func deserializeChanEdgePolicy(r io.Reader, edge := &ChannelEdgePolicy{} + sigBytes, err := wire.ReadVarBytes(r, 0, 80, "sig") + if err != nil { + return nil, err + } + + edge.Signature, err = btcec.ParseSignature(sigBytes, btcec.S256()) + if err != nil { + return nil, err + } + if err := binary.Read(r, byteOrder, &edge.ChannelID); err != nil { return nil, err } diff --git a/channeldb/graph_test.go b/channeldb/graph_test.go index 85db3a27..26232db3 100644 --- a/channeldb/graph_test.go +++ b/channeldb/graph_test.go @@ -50,6 +50,7 @@ func createTestVertex(db *DB) (*LightningNode, error) { pub := priv.PubKey().SerializeCompressed() return &LightningNode{ + AuthSig: testSig, LastUpdate: time.Unix(updateTime, 0), PubKey: priv.PubKey(), Color: color.RGBA{1, 2, 3, 0}, @@ -73,6 +74,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) { // graph, so we'll create a test vertex to start with. _, testPub := btcec.PrivKeyFromBytes(btcec.S256(), key[:]) node := &LightningNode{ + AuthSig: testSig, LastUpdate: time.Unix(1232342, 0), PubKey: testPub, Color: color.RGBA{1, 2, 3, 0}, @@ -400,6 +402,7 @@ func TestEdgeInfoUpdates(t *testing.T) { // With the edge added, we can now create some fake edge information to // update for both edges. edge1 := &ChannelEdgePolicy{ + Signature: testSig, ChannelID: chanID, LastUpdate: time.Unix(433453, 0), Flags: 0, @@ -411,6 +414,7 @@ func TestEdgeInfoUpdates(t *testing.T) { db: db, } edge2 := &ChannelEdgePolicy{ + Signature: testSig, ChannelID: chanID, LastUpdate: time.Unix(124234, 0), Flags: 1, @@ -589,6 +593,7 @@ func TestGraphTraversal(t *testing.T) { edge := randEdgePolicy(chanID, op, db) edge.Flags = 0 edge.Node = secondNode + edge.Signature = testSig if err := graph.UpdateEdgePolicy(edge); err != nil { t.Fatalf("unable to update edge: %v", err) } @@ -598,6 +603,7 @@ func TestGraphTraversal(t *testing.T) { edge = randEdgePolicy(chanID, op, db) edge.Flags = 1 edge.Node = firstNode + edge.Signature = testSig if err := graph.UpdateEdgePolicy(edge); err != nil { t.Fatalf("unable to update edge: %v", err) } @@ -743,6 +749,7 @@ func TestGraphPruning(t *testing.T) { edge := randEdgePolicy(chanID, op, db) edge.Flags = 0 edge.Node = graphNodes[i] + edge.Signature = testSig if err := graph.UpdateEdgePolicy(edge); err != nil { t.Fatalf("unable to update edge: %v", err) } @@ -752,6 +759,7 @@ func TestGraphPruning(t *testing.T) { edge = randEdgePolicy(chanID, op, db) edge.Flags = 1 edge.Node = graphNodes[i] + edge.Signature = testSig if err := graph.UpdateEdgePolicy(edge); err != nil { t.Fatalf("unable to update edge: %v", err) } diff --git a/routing/notifications_test.go b/routing/notifications_test.go index 3c35fa92..e0170885 100644 --- a/routing/notifications_test.go +++ b/routing/notifications_test.go @@ -49,6 +49,7 @@ func createGraphNode() (*channeldb.LightningNode, error) { PubKey: priv.PubKey(), Color: color.RGBA{1, 2, 3, 0}, Alias: "kek" + string(pub[:]), + AuthSig: testSig, Features: testFeatures, }, nil } @@ -79,6 +80,7 @@ func randEdgePolicy(chanID lnwire.ShortChannelID, node *channeldb.LightningNode) *channeldb.ChannelEdgePolicy { return &channeldb.ChannelEdgePolicy{ + Signature: testSig, ChannelID: chanID.ToUint64(), LastUpdate: time.Unix(int64(prand.Int31()), 0), TimeLockDelta: uint16(prand.Int63()), diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index 596c826c..ba879c6c 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -163,6 +163,7 @@ func parseTestGraph(path string) (*channeldb.ChannelGraph, func(), aliasMap, err } dbNode := &channeldb.LightningNode{ + AuthSig: testSig, LastUpdate: time.Now(), Addresses: testAddrs, PubKey: pub, @@ -257,6 +258,7 @@ func parseTestGraph(path string) (*channeldb.ChannelGraph, func(), aliasMap, err } edgePolicy := &channeldb.ChannelEdgePolicy{ + Signature: testSig, ChannelID: edge.ChannelID, LastUpdate: time.Now(), TimeLockDelta: edge.Expiry,