Skip to content

Commit

Permalink
Merge pull request #444 from node-real/fix-gas-tracing
Browse files Browse the repository at this point in the history
Correct ordering of system contract updates
  • Loading branch information
MatusKysel authored Jul 17, 2024
2 parents 3f4599c + e81aea9 commit 999ea75
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
21 changes: 11 additions & 10 deletions core/system_contract_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package core

import (
"fmt"

"github.com/ledgerwatch/erigon-lib/chain/networkname"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"strconv"

"github.com/ledgerwatch/erigon/core/systemcontracts"
"github.com/ledgerwatch/erigon/core/types"
Expand All @@ -25,20 +25,21 @@ func init() {
if parliaConfig == nil || parliaConfig.BlockAlloc == nil {
return
}
for blockNumOrTime, genesisAlloc := range parliaConfig.BlockAlloc {
numOrTime, err := strconv.ParseUint(blockNumOrTime, 10, 64)
if err != nil {
panic(fmt.Errorf("failed to parse block number in BlockAlloc: %s", err.Error()))
}
alloc, err := types.DecodeGenesisAlloc(genesisAlloc)
blockAlloc, err := parliaConfig.SortedBlockAlloc()
if err != nil {
panic(fmt.Errorf("failed to sort block alloc: %v", err))
}

for _, pair := range blockAlloc {
alloc, err := types.DecodeGenesisAlloc(pair.BlockAlloc)
if err != nil {
panic(fmt.Errorf("failed to decode block alloc: %v", err))
}
var blockNum, blockTime uint64
if numOrTime >= chainConfig.ShanghaiTime.Uint64() {
blockTime = numOrTime
if pair.NumOrTime >= chainConfig.ShanghaiTime.Uint64() {
blockTime = pair.NumOrTime
} else {
blockNum = numOrTime
blockNum = pair.NumOrTime
}
allocToCodeRecords(alloc, byChain, blockNum, blockTime)
}
Expand Down
5 changes: 3 additions & 2 deletions core/systemcontracts/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package systemcontracts

import (
"fmt"
"math/big"
"strconv"

"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/log/v3"
"math/big"
"strconv"
)

type UpgradeConfig struct {
Expand Down
22 changes: 22 additions & 0 deletions erigon-lib/chain/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"math/big"
"sort"
"strconv"

"github.com/ledgerwatch/erigon-lib/common"
Expand Down Expand Up @@ -710,6 +711,27 @@ type ParliaConfig struct {
BlockAlloc map[string]interface{} `json:"blockAlloc"` // For systemContract upgrade
}

type KeyValues struct {
NumOrTime uint64
BlockAlloc interface{}
}

func (b *ParliaConfig) SortedBlockAlloc() ([]KeyValues, error) {
ret := make([]KeyValues, 0, len(b.BlockAlloc))
for blockNumberOrTime, genesisAlloc := range b.BlockAlloc {
numOrTime, err := strconv.ParseUint(blockNumberOrTime, 10, 64)
if err != nil {
return nil, err
}
ret = append(ret, KeyValues{NumOrTime: numOrTime, BlockAlloc: genesisAlloc})
}
// sort ret by keys in ascending order
sort.Slice(ret, func(i, j int) bool {
return ret[i].NumOrTime < ret[j].NumOrTime
})
return ret, nil
}

// String implements the stringer interface, returning the consensus engine details.
func (b *ParliaConfig) String() string {
return "parlia"
Expand Down

0 comments on commit 999ea75

Please sign in to comment.