Merge pull request #4660 from yyforyongyu/add-temp-miner-logs
itest: save temp miner's logs
This commit is contained in:
commit
ef0bca7a8e
@ -2339,28 +2339,25 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Set up a new miner that we can use to cause a reorg.
|
// Set up a new miner that we can use to cause a reorg.
|
||||||
args := []string{
|
tempLogDir := "./.tempminerlogs"
|
||||||
"--rejectnonstd",
|
logFilename := "output-open_channel_reorg-temp_miner.log"
|
||||||
"--txindex",
|
tempMiner, tempMinerCleanUp, err := lntest.NewMiner(
|
||||||
"--nowinservice",
|
tempLogDir, logFilename,
|
||||||
"--nobanning",
|
harnessNetParams, &rpcclient.NotificationHandlers{},
|
||||||
}
|
|
||||||
tempMiner, err := rpctest.New(
|
|
||||||
harnessNetParams, &rpcclient.NotificationHandlers{}, args,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
require.NoError(t.t, err, "failed to create temp miner")
|
||||||
t.Fatalf("unable to create mining node: %v", err)
|
|
||||||
}
|
|
||||||
if err := tempMiner.SetUp(false, 0); err != nil {
|
|
||||||
t.Fatalf("unable to set up mining node: %v", err)
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
require.NoError(
|
require.NoError(
|
||||||
t.t, tempMiner.TearDown(),
|
t.t, tempMinerCleanUp(),
|
||||||
"failed to tear down temp miner",
|
"failed to clean up temp miner",
|
||||||
)
|
)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Setup the temp miner
|
||||||
|
require.NoError(
|
||||||
|
t.t, tempMiner.SetUp(false, 0), "unable to set up mining node",
|
||||||
|
)
|
||||||
|
|
||||||
// We start by connecting the new miner to our original miner,
|
// We start by connecting the new miner to our original miner,
|
||||||
// such that it will sync to our original chain.
|
// such that it will sync to our original chain.
|
||||||
err = net.Miner.Node.Node(
|
err = net.Miner.Node.Node(
|
||||||
@ -14060,43 +14057,18 @@ func TestLightningNetworkDaemon(t *testing.T) {
|
|||||||
//
|
//
|
||||||
// We will also connect it to our chain backend.
|
// We will also connect it to our chain backend.
|
||||||
minerLogDir := "./.minerlogs"
|
minerLogDir := "./.minerlogs"
|
||||||
args := []string{
|
|
||||||
"--rejectnonstd",
|
|
||||||
"--txindex",
|
|
||||||
"--debuglevel=debug",
|
|
||||||
"--logdir=" + minerLogDir,
|
|
||||||
"--trickleinterval=100ms",
|
|
||||||
"--nowinservice",
|
|
||||||
"--nobanning",
|
|
||||||
}
|
|
||||||
handlers := &rpcclient.NotificationHandlers{
|
handlers := &rpcclient.NotificationHandlers{
|
||||||
OnTxAccepted: func(hash *chainhash.Hash, amt btcutil.Amount) {
|
OnTxAccepted: func(hash *chainhash.Hash, amt btcutil.Amount) {
|
||||||
lndHarness.OnTxAccepted(hash)
|
lndHarness.OnTxAccepted(hash)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
miner, minerCleanUp, err := lntest.NewMiner(
|
||||||
miner, err := rpctest.New(harnessNetParams, handlers, args)
|
minerLogDir, "output_btcd_miner.log",
|
||||||
if err != nil {
|
harnessNetParams, handlers,
|
||||||
ht.Fatalf("unable to create mining node: %v", err)
|
)
|
||||||
}
|
require.NoError(t, err, "failed to create new miner")
|
||||||
defer func() {
|
defer func() {
|
||||||
require.NoError(
|
require.NoError(t, minerCleanUp(), "failed to clean up miner")
|
||||||
t, miner.TearDown(), "failed to tear down miner",
|
|
||||||
)
|
|
||||||
|
|
||||||
// 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(minerLogDir); err != nil {
|
|
||||||
fmt.Printf("Cannot remove dir %s: %v\n",
|
|
||||||
minerLogDir, err)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Start a chain backend.
|
// Start a chain backend.
|
||||||
|
@ -19,6 +19,8 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
|
"github.com/btcsuite/btcd/integration/rpctest"
|
||||||
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
@ -351,6 +353,59 @@ func newNode(cfg NodeConfig) (*HarnessNode, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMiner creates a new miner using btcd backend. The logDir specifies the
|
||||||
|
// miner node's log dir. When tests finished, during clean up, its logs are
|
||||||
|
// copied to a file specified as logFilename.
|
||||||
|
func NewMiner(logDir, logFilename string, netParams *chaincfg.Params,
|
||||||
|
handler *rpcclient.NotificationHandlers) (*rpctest.Harness,
|
||||||
|
func() error, error) {
|
||||||
|
|
||||||
|
args := []string{
|
||||||
|
"--rejectnonstd",
|
||||||
|
"--txindex",
|
||||||
|
"--nowinservice",
|
||||||
|
"--nobanning",
|
||||||
|
"--debuglevel=debug",
|
||||||
|
"--logdir=" + logDir,
|
||||||
|
"--trickleinterval=100ms",
|
||||||
|
}
|
||||||
|
|
||||||
|
miner, err := rpctest.New(netParams, handler, args)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf(
|
||||||
|
"unable to create mining node: %v", err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanUp := func() error {
|
||||||
|
if err := miner.TearDown(); err != nil {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"failed to tear down miner, got error: %s", err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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", logDir, netParams.Name,
|
||||||
|
)
|
||||||
|
copyPath := fmt.Sprintf("./%s", logFilename)
|
||||||
|
err := CopyFile(copyPath, logFile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to copy file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = os.RemoveAll(logDir); err != nil {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"cannot remove dir %s: %v", logDir, err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return miner, cleanUp, nil
|
||||||
|
}
|
||||||
|
|
||||||
// DBPath returns the filepath to the channeldb database file for this node.
|
// DBPath returns the filepath to the channeldb database file for this node.
|
||||||
func (hn *HarnessNode) DBPath() string {
|
func (hn *HarnessNode) DBPath() string {
|
||||||
return hn.Cfg.DBPath()
|
return hn.Cfg.DBPath()
|
||||||
|
Loading…
Reference in New Issue
Block a user