Skip to content

Commit

Permalink
peer: Remove getheaders response deadline.
Browse files Browse the repository at this point in the history
This removes the response dealine for getheaders since there is no
guaranteed response if the remote peer does not have any headers for the
locator.

Also, while here, modify the debug logging to only log a deadline was
added when it actually was.
  • Loading branch information
davecgh committed Jan 17, 2021
1 parent c2f4537 commit 38758c3
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,40 +1090,45 @@ func (p *Peer) maybeAddDeadline(pendingResponses map[string]time.Time, msgCmd st
// sent asynchronously and as a result of a long backlog of messages,
// such as is typical in the case of initial block download, the
// response won't be received in time.
log.Debugf("Adding deadline for command %s for peer %s", msgCmd, p.addr)

//
// Also, getheaders is intentionally ignored since there is no guaranteed
// response if the remote peer does not have any headers for the locator.
var addedDeadline bool
deadline := time.Now().Add(stallResponseTimeout)
switch msgCmd {
case wire.CmdVersion:
// Expects a verack message.
pendingResponses[wire.CmdVerAck] = deadline
addedDeadline = true

case wire.CmdMemPool:
// Expects an inv message.
pendingResponses[wire.CmdInv] = deadline
addedDeadline = true

case wire.CmdGetBlocks:
// Expects an inv message.
pendingResponses[wire.CmdInv] = deadline
addedDeadline = true

case wire.CmdGetData:
// Expects a block, tx, or notfound message.
pendingResponses[wire.CmdBlock] = deadline
pendingResponses[wire.CmdTx] = deadline
pendingResponses[wire.CmdNotFound] = deadline

case wire.CmdGetHeaders:
// Expects a headers message. Use a longer deadline since it
// can take a while for the remote peer to load all of the
// headers.
deadline = time.Now().Add(stallResponseTimeout * 3)
pendingResponses[wire.CmdHeaders] = deadline
addedDeadline = true

case wire.CmdGetMiningState:
pendingResponses[wire.CmdMiningState] = deadline
addedDeadline = true

case wire.CmdGetInitState:
pendingResponses[wire.CmdInitState] = deadline
addedDeadline = true
}

if addedDeadline {
log.Debugf("Adding deadline for command %s for peer %s", msgCmd, p.addr)
}
}

Expand Down

0 comments on commit 38758c3

Please sign in to comment.