lntest: use nextAvailablePort for bitcoind

This commit is contained in:
Oliver Gugger 2020-11-04 11:03:27 +01:00
parent 5c04449dfd
commit 891eb0d63d
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/rand"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -93,10 +92,10 @@ func newBackend(miner string, netParams *chaincfg.Params, extraArgs []string) (
fmt.Errorf("unable to create temp directory: %v", err) fmt.Errorf("unable to create temp directory: %v", err)
} }
zmqBlockPath := "ipc:///" + tempBitcoindDir + "/blocks.socket" zmqBlockAddr := fmt.Sprintf("tcp://127.0.0.1:%d", nextAvailablePort())
zmqTxPath := "ipc:///" + tempBitcoindDir + "/txs.socket" zmqTxAddr := fmt.Sprintf("tcp://127.0.0.1:%d", nextAvailablePort())
rpcPort := rand.Int()%(65536-1024) + 1024 rpcPort := nextAvailablePort()
p2pPort := rand.Int()%(65536-1024) + 1024 p2pPort := nextAvailablePort()
cmdArgs := []string{ cmdArgs := []string{
"-datadir=" + tempBitcoindDir, "-datadir=" + tempBitcoindDir,
@ -106,8 +105,8 @@ func newBackend(miner string, netParams *chaincfg.Params, extraArgs []string) (
"220110063096c221be9933c82d38e1", "220110063096c221be9933c82d38e1",
fmt.Sprintf("-rpcport=%d", rpcPort), fmt.Sprintf("-rpcport=%d", rpcPort),
fmt.Sprintf("-port=%d", p2pPort), fmt.Sprintf("-port=%d", p2pPort),
"-zmqpubrawblock=" + zmqBlockPath, "-zmqpubrawblock=" + zmqBlockAddr,
"-zmqpubrawtx=" + zmqTxPath, "-zmqpubrawtx=" + zmqTxAddr,
"-debuglogfile=" + logFile, "-debuglogfile=" + logFile,
} }
cmdArgs = append(cmdArgs, extraArgs...) cmdArgs = append(cmdArgs, extraArgs...)
@ -178,8 +177,8 @@ func newBackend(miner string, netParams *chaincfg.Params, extraArgs []string) (
rpcHost: rpcHost, rpcHost: rpcHost,
rpcUser: rpcUser, rpcUser: rpcUser,
rpcPass: rpcPass, rpcPass: rpcPass,
zmqBlockPath: zmqBlockPath, zmqBlockPath: zmqBlockAddr,
zmqTxPath: zmqTxPath, zmqTxPath: zmqTxAddr,
p2pPort: p2pPort, p2pPort: p2pPort,
rpcClient: client, rpcClient: client,
minerAddr: miner, minerAddr: miner,