Skip to content

Commit

Permalink
Add integration tests for new rpcpolling mode
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalturtle committed Jan 31, 2022
1 parent 4ea2cf1 commit 2b1863c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lntest/bitcoind.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build bitcoind && !notxindex
// +build bitcoind,!notxindex
//go:build bitcoind && !notxindex && !rpcpolling
// +build bitcoind,!notxindex,!rpcpolling

package lntest

Expand All @@ -19,5 +19,5 @@ func NewBackend(miner string, netParams *chaincfg.Params) (
"-disablewallet",
}

return newBackend(miner, netParams, extraArgs)
return newBackend(miner, netParams, extraArgs, false)
}
22 changes: 16 additions & 6 deletions lntest/bitcoind_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type BitcoindBackendConfig struct {
zmqBlockPath string
zmqTxPath string
p2pPort int
RpcPolling bool
rpcClient *rpcclient.Client

// minerAddr is the p2p address of the miner to connect to.
Expand All @@ -46,10 +47,17 @@ func (b BitcoindBackendConfig) GenArgs() []string {
args = append(args, fmt.Sprintf("--bitcoind.rpchost=%v", b.rpcHost))
args = append(args, fmt.Sprintf("--bitcoind.rpcuser=%v", b.rpcUser))
args = append(args, fmt.Sprintf("--bitcoind.rpcpass=%v", b.rpcPass))
args = append(args, fmt.Sprintf("--bitcoind.zmqpubrawblock=%v",
b.zmqBlockPath))
args = append(args, fmt.Sprintf("--bitcoind.zmqpubrawtx=%v",
b.zmqTxPath))
if b.RpcPolling {
args = append(args, "--bitcoind.rpcpolling",
"--bitcoind.pollblocktimer=500ms",
"--bitcoind.polltxtimer=500ms",
)
} else {
args = append(args, fmt.Sprintf("--bitcoind.zmqpubrawblock=%v",
b.zmqBlockPath))
args = append(args, fmt.Sprintf("--bitcoind.zmqpubrawtx=%v",
b.zmqTxPath))
}

return args
}
Expand All @@ -71,8 +79,8 @@ func (b BitcoindBackendConfig) Name() string {

// newBackend starts a bitcoind node with the given extra parameters and returns
// a BitcoindBackendConfig for that node.
func newBackend(miner string, netParams *chaincfg.Params, extraArgs []string) (
*BitcoindBackendConfig, func() error, error) {
func newBackend(miner string, netParams *chaincfg.Params, extraArgs []string,
rpcPolling bool) (*BitcoindBackendConfig, func() error, error) {

baseLogDir := fmt.Sprintf(logDirPattern, GetLogDir())
if netParams != &chaincfg.RegressionNetParams {
Expand Down Expand Up @@ -111,6 +119,7 @@ func newBackend(miner string, netParams *chaincfg.Params, extraArgs []string) (
"-zmqpubrawtx=" + zmqTxAddr,
"-debuglogfile=" + logFile,
}

cmdArgs = append(cmdArgs, extraArgs...)
bitcoind := exec.Command("bitcoind", cmdArgs...)

Expand Down Expand Up @@ -185,6 +194,7 @@ func newBackend(miner string, netParams *chaincfg.Params, extraArgs []string) (
zmqBlockPath: zmqBlockAddr,
zmqTxPath: zmqTxAddr,
p2pPort: p2pPort,
RpcPolling: rpcPolling,
rpcClient: client,
minerAddr: miner,
}
Expand Down
2 changes: 1 addition & 1 deletion lntest/bitcoind_notxindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ func NewBackend(miner string, netParams *chaincfg.Params) (
"-disablewallet",
}

return newBackend(miner, netParams, extraArgs)
return newBackend(miner, netParams, extraArgs, false)
}
22 changes: 22 additions & 0 deletions lntest/bitcoind_rpcpolling.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build bitcoind && rpcpolling
// +build bitcoind,rpcpolling

package lntest

import (
"github.com/btcsuite/btcd/chaincfg"
)

// NewBackend starts a bitcoind node with the txindex enabled and returns a
// BitcoindBackendConfig for that node.
func NewBackend(miner string, netParams *chaincfg.Params) (
*BitcoindBackendConfig, func() error, error) {

extraArgs := []string{
"-debug",
"-regtest",
"-disablewallet",
}

return newBackend(miner, netParams, extraArgs, true)
}

0 comments on commit 2b1863c

Please sign in to comment.