From cc08271c5f8aa8a6fc104a01fb960dba650e72d9 Mon Sep 17 00:00:00 2001 From: ErikEk Date: Thu, 28 Jul 2022 12:46:18 +0200 Subject: [PATCH 1/3] itest: add neutrinoclient to harnessnode --- lntemp/rpc/harness_rpc.go | 3 +++ lntemp/rpc/neutrino_kit.go | 54 ++++++++++++++++++++++++++++++++++++++ lntest/harness_node.go | 6 +++++ 3 files changed, 63 insertions(+) create mode 100644 lntemp/rpc/neutrino_kit.go diff --git a/lntemp/rpc/harness_rpc.go b/lntemp/rpc/harness_rpc.go index 855227c60..549d2dc76 100644 --- a/lntemp/rpc/harness_rpc.go +++ b/lntemp/rpc/harness_rpc.go @@ -8,6 +8,7 @@ import ( "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/chainrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" + "github.com/lightningnetwork/lnd/lnrpc/neutrinorpc" "github.com/lightningnetwork/lnd/lnrpc/peersrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/signrpc" @@ -40,6 +41,7 @@ type HarnessRPC struct { State lnrpc.StateClient ChainClient chainrpc.ChainNotifierClient ChainKit chainrpc.ChainKitClient + NeutrinoKit neutrinorpc.NeutrinoKitClient Peer peersrpc.PeersClient // Name is the HarnessNode's name. @@ -70,6 +72,7 @@ func NewHarnessRPC(ctxt context.Context, t *testing.T, c *grpc.ClientConn, State: lnrpc.NewStateClient(c), ChainClient: chainrpc.NewChainNotifierClient(c), ChainKit: chainrpc.NewChainKitClient(c), + NeutrinoKit: neutrinorpc.NewNeutrinoKitClient(c), Peer: peersrpc.NewPeersClient(c), Name: name, } diff --git a/lntemp/rpc/neutrino_kit.go b/lntemp/rpc/neutrino_kit.go new file mode 100644 index 000000000..9cde1eb14 --- /dev/null +++ b/lntemp/rpc/neutrino_kit.go @@ -0,0 +1,54 @@ +package rpc + +import ( + "context" + + "github.com/lightningnetwork/lnd/lnrpc/neutrinorpc" +) + +// ===================== +// NeutrinoKitClient related RPCs. +// ===================== + +// Status makes an RPC call to neutrino kit client's Status and asserts. +func (h *HarnessRPC) Status( + req *neutrinorpc.StatusRequest) *neutrinorpc.StatusResponse { + + if req == nil { + req = &neutrinorpc.StatusRequest{} + } + + ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout) + defer cancel() + + resp, err := h.NeutrinoKit.Status(ctxt, req) + h.NoError(err, "Status") + + return resp +} + +// GetCFilter makes an RPC call to neutrino kit client's GetCFilter and asserts. +func (h *HarnessRPC) GetCFilter( + req *neutrinorpc.GetCFilterRequest) *neutrinorpc.GetCFilterResponse { + + ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout) + defer cancel() + + resp, err := h.NeutrinoKit.GetCFilter(ctxt, req) + h.NoError(err, "GetCFilter") + + return resp +} + +// AddPeer makes an RPC call to neutrino kit client's AddPeer and asserts. +func (h *HarnessRPC) AddPeer( + req *neutrinorpc.AddPeerRequest) *neutrinorpc.AddPeerResponse { + + ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout) + defer cancel() + + resp, err := h.NeutrinoKit.AddPeer(ctxt, req) + h.NoError(err, "AddPeer") + + return resp +} diff --git a/lntest/harness_node.go b/lntest/harness_node.go index 74bb544f1..1eb0b9ac8 100644 --- a/lntest/harness_node.go +++ b/lntest/harness_node.go @@ -25,6 +25,7 @@ import ( "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/chainrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" + "github.com/lightningnetwork/lnd/lnrpc/neutrinorpc" "github.com/lightningnetwork/lnd/lnrpc/peersrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/signrpc" @@ -368,6 +369,7 @@ type HarnessNode struct { StateClient lnrpc.StateClient ChainClient chainrpc.ChainNotifierClient ChainKit chainrpc.ChainKitClient + NeutrinoClient neutrinorpc.NeutrinoKitClient } // RPCClients wraps a list of RPC clients into a single struct for easier @@ -387,6 +389,7 @@ type RPCClients struct { State lnrpc.StateClient ChainClient chainrpc.ChainNotifierClient ChainKit chainrpc.ChainKitClient + NeutrinoClient neutrinorpc.NeutrinoKitClient } // Assert *HarnessNode implements the lnrpc.LightningClient interface. @@ -941,6 +944,7 @@ func (hn *HarnessNode) InitRPCClients(c *grpc.ClientConn) { State: lnrpc.NewStateClient(c), ChainClient: chainrpc.NewChainNotifierClient(c), ChainKit: chainrpc.NewChainKitClient(c), + NeutrinoClient: neutrinorpc.NewNeutrinoKitClient(c), } } @@ -964,6 +968,7 @@ func (hn *HarnessNode) initLightningClient() error { hn.StateClient = lnrpc.NewStateClient(conn) hn.ChainClient = chainrpc.NewChainNotifierClient(conn) hn.ChainKit = chainrpc.NewChainKitClient(conn) + hn.NeutrinoClient = neutrinorpc.NewNeutrinoKitClient(conn) // Wait until the server is fully started. if err := hn.WaitUntilServerActive(); err != nil { @@ -1183,6 +1188,7 @@ func (hn *HarnessNode) stop() error { hn.WalletUnlockerClient = nil hn.Watchtower = nil hn.WatchtowerClient = nil + hn.NeutrinoClient = nil // Close any attempts at further grpc connections. if hn.rpc.conn != nil { From 20fd630465e39da2c9a20382b0c32e74c59b4539 Mon Sep 17 00:00:00 2001 From: ErikEk Date: Thu, 18 Aug 2022 18:16:27 +0200 Subject: [PATCH 2/3] itest: test neutrino sub server --- lntest/itest/list_on_test.go | 4 ++++ lntest/itest/lnd_neutrino_test.go | 33 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 lntest/itest/lnd_neutrino_test.go diff --git a/lntest/itest/list_on_test.go b/lntest/itest/list_on_test.go index bb94c7394..91e808e5e 100644 --- a/lntest/itest/list_on_test.go +++ b/lntest/itest/list_on_test.go @@ -227,4 +227,8 @@ var allTestCasesTemp = []*lntemp.TestCase{ Name: "chain kit", TestFunc: testChainKit, }, + { + Name: "neutrino kit", + TestFunc: testNeutrino, + }, } diff --git a/lntest/itest/lnd_neutrino_test.go b/lntest/itest/lnd_neutrino_test.go new file mode 100644 index 000000000..902eac430 --- /dev/null +++ b/lntest/itest/lnd_neutrino_test.go @@ -0,0 +1,33 @@ +package itest + +import ( + "github.com/lightningnetwork/lnd/lnrpc/neutrinorpc" + "github.com/lightningnetwork/lnd/lntemp" + "github.com/lightningnetwork/lnd/lntest" + "github.com/stretchr/testify/require" +) + +// testNeutrino checks that the neutrino sub-server can fetch compact +// block filters, server status and connect to a connected peer. +func testNeutrino(ht *lntemp.HarnessTest) { + if ht.ChainBackendName() != lntest.NeutrinoBackendName { + ht.Skipf("skipping test for non neutrino backends") + } + + // Check if the neutrino sub server is running. + statusRes := ht.Alice.RPC.Status(nil) + require.True(ht, statusRes.Active) + require.Len(ht, statusRes.Peers, 1, "unable to find a peer") + + // Request the compact block filter of the best block. + cFilterReq := &neutrinorpc.GetCFilterRequest{ + Hash: statusRes.GetBlockHash(), + } + ht.Alice.RPC.GetCFilter(cFilterReq) + + // Try to reconnect to a connected peer. + addPeerReq := &neutrinorpc.AddPeerRequest{ + PeerAddrs: statusRes.Peers[0], + } + ht.Alice.RPC.AddPeer(addPeerReq) +} From 520c63393810a645f15cc9c1ba74478bed60dab3 Mon Sep 17 00:00:00 2001 From: ErikEk Date: Thu, 18 Aug 2022 18:18:57 +0200 Subject: [PATCH 3/3] docs: update release note --- docs/release-notes/release-notes-0.16.0.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/release-notes/release-notes-0.16.0.md b/docs/release-notes/release-notes-0.16.0.md index d6c889a90..7326d2a15 100644 --- a/docs/release-notes/release-notes-0.16.0.md +++ b/docs/release-notes/release-notes-0.16.0.md @@ -139,6 +139,9 @@ certain large transactions](https://github.com/lightningnetwork/lnd/pull/7100). * [The macaroon key store implementation was refactored to be more generally usable](https://github.com/lightningnetwork/lnd/pull/6509). +* Add [an itest for the neutrino + sub-server](https://github.com/lightningnetwork/lnd/pull/6783). + * [Fixed a bug where cookie authentication with Tor would fail if the cookie path contained spaces](https://github.com/lightningnetwork/lnd/pull/6829). [With the module updated](https://github.com/lightningnetwork/lnd/pull/6836),