mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-18 12:52:25 +02:00
lntest: create new package lntest/miner
for itest miner
This commit moves the `HarnessMiner` into a new package to avoid confusion about incoming changes.
This commit is contained in:
parent
578e1d4965
commit
a881477404
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/btcsuite/btcd/integration/rpctest"
|
"github.com/btcsuite/btcd/integration/rpctest"
|
||||||
"github.com/btcsuite/btcd/rpcclient"
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
|
"github.com/lightningnetwork/lnd/lntest/miner"
|
||||||
"github.com/lightningnetwork/lnd/lntest/node"
|
"github.com/lightningnetwork/lnd/lntest/node"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -53,12 +54,14 @@ func (b BtcdBackendConfig) GenArgs() []string {
|
|||||||
|
|
||||||
// ConnectMiner is called to establish a connection to the test miner.
|
// ConnectMiner is called to establish a connection to the test miner.
|
||||||
func (b BtcdBackendConfig) ConnectMiner() error {
|
func (b BtcdBackendConfig) ConnectMiner() error {
|
||||||
return b.harness.Client.Node(btcjson.NConnect, b.minerAddr, &temp)
|
return b.harness.Client.Node(btcjson.NConnect, b.minerAddr, &miner.Temp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisconnectMiner is called to disconnect the miner.
|
// DisconnectMiner is called to disconnect the miner.
|
||||||
func (b BtcdBackendConfig) DisconnectMiner() error {
|
func (b BtcdBackendConfig) DisconnectMiner() error {
|
||||||
return b.harness.Client.Node(btcjson.NDisconnect, b.minerAddr, &temp)
|
return b.harness.Client.Node(
|
||||||
|
btcjson.NDisconnect, b.minerAddr, &miner.Temp,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Credentials returns the rpc username, password and host for the backend.
|
// Credentials returns the rpc username, password and host for the backend.
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
||||||
|
"github.com/lightningnetwork/lnd/lntest/miner"
|
||||||
"github.com/lightningnetwork/lnd/lntest/node"
|
"github.com/lightningnetwork/lnd/lntest/node"
|
||||||
"github.com/lightningnetwork/lnd/lntest/rpc"
|
"github.com/lightningnetwork/lnd/lntest/rpc"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
@ -78,7 +79,7 @@ type HarnessTest struct {
|
|||||||
|
|
||||||
// Miner is a reference to a running full node that can be used to
|
// Miner is a reference to a running full node that can be used to
|
||||||
// create new blocks on the network.
|
// create new blocks on the network.
|
||||||
Miner *HarnessMiner
|
Miner *miner.HarnessMiner
|
||||||
|
|
||||||
// manager handles the start and stop of a given node.
|
// manager handles the start and stop of a given node.
|
||||||
manager *nodeManager
|
manager *nodeManager
|
||||||
@ -158,7 +159,9 @@ func NewHarnessTest(t *testing.T, lndBinary string, feeService WebFeeService,
|
|||||||
|
|
||||||
// Start will assemble the chain backend and the miner for the HarnessTest. It
|
// Start will assemble the chain backend and the miner for the HarnessTest. It
|
||||||
// also starts the fee service and watches lnd process error.
|
// also starts the fee service and watches lnd process error.
|
||||||
func (h *HarnessTest) Start(chain node.BackendConfig, miner *HarnessMiner) {
|
func (h *HarnessTest) Start(chain node.BackendConfig,
|
||||||
|
miner *miner.HarnessMiner) {
|
||||||
|
|
||||||
// Spawn a new goroutine to watch for any fatal errors that any of the
|
// Spawn a new goroutine to watch for any fatal errors that any of the
|
||||||
// running lnd processes encounter. If an error occurs, then the test
|
// running lnd processes encounter. If an error occurs, then the test
|
||||||
// case should naturally as a result and we log the server error here
|
// case should naturally as a result and we log the server error here
|
||||||
@ -1599,7 +1602,7 @@ func (h *HarnessTest) OpenChannelPsbt(srcNode, destNode *node.HarnessNode,
|
|||||||
// Make sure the channel funding address has the correct type for the
|
// Make sure the channel funding address has the correct type for the
|
||||||
// given commitment type.
|
// given commitment type.
|
||||||
fundingAddr, err := btcutil.DecodeAddress(
|
fundingAddr, err := btcutil.DecodeAddress(
|
||||||
upd.PsbtFund.FundingAddress, harnessNetParams,
|
upd.PsbtFund.FundingAddress, miner.HarnessNetParams,
|
||||||
)
|
)
|
||||||
require.NoError(h, err)
|
require.NoError(h, err)
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
||||||
|
"github.com/lightningnetwork/lnd/lntest/miner"
|
||||||
"github.com/lightningnetwork/lnd/lntest/node"
|
"github.com/lightningnetwork/lnd/lntest/node"
|
||||||
"github.com/lightningnetwork/lnd/lntest/rpc"
|
"github.com/lightningnetwork/lnd/lntest/rpc"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
@ -937,7 +938,7 @@ func (h *HarnessTest) RandomPreimage() lntypes.Preimage {
|
|||||||
|
|
||||||
// DecodeAddress decodes a given address and asserts there's no error.
|
// DecodeAddress decodes a given address and asserts there's no error.
|
||||||
func (h *HarnessTest) DecodeAddress(addr string) btcutil.Address {
|
func (h *HarnessTest) DecodeAddress(addr string) btcutil.Address {
|
||||||
resp, err := btcutil.DecodeAddress(addr, harnessNetParams)
|
resp, err := btcutil.DecodeAddress(addr, miner.HarnessNetParams)
|
||||||
require.NoError(h, err, "DecodeAddress failed")
|
require.NoError(h, err, "DecodeAddress failed")
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
@ -2015,6 +2016,7 @@ func (h *HarnessTest) CreateBurnAddr(addrType lnrpc.AddressType) ([]byte,
|
|||||||
require.NoError(h, err)
|
require.NoError(h, err)
|
||||||
|
|
||||||
randomKeyBytes := randomPrivKey.PubKey().SerializeCompressed()
|
randomKeyBytes := randomPrivKey.PubKey().SerializeCompressed()
|
||||||
|
harnessNetParams := miner.HarnessNetParams
|
||||||
|
|
||||||
var addr btcutil.Address
|
var addr btcutil.Address
|
||||||
switch addrType {
|
switch addrType {
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
|
"github.com/lightningnetwork/lnd/lntest/miner"
|
||||||
"github.com/lightningnetwork/lnd/lntest/node"
|
"github.com/lightningnetwork/lnd/lntest/node"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
)
|
)
|
||||||
@ -88,7 +89,7 @@ func (nm *nodeManager) newNode(t *testing.T, name string, extraArgs []string,
|
|||||||
NativeSQL: nm.nativeSQL,
|
NativeSQL: nm.nativeSQL,
|
||||||
NodeID: nm.nextNodeID(),
|
NodeID: nm.nextNodeID(),
|
||||||
LndBinary: nm.lndBinary,
|
LndBinary: nm.lndBinary,
|
||||||
NetParams: harnessNetParams,
|
NetParams: miner.HarnessNetParams,
|
||||||
SkipUnlock: noAuth,
|
SkipUnlock: noAuth,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/integration/rpctest"
|
"github.com/btcsuite/btcd/integration/rpctest"
|
||||||
|
"github.com/lightningnetwork/lnd/lntest/miner"
|
||||||
"github.com/lightningnetwork/lnd/lntest/node"
|
"github.com/lightningnetwork/lnd/lntest/node"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -65,27 +66,27 @@ func SetupHarness(t *testing.T, binaryPath, dbBackendName string,
|
|||||||
// transactions on simnet to reject them. Transactions on the lightning network
|
// transactions on simnet to reject them. Transactions on the lightning network
|
||||||
// should always be standard to get better guarantees of getting included in to
|
// should always be standard to get better guarantees of getting included in to
|
||||||
// blocks.
|
// blocks.
|
||||||
func prepareMiner(ctxt context.Context, t *testing.T) *HarnessMiner {
|
func prepareMiner(ctxt context.Context, t *testing.T) *miner.HarnessMiner {
|
||||||
miner := NewMiner(ctxt, t)
|
m := miner.NewMiner(ctxt, t)
|
||||||
|
|
||||||
// Before we start anything, we want to overwrite some of the
|
// Before we start anything, we want to overwrite some of the
|
||||||
// connection settings to make the tests more robust. We might need to
|
// connection settings to make the tests more robust. We might need to
|
||||||
// restart the miner while there are already blocks present, which will
|
// restart the miner while there are already blocks present, which will
|
||||||
// take a bit longer than the 1 second the default settings amount to.
|
// take a bit longer than the 1 second the default settings amount to.
|
||||||
// Doubling both values will give us retries up to 4 seconds.
|
// Doubling both values will give us retries up to 4 seconds.
|
||||||
miner.MaxConnRetries = rpctest.DefaultMaxConnectionRetries * 2
|
m.MaxConnRetries = rpctest.DefaultMaxConnectionRetries * 2
|
||||||
miner.ConnectionRetryTimeout = rpctest.DefaultConnectionRetryTimeout * 2
|
m.ConnectionRetryTimeout = rpctest.DefaultConnectionRetryTimeout * 2
|
||||||
|
|
||||||
// Set up miner and connect chain backend to it.
|
// Set up miner and connect chain backend to it.
|
||||||
require.NoError(t, miner.SetUp(true, 50))
|
require.NoError(t, m.SetUp(true, 50))
|
||||||
require.NoError(t, miner.Client.NotifyNewTransactions(false))
|
require.NoError(t, m.Client.NotifyNewTransactions(false))
|
||||||
|
|
||||||
// Next mine enough blocks in order for segwit and the CSV package
|
// Next mine enough blocks in order for segwit and the CSV package
|
||||||
// soft-fork to activate on SimNet.
|
// soft-fork to activate on SimNet.
|
||||||
numBlocks := harnessNetParams.MinerConfirmationWindow * 2
|
numBlocks := miner.HarnessNetParams.MinerConfirmationWindow * 2
|
||||||
miner.GenerateBlocks(numBlocks)
|
m.GenerateBlocks(numBlocks)
|
||||||
|
|
||||||
return miner
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepareChainBackend creates a new chain backend.
|
// prepareChainBackend creates a new chain backend.
|
||||||
@ -93,7 +94,7 @@ func prepareChainBackend(t *testing.T,
|
|||||||
minerAddr string) (node.BackendConfig, func()) {
|
minerAddr string) (node.BackendConfig, func()) {
|
||||||
|
|
||||||
chainBackend, cleanUp, err := NewBackend(
|
chainBackend, cleanUp, err := NewBackend(
|
||||||
minerAddr, harnessNetParams,
|
minerAddr, miner.HarnessNetParams,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "new backend")
|
require.NoError(t, err, "new backend")
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package lntest
|
package miner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -34,13 +34,13 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
harnessNetParams = &chaincfg.RegressionNetParams
|
HarnessNetParams = &chaincfg.RegressionNetParams
|
||||||
|
|
||||||
// temp is used to signal we want to establish a temporary connection
|
// temp is used to signal we want to establish a temporary connection
|
||||||
// using the btcd Node API.
|
// using the btcd Node API.
|
||||||
//
|
//
|
||||||
// NOTE: Cannot be const, since the node API expects a reference.
|
// NOTE: Cannot be const, since the node API expects a reference.
|
||||||
temp = "temp"
|
Temp = "temp"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HarnessMiner struct {
|
type HarnessMiner struct {
|
||||||
@ -99,7 +99,7 @@ func newMiner(ctxb context.Context, t *testing.T, minerDirName,
|
|||||||
"--nostalldetect",
|
"--nostalldetect",
|
||||||
}
|
}
|
||||||
|
|
||||||
miner, err := rpctest.New(harnessNetParams, handler, args, btcdBinary)
|
miner, err := rpctest.New(HarnessNetParams, handler, args, btcdBinary)
|
||||||
require.NoError(t, err, "unable to create mining node")
|
require.NoError(t, err, "unable to create mining node")
|
||||||
|
|
||||||
ctxt, cancel := context.WithCancel(ctxb)
|
ctxt, cancel := context.WithCancel(ctxb)
|
||||||
@ -119,7 +119,7 @@ func newMiner(ctxb context.Context, t *testing.T, minerDirName,
|
|||||||
func (h *HarnessMiner) saveLogs() {
|
func (h *HarnessMiner) saveLogs() {
|
||||||
// After shutting down the miner, we'll make a copy of the log files
|
// After shutting down the miner, we'll make a copy of the log files
|
||||||
// before deleting the temporary log dir.
|
// before deleting the temporary log dir.
|
||||||
path := fmt.Sprintf("%s/%s", h.logPath, harnessNetParams.Name)
|
path := fmt.Sprintf("%s/%s", h.logPath, HarnessNetParams.Name)
|
||||||
files, err := os.ReadDir(path)
|
files, err := os.ReadDir(path)
|
||||||
require.NoError(h, err, "unable to read log directory")
|
require.NoError(h, err, "unable to read log directory")
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ func (h *HarnessMiner) saveLogs() {
|
|||||||
copyPath := fmt.Sprintf("%s/../%s", h.logPath, newFilename)
|
copyPath := fmt.Sprintf("%s/../%s", h.logPath, newFilename)
|
||||||
|
|
||||||
logFile := fmt.Sprintf("%s/%s", path, file.Name())
|
logFile := fmt.Sprintf("%s/%s", path, file.Name())
|
||||||
err := CopyFile(filepath.Clean(copyPath), logFile)
|
err := node.CopyFile(filepath.Clean(copyPath), logFile)
|
||||||
require.NoError(h, err, "unable to copy file")
|
require.NoError(h, err, "unable to copy file")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,7 +533,7 @@ func (h *HarnessMiner) SpawnTempMiner() *HarnessMiner {
|
|||||||
require.NoError(tempMiner.SetUp(false, 0), "unable to setup miner")
|
require.NoError(tempMiner.SetUp(false, 0), "unable to setup miner")
|
||||||
|
|
||||||
// Connect the temp miner to the original miner.
|
// Connect the temp miner to the original miner.
|
||||||
err := h.Client.Node(btcjson.NConnect, tempMiner.P2PAddress(), &temp)
|
err := h.Client.Node(btcjson.NConnect, tempMiner.P2PAddress(), &Temp)
|
||||||
require.NoError(err, "unable to connect node")
|
require.NoError(err, "unable to connect node")
|
||||||
|
|
||||||
// Sync the blocks.
|
// Sync the blocks.
|
||||||
@ -546,7 +546,7 @@ func (h *HarnessMiner) SpawnTempMiner() *HarnessMiner {
|
|||||||
|
|
||||||
// Once synced, we now disconnect the temp miner so it'll be
|
// Once synced, we now disconnect the temp miner so it'll be
|
||||||
// independent from the original miner.
|
// independent from the original miner.
|
||||||
err = h.Client.Node(btcjson.NDisconnect, tempMiner.P2PAddress(), &temp)
|
err = h.Client.Node(btcjson.NDisconnect, tempMiner.P2PAddress(), &Temp)
|
||||||
require.NoError(err, "unable to disconnect miners")
|
require.NoError(err, "unable to disconnect miners")
|
||||||
|
|
||||||
return tempMiner
|
return tempMiner
|
||||||
@ -557,7 +557,7 @@ func (h *HarnessMiner) ConnectMiner(tempMiner *HarnessMiner) {
|
|||||||
require := require.New(h.T)
|
require := require.New(h.T)
|
||||||
|
|
||||||
// Connect the current miner to the temporary miner.
|
// Connect the current miner to the temporary miner.
|
||||||
err := h.Client.Node(btcjson.NConnect, tempMiner.P2PAddress(), &temp)
|
err := h.Client.Node(btcjson.NConnect, tempMiner.P2PAddress(), &Temp)
|
||||||
require.NoError(err, "unable to connect temp miner")
|
require.NoError(err, "unable to connect temp miner")
|
||||||
|
|
||||||
nodes := []*rpctest.Harness{tempMiner.Harness, h.Harness}
|
nodes := []*rpctest.Harness{tempMiner.Harness, h.Harness}
|
||||||
@ -567,7 +567,7 @@ func (h *HarnessMiner) ConnectMiner(tempMiner *HarnessMiner) {
|
|||||||
|
|
||||||
// DisconnectMiner disconnects the miner from the temp miner.
|
// DisconnectMiner disconnects the miner from the temp miner.
|
||||||
func (h *HarnessMiner) DisconnectMiner(tempMiner *HarnessMiner) {
|
func (h *HarnessMiner) DisconnectMiner(tempMiner *HarnessMiner) {
|
||||||
err := h.Client.Node(btcjson.NDisconnect, tempMiner.P2PAddress(), &temp)
|
err := h.Client.Node(btcjson.NDisconnect, tempMiner.P2PAddress(), &Temp)
|
||||||
require.NoError(h.T, err, "unable to disconnect temp miner")
|
require.NoError(h.T, err, "unable to disconnect temp miner")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -597,6 +597,6 @@ func (h *HarnessMiner) AssertMinerBlockHeightDelta(tempMiner *HarnessMiner,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, DefaultTimeout)
|
}, wait.DefaultTimeout)
|
||||||
require.NoError(h.T, err, "failed to assert block height delta")
|
require.NoError(h.T, err, "failed to assert block height delta")
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user