• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 13035292482

29 Jan 2025 03:59PM UTC coverage: 49.3% (-9.5%) from 58.777%
13035292482

Pull #9456

github

mohamedawnallah
docs: update release-notes-0.19.0.md

In this commit, we warn users about the removal
of RPCs `SendToRoute`, `SendToRouteSync`, `SendPayment`,
and `SendPaymentSync` in the next release 0.20.
Pull Request #9456: lnrpc+docs: deprecate warning `SendToRoute`, `SendToRouteSync`, `SendPayment`, and `SendPaymentSync` in Release 0.19

100634 of 204126 relevant lines covered (49.3%)

1.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.93
/lntest/unittest/backend.go
1
package unittest
2

3
import (
4
        "fmt"
5
        "os/exec"
6
        "path/filepath"
7
        "testing"
8
        "time"
9

10
        "github.com/btcsuite/btcd/chaincfg"
11
        "github.com/btcsuite/btcd/integration/rpctest"
12
        "github.com/btcsuite/btcwallet/chain"
13
        "github.com/btcsuite/btcwallet/walletdb"
14
        "github.com/lightninglabs/neutrino"
15
        "github.com/lightningnetwork/lnd/kvdb"
16
        "github.com/lightningnetwork/lnd/lntest/port"
17
        "github.com/lightningnetwork/lnd/lntest/wait"
18
        "github.com/stretchr/testify/require"
19
)
20

21
var (
22
        // TrickleInterval is the interval at which the miner should trickle
23
        // transactions to its peers. We'll set it small to ensure the miner
24
        // propagates transactions quickly in the tests.
25
        TrickleInterval = 10 * time.Millisecond
26
)
27

28
var (
29
        // NetParams are the default network parameters for the tests.
30
        NetParams = &chaincfg.RegressionNetParams
31
)
32

33
// NewMiner spawns testing harness backed by a btcd node that can serve as a
34
// miner.
35
func NewMiner(t *testing.T, netParams *chaincfg.Params, extraArgs []string,
36
        createChain bool, spendableOutputs uint32) *rpctest.Harness {
×
37

×
38
        t.Helper()
×
39

×
40
        // Add the trickle interval argument to the extra args.
×
41
        trickle := fmt.Sprintf("--trickleinterval=%v", TrickleInterval)
×
42
        extraArgs = append(extraArgs, trickle)
×
43

×
44
        node, err := rpctest.New(netParams, nil, extraArgs, "")
×
45
        require.NoError(t, err, "unable to create backend node")
×
46
        t.Cleanup(func() {
×
47
                require.NoError(t, node.TearDown())
×
48
        })
×
49

50
        // We want to overwrite some of the connection settings to make the
51
        // tests more robust. We might need to restart the backend while there
52
        // are already blocks present, which will take a bit longer than the
53
        // 1 second the default settings amount to. Doubling both values will
54
        // give us retries up to 4 seconds.
55
        node.MaxConnRetries = rpctest.DefaultMaxConnectionRetries * 2
×
56
        node.ConnectionRetryTimeout = rpctest.DefaultConnectionRetryTimeout * 2
×
57

×
58
        if err := node.SetUp(createChain, spendableOutputs); err != nil {
×
59
                t.Fatalf("unable to set up backend node: %v", err)
×
60
        }
×
61

62
        // Next mine enough blocks in order for segwit and the CSV package
63
        // soft-fork to activate.
64
        numBlocks := netParams.MinerConfirmationWindow*2 + 17
×
65
        _, err = node.Client.Generate(numBlocks)
×
66
        require.NoError(t, err, "failed to generate blocks")
×
67

×
68
        return node
×
69
}
70

71
// NewBitcoindBackend spawns a new bitcoind node that connects to a miner at the
72
// specified address. The txindex boolean can be set to determine whether the
73
// backend node should maintain a transaction index. The rpcpolling boolean
74
// can be set to determine whether bitcoind's RPC polling interface should be
75
// used for block and tx notifications or if its ZMQ interface should be used.
76
// A connection to the newly spawned bitcoind node is returned.
77
func NewBitcoindBackend(t *testing.T, netParams *chaincfg.Params,
78
        minerAddr string, txindex, rpcpolling bool) *chain.BitcoindConn {
×
79

×
80
        t.Helper()
×
81

×
82
        tempBitcoindDir := t.TempDir()
×
83

×
84
        rpcPort := port.NextAvailablePort()
×
85
        torBindPort := port.NextAvailablePort()
×
86
        zmqBlockPort := port.NextAvailablePort()
×
87
        zmqTxPort := port.NextAvailablePort()
×
88
        zmqBlockHost := fmt.Sprintf("tcp://127.0.0.1:%d", zmqBlockPort)
×
89
        zmqTxHost := fmt.Sprintf("tcp://127.0.0.1:%d", zmqTxPort)
×
90

×
91
        args := []string{
×
92
                "-connect=" + minerAddr,
×
93
                "-datadir=" + tempBitcoindDir,
×
94
                "-regtest",
×
95
                "-rpcauth=weks:469e9bb14ab2360f8e226efed5ca6fd$507c670e800a95" +
×
96
                        "284294edb5773b05544b220110063096c221be9933c82d38e1",
×
97
                fmt.Sprintf("-rpcport=%d", rpcPort),
×
98
                fmt.Sprintf("-bind=127.0.0.1:%d=onion", torBindPort),
×
99
                "-disablewallet",
×
100
                "-zmqpubrawblock=" + zmqBlockHost,
×
101
                "-zmqpubrawtx=" + zmqTxHost,
×
102
        }
×
103
        if txindex {
×
104
                args = append(args, "-txindex")
×
105
        }
×
106

107
        bitcoind := exec.Command("bitcoind", args...)
×
108
        if err := bitcoind.Start(); err != nil {
×
109
                t.Fatalf("unable to start bitcoind: %v", err)
×
110
        }
×
111
        t.Cleanup(func() {
×
112
                _ = bitcoind.Process.Kill()
×
113
                _ = bitcoind.Wait()
×
114
        })
×
115

116
        // Wait for the bitcoind instance to start up.
117
        time.Sleep(time.Second)
×
118

×
119
        host := fmt.Sprintf("127.0.0.1:%d", rpcPort)
×
120
        cfg := &chain.BitcoindConfig{
×
121
                ChainParams: netParams,
×
122
                Host:        host,
×
123
                User:        "weks",
×
124
                Pass:        "weks",
×
125
                // Fields only required for pruned nodes, not needed for these
×
126
                // tests.
×
127
                Dialer:             nil,
×
128
                PrunedModeMaxPeers: 0,
×
129
        }
×
130

×
131
        if rpcpolling {
×
132
                cfg.PollingConfig = &chain.PollingConfig{
×
133
                        BlockPollingInterval: time.Millisecond * 20,
×
134
                        TxPollingInterval:    time.Millisecond * 20,
×
135
                }
×
136
        } else {
×
137
                cfg.ZMQConfig = &chain.ZMQConfig{
×
138
                        ZMQBlockHost:    zmqBlockHost,
×
139
                        ZMQTxHost:       zmqTxHost,
×
140
                        ZMQReadDeadline: 5 * time.Second,
×
141
                }
×
142
        }
×
143

144
        var conn *chain.BitcoindConn
×
145
        err := wait.NoError(func() error {
×
146
                var err error
×
147
                conn, err = chain.NewBitcoindConn(cfg)
×
148
                if err != nil {
×
149
                        return err
×
150
                }
×
151

152
                return conn.Start()
×
153
        }, 10*time.Second)
154
        if err != nil {
×
155
                t.Fatalf("unable to establish connection to bitcoind at %v: "+
×
156
                        "%v", tempBitcoindDir, err)
×
157
        }
×
158
        t.Cleanup(conn.Stop)
×
159

×
160
        return conn
×
161
}
162

163
// NewNeutrinoBackend spawns a new neutrino node that connects to a miner at
164
// the specified address.
165
func NewNeutrinoBackend(t *testing.T, netParams *chaincfg.Params,
166
        minerAddr string) *neutrino.ChainService {
×
167

×
168
        t.Helper()
×
169

×
170
        spvDir := t.TempDir()
×
171

×
172
        dbName := filepath.Join(spvDir, "neutrino.db")
×
173
        spvDatabase, err := walletdb.Create(
×
174
                "bdb", dbName, true, kvdb.DefaultDBTimeout,
×
175
        )
×
176
        if err != nil {
×
177
                t.Fatalf("unable to create walletdb: %v", err)
×
178
        }
×
179
        t.Cleanup(func() {
×
180
                spvDatabase.Close()
×
181
        })
×
182

183
        // Create an instance of neutrino connected to the running btcd
184
        // instance.
185
        spvConfig := neutrino.Config{
×
186
                DataDir:      spvDir,
×
187
                Database:     spvDatabase,
×
188
                ChainParams:  *netParams,
×
189
                ConnectPeers: []string{minerAddr},
×
190
        }
×
191
        spvNode, err := neutrino.NewChainService(spvConfig)
×
192
        if err != nil {
×
193
                t.Fatalf("unable to create neutrino: %v", err)
×
194
        }
×
195

196
        // We'll also wait for the instance to sync up fully to the chain
197
        // generated by the btcd instance.
198
        _ = spvNode.Start()
×
199
        for !spvNode.IsCurrent() {
×
200
                time.Sleep(time.Millisecond * 100)
×
201
        }
×
202
        t.Cleanup(func() {
×
203
                _ = spvNode.Stop()
×
204
        })
×
205

206
        return spvNode
×
207
}
208

209
func init() {
3✔
210
        // Before we start any node, we need to make sure that any btcd or
3✔
211
        // bitcoind node that is started through the RPC harness uses a unique
3✔
212
        // port as well to avoid any port collisions.
3✔
213
        rpctest.ListenAddressGenerator =
3✔
214
                port.GenerateSystemUniqueListenerAddresses
3✔
215
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc