Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Problem: headers is changed in FilterHeaders, so the if statement is …
Browse files Browse the repository at this point in the history
…not necessarily always true

See ethereum/go-ethereum#14848 for an explanation of why the line `len(headers) > 0 || !filter` is added back.

I still don't think we should check total difficulty of the peer with the fork header like ETH does. It might break light clients that only keep the last 256 blocks and does not prevent network attacks. See #313 for an explanation.
  • Loading branch information
sorpaas authored Jul 26, 2017
1 parent f69b80b commit 5fb1ef7
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,25 +404,36 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
if err := msg.Decode(&headers); err != nil {
return errResp(ErrDecode, "msg %v: %v", msg, err)
}
// Good will assumption. Even if the peer is ahead of the fork check header but returns
// empty header response, it might be that the peer is a light client which only keeps
// the last 256 block headers. Besides it does not prevent network attacks. See #313 for
// an explaination.
if len(headers) == 0 && p.timeout != nil {
// Disable the fork drop timeout
p.timeout.Stop()
p.timeout = nil
return nil
}
// Filter out any explicitly requested headers, deliver the rest to the downloader
if len(headers) == 0 || len(headers) == 1 {
filter := len(headers) == 1
if filter {
if p.timeout != nil {
// Disable the fork drop timeout
p.timeout.Stop()
p.timeout = nil
}
}
if len(headers) == 1 {
if err := pm.chainConfig.HeaderCheck(headers[0]); err != nil {
pm.removePeer(p.id)
return err
}
// Irrelevant of the fork checks, send the header to the fetcher just in case
headers = pm.fetcher.FilterHeaders(headers, time.Now())
}
err := pm.downloader.DeliverHeaders(p.id, headers)
if err != nil {
glog.V(logger.Debug).Infoln(err)
if len(headers) > 0 || !filter {
err := pm.downloader.DeliverHeaders(p.id, headers)
if err != nil {
glog.V(logger.Debug).Infoln(err)
}
}

case p.version >= eth62 && msg.Code == GetBlockBodiesMsg:
Expand Down

0 comments on commit 5fb1ef7

Please sign in to comment.