diff options
author | Wenbiao Zheng <delweng@gmail.com> | 2018-09-30 04:13:39 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2018-09-30 04:13:39 +0800 |
commit | 024b22c30e1b40b702f8f7b0831baebce333c8db (patch) | |
tree | f0fd48844351cd18730a6605338c01a6154d187d /eth | |
parent | ffca6dfe0162074cb9224a26aa667ac724be0ab8 (diff) | |
download | dexon-024b22c30e1b40b702f8f7b0831baebce333c8db.tar.gz dexon-024b22c30e1b40b702f8f7b0831baebce333c8db.tar.zst dexon-024b22c30e1b40b702f8f7b0831baebce333c8db.zip |
eth/downloader: use intermediate variable for better readability (#17510)
Diffstat (limited to 'eth')
-rw-r--r-- | eth/downloader/downloader.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index fbde9c6ca..805195034 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -658,8 +658,10 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err continue } // Otherwise check if we already know the header or not - if (d.mode == FullSync && d.blockchain.HasBlock(headers[i].Hash(), headers[i].Number.Uint64())) || (d.mode != FullSync && d.lightchain.HasHeader(headers[i].Hash(), headers[i].Number.Uint64())) { - number, hash = headers[i].Number.Uint64(), headers[i].Hash() + h := headers[i].Hash() + n := headers[i].Number.Uint64() + if (d.mode == FullSync && d.blockchain.HasBlock(h, n)) || (d.mode != FullSync && d.lightchain.HasHeader(h, n)) { + number, hash = n, h // If every header is known, even future ones, the peer straight out lied about its head if number > height && i == limit-1 { @@ -723,11 +725,13 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err arrived = true // Modify the search interval based on the response - if (d.mode == FullSync && !d.blockchain.HasBlock(headers[0].Hash(), headers[0].Number.Uint64())) || (d.mode != FullSync && !d.lightchain.HasHeader(headers[0].Hash(), headers[0].Number.Uint64())) { + h := headers[0].Hash() + n := headers[0].Number.Uint64() + if (d.mode == FullSync && !d.blockchain.HasBlock(h, n)) || (d.mode != FullSync && !d.lightchain.HasHeader(h, n)) { end = check break } - header := d.lightchain.GetHeaderByHash(headers[0].Hash()) // Independent of sync mode, header surely exists + header := d.lightchain.GetHeaderByHash(h) // Independent of sync mode, header surely exists if header.Number.Uint64() != check { p.log.Debug("Received non requested header", "number", header.Number, "hash", header.Hash(), "request", check) return 0, errBadPeer |