From b83019e5c6b73995e39f86060c289054d76ff100 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Wed, 18 Jan 2023 10:31:49 +0200 Subject: [PATCH] Remove invalid fake channels check. We no longer need to check for confirmed channels so now we return empty map instead to satisfy the client. This is untill we will release a new client that doesn't use this endpoint at all. --- db.go | 30 ------------------------------ server.go | 24 +----------------------- 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/db.go b/db.go index f982d69..4e40169 100644 --- a/db.go +++ b/db.go @@ -2,7 +2,6 @@ package main import ( "context" - "encoding/hex" "fmt" "log" "time" @@ -101,35 +100,6 @@ func insertChannel(initialChanID, confirmedChanId uint64, channelPoint string, n return nil } -func confirmedChannels(sNodeID string) (map[string]uint64, error) { - nodeID, err := hex.DecodeString(sNodeID) - if err != nil { - return nil, fmt.Errorf("hex.DecodeString(%v) error: %w", sNodeID, err) - } - rows, err := pgxPool.Query(context.Background(), - `SELECT confirmed_chanid, channel_point - FROM channels - WHERE nodeid=$1 AND confirmed_chanid IS NOT NULL`, - nodeID) - if err != nil { - return nil, fmt.Errorf("channels(%x) error: %w", nodeID, err) - } - defer rows.Close() - chans := make(map[string]uint64) - for rows.Next() { - var ( - chanID int64 - channelPoint string - ) - err = rows.Scan(&chanID, &channelPoint) - if err != nil { - return nil, fmt.Errorf("channels(%x) rows.Scan error: %w", nodeID, err) - } - chans[channelPoint] = uint64(chanID) - } - return chans, rows.Err() -} - func lastForwardingEvent() (int64, error) { var last int64 err := pgxPool.QueryRow(context.Background(), diff --git a/server.go b/server.go index 16e2069..a02ab98 100644 --- a/server.go +++ b/server.go @@ -206,18 +206,13 @@ func (s *server) CheckChannels(ctx context.Context, in *lspdrpc.Encrypted) (*lsp log.Printf("proto.Unmarshal(%x) error: %v", data, err) return nil, fmt.Errorf("proto.Unmarshal(%x) error: %w", data, err) } - notFakeChannels, err := getNotFakeChannels(nodeID, checkChannelsRequest.FakeChannels) - if err != nil { - log.Printf("getNotFakeChannels(%v) error: %v", checkChannelsRequest.FakeChannels, err) - return nil, fmt.Errorf("getNotFakeChannels(%v) error: %w", checkChannelsRequest.FakeChannels, err) - } closedChannels, err := node.client.GetClosedChannels(nodeID, checkChannelsRequest.WaitingCloseChannels) if err != nil { log.Printf("GetClosedChannels(%v) error: %v", checkChannelsRequest.FakeChannels, err) return nil, fmt.Errorf("GetClosedChannels(%v) error: %w", checkChannelsRequest.FakeChannels, err) } checkChannelsReply := lspdrpc.CheckChannelsReply{ - NotFakeChannels: notFakeChannels, + NotFakeChannels: make(map[string]uint64), ClosedChannels: closedChannels, } dataReply, err := proto.Marshal(&checkChannelsReply) @@ -249,23 +244,6 @@ func (s *server) CheckChannels(ctx context.Context, in *lspdrpc.Encrypted) (*lsp return &lspdrpc.Encrypted{Data: encrypted}, nil } -func getNotFakeChannels(nodeID string, channelPoints map[string]uint64) (map[string]uint64, error) { - r := make(map[string]uint64) - if len(channelPoints) == 0 { - return r, nil - } - channels, err := confirmedChannels(nodeID) - if err != nil { - return nil, err - } - for channelPoint, chanID := range channels { - if _, ok := channelPoints[channelPoint]; ok { - r[channelPoint] = chanID - } - } - return r, nil -} - func NewGrpcServer(configs []*NodeConfig, address string, certmagicDomain string) (*server, error) { if len(configs) == 0 { return nil, fmt.Errorf("no nodes supplied")