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

Chain repair fixes #1163

Merged
merged 16 commits into from
Oct 15, 2020
Prev Previous commit
Next Next commit
debugging
  • Loading branch information
mrsmkl committed Sep 17, 2020
commit 0550ea10651fe97b8e37f216ba36ca497feadbed
4 changes: 2 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func (bc *BlockChain) SetHead(head uint64) error {
// Rewind the block chain, ensuring we don't end up with a stateless head
// block. Note, depth equality is permitted to allow using SetHead as a
// chain reparation mechanism without deleting any data!
log.Info("updatefn", "frozen", frozen, "header", header.Number)
// log.Info("updatefn", "frozen", frozen, "header", header.Number)
if currentBlock := bc.CurrentBlock(); currentBlock != nil && header.Number.Uint64() <= currentBlock.NumberU64() {
newHeadBlock := bc.GetBlock(header.Hash(), header.Number.Uint64())
if newHeadBlock == nil {
Expand Down Expand Up @@ -464,7 +464,7 @@ func (bc *BlockChain) SetHead(head uint64) error {
}
head := bc.CurrentBlock().NumberU64()

log.Info("updatefn2", "frozen", frozen, "head", head)
// log.Info("updatefn2", "frozen", frozen, "head", head)

// If setHead underflown the freezer threshold and the block processing
// intent afterwards is full block importing, delete the chain segment
Expand Down
2 changes: 1 addition & 1 deletion core/headerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ func (hc *HeaderChain) SetHead(head uint64, updateFn UpdateHeadBlocksCallback, d
}
nums = append(nums, num)

log.Info("removing", "nums", nums)
// log.Info("removing", "nums", nums)

// Remove the related data from the database on all sidechains
for _, num := range nums {
Expand Down
19 changes: 13 additions & 6 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ func (d *Downloader) fetchHeight(p *peerConnection) (*types.Header, error) {
// Make sure the peer actually gave something valid
headers := packet.(*headerPack).headers
if len(headers) != 1 {
p.log.Debug("Multiple headers for single request", "headers", len(headers))
p.log.Info("Multiple headers for single request", "headers", len(headers))
return nil, errBadPeer
}
head := headers[0]
Expand Down Expand Up @@ -884,7 +884,7 @@ func (d *Downloader) findAncestor(p *peerConnection, remoteHeader *types.Header)
// Make sure the peer actually gave something valid
headers := packer.(*headerPack).headers
if len(headers) != 1 {
p.log.Debug("Multiple headers for single request", "headers", len(headers))
p.log.Info("Multiple headers for single request", "headers", len(headers))
return 0, errBadPeer
}
arrived = true
Expand All @@ -908,7 +908,7 @@ func (d *Downloader) findAncestor(p *peerConnection, remoteHeader *types.Header)
}
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)
p.log.Info("Received non requested header", "number", header.Number, "hash", header.Hash(), "request", check)
return 0, errBadPeer
}
start = check
Expand Down Expand Up @@ -1175,7 +1175,7 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, pivot uint64,
break
}
// Header retrieval timed out, consider the peer bad and drop
p.log.Debug("Header request timed out", "elapsed", ttl)
p.log.Info("Header request timed out", "elapsed", ttl)
headerTimeoutMeter.Mark(1)
d.dropPeer(p.id)

Expand Down Expand Up @@ -1515,6 +1515,7 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
for {
select {
case <-d.cancelCh:
rollbackErr = errCanceled
return errCanceled

case headers := <-d.headerProcCh:
Expand Down Expand Up @@ -1542,6 +1543,7 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
if d.Mode.SyncFullBlockChain() {
head := d.blockchain.CurrentBlock()
if !gotHeaders && td.Cmp(d.blockchain.GetTd(head.Hash(), head.NumberU64())) > 0 {
rollbackErr = errStallingPeer
return errStallingPeer
}
}
Expand All @@ -1556,6 +1558,7 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
if d.Mode == FastSync || d.Mode == LightSync {
head := d.lightchain.CurrentHeader()
if td.Cmp(d.lightchain.GetTd(head.Hash(), head.Number.Uint64())) > 0 {
rollbackErr = errStallingPeer
return errStallingPeer
}
}
Expand All @@ -1569,6 +1572,7 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
// Terminate if something failed in between processing chunks
select {
case <-d.cancelCh:
rollbackErr = errCanceled
return errCanceled
default:
}
Expand All @@ -1593,7 +1597,8 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
if n > 0 && rollback == 0 {
rollback = chunk[0].Number.Uint64()
}
log.Debug("Invalid header encountered", "number", chunk[n].Number, "hash", chunk[n].Hash(), "err", err)
log.Info("Invalid header encountered", "number", chunk[n].Number, "hash", chunk[n].Hash(), "err", err)

return errInvalidChain
}
// All verifications passed, track all headers within the alloted limits
Expand All @@ -1608,14 +1613,16 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
for d.queue.PendingBlocks() >= maxQueuedHeaders || d.queue.PendingReceipts() >= maxQueuedHeaders {
select {
case <-d.cancelCh:
rollbackErr = errCanceled
return errCanceled
case <-time.After(time.Second):
}
}
// Otherwise insert the headers for content retrieval
inserts := d.queue.Schedule(chunk, origin)
if len(inserts) != len(chunk) {
log.Debug("Stale headers")
log.Info("Stale headers")
rollbackErr = errBadPeer
return errBadPeer
}
}
Expand Down