lnd_test+lntest: seperate miner and chain backend

Since we are no longer passing in the miner as the chain backend, we
don't have to export the fields.
This commit is contained in:
Johan T. Halseth 2018-12-14 09:24:00 +01:00
parent 989fe50da8
commit 92b984a233
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 54 additions and 42 deletions

@ -12930,54 +12930,73 @@ var testsCases = []*testCase{
func TestLightningNetworkDaemon(t *testing.T) {
ht := newHarnessTest(t)
// Start a btcd chain backend.
chainBackend, cleanUp, err := lntest.NewBtcdBackend()
if err != nil {
ht.Fatalf("unable to start btcd: %v", err)
}
defer cleanUp()
// Declare the network harness here to gain access to its
// 'OnTxAccepted' call back.
var lndHarness *lntest.NetworkHarness
// First create an instance of the btcd's rpctest.Harness. This will be
// used to fund the wallets of the nodes within the test network and to
// drive blockchain related events within the network. Revert the default
// setting of accepting non-standard transactions on simnet to reject them.
// Transactions on the lightning network should always be standard to get
// better guarantees of getting included in to blocks.
logDir := "./.backendlogs"
// Create an instance of the btcd's rpctest.Harness that will act as
// the miner for all tests. This will be used to fund the wallets of
// the nodes within the test network and to drive blockchain related
// events within the network. Revert the default setting of accepting
// non-standard transactions on simnet to reject them. Transactions on
// the lightning network should always be standard to get better
// guarantees of getting included in to blocks.
//
// We will also connect it to our chain backend.
minerLogDir := "./.minerlogs"
args := []string{
"--rejectnonstd",
"--txindex",
"--debuglevel=debug",
"--logdir=" + logDir,
"--logdir=" + minerLogDir,
"--trickleinterval=100ms",
"--connect=" + chainBackend.P2PAddr(),
}
handlers := &rpcclient.NotificationHandlers{
OnTxAccepted: func(hash *chainhash.Hash, amt btcutil.Amount) {
lndHarness.OnTxAccepted(hash)
},
}
btcdHarness, err := rpctest.New(harnessNetParams, handlers, args)
miner, err := rpctest.New(harnessNetParams, handlers, args)
if err != nil {
ht.Fatalf("unable to create mining node: %v", err)
}
defer func() {
btcdHarness.TearDown()
miner.TearDown()
// After shutting down the chain backend, we'll make a copy of
// the log file before deleting the temporary log dir.
logFile := logDir + "/" + harnessNetParams.Name + "/btcd.log"
err := lntest.CopyFile("./output_btcd_chainbackend.log",
logFile)
// After shutting down the miner, we'll make a copy of the log
// file before deleting the temporary log dir.
logFile := fmt.Sprintf(
"%s/%s/btcd.log", minerLogDir, harnessNetParams.Name,
)
err := lntest.CopyFile("./output_btcd_miner.log", logFile)
if err != nil {
fmt.Printf("unable to copy file: %v\n", err)
}
if err = os.RemoveAll(logDir); err != nil {
fmt.Printf("Cannot remove dir %s: %v\n", logDir, err)
if err = os.RemoveAll(minerLogDir); err != nil {
fmt.Printf("Cannot remove dir %s: %v\n",
minerLogDir, err)
}
}()
chainBackend := lntest.BtcdBackendConfig{
RPCConfig: btcdHarness.RPCConfig(),
P2PAddress: btcdHarness.P2PAddress(),
if err := miner.SetUp(true, 50); err != nil {
ht.Fatalf("unable to set up mining node: %v", err)
}
if err := miner.Node.NotifyNewTransactions(false); err != nil {
ht.Fatalf("unable to request transaction notifications: %v", err)
}
// First create the network harness to gain access to its
// 'OnTxAccepted' call back.
lndHarness, err = lntest.NewNetworkHarness(btcdHarness, chainBackend)
// Now we can set up our test harness (LND instance), with the chain
// backend we just created.
lndHarness, err = lntest.NewNetworkHarness(miner, chainBackend)
if err != nil {
ht.Fatalf("unable to create lightning network harness: %v", err)
}
@ -12999,17 +13018,10 @@ func TestLightningNetworkDaemon(t *testing.T) {
}
}()
if err := btcdHarness.SetUp(true, 50); err != nil {
ht.Fatalf("unable to set up mining node: %v", err)
}
if err := btcdHarness.Node.NotifyNewTransactions(false); err != nil {
ht.Fatalf("unable to request transaction notifications: %v", err)
}
// Next mine enough blocks in order for segwit and the CSV package
// soft-fork to activate on SimNet.
numBlocks := chaincfg.SimNetParams.MinerConfirmationWindow * 2
if _, err := btcdHarness.Node.Generate(numBlocks); err != nil {
if _, err := miner.Node.Generate(numBlocks); err != nil {
ht.Fatalf("unable to generate blocks: %v", err)
}

@ -16,22 +16,22 @@ const logDir = "./.backendlogs"
// BtcdBackendConfig is an implementation of the BackendConfig interface
// backed by a btcd node.
type BtcdBackendConfig struct {
// RPCConfig houses the connection config to the backing btcd instance.
RPCConfig rpcclient.ConnConfig
// rpcConfig houses the connection config to the backing btcd instance.
rpcConfig rpcclient.ConnConfig
// P2PAddress is the p2p address of the btcd instance.
P2PAddress string
// p2pAddress is the p2p address of the btcd instance.
p2pAddress string
}
// GenArgs returns the arguments needed to be passed to LND at startup for
// using this node as a chain backend.
func (b BtcdBackendConfig) GenArgs() []string {
var args []string
encodedCert := hex.EncodeToString(b.RPCConfig.Certificates)
encodedCert := hex.EncodeToString(b.rpcConfig.Certificates)
args = append(args, "--bitcoin.node=btcd")
args = append(args, fmt.Sprintf("--btcd.rpchost=%v", b.RPCConfig.Host))
args = append(args, fmt.Sprintf("--btcd.rpcuser=%v", b.RPCConfig.User))
args = append(args, fmt.Sprintf("--btcd.rpcpass=%v", b.RPCConfig.Pass))
args = append(args, fmt.Sprintf("--btcd.rpchost=%v", b.rpcConfig.Host))
args = append(args, fmt.Sprintf("--btcd.rpcuser=%v", b.rpcConfig.User))
args = append(args, fmt.Sprintf("--btcd.rpcpass=%v", b.rpcConfig.Pass))
args = append(args, fmt.Sprintf("--btcd.rawrpccert=%v", encodedCert))
return args
@ -40,7 +40,7 @@ func (b BtcdBackendConfig) GenArgs() []string {
// P2PAddr returns the address of this node to be used when connection over the
// Bitcoin P2P network.
func (b BtcdBackendConfig) P2PAddr() string {
return b.P2PAddress
return b.p2pAddress
}
// NewBtcdBackend starts a new rpctest.Harness and returns a BtcdBackendConfig
@ -64,8 +64,8 @@ func NewBtcdBackend() (*BtcdBackendConfig, func(), error) {
}
bd := &BtcdBackendConfig{
RPCConfig: chainBackend.RPCConfig(),
P2PAddress: chainBackend.P2PAddress(),
rpcConfig: chainBackend.RPCConfig(),
p2pAddress: chainBackend.P2PAddress(),
}
cleanUp := func() {