Skip to content

Commit e6974af

Browse files
authored
Merge pull request #220 from lightninglabs/config-broadcast-timeout
neutrino+pushtx: make broadcast timeout configurable with fallback
2 parents 4dea380 + 0494024 commit e6974af

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

neutrino.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,16 @@ type Config struct {
587587
// up and this filter header state has diverged, then it'll remove the
588588
// current on disk filter headers to sync them anew.
589589
AssertFilterHeader *headerfs.FilterHeader
590+
591+
// BroadcastTimeout is the amount of time we'll wait before giving up on
592+
// a transaction broadcast attempt. Broadcasting transactions consists
593+
// of three steps:
594+
//
595+
// 1. Neutrino sends an inv for the transaction.
596+
// 2. The recipient node determines if the inv is known, and if it's
597+
// not, replies with a getdata message.
598+
// 3. Neutrino sends the raw transaction.
599+
BroadcastTimeout time.Duration
590600
}
591601

592602
// peerSubscription holds a peer subscription which we'll notify about any
@@ -649,12 +659,19 @@ type ChainService struct {
649659

650660
nameResolver func(string) ([]net.IP, error)
651661
dialer func(net.Addr) (net.Conn, error)
662+
663+
broadcastTimeout time.Duration
652664
}
653665

654666
// NewChainService returns a new chain service configured to connect to the
655667
// bitcoin network type specified by chainParams. Use start to begin syncing
656668
// with peers.
657669
func NewChainService(cfg Config) (*ChainService, error) {
670+
// Use the default broadcast timeout if one isn't provided.
671+
if cfg.BroadcastTimeout == 0 {
672+
cfg.BroadcastTimeout = pushtx.DefaultBroadcastTimeout
673+
}
674+
658675
// First, we'll sort out the methods that we'll use to established
659676
// outbound TCP connections, as well as perform any DNS queries.
660677
//
@@ -702,6 +719,7 @@ func NewChainService(cfg Config) (*ChainService, error) {
702719
nameResolver: nameResolver,
703720
dialer: dialer,
704721
persistToDisk: cfg.PersistToDisk,
722+
broadcastTimeout: cfg.BroadcastTimeout,
705723
}
706724
s.workManager = query.New(&query.Config{
707725
ConnectedPeers: s.ConnectedPeers,

pushtx/broadcaster.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ var (
2020
)
2121

2222
const (
23+
// DefaultBroadcastTimeout is the default timeout used when broadcasting
24+
// transactions to network peers.
25+
DefaultBroadcastTimeout = 5 * time.Second
26+
2327
// DefaultRebroadcastInterval is the default period that we'll wait
2428
// between blocks to attempt another rebroadcast.
2529
DefaultRebroadcastInterval = time.Minute

query.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,10 +1114,8 @@ func (s *ChainService) sendTransaction(tx *wire.MsgTx, options ...QueryOption) e
11141114
rejections[*broadcastErr]++
11151115
}
11161116
},
1117-
// Default to 10s timeout. Default for queryAllPeers is a
1118-
// single try.
11191117
append(
1120-
[]QueryOption{Timeout(time.Second * 10)},
1118+
[]QueryOption{Timeout(s.broadcastTimeout)},
11211119
options...,
11221120
)...,
11231121
)

0 commit comments

Comments
 (0)