Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
core/types: remove BlockBy sorting code (ethereum#20355)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl authored and elizabethengelman committed Dec 20, 2019
1 parent 2f20253 commit d4520b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
6 changes: 4 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"
"math/big"
mrand "math/rand"
"sort"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -859,8 +860,9 @@ func (bc *BlockChain) procFutureBlocks() {
}
}
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
for i := range blocks {
bc.InsertChain(blocks[i : i+1])
Expand Down
24 changes: 0 additions & 24 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"io"
"math/big"
"reflect"
"sort"
"sync/atomic"
"time"

Expand Down Expand Up @@ -394,26 +393,3 @@ func (b *Block) Hash() common.Hash {
}

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 }

0 comments on commit d4520b0

Please sign in to comment.