diff --git a/core/mkalloc.go b/core/mkalloc.go index 0eb2e86e2d..b840b8c935 100644 --- a/core/mkalloc.go +++ b/core/mkalloc.go @@ -30,7 +30,7 @@ import ( "fmt" "math/big" "os" - "sort" + "slices" "strconv" "github.com/XinFinOrg/XDPoSChain/core" @@ -39,23 +39,19 @@ import ( type allocItem struct{ Addr, Balance *big.Int } -type allocList []allocItem - -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)) +func makelist(g *core.Genesis) []allocItem { + items := make([]allocItem, 0, len(g.Alloc)) for addr, account := range g.Alloc { if len(account.Storage) > 0 || len(account.Code) > 0 || account.Nonce != 0 { panic(fmt.Sprintf("can't encode account %x", addr)) } bigAddr := new(big.Int).SetBytes(addr.Bytes()) - a = append(a, allocItem{bigAddr, account.Balance}) + items = append(items, allocItem{bigAddr, account.Balance}) } - sort.Sort(a) - return a + slices.SortFunc(items, func(a, b allocItem) int { + return a.Addr.Cmp(b.Addr) + }) + return items } func makealloc(g *core.Genesis) string { diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 4a520e5f82..ff783c6c05 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -676,8 +676,8 @@ func WriteBadBlock(db ethdb.KeyValueStore, block *types.Block) { Body: block.Body(), }) slices.SortFunc(badBlocks, func(a, b *badBlock) int { - // Note: sorting in descending number order. - return -a.Header.Number.Cmp(b.Header.Number) + // NOTE: sorting in descending number order. + return b.Header.Number.Cmp(a.Header.Number) }) if len(badBlocks) > badBlockToKeep { badBlocks = badBlocks[:badBlockToKeep]