Merge pull request #1222 from halseth/trickle-timeout

config/peer: make trickleTimeout configurable
This commit is contained in:
Olaoluwa Osuntokun 2018-08-22 19:39:33 -07:00 committed by GitHub
commit bb912b6e03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 5 deletions

View file

@ -47,6 +47,7 @@ const (
defaultMaxRPCConcurrentReqs = 20 defaultMaxRPCConcurrentReqs = 20
defaultDbType = "ffldb" defaultDbType = "ffldb"
defaultFreeTxRelayLimit = 15.0 defaultFreeTxRelayLimit = 15.0
defaultTrickleTimeout = time.Second * 10
defaultBlockMinSize = 0 defaultBlockMinSize = 0
defaultBlockMaxSize = 750000 defaultBlockMaxSize = 750000
defaultBlockMinWeight = 0 defaultBlockMinWeight = 0
@ -140,6 +141,7 @@ type config struct {
MinRelayTxFee float64 `long:"minrelaytxfee" description:"The minimum transaction fee in BTC/kB to be considered a non-zero fee."` MinRelayTxFee float64 `long:"minrelaytxfee" description:"The minimum transaction fee in BTC/kB to be considered a non-zero fee."`
FreeTxRelayLimit float64 `long:"limitfreerelay" description:"Limit relay of transactions with no transaction fee to the given amount in thousands of bytes per minute"` FreeTxRelayLimit float64 `long:"limitfreerelay" description:"Limit relay of transactions with no transaction fee to the given amount in thousands of bytes per minute"`
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"`
TrickleTimeout time.Duration `long:"trickletimeout" description:"Minimum time between attempts to send new inventory to a connected peer"`
MaxOrphanTxs int `long:"maxorphantx" description:"Max number of orphan transactions to keep in memory"` MaxOrphanTxs int `long:"maxorphantx" description:"Max number of orphan transactions to keep in memory"`
Generate bool `long:"generate" description:"Generate (mine) bitcoins using the CPU"` Generate bool `long:"generate" description:"Generate (mine) bitcoins using the CPU"`
MiningAddrs []string `long:"miningaddr" description:"Add the specified payment address to the list of addresses to use for generated blocks -- At least one address is required if the generate option is set"` MiningAddrs []string `long:"miningaddr" description:"Add the specified payment address to the list of addresses to use for generated blocks -- At least one address is required if the generate option is set"`
@ -415,6 +417,7 @@ func loadConfig() (*config, []string, error) {
RPCCert: defaultRPCCertFile, RPCCert: defaultRPCCertFile,
MinRelayTxFee: mempool.DefaultMinRelayTxFee.ToBTC(), MinRelayTxFee: mempool.DefaultMinRelayTxFee.ToBTC(),
FreeTxRelayLimit: defaultFreeTxRelayLimit, FreeTxRelayLimit: defaultFreeTxRelayLimit,
TrickleTimeout: defaultTrickleTimeout,
BlockMinSize: defaultBlockMinSize, BlockMinSize: defaultBlockMinSize,
BlockMaxSize: defaultBlockMaxSize, BlockMaxSize: defaultBlockMaxSize,
BlockMinWeight: defaultBlockMinWeight, BlockMinWeight: defaultBlockMinWeight,

View file

@ -23,6 +23,7 @@ func mockRemotePeer() error {
UserAgentName: "peer", // User agent name to advertise. UserAgentName: "peer", // User agent name to advertise.
UserAgentVersion: "1.0.0", // User agent version to advertise. UserAgentVersion: "1.0.0", // User agent version to advertise.
ChainParams: &chaincfg.SimNetParams, ChainParams: &chaincfg.SimNetParams,
TrickleTimeout: time.Second * 10,
} }
// Accept connections on the simnet port. // Accept connections on the simnet port.
@ -69,6 +70,7 @@ func Example_newOutboundPeer() {
UserAgentVersion: "1.0.0", // User agent version to advertise. UserAgentVersion: "1.0.0", // User agent version to advertise.
ChainParams: &chaincfg.SimNetParams, ChainParams: &chaincfg.SimNetParams,
Services: 0, Services: 0,
TrickleTimeout: time.Second * 10,
Listeners: peer.MessageListeners{ Listeners: peer.MessageListeners{
OnVersion: func(p *peer.Peer, msg *wire.MsgVersion) { OnVersion: func(p *peer.Peer, msg *wire.MsgVersion) {
fmt.Println("outbound: received version") fmt.Println("outbound: received version")

View file

@ -64,10 +64,6 @@ const (
// stalling. The deadlines are adjusted for callback running times and // stalling. The deadlines are adjusted for callback running times and
// only checked on each stall tick interval. // only checked on each stall tick interval.
stallResponseTimeout = 30 * time.Second stallResponseTimeout = 30 * time.Second
// trickleTimeout is the duration of the ticker which trickles down the
// inventory to a peer.
trickleTimeout = 10 * time.Second
) )
var ( var (
@ -268,6 +264,10 @@ type Config struct {
// Listeners houses callback functions to be invoked on receiving peer // Listeners houses callback functions to be invoked on receiving peer
// messages. // messages.
Listeners MessageListeners Listeners MessageListeners
// TrickleTimeout is the duration of the ticker which trickles down the
// inventory to a peer.
TrickleTimeout time.Duration
} }
// minUint32 is a helper function to return the minimum of two uint32s. // minUint32 is a helper function to return the minimum of two uint32s.
@ -1693,7 +1693,7 @@ out:
func (p *Peer) queueHandler() { func (p *Peer) queueHandler() {
pendingMsgs := list.New() pendingMsgs := list.New()
invSendQueue := list.New() invSendQueue := list.New()
trickleTicker := time.NewTicker(trickleTimeout) trickleTicker := time.NewTicker(p.cfg.TrickleTimeout)
defer trickleTicker.Stop() defer trickleTicker.Stop()
// We keep the waiting flag so that we know if we have a message queued // We keep the waiting flag so that we know if we have a message queued

View file

@ -236,6 +236,7 @@ func TestPeerConnection(t *testing.T) {
ChainParams: &chaincfg.MainNetParams, ChainParams: &chaincfg.MainNetParams,
ProtocolVersion: wire.RejectVersion, // Configure with older version ProtocolVersion: wire.RejectVersion, // Configure with older version
Services: 0, Services: 0,
TrickleTimeout: time.Second * 10,
} }
peer2Cfg := &peer.Config{ peer2Cfg := &peer.Config{
Listeners: peer1Cfg.Listeners, Listeners: peer1Cfg.Listeners,
@ -244,6 +245,7 @@ func TestPeerConnection(t *testing.T) {
UserAgentComments: []string{"comment"}, UserAgentComments: []string{"comment"},
ChainParams: &chaincfg.MainNetParams, ChainParams: &chaincfg.MainNetParams,
Services: wire.SFNodeNetwork | wire.SFNodeWitness, Services: wire.SFNodeNetwork | wire.SFNodeWitness,
TrickleTimeout: time.Second * 10,
} }
wantStats1 := peerStats{ wantStats1 := peerStats{
@ -447,6 +449,7 @@ func TestPeerListeners(t *testing.T) {
UserAgentComments: []string{"comment"}, UserAgentComments: []string{"comment"},
ChainParams: &chaincfg.MainNetParams, ChainParams: &chaincfg.MainNetParams,
Services: wire.SFNodeBloom, Services: wire.SFNodeBloom,
TrickleTimeout: time.Second * 10,
} }
inConn, outConn := pipe( inConn, outConn := pipe(
&conn{raddr: "10.0.0.1:8333"}, &conn{raddr: "10.0.0.1:8333"},
@ -617,6 +620,7 @@ func TestOutboundPeer(t *testing.T) {
UserAgentComments: []string{"comment"}, UserAgentComments: []string{"comment"},
ChainParams: &chaincfg.MainNetParams, ChainParams: &chaincfg.MainNetParams,
Services: 0, Services: 0,
TrickleTimeout: time.Second * 10,
} }
r, w := io.Pipe() r, w := io.Pipe()
@ -757,6 +761,7 @@ func TestUnsupportedVersionPeer(t *testing.T) {
UserAgentComments: []string{"comment"}, UserAgentComments: []string{"comment"},
ChainParams: &chaincfg.MainNetParams, ChainParams: &chaincfg.MainNetParams,
Services: 0, Services: 0,
TrickleTimeout: time.Second * 10,
} }
localNA := wire.NewNetAddressIPPort( localNA := wire.NewNetAddressIPPort(

View file

@ -1943,6 +1943,7 @@ func newPeerConfig(sp *serverPeer) *peer.Config {
Services: sp.server.services, Services: sp.server.services,
DisableRelayTx: cfg.BlocksOnly, DisableRelayTx: cfg.BlocksOnly,
ProtocolVersion: peer.MaxProtocolVersion, ProtocolVersion: peer.MaxProtocolVersion,
TrickleTimeout: cfg.TrickleTimeout,
} }
} }