peer+server: add new config option to optionally disable stall detection

In this commit, we add a new config options that allows one to start
`btcd` in an operating mode that disables the stall detection. This can
be useful in simnet/regtest integration tests settings where it's
important that `btcd` holds on to its possibly sole connection to the
only other node in the test harness.

A new config flag has been added to gate this behavior, which is off by
default.
This commit is contained in:
Olaoluwa Osuntokun 2021-09-15 18:12:37 -07:00
parent 4caf037c52
commit e98a1a1b4c
No known key found for this signature in database
GPG key ID: 3BBD59E99B280306
3 changed files with 39 additions and 11 deletions

View file

@ -29,6 +29,7 @@ import (
_ "github.com/btcsuite/btcd/database/ffldb" _ "github.com/btcsuite/btcd/database/ffldb"
"github.com/btcsuite/btcd/mempool" "github.com/btcsuite/btcd/mempool"
"github.com/btcsuite/btcd/peer" "github.com/btcsuite/btcd/peer"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/go-socks/socks" "github.com/btcsuite/go-socks/socks"
flags "github.com/jessevdk/go-flags" flags "github.com/jessevdk/go-flags"
@ -135,6 +136,7 @@ type config struct {
NoRelayPriority bool `long:"norelaypriority" description:"Do not require free or low-fee transactions to have high priority for relaying"` NoRelayPriority bool `long:"norelaypriority" description:"Do not require free or low-fee transactions to have high priority for relaying"`
NoWinService bool `long:"nowinservice" description:"Do not start as a background service on Windows -- NOTE: This flag only works on the command line, not in the config file"` NoWinService bool `long:"nowinservice" description:"Do not start as a background service on Windows -- NOTE: This flag only works on the command line, not in the config file"`
DisableRPC bool `long:"norpc" description:"Disable built-in RPC server -- NOTE: The RPC server is disabled by default if no rpcuser/rpcpass or rpclimituser/rpclimitpass is specified"` DisableRPC bool `long:"norpc" description:"Disable built-in RPC server -- NOTE: The RPC server is disabled by default if no rpcuser/rpcpass or rpclimituser/rpclimitpass is specified"`
DisableStallHandler bool `long:"nostalldetect" description:"Disables the stall handler system for each peer, useful in simnet/regtest integration tests frameworks"`
DisableTLS bool `long:"notls" description:"Disable TLS for the RPC server -- NOTE: This is only allowed if the RPC server is bound to localhost"` DisableTLS bool `long:"notls" description:"Disable TLS for the RPC server -- NOTE: This is only allowed if the RPC server is bound to localhost"`
OnionProxy string `long:"onion" description:"Connect to tor hidden services via SOCKS5 proxy (eg. 127.0.0.1:9050)"` OnionProxy string `long:"onion" description:"Connect to tor hidden services via SOCKS5 proxy (eg. 127.0.0.1:9050)"`
OnionProxyPass string `long:"onionpass" default-mask:"-" description:"Password for onion proxy server"` OnionProxyPass string `long:"onionpass" default-mask:"-" description:"Password for onion proxy server"`
@ -603,6 +605,16 @@ func loadConfig() (*config, []string, error) {
return nil, nil, err return nil, nil, err
} }
// If mainnet is active, then we won't allow the stall handler to be
// disabled.
if activeNetParams.Params.Net == wire.MainNet && cfg.DisableStallHandler {
str := "%s: stall handler cannot be disabled on mainnet"
err := fmt.Errorf(str, funcName)
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, usageMessage)
return nil, nil, err
}
// Set the default policy for relaying non-standard transactions // Set the default policy for relaying non-standard transactions
// according to the default of the active network. The set // according to the default of the active network. The set
// configuration value takes precedence over the default value for the // configuration value takes precedence over the default value for the

View file

@ -276,6 +276,13 @@ type Config struct {
// connection detecting and disconnect logic since they intentionally // connection detecting and disconnect logic since they intentionally
// do so for testing purposes. // do so for testing purposes.
AllowSelfConns bool AllowSelfConns bool
// DisableStallHandler if true, then the stall handler that attempts to
// disconnect from peers that appear to be taking too long to respond
// to requests won't be activated. This can be useful in certain simnet
// scenarios where the stall behavior isn't important to the system
// under test.
DisableStallHandler bool
} }
// minUint32 is a helper function to return the minimum of two uint32s. // minUint32 is a helper function to return the minimum of two uint32s.
@ -1202,6 +1209,10 @@ out:
for { for {
select { select {
case msg := <-p.stallControl: case msg := <-p.stallControl:
if p.cfg.DisableStallHandler {
continue
}
switch msg.command { switch msg.command {
case sccSendMessage: case sccSendMessage:
// Add a deadline for the expected response // Add a deadline for the expected response
@ -1264,6 +1275,10 @@ out:
} }
case <-stallTicker.C: case <-stallTicker.C:
if p.cfg.DisableStallHandler {
continue
}
// Calculate the offset to apply to the deadline based // Calculate the offset to apply to the deadline based
// on how long the handlers have taken to execute since // on how long the handlers have taken to execute since
// the last tick. // the last tick.

View file

@ -2054,17 +2054,18 @@ func newPeerConfig(sp *serverPeer) *peer.Config {
// other implementations' alert messages, we will not relay theirs. // other implementations' alert messages, we will not relay theirs.
OnAlert: nil, OnAlert: nil,
}, },
NewestBlock: sp.newestBlock, NewestBlock: sp.newestBlock,
HostToNetAddress: sp.server.addrManager.HostToNetAddress, HostToNetAddress: sp.server.addrManager.HostToNetAddress,
Proxy: cfg.Proxy, Proxy: cfg.Proxy,
UserAgentName: userAgentName, UserAgentName: userAgentName,
UserAgentVersion: userAgentVersion, UserAgentVersion: userAgentVersion,
UserAgentComments: cfg.UserAgentComments, UserAgentComments: cfg.UserAgentComments,
ChainParams: sp.server.chainParams, ChainParams: sp.server.chainParams,
Services: sp.server.services, Services: sp.server.services,
DisableRelayTx: cfg.BlocksOnly, DisableRelayTx: cfg.BlocksOnly,
ProtocolVersion: peer.MaxProtocolVersion, ProtocolVersion: peer.MaxProtocolVersion,
TrickleInterval: cfg.TrickleInterval, TrickleInterval: cfg.TrickleInterval,
DisableStallHandler: cfg.DisableStallHandler,
} }
} }