core: handle future block more elegantly, close XFN-101 (#1672)

This commit is contained in:
Daniel Liu 2025-11-03 15:22:22 +08:00 committed by benjamin202410
parent 22e8b476d9
commit f3fb1441d1

View file

@ -1144,7 +1144,11 @@ func (bc *BlockChain) insertStopped() bool {
}
func (bc *BlockChain) procFutureBlocks() {
blocks := make([]*types.Block, 0, bc.futureBlocks.Len())
capacity := bc.futureBlocks.Len()
if capacity == 0 {
return
}
blocks := make([]*types.Block, 0, capacity)
for _, hash := range bc.futureBlocks.Keys() {
if block, exist := bc.futureBlocks.Peek(hash); exist {
blocks = append(blocks, block)
@ -2586,8 +2590,9 @@ func (bc *BlockChain) PostChainEvents(events []interface{}, logs []*types.Log) {
func (bc *BlockChain) futureBlocksLoop() {
defer bc.wg.Done()
futureTimer := time.NewTicker(10 * time.Millisecond)
futureTimer := time.NewTicker(100 * time.Millisecond)
defer futureTimer.Stop()
for {
select {
case <-futureTimer.C: