mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 01:36:24 +01:00
lnrpc/peers: handle color changes in updateNodeAnnouncement
This commit is contained in:
parent
ce4813940d
commit
aacb2565f5
4 changed files with 37 additions and 1 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||||
|
"github.com/lightningnetwork/lnd/lncfg"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/netann"
|
"github.com/lightningnetwork/lnd/netann"
|
||||||
|
@ -177,7 +178,25 @@ func (s *Server) UpdateNodeAnnouncement(_ context.Context,
|
||||||
|
|
||||||
// TODO(positiveblue): apply feature bit modifications
|
// TODO(positiveblue): apply feature bit modifications
|
||||||
|
|
||||||
// TODO(positiveblue): apply color modifications
|
if req.Color != "" {
|
||||||
|
color, err := lncfg.ParseHexColor(req.Color)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to parse color: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if color != currentNodeAnn.RGBColor {
|
||||||
|
resp.Ops = append(resp.Ops, &lnrpc.Op{
|
||||||
|
Entity: "color",
|
||||||
|
Actions: []string{
|
||||||
|
fmt.Sprintf("changed to %v", color),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
nodeModifiers = append(
|
||||||
|
nodeModifiers,
|
||||||
|
netann.NodeAnnSetColor(color),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if req.Alias != "" {
|
if req.Alias != "" {
|
||||||
alias, err := lnwire.NewNodeAlias(req.Alias)
|
alias, err := lnwire.NewNodeAlias(req.Alias)
|
||||||
|
|
|
@ -1862,6 +1862,9 @@ func assertAnchorOutputLost(t *harnessTest, node *lntest.HarnessNode,
|
||||||
func assertNodeAnnouncement(t *harnessTest, n1, n2 *lnrpc.NodeUpdate) {
|
func assertNodeAnnouncement(t *harnessTest, n1, n2 *lnrpc.NodeUpdate) {
|
||||||
// Alias should match.
|
// Alias should match.
|
||||||
require.Equal(t.t, n1.Alias, n2.Alias, "alias don't match")
|
require.Equal(t.t, n1.Alias, n2.Alias, "alias don't match")
|
||||||
|
|
||||||
|
// Color should match.
|
||||||
|
require.Equal(t.t, n1.Color, n2.Color, "color don't match")
|
||||||
}
|
}
|
||||||
|
|
||||||
// assertUpdateNodeAnnouncementResponse is a helper function to assert
|
// assertUpdateNodeAnnouncementResponse is a helper function to assert
|
||||||
|
|
|
@ -821,6 +821,7 @@ func testUpdateNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) {
|
||||||
|
|
||||||
defaultDaveNodeAnn := &lnrpc.NodeUpdate{
|
defaultDaveNodeAnn := &lnrpc.NodeUpdate{
|
||||||
Alias: resp.Alias,
|
Alias: resp.Alias,
|
||||||
|
Color: resp.Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dave must have an open channel before he can send a node
|
// Dave must have an open channel before he can send a node
|
||||||
|
@ -866,15 +867,18 @@ func testUpdateNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) {
|
||||||
|
|
||||||
// Update Node.
|
// Update Node.
|
||||||
newAlias := "new-alias"
|
newAlias := "new-alias"
|
||||||
|
newColor := "#2288ee"
|
||||||
|
|
||||||
nodeAnnReq := &peersrpc.NodeAnnouncementUpdateRequest{
|
nodeAnnReq := &peersrpc.NodeAnnouncementUpdateRequest{
|
||||||
Alias: newAlias,
|
Alias: newAlias,
|
||||||
|
Color: newColor,
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := dave.UpdateNodeAnnouncement(ctxt, nodeAnnReq)
|
response, err := dave.UpdateNodeAnnouncement(ctxt, nodeAnnReq)
|
||||||
require.NoError(t.t, err, "unable to update dave's node announcement")
|
require.NoError(t.t, err, "unable to update dave's node announcement")
|
||||||
|
|
||||||
expectedOps := map[string]int{
|
expectedOps := map[string]int{
|
||||||
|
"color": 1,
|
||||||
"alias": 1,
|
"alias": 1,
|
||||||
}
|
}
|
||||||
assertUpdateNodeAnnouncementResponse(t, response, expectedOps)
|
assertUpdateNodeAnnouncementResponse(t, response, expectedOps)
|
||||||
|
@ -883,6 +887,7 @@ func testUpdateNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) {
|
||||||
// the requested color, requested alias and the new added addresses.
|
// the requested color, requested alias and the new added addresses.
|
||||||
newDaveNodeAnn := &lnrpc.NodeUpdate{
|
newDaveNodeAnn := &lnrpc.NodeUpdate{
|
||||||
Alias: newAlias,
|
Alias: newAlias,
|
||||||
|
Color: newColor,
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll then wait for Alice to receive dave's node announcement
|
// We'll then wait for Alice to receive dave's node announcement
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package netann
|
package netann
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image/color"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -29,6 +30,14 @@ func NodeAnnSetAddrs(addrs []net.Addr) func(*lnwire.NodeAnnouncement) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NodeAnnSetColor is a functional option that sets the color of the
|
||||||
|
// given node announcment.
|
||||||
|
func NodeAnnSetColor(newColor color.RGBA) func(*lnwire.NodeAnnouncement) {
|
||||||
|
return func(nodeAnn *lnwire.NodeAnnouncement) {
|
||||||
|
nodeAnn.RGBColor = newColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NodeAnnSetTimestamp is a functional option that sets the timestamp of the
|
// NodeAnnSetTimestamp is a functional option that sets the timestamp of the
|
||||||
// announcement to the current time, or increments it if the timestamp is
|
// announcement to the current time, or increments it if the timestamp is
|
||||||
// already in the future.
|
// already in the future.
|
||||||
|
|
Loading…
Add table
Reference in a new issue