diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b0217e611..5e568885a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/chainreg/chainregistry.go b/chainreg/chainregistry.go index c2d44d6e8..bd6f34b0b 100644 --- a/chainreg/chainregistry.go +++ b/chainreg/chainregistry.go @@ -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 diff --git a/config.go b/config.go index a18021233..48cc3f16b 100644 --- a/config.go +++ b/config.go @@ -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. diff --git a/lntest/bitcoind.go b/lntest/bitcoind.go index 37ff5fb5d..37800169b 100644 --- a/lntest/bitcoind.go +++ b/lntest/bitcoind.go @@ -1,5 +1,5 @@ -//go:build bitcoind && !notxindex -// +build bitcoind,!notxindex +//go:build bitcoind && !notxindex && !rpcpolling +// +build bitcoind,!notxindex,!rpcpolling package lntest @@ -19,5 +19,5 @@ func NewBackend(miner string, netParams *chaincfg.Params) ( "-disablewallet", } - return newBackend(miner, netParams, extraArgs) + return newBackend(miner, netParams, extraArgs, false) } diff --git a/lntest/bitcoind_common.go b/lntest/bitcoind_common.go index 937aca540..d9bf102f6 100644 --- a/lntest/bitcoind_common.go +++ b/lntest/bitcoind_common.go @@ -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 @@ -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 } @@ -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 { @@ -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 diff --git a/lntest/bitcoind_notxindex.go b/lntest/bitcoind_notxindex.go index 2aa7e4a63..de7959eba 100644 --- a/lntest/bitcoind_notxindex.go +++ b/lntest/bitcoind_notxindex.go @@ -1,5 +1,5 @@ -//go:build bitcoind && notxindex -// +build bitcoind,notxindex +//go:build bitcoind && notxindex && !rpcpolling +// +build bitcoind,notxindex,!rpcpolling package lntest @@ -18,5 +18,5 @@ func NewBackend(miner string, netParams *chaincfg.Params) ( "-disablewallet", } - return newBackend(miner, netParams, extraArgs) + return newBackend(miner, netParams, extraArgs, false) } diff --git a/lntest/bitcoind_rpcpolling.go b/lntest/bitcoind_rpcpolling.go new file mode 100644 index 000000000..ca203ad2c --- /dev/null +++ b/lntest/bitcoind_rpcpolling.go @@ -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) +}