Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmd/devnet/networks/devnet_bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"strconv"
"time"

"github.com/jinzhu/copier"

"github.com/erigontech/erigon-lib/chain"
"github.com/erigontech/erigon-lib/chain/networkname"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon-lib/types"
Expand Down Expand Up @@ -230,7 +233,8 @@ func NewBorDevnetWithLocalHeimdall(
consoleLogLevel log.Lvl,
dirLogLevel log.Lvl,
) devnet.Devnet {
config := *params.BorDevnetChainConfig
var config chain.Config
copier.Copy(&config, params.BorDevnetChainConfig)
borConfig := config.Bor.(*borcfg.BorConfig)
if sprintSize > 0 {
borConfig.Sprint = map[string]uint64{"0": sprintSize}
Expand Down
4 changes: 2 additions & 2 deletions cmd/evm/internal/t8ntool/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/urfave/cli/v2"

"github.com/erigontech/erigon/core/vm"
"github.com/erigontech/erigon/tests"
"github.com/erigontech/erigon/execution/testutil"
)

var (
Expand Down Expand Up @@ -100,7 +100,7 @@ var (
"\n\tAvailable extra eips:"+
"\n\t %v"+
"\n\tSyntax <forkname>(+ExtraEip)",
strings.Join(tests.AvailableForks(), "\n\t "),
strings.Join(testutil.AvailableForks(), "\n\t "),
strings.Join(vm.ActivateableEips(), ", ")),
Value: "Merge",
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ func stageBodies(db kv.TemporalRwDB, ctx context.Context, logger log.Logger) err
}

u := sync.NewUnwindState(stages.Bodies, s.BlockNumber-unwind, s.BlockNumber, true, false)
cfg := stagedsync.StageBodiesCfg(db, nil, nil, nil, nil, 0, *chainConfig, br, bw)
cfg := stagedsync.StageBodiesCfg(db, nil, nil, nil, nil, 0, chainConfig, br, bw)
if err := stagedsync.UnwindBodiesStage(u, tx, cfg, ctx); err != nil {
return err
}
Expand Down Expand Up @@ -1349,7 +1349,7 @@ func newSync(ctx context.Context, db kv.TemporalRwDB, miningConfig *params.Minin
miningSync := stagedsync.New(
cfg.Sync,
stagedsync.MiningStages(ctx,
stagedsync.StageMiningCreateBlockCfg(db, miner, *chainConfig, engine, nil, dirs.Tmp, blockReader),
stagedsync.StageMiningCreateBlockCfg(db, miner, chainConfig, engine, nil, dirs.Tmp, blockReader),
stagedsync.StageExecuteBlocksCfg(
db,
cfg.Prune,
Expand All @@ -1368,8 +1368,8 @@ func newSync(ctx context.Context, db kv.TemporalRwDB, miningConfig *params.Minin
nil,
),
stagedsync.StageSendersCfg(db, sentryControlServer.ChainConfig, cfg.Sync, false, dirs.Tmp, cfg.Prune, blockReader, sentryControlServer.Hd),
stagedsync.StageMiningExecCfg(db, miner, events, *chainConfig, engine, &vm.Config{}, dirs.Tmp, nil, 0, nil, blockReader),
stagedsync.StageMiningFinishCfg(db, *chainConfig, engine, miner, miningCancel, blockReader, builder.NewLatestBlockBuiltStore()),
stagedsync.StageMiningExecCfg(db, miner, events, chainConfig, engine, &vm.Config{}, dirs.Tmp, nil, 0, nil, blockReader),
stagedsync.StageMiningFinishCfg(db, chainConfig, engine, miner, miningCancel, blockReader, builder.NewLatestBlockBuiltStore()),
false,
),
stagedsync.MiningUnwindOrder,
Expand Down
2 changes: 1 addition & 1 deletion cmd/integration/commands/state_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func syncBySmallSteps(db kv.TemporalRwDB, miningConfig params.MiningConfig, ctx
miner.MiningConfig.ExtraData = nextBlock.Extra()
miningStages.MockExecFunc(stages.MiningCreateBlock, func(badBlockUnwind bool, s *stagedsync.StageState, u stagedsync.Unwinder, txc wrap.TxContainer, logger log.Logger) error {
err = stagedsync.SpawnMiningCreateBlockStage(s, txc,
stagedsync.StageMiningCreateBlockCfg(db, miner, *chainConfig, engine, nil, dirs.Tmp, br),
stagedsync.StageMiningCreateBlockCfg(db, miner, chainConfig, engine, nil, dirs.Tmp, br),
quit, logger)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2056,7 +2056,6 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C

if ctx.IsSet(OverridePragueFlag.Name) {
cfg.OverridePragueTime = flags.GlobalBig(ctx, OverridePragueFlag.Name)
cfg.TxPool.OverridePragueTime = cfg.OverridePragueTime
}

if clparams.EmbeddedSupported(cfg.NetworkID) || cfg.CaplinConfig.IsDevnet() {
Expand Down
4 changes: 2 additions & 2 deletions core/block_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestHeaderVerification(t *testing.T) {
if err := m.DB.View(context.Background(), func(tx kv.Tx) error {
for j, valid := range []bool{true, false} {
chainReader := stagedsync.ChainReader{
Cfg: *libchain.TestChainConfig,
Cfg: libchain.TestChainConfig,
Db: tx,
BlockReader: m.BlockReader,
Logger: logger,
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestHeaderWithSealVerification(t *testing.T) {
if err := m.DB.View(context.Background(), func(tx kv.Tx) error {
for j, valid := range []bool{true, false} {
chainReader := stagedsync.ChainReader{
Cfg: *libchain.TestChainAuraConfig,
Cfg: libchain.TestChainAuraConfig,
Db: tx,
BlockReader: m.BlockReader,
Logger: logger,
Expand Down
4 changes: 3 additions & 1 deletion core/genesis_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/c2h5oh/datasize"
"github.com/holiman/uint256"
"github.com/jinzhu/copier"
"golang.org/x/sync/errgroup"

"github.com/erigontech/erigon-db/rawdb"
Expand Down Expand Up @@ -406,7 +407,8 @@ var DevnetSignKey = func(address common.Address) *ecdsa.PrivateKey {
// DeveloperGenesisBlock returns the 'geth --dev' genesis block.
func DeveloperGenesisBlock(period uint64, faucet common.Address) *types.Genesis {
// Override the default period to the user requested one
config := *params2.AllCliqueProtocolChanges
var config chain.Config
copier.Copy(&config, params2.AllCliqueProtocolChanges)
config.Clique.Period = period

// Assemble and return the genesis with the precompiles and faucet pre-funded
Expand Down
185 changes: 92 additions & 93 deletions erigon-lib/chain/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ import (
"encoding/json"
"fmt"
"math/big"
"strconv"
"sync"
"time"

"github.com/erigontech/erigon-lib/chain/params"
"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/common/generics"
)

// Config is the core config which determines the blockchain settings.
//
// Config is stored in the database on a per block basis. This means
// that any network, identified by its genesis block, can have its own
// set of configuration options.
//
// Config must be copied only with jinzhu/copier since it contains a sync.Once.
type Config struct {
ChainName string `json:"chainName"` // chain name, eg: mainnet, sepolia, bor-mainnet
ChainID *big.Int `json:"chainId"` // chainId identifies the current chain and is used for replay protection
Expand Down Expand Up @@ -70,9 +73,16 @@ type Config struct {
PragueTime *big.Int `json:"pragueTime,omitempty"`
OsakaTime *big.Int `json:"osakaTime,omitempty"`

// Optional EIP-4844 parameters (see also EIP-7691 & EIP-7840)
MinBlobGasPrice *uint64 `json:"minBlobGasPrice,omitempty"`
BlobSchedule *BlobSchedule `json:"blobSchedule,omitempty"`
// Optional EIP-4844 parameters (see also EIP-7691, EIP-7840, EIP-7892)
MinBlobGasPrice *uint64 `json:"minBlobGasPrice,omitempty"`
BlobSchedule map[string]*params.BlobConfig `json:"blobSchedule,omitempty"`
Bpo1Time *big.Int `json:"bpo1Time,omitempty"`
Bpo2Time *big.Int `json:"bpo2Time,omitempty"`
Bpo3Time *big.Int `json:"bpo3Time,omitempty"`
Bpo4Time *big.Int `json:"bpo4Time,omitempty"`
Bpo5Time *big.Int `json:"bpo5Time,omitempty"`
parseBlobScheduleOnce sync.Once `copier:"-"`
parsedBlobSchedule map[uint64]*params.BlobConfig

// (Optional) governance contract where EIP-1559 fees will be sent to, which otherwise would be burnt since the London fork.
// A key corresponds to the block number, starting from which the fees are sent to the address (map value).
Expand Down Expand Up @@ -154,57 +164,6 @@ var (
}
)

type BlobConfig struct {
Target *uint64 `json:"target,omitempty"`
Max *uint64 `json:"max,omitempty"`
BaseFeeUpdateFraction *uint64 `json:"baseFeeUpdateFraction,omitempty"`
}

// See EIP-7840: Add blob schedule to EL config files
type BlobSchedule struct {
Cancun *BlobConfig `json:"cancun,omitempty"`
Prague *BlobConfig `json:"prague,omitempty"`
}

func (b *BlobSchedule) TargetBlobsPerBlock(isPrague bool) uint64 {
if isPrague {
if b != nil && b.Prague != nil && b.Prague.Target != nil {
return *b.Prague.Target
}
return 6 // EIP-7691
}
if b != nil && b.Cancun != nil && b.Cancun.Target != nil {
return *b.Cancun.Target
}
return 3 // EIP-4844
}

func (b *BlobSchedule) MaxBlobsPerBlock(isPrague bool) uint64 {
if isPrague {
if b != nil && b.Prague != nil && b.Prague.Max != nil {
return *b.Prague.Max
}
return 9 // EIP-7691
}
if b != nil && b.Cancun != nil && b.Cancun.Max != nil {
return *b.Cancun.Max
}
return 6 // EIP-4844
}

func (b *BlobSchedule) BaseFeeUpdateFraction(isPrague bool) uint64 {
if isPrague {
if b != nil && b.Prague != nil && b.Prague.BaseFeeUpdateFraction != nil {
return *b.Prague.BaseFeeUpdateFraction
}
return 5007716 // EIP-7691
}
if b != nil && b.Cancun != nil && b.Cancun.BaseFeeUpdateFraction != nil {
return *b.Cancun.BaseFeeUpdateFraction
}
return 3338477 // EIP-4844
}

type BorConfig interface {
fmt.Stringer
IsAgra(num uint64) bool
Expand Down Expand Up @@ -242,13 +201,18 @@ func (c *Config) String() string {
)
}

return fmt.Sprintf("{ChainID: %v, Terminal Total Difficulty: %v, Shapella: %v, Dencun: %v, Pectra: %v, Fusaka: %v, Engine: %v}",
return fmt.Sprintf("{ChainID: %v, Terminal Total Difficulty: %v, Shapella: %v, Dencun: %v, Pectra: %v, Fusaka: %v, BPO1: %v, BPO2: %v, BPO3: %v, BPO4: %v, BPO5: %v, Engine: %v}",
c.ChainID,
c.TerminalTotalDifficulty,
timestampToTime(c.ShanghaiTime),
timestampToTime(c.CancunTime),
timestampToTime(c.PragueTime),
timestampToTime(c.OsakaTime),
timestampToTime(c.Bpo1Time),
timestampToTime(c.Bpo2Time),
Comment thread
yperbasis marked this conversation as resolved.
timestampToTime(c.Bpo3Time),
timestampToTime(c.Bpo4Time),
timestampToTime(c.Bpo5Time),
engine,
)
}
Expand Down Expand Up @@ -377,7 +341,7 @@ func (c *Config) GetBurntContract(num uint64) *common.Address {
if len(c.BurntContract) == 0 {
return nil
}
addr := ConfigValueLookup(c.BurntContract, num)
addr := ConfigValueLookup(common.ParseMapKeysIntoUint64(c.BurntContract), num)
return &addr
}

Expand All @@ -388,32 +352,74 @@ func (c *Config) GetMinBlobGasPrice() uint64 {
return 1 // MIN_BLOB_GASPRICE (EIP-4844)
}

func (c *Config) GetMaxBlobGasPerBlock(t uint64) uint64 {
return c.GetMaxBlobsPerBlock(t) * params.BlobGasPerBlob
func (c *Config) getBlobConfig(time uint64) *params.BlobConfig {
c.parseBlobScheduleOnce.Do(func() {
// Populate with default values
c.parsedBlobSchedule = map[uint64]*params.BlobConfig{
0: {},
}
if c.CancunTime != nil {
c.parsedBlobSchedule[c.CancunTime.Uint64()] = &params.DefaultCancunBlobConfig
}
if c.PragueTime != nil {
c.parsedBlobSchedule[c.PragueTime.Uint64()] = &params.DefaultPragueBlobConfig
}
if c.OsakaTime != nil {
c.parsedBlobSchedule[c.OsakaTime.Uint64()] = &params.DefaultOsakaBlobConfig
}

// Override with supplied values
val, ok := c.BlobSchedule["cancun"]
if ok && c.CancunTime != nil {
c.parsedBlobSchedule[c.CancunTime.Uint64()] = val
}
val, ok = c.BlobSchedule["prague"]
if ok && c.PragueTime != nil {
c.parsedBlobSchedule[c.PragueTime.Uint64()] = val
}
val, ok = c.BlobSchedule["osaka"]
if ok && c.OsakaTime != nil {
c.parsedBlobSchedule[c.OsakaTime.Uint64()] = val
}
val, ok = c.BlobSchedule["bpo1"]
if ok && c.Bpo1Time != nil {
c.parsedBlobSchedule[c.Bpo1Time.Uint64()] = val
}
val, ok = c.BlobSchedule["bpo2"]
if ok && c.Bpo2Time != nil {
c.parsedBlobSchedule[c.Bpo2Time.Uint64()] = val
}
val, ok = c.BlobSchedule["bpo3"]
if ok && c.Bpo3Time != nil {
c.parsedBlobSchedule[c.Bpo3Time.Uint64()] = val
}
val, ok = c.BlobSchedule["bpo4"]
if ok && c.Bpo4Time != nil {
c.parsedBlobSchedule[c.Bpo4Time.Uint64()] = val
}
val, ok = c.BlobSchedule["bpo5"]
if ok && c.Bpo5Time != nil {
c.parsedBlobSchedule[c.Bpo5Time.Uint64()] = val
}
})

return ConfigValueLookup(c.parsedBlobSchedule, time)
}

func (c *Config) GetMaxBlobsPerBlock(time uint64) uint64 {
var b *BlobSchedule
if c != nil {
b = c.BlobSchedule
}
return b.MaxBlobsPerBlock(c.IsPrague(time))
return c.getBlobConfig(time).Max
}

func (c *Config) GetTargetBlobGasPerBlock(t uint64) uint64 {
var b *BlobSchedule
if c != nil {
b = c.BlobSchedule
}
return b.TargetBlobsPerBlock(c.IsPrague(t)) * params.BlobGasPerBlob
func (c *Config) GetMaxBlobGasPerBlock(time uint64) uint64 {
return c.getBlobConfig(time).Max * params.BlobGasPerBlob
}

func (c *Config) GetBlobGasPriceUpdateFraction(t uint64) uint64 {
var b *BlobSchedule
if c != nil {
b = c.BlobSchedule
}
return b.BaseFeeUpdateFraction(c.IsPrague(t))
func (c *Config) GetTargetBlobGasPerBlock(time uint64) uint64 {
return c.getBlobConfig(time).Target * params.BlobGasPerBlob
}

func (c *Config) GetBlobGasPriceUpdateFraction(time uint64) uint64 {
return c.getBlobConfig(time).BaseFeeUpdateFraction
}

func (c *Config) SecondsPerSlot() uint64 {
Expand Down Expand Up @@ -621,28 +627,21 @@ func (c *CliqueConfig) String() string {

// Looks up a config value as of a given block number (or time).
// The assumption here is that config is a càdlàg map of starting_from_block -> value.
// For example, config of {"0": "0xA", "10": "0xB", "20": "0xC"}
// means that the config value is 0xA for blocks 0–9,
// 0xB for blocks 10–19, and 0xC for block 20 and above.
func ConfigValueLookup[T uint64 | common.Address](field map[string]T, number uint64) T {
fieldUint := make(map[uint64]T)
for k, v := range field {
keyUint, err := strconv.ParseUint(k, 10, 64)
if err != nil {
panic(err)
}
fieldUint[keyUint] = v
// For example, config of {5: "A", 10: "B", 20: "C"}
// means that the config value is "A" for blocks 5–9,
// "B" for blocks 10–19, and "C" for block 20 and above.
// For blocks 0–4 an empty string will be returned.
func ConfigValueLookup[T any](field map[uint64]T, number uint64) T {
keys := common.SortedKeys(field)
if number < keys[0] {
return generics.Zero[T]()
}

keys := common.SortedKeys(fieldUint)

for i := 0; i < len(keys)-1; i++ {
if number >= keys[i] && number < keys[i+1] {
return fieldUint[keys[i]]
return field[keys[i]]
}
}

return fieldUint[keys[len(keys)-1]]
return field[keys[len(keys)-1]]
}

// Rules is syntactic sugar over Config. It can be used for functions
Expand Down
Loading
Loading