Skip to content

Commit 8356c21

Browse files
authored
improvement(header/p2p): get bestHead if timeout is reached (#1319)
сloses #1309
1 parent a95b114 commit 8356c21

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

header/p2p/exchange.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func NewExchange(host host.Host, peers peer.IDSlice, protocolSuffix string) *Exc
6161

6262
// Head requests the latest ExtendedHeader. Note that the ExtendedHeader
6363
// must be verified thereafter.
64+
// NOTE:
65+
// It is fine to continue handling head request if the timeout will be reached.
66+
// As we are requesting head from multiple trusted peers,
67+
// we may already have some headers when the timeout will be reached.
6468
func (ex *Exchange) Head(ctx context.Context) (*header.ExtendedHeader, error) {
6569
log.Debug("requesting head")
6670
// create request
@@ -85,14 +89,15 @@ func (ex *Exchange) Head(ctx context.Context) (*header.ExtendedHeader, error) {
8589
}
8690

8791
result := make([]*header.ExtendedHeader, 0, len(ex.trustedPeers))
92+
LOOP:
8893
for range ex.trustedPeers {
8994
select {
9095
case h := <-headerCh:
9196
if h != nil {
9297
result = append(result, h)
9398
}
9499
case <-ctx.Done():
95-
return nil, ctx.Err()
100+
break LOOP
96101
}
97102
}
98103

0 commit comments

Comments
 (0)