mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-16 18:00:46 +00:00
parent
0ad629d484
commit
62dbd3bceb
2 changed files with 10 additions and 14 deletions
|
|
@ -30,7 +30,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/core"
|
"github.com/XinFinOrg/XDPoSChain/core"
|
||||||
|
|
@ -39,23 +39,19 @@ import (
|
||||||
|
|
||||||
type allocItem struct{ Addr, Balance *big.Int }
|
type allocItem struct{ Addr, Balance *big.Int }
|
||||||
|
|
||||||
type allocList []allocItem
|
func makelist(g *core.Genesis) []allocItem {
|
||||||
|
items := make([]allocItem, 0, len(g.Alloc))
|
||||||
func (a allocList) Len() int { return len(a) }
|
|
||||||
func (a allocList) Less(i, j int) bool { return a[i].Addr.Cmp(a[j].Addr) < 0 }
|
|
||||||
func (a allocList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
||||||
|
|
||||||
func makelist(g *core.Genesis) allocList {
|
|
||||||
a := make(allocList, 0, len(g.Alloc))
|
|
||||||
for addr, account := range g.Alloc {
|
for addr, account := range g.Alloc {
|
||||||
if len(account.Storage) > 0 || len(account.Code) > 0 || account.Nonce != 0 {
|
if len(account.Storage) > 0 || len(account.Code) > 0 || account.Nonce != 0 {
|
||||||
panic(fmt.Sprintf("can't encode account %x", addr))
|
panic(fmt.Sprintf("can't encode account %x", addr))
|
||||||
}
|
}
|
||||||
bigAddr := new(big.Int).SetBytes(addr.Bytes())
|
bigAddr := new(big.Int).SetBytes(addr.Bytes())
|
||||||
a = append(a, allocItem{bigAddr, account.Balance})
|
items = append(items, allocItem{bigAddr, account.Balance})
|
||||||
}
|
}
|
||||||
sort.Sort(a)
|
slices.SortFunc(items, func(a, b allocItem) int {
|
||||||
return a
|
return a.Addr.Cmp(b.Addr)
|
||||||
|
})
|
||||||
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
func makealloc(g *core.Genesis) string {
|
func makealloc(g *core.Genesis) string {
|
||||||
|
|
|
||||||
|
|
@ -676,8 +676,8 @@ func WriteBadBlock(db ethdb.KeyValueStore, block *types.Block) {
|
||||||
Body: block.Body(),
|
Body: block.Body(),
|
||||||
})
|
})
|
||||||
slices.SortFunc(badBlocks, func(a, b *badBlock) int {
|
slices.SortFunc(badBlocks, func(a, b *badBlock) int {
|
||||||
// Note: sorting in descending number order.
|
// NOTE: sorting in descending number order.
|
||||||
return -a.Header.Number.Cmp(b.Header.Number)
|
return b.Header.Number.Cmp(a.Header.Number)
|
||||||
})
|
})
|
||||||
if len(badBlocks) > badBlockToKeep {
|
if len(badBlocks) > badBlockToKeep {
|
||||||
badBlocks = badBlocks[:badBlockToKeep]
|
badBlocks = badBlocks[:badBlockToKeep]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue