core/types: remove BlockBy sorting code (#20355)

This commit is contained in:
Felix Lange 2019-11-21 15:35:22 +01:00 committed by Péter Szilágyi
parent 0ec5ab4175
commit b6d4f6b66e
2 changed files with 4 additions and 26 deletions

@ -23,6 +23,7 @@ import (
"io" "io"
"math/big" "math/big"
mrand "math/rand" mrand "math/rand"
"sort"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -855,8 +856,9 @@ func (bc *BlockChain) procFutureBlocks() {
} }
} }
if len(blocks) > 0 { if len(blocks) > 0 {
types.BlockBy(types.Number).Sort(blocks) sort.Slice(blocks, func(i, j int) bool {
return blocks[i].NumberU64() < blocks[j].NumberU64()
})
// Insert one by one as chain insertion needs contiguous ancestry between blocks // Insert one by one as chain insertion needs contiguous ancestry between blocks
for i := range blocks { for i := range blocks {
bc.InsertChain(blocks[i : i+1]) bc.InsertChain(blocks[i : i+1])

@ -23,7 +23,6 @@ import (
"io" "io"
"math/big" "math/big"
"reflect" "reflect"
"sort"
"sync/atomic" "sync/atomic"
"time" "time"
@ -394,26 +393,3 @@ func (b *Block) Hash() common.Hash {
} }
type Blocks []*Block type Blocks []*Block
type BlockBy func(b1, b2 *Block) bool
func (self BlockBy) Sort(blocks Blocks) {
bs := blockSorter{
blocks: blocks,
by: self,
}
sort.Sort(bs)
}
type blockSorter struct {
blocks Blocks
by func(b1, b2 *Block) bool
}
func (self blockSorter) Len() int { return len(self.blocks) }
func (self blockSorter) Swap(i, j int) {
self.blocks[i], self.blocks[j] = self.blocks[j], self.blocks[i]
}
func (self blockSorter) Less(i, j int) bool { return self.by(self.blocks[i], self.blocks[j]) }
func Number(b1, b2 *Block) bool { return b1.header.Number.Cmp(b2.header.Number) < 0 }