diff --git a/config.go b/config.go index 772c5ef8..f5d892a7 100644 --- a/config.go +++ b/config.go @@ -47,6 +47,7 @@ const ( defaultMaxRPCConcurrentReqs = 20 defaultDbType = "ffldb" defaultFreeTxRelayLimit = 15.0 + defaultTrickleTimeout = time.Second * 10 defaultBlockMinSize = 0 defaultBlockMaxSize = 750000 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."` 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"` + 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"` 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"` @@ -415,6 +417,7 @@ func loadConfig() (*config, []string, error) { RPCCert: defaultRPCCertFile, MinRelayTxFee: mempool.DefaultMinRelayTxFee.ToBTC(), FreeTxRelayLimit: defaultFreeTxRelayLimit, + TrickleTimeout: defaultTrickleTimeout, BlockMinSize: defaultBlockMinSize, BlockMaxSize: defaultBlockMaxSize, BlockMinWeight: defaultBlockMinWeight, diff --git a/peer/example_test.go b/peer/example_test.go index e4429f85..5c4b570d 100644 --- a/peer/example_test.go +++ b/peer/example_test.go @@ -23,6 +23,7 @@ func mockRemotePeer() error { UserAgentName: "peer", // User agent name to advertise. UserAgentVersion: "1.0.0", // User agent version to advertise. ChainParams: &chaincfg.SimNetParams, + TrickleTimeout: time.Second * 10, } // Accept connections on the simnet port. @@ -69,6 +70,7 @@ func Example_newOutboundPeer() { UserAgentVersion: "1.0.0", // User agent version to advertise. ChainParams: &chaincfg.SimNetParams, Services: 0, + TrickleTimeout: time.Second * 10, Listeners: peer.MessageListeners{ OnVersion: func(p *peer.Peer, msg *wire.MsgVersion) { fmt.Println("outbound: received version") diff --git a/peer/peer.go b/peer/peer.go index 2fdf3e42..f0dd5706 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -64,10 +64,6 @@ const ( // stalling. The deadlines are adjusted for callback running times and // only checked on each stall tick interval. stallResponseTimeout = 30 * time.Second - - // trickleTimeout is the duration of the ticker which trickles down the - // inventory to a peer. - trickleTimeout = 10 * time.Second ) var ( @@ -268,6 +264,10 @@ type Config struct { // Listeners houses callback functions to be invoked on receiving peer // messages. 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. @@ -1693,7 +1693,7 @@ out: func (p *Peer) queueHandler() { pendingMsgs := list.New() invSendQueue := list.New() - trickleTicker := time.NewTicker(trickleTimeout) + trickleTicker := time.NewTicker(p.cfg.TrickleTimeout) defer trickleTicker.Stop() // We keep the waiting flag so that we know if we have a message queued diff --git a/peer/peer_test.go b/peer/peer_test.go index 34ab1144..e87d2f95 100644 --- a/peer/peer_test.go +++ b/peer/peer_test.go @@ -236,6 +236,7 @@ func TestPeerConnection(t *testing.T) { ChainParams: &chaincfg.MainNetParams, ProtocolVersion: wire.RejectVersion, // Configure with older version Services: 0, + TrickleTimeout: time.Second * 10, } peer2Cfg := &peer.Config{ Listeners: peer1Cfg.Listeners, @@ -244,6 +245,7 @@ func TestPeerConnection(t *testing.T) { UserAgentComments: []string{"comment"}, ChainParams: &chaincfg.MainNetParams, Services: wire.SFNodeNetwork | wire.SFNodeWitness, + TrickleTimeout: time.Second * 10, } wantStats1 := peerStats{ @@ -447,6 +449,7 @@ func TestPeerListeners(t *testing.T) { UserAgentComments: []string{"comment"}, ChainParams: &chaincfg.MainNetParams, Services: wire.SFNodeBloom, + TrickleTimeout: time.Second * 10, } inConn, outConn := pipe( &conn{raddr: "10.0.0.1:8333"}, @@ -617,6 +620,7 @@ func TestOutboundPeer(t *testing.T) { UserAgentComments: []string{"comment"}, ChainParams: &chaincfg.MainNetParams, Services: 0, + TrickleTimeout: time.Second * 10, } r, w := io.Pipe() @@ -757,6 +761,7 @@ func TestUnsupportedVersionPeer(t *testing.T) { UserAgentComments: []string{"comment"}, ChainParams: &chaincfg.MainNetParams, Services: 0, + TrickleTimeout: time.Second * 10, } localNA := wire.NewNetAddressIPPort( diff --git a/server.go b/server.go index 906eb57e..a581a081 100644 --- a/server.go +++ b/server.go @@ -1943,6 +1943,7 @@ func newPeerConfig(sp *serverPeer) *peer.Config { Services: sp.server.services, DisableRelayTx: cfg.BlocksOnly, ProtocolVersion: peer.MaxProtocolVersion, + TrickleTimeout: cfg.TrickleTimeout, } }