Skip to content

Commit

Permalink
Merge pull request #2230 from CortexFoundation/dev
Browse files Browse the repository at this point in the history
mkalloc fix
  • Loading branch information
ucwong authored Dec 20, 2024
2 parents fa6578a + 9138cfc commit 7f95ba0
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions core/mkalloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,50 @@ import (

"slices"

"github.com/CortexFoundation/CortexTheseus/common"
"github.com/CortexFoundation/CortexTheseus/core"
"github.com/CortexFoundation/CortexTheseus/rlp"
)

type allocItem struct{ Addr, Balance *big.Int }
type allocItem struct {
Addr *big.Int
Balance *big.Int
Misc *allocItemMisc `rlp:"optional"`
}

type allocItemMisc struct {
Nonce uint64
Code []byte
Slots []allocItemStorageItem
}

type allocItemStorageItem struct {
Key common.Hash
Val common.Hash
}

func makelist(g *core.Genesis) []allocItem {
items := make([]allocItem, 0, len(g.Alloc))
for addr, account := range g.Alloc {
var misc *allocItemMisc
if len(account.Storage) > 0 || len(account.Code) > 0 || account.Nonce != 0 {
panic(fmt.Sprintf("can't encode account %x", addr))
misc = &allocItemMisc{
Nonce: account.Nonce,
Code: account.Code,
Slots: make([]allocItemStorageItem, 0, len(account.Storage)),
}
for key, val := range account.Storage {
misc.Slots = append(misc.Slots, allocItemStorageItem{key, val})
}
slices.SortFunc(misc.Slots, func(a, b allocItemStorageItem) int {
return a.Key.Cmp(b.Key)
})
}
bigAddr := new(big.Int).SetBytes(addr.Bytes())
items = append(items, allocItem{bigAddr, account.Balance})
items = append(items, allocItem{bigAddr, account.Balance, misc})
}
slices.SortFunc(items, func(a, b allocItem) bool {
return a.Addr.Cmp(b.Addr) < 0
slices.SortFunc(items, func(a, b allocItem) int {
return a.Addr.Cmp(b.Addr)
})
return items
}
Expand Down

0 comments on commit 7f95ba0

Please sign in to comment.