Skip to content

Commit

Permalink
multi: new bitcoind rpcpolling backend for itests
Browse files Browse the repository at this point in the history
  • Loading branch information
ellemouton committed May 6, 2022
1 parent 026ee44 commit 2b9790f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ jobs:
args: backend=bitcoind
- name: bitcoind-notxindex
args: backend="bitcoind notxindex"
- name: bitcoind-rpcpolling
args: backend="bitcoind rpcpolling"
- name: bitcoind-etcd
args: backend=bitcoind dbbackend=etcd
- name: bitcoind-postgres
Expand Down
2 changes: 1 addition & 1 deletion chainreg/chainregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
// version 0.17.0) we make sure lnd subscribes to the correct
// zmq events. We do this to avoid a situation in which we are
// not notified of new transactions or blocks.
if ver >= 170000 {
if ver >= 170000 && !bitcoindMode.RPCPolling {
zmqPubRawBlockURL, err := url.Parse(bitcoindMode.ZMQPubRawBlock)
if err != nil {
return nil, nil, err
Expand Down
18 changes: 13 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1777,11 +1777,19 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
}
}

// If all of RPCUser, RPCPass, ZMQBlockHost, and ZMQTxHost are
// set, we assume those parameters are good to use.
if conf.RPCUser != "" && conf.RPCPass != "" &&
conf.ZMQPubRawBlock != "" && conf.ZMQPubRawTx != "" {
return nil
if conf.RPCUser != "" && conf.RPCPass != "" {
// If all of RPCUser, RPCPass, ZMQBlockHost, and
// ZMQTxHost are set, we assume those parameters are
// good to use.
if conf.ZMQPubRawBlock != "" && conf.ZMQPubRawTx != "" {
return nil
}

// If RPCUser and RPCPass are set and RPCPolling is
// enabled, we assume the parameters are good to use.
if conf.RPCPolling {
return nil
}
}

// Get the daemon name for displaying proper errors.
Expand Down
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)
}
23 changes: 17 additions & 6 deletions lntest/bitcoind_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type BitcoindBackendConfig struct {
zmqTxPath string
p2pPort int
rpcClient *rpcclient.Client
rpcPolling bool

// minerAddr is the p2p address of the miner to connect to.
minerAddr string
Expand All @@ -46,10 +47,19 @@ 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, fmt.Sprintf("--bitcoind.rpcpolling"))
args = append(args,
fmt.Sprintf("--bitcoind.blockpollinginterval=10ms"))
args = append(args,
fmt.Sprintf("--bitcoind.txpollinginterval=10ms"))
} 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 @@ -76,8 +86,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 @@ -192,6 +202,7 @@ func newBackend(miner string, netParams *chaincfg.Params, extraArgs []string) (
p2pPort: p2pPort,
rpcClient: client,
minerAddr: miner,
rpcPolling: rpcPolling,
}

return &bd, cleanUp, nil
Expand Down
6 changes: 3 additions & 3 deletions lntest/bitcoind_notxindex.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 @@ -18,5 +18,5 @@ func NewBackend(miner string, netParams *chaincfg.Params) (
"-disablewallet",
}

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

package lntest

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

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

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

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

0 comments on commit 2b9790f

Please sign in to comment.