Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite internal logic of block sync client #2715

Merged
merged 17 commits into from
Aug 6, 2020
Merged
6 changes: 2 additions & 4 deletions chain/blocksync/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,12 @@ func (client *BlockSync) sendRequestToPeer(
_ = stream.SetWriteDeadline(time.Now().Add(WRITE_REQ_DEADLINE))
if err := cborutil.WriteCborRPC(stream, req); err != nil {
_ = stream.SetWriteDeadline(time.Time{})
// FIXME: What's the point of setting a blank deadline that won't time out?
// Is this our way of clearing the old one?
client.peerTracker.logFailure(peer, build.Clock.Since(connectionStart))
// FIXME: Should we also remove peer here?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i currently assume the peer tracker won't try the peer again unless they are our only other option

return nil, err
}
// FIXME: Same, why are we doing this again here?
_ = stream.SetWriteDeadline(time.Time{})
_ = stream.SetWriteDeadline(time.Time{}) // clear deadline // FIXME: Needs
// its own API (/~https://github.com/libp2p/go-libp2p-core/issues/162).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing Deadline by empty time is the Go's standard, I agree specific API might be nice.


// Read response.
var res Response
Expand Down
2 changes: 2 additions & 0 deletions chain/blocksync/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ func (server *BlockSyncService) HandleStream(stream inet.Stream) {

_ = stream.SetDeadline(time.Now().Add(WRITE_RES_DEADLINE))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to clear the deadline too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 6551219

if err := cborutil.WriteCborRPC(stream, resp); err != nil {
_ = stream.SetDeadline(time.Time{})
log.Warnw("failed to write back response for handle stream",
"err", err, "peer", stream.Conn().RemotePeer())
return
}
_ = stream.SetDeadline(time.Time{})
}

// Validate and service the request. We return either a protocol
Expand Down