eth/downloader: ignore zero size header batch for importing (#24569)
* eth/downloader: ignore zero size header batch for importing * core, light: reject empty header batch for importing
This commit is contained in:
parent
7ae6c4a790
commit
e0e8bf31c5
@ -2309,6 +2309,9 @@ Error: %v
|
|||||||
// of the header retrieval mechanisms already need to verify nonces, as well as
|
// of the header retrieval mechanisms already need to verify nonces, as well as
|
||||||
// because nonces can be verified sparsely, not needing to check each.
|
// because nonces can be verified sparsely, not needing to check each.
|
||||||
func (bc *BlockChain) InsertHeaderChain(chain []*types.Header, checkFreq int) (int, error) {
|
func (bc *BlockChain) InsertHeaderChain(chain []*types.Header, checkFreq int) (int, error) {
|
||||||
|
if len(chain) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
if i, err := bc.hc.ValidateHeaderChain(chain, checkFreq); err != nil {
|
if i, err := bc.hc.ValidateHeaderChain(chain, checkFreq); err != nil {
|
||||||
return i, err
|
return i, err
|
||||||
|
@ -1377,6 +1377,7 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(chunkHeaders) > 0 {
|
||||||
if n, err := d.lightchain.InsertHeaderChain(chunkHeaders, frequency); err != nil {
|
if n, err := d.lightchain.InsertHeaderChain(chunkHeaders, frequency); err != nil {
|
||||||
rollbackErr = err
|
rollbackErr = err
|
||||||
|
|
||||||
@ -1387,7 +1388,7 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode
|
|||||||
log.Warn("Invalid header encountered", "number", chunkHeaders[n].Number, "hash", chunkHashes[n], "parent", chunkHeaders[n].ParentHash, "err", err)
|
log.Warn("Invalid header encountered", "number", chunkHeaders[n].Number, "hash", chunkHashes[n], "parent", chunkHeaders[n].ParentHash, "err", err)
|
||||||
return fmt.Errorf("%w: %v", errInvalidChain, err)
|
return fmt.Errorf("%w: %v", errInvalidChain, err)
|
||||||
}
|
}
|
||||||
// All verifications passed, track all headers within the alloted limits
|
// All verifications passed, track all headers within the allowed limits
|
||||||
if mode == SnapSync {
|
if mode == SnapSync {
|
||||||
head := chunkHeaders[len(chunkHeaders)-1].Number.Uint64()
|
head := chunkHeaders[len(chunkHeaders)-1].Number.Uint64()
|
||||||
if head-rollback > uint64(fsHeaderSafetyNet) {
|
if head-rollback > uint64(fsHeaderSafetyNet) {
|
||||||
@ -1396,6 +1397,7 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode
|
|||||||
rollback = 1
|
rollback = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if len(rejected) != 0 {
|
if len(rejected) != 0 {
|
||||||
// Merge threshold reached, stop importing, but don't roll back
|
// Merge threshold reached, stop importing, but don't roll back
|
||||||
rollback = 0
|
rollback = 0
|
||||||
|
@ -419,6 +419,9 @@ func (lc *LightChain) SetChainHead(header *types.Header) error {
|
|||||||
// In the case of a light chain, InsertHeaderChain also creates and posts light
|
// In the case of a light chain, InsertHeaderChain also creates and posts light
|
||||||
// chain events when necessary.
|
// chain events when necessary.
|
||||||
func (lc *LightChain) InsertHeaderChain(chain []*types.Header, checkFreq int) (int, error) {
|
func (lc *LightChain) InsertHeaderChain(chain []*types.Header, checkFreq int) (int, error) {
|
||||||
|
if len(chain) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
if atomic.LoadInt32(&lc.disableCheckFreq) == 1 {
|
if atomic.LoadInt32(&lc.disableCheckFreq) == 1 {
|
||||||
checkFreq = 0
|
checkFreq = 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user