Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
_ "github.com/btcsuite/btcd/database/ffldb"
"github.com/btcsuite/btcd/mempool"
"github.com/btcsuite/btcd/peer"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/go-socks/socks"
flags "github.com/jessevdk/go-flags"
Expand Down Expand Up @@ -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"`
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"`
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"`
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"`
Expand Down Expand Up @@ -603,6 +605,16 @@ func loadConfig() (*config, []string, error) {
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
// according to the default of the active network. The set
// configuration value takes precedence over the default value for the
Expand Down
15 changes: 15 additions & 0 deletions peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ type Config struct {
// connection detecting and disconnect logic since they intentionally
// do so for testing purposes.
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.
Expand Down Expand Up @@ -1202,6 +1209,10 @@ out:
for {
select {
case msg := <-p.stallControl:
if p.cfg.DisableStallHandler {
continue
}

switch msg.command {
case sccSendMessage:
// Add a deadline for the expected response
Expand Down Expand Up @@ -1264,6 +1275,10 @@ out:
}

case <-stallTicker.C:
if p.cfg.DisableStallHandler {
continue
}

// Calculate the offset to apply to the deadline based
// on how long the handlers have taken to execute since
// the last tick.
Expand Down
23 changes: 12 additions & 11 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2054,17 +2054,18 @@ func newPeerConfig(sp *serverPeer) *peer.Config {
// other implementations' alert messages, we will not relay theirs.
OnAlert: nil,
},
NewestBlock: sp.newestBlock,
HostToNetAddress: sp.server.addrManager.HostToNetAddress,
Proxy: cfg.Proxy,
UserAgentName: userAgentName,
UserAgentVersion: userAgentVersion,
UserAgentComments: cfg.UserAgentComments,
ChainParams: sp.server.chainParams,
Services: sp.server.services,
DisableRelayTx: cfg.BlocksOnly,
ProtocolVersion: peer.MaxProtocolVersion,
TrickleInterval: cfg.TrickleInterval,
NewestBlock: sp.newestBlock,
HostToNetAddress: sp.server.addrManager.HostToNetAddress,
Proxy: cfg.Proxy,
UserAgentName: userAgentName,
UserAgentVersion: userAgentVersion,
UserAgentComments: cfg.UserAgentComments,
ChainParams: sp.server.chainParams,
Services: sp.server.services,
DisableRelayTx: cfg.BlocksOnly,
ProtocolVersion: peer.MaxProtocolVersion,
TrickleInterval: cfg.TrickleInterval,
DisableStallHandler: cfg.DisableStallHandler,
}
}

Expand Down