From 9100be5ba53af32e3c7133013fdfb518442b36d1 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Sat, 21 Jun 2025 12:19:31 -0300 Subject: [PATCH] lntest: add method P2PAddr to backend It is useful if we want to keep bitcoind main itest mode, but connect one node using neutrino. --- lntest/bitcoind_common.go | 5 +++++ lntest/btcd.go | 5 +++++ lntest/neutrino.go | 5 +++++ lntest/node/config.go | 3 +++ 4 files changed, 18 insertions(+) diff --git a/lntest/bitcoind_common.go b/lntest/bitcoind_common.go index ed3c45f02..6d5cacc43 100644 --- a/lntest/bitcoind_common.go +++ b/lntest/bitcoind_common.go @@ -85,6 +85,11 @@ func (b BitcoindBackendConfig) Name() string { return "bitcoind" } +// P2PAddr return bitcoin p2p ip:port. +func (b BitcoindBackendConfig) P2PAddr() (string, error) { + return fmt.Sprintf("127.0.0.1:%d", b.p2pPort), nil +} + // newBackend starts a bitcoind node with the given extra parameters and returns // a BitcoindBackendConfig for that node. func newBackend(miner string, netParams *chaincfg.Params, extraArgs []string, diff --git a/lntest/btcd.go b/lntest/btcd.go index 91b25411c..21c343243 100644 --- a/lntest/btcd.go +++ b/lntest/btcd.go @@ -74,6 +74,11 @@ func (b BtcdBackendConfig) Name() string { return "btcd" } +// P2PAddr return bitcoin p2p ip:port. +func (b BtcdBackendConfig) P2PAddr() (string, error) { + return b.harness.P2PAddress(), nil +} + // NewBackend starts a new rpctest.Harness and returns a BtcdBackendConfig for // that node. miner should be set to the P2P address of the miner to connect // to. diff --git a/lntest/neutrino.go b/lntest/neutrino.go index 11f13612f..568007097 100644 --- a/lntest/neutrino.go +++ b/lntest/neutrino.go @@ -54,6 +54,11 @@ func (b NeutrinoBackendConfig) Name() string { return NeutrinoBackendName } +// P2PAddr return bitcoin p2p ip:port. +func (b NeutrinoBackendConfig) P2PAddr() (string, error) { + return b.minerAddr, nil +} + // NewBackend starts and returns a NeutrinoBackendConfig for the node. func NewBackend(miner string, _ *chaincfg.Params) ( *NeutrinoBackendConfig, func() error, error) { diff --git a/lntest/node/config.go b/lntest/node/config.go index 168dc87ec..bd003eb01 100644 --- a/lntest/node/config.go +++ b/lntest/node/config.go @@ -114,6 +114,9 @@ type BackendConfig interface { // Credentials returns the rpc username, password and host for the // backend. Credentials() (string, string, string, error) + + // P2PAddr return bitcoin p2p ip:port. + P2PAddr() (string, error) } // BaseNodeConfig is the base node configuration.