Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 0 additions & 2 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ var (
utils.DARecoverySignBlocksFlag,
utils.DARecoveryL2EndBlockFlag,
utils.DARecoveryProduceBlocksFlag,
utils.L2BaseFeeScalarFlag,
utils.L2BaseFeeOverheadFlag,
}

rpcFlags = []cli.Flag{
Expand Down
2 changes: 0 additions & 2 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.L1DeploymentBlockFlag,
utils.L1DisableMessageQueueV2Flag,
utils.RollupVerifyEnabledFlag,
utils.L2BaseFeeScalarFlag,
utils.L2BaseFeeOverheadFlag,
utils.DASyncEnabledFlag,
utils.DABlobScanAPIEndpointFlag,
utils.DABlockNativeAPIEndpointFlag,
Expand Down
37 changes: 0 additions & 37 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"github.com/scroll-tech/go-ethereum/consensus"
"github.com/scroll-tech/go-ethereum/consensus/clique"
"github.com/scroll-tech/go-ethereum/consensus/ethash"
"github.com/scroll-tech/go-ethereum/consensus/misc"
"github.com/scroll-tech/go-ethereum/core"
"github.com/scroll-tech/go-ethereum/core/rawdb"
"github.com/scroll-tech/go-ethereum/core/vm"
Expand Down Expand Up @@ -935,18 +934,6 @@ var (
Name: "da.recovery.produceblocks",
Usage: "Produce unsigned blocks after L1 recovery for permissionless batch submission",
}

// L2 base fee settings
L2BaseFeeScalarFlag = BigFlag{
Name: "basefee.scalar",
Usage: "Scalar used in the l2 base fee formula. Signer nodes will use this for computing the next block's base fee. Follower nodes will use this in RPC.",
Value: misc.DefaultBaseFeeScalar,
}
L2BaseFeeOverheadFlag = BigFlag{
Name: "basefee.overhead",
Usage: "Overhead used in the l2 base fee formula. Signer nodes will use this for computing the next block's base fee. Follower nodes will use this in RPC.",
Value: misc.DefaultBaseFeeOverhead,
}
)

// MakeDataDir retrieves the currently requested data directory, terminating
Expand Down Expand Up @@ -1722,29 +1709,6 @@ func setDA(ctx *cli.Context, cfg *ethconfig.Config) {
}
}

func setBaseFee(ctx *cli.Context, cfg *ethconfig.Config) {
cfg.BaseFeeScalar = misc.DefaultBaseFeeScalar
if ctx.GlobalIsSet(L2BaseFeeScalarFlag.Name) {
cfg.BaseFeeScalar = GlobalBig(ctx, L2BaseFeeScalarFlag.Name)
}
cfg.BaseFeeOverhead = misc.DefaultBaseFeeOverhead
if ctx.GlobalIsSet(L2BaseFeeOverheadFlag.Name) {
cfg.BaseFeeOverhead = GlobalBig(ctx, L2BaseFeeOverheadFlag.Name)
}

log.Info("L2 base fee coefficients", "scalar", cfg.BaseFeeScalar, "overhead", cfg.BaseFeeOverhead)

var minBaseFee uint64
if fee := misc.MinBaseFee(cfg.BaseFeeScalar, cfg.BaseFeeOverhead); fee.IsUint64() {
minBaseFee = fee.Uint64()
}

if cfg.TxPool.PriceLimit < minBaseFee {
log.Warn("Updating txpool price limit to min L2 base fee", "provided", cfg.TxPool.PriceLimit, "updated", minBaseFee)
cfg.TxPool.PriceLimit = minBaseFee
}
}

func setMaxBlockRange(ctx *cli.Context, cfg *ethconfig.Config) {
if ctx.GlobalIsSet(MaxBlockRangeFlag.Name) {
cfg.MaxBlockRange = ctx.GlobalInt64(MaxBlockRangeFlag.Name)
Expand Down Expand Up @@ -1821,7 +1785,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
setCircuitCapacityCheck(ctx, cfg)
setEnableRollupVerify(ctx, cfg)
setDA(ctx, cfg)
setBaseFee(ctx, cfg)
setMaxBlockRange(ctx, cfg)
if ctx.GlobalIsSet(ShadowforkPeersFlag.Name) {
cfg.ShadowForkPeerIDs = ctx.GlobalStringSlice(ShadowforkPeersFlag.Name)
Expand Down
32 changes: 19 additions & 13 deletions consensus/misc/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package misc
import (
"fmt"
"math/big"
"sync"

"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/params"
Expand All @@ -33,11 +34,23 @@ const MaximumL2BaseFee = 10000000000
// `scalar` accounts for finalization costs. `overhead` accounts for sequencing and proving costs.
// we use 1e18 for precision to match the contract implementation.
var (
BaseFeePrecision = new(big.Int).SetUint64(1e18)
DefaultBaseFeeScalar = new(big.Int).SetUint64(34000000000000)
DefaultBaseFeeOverhead = new(big.Int).SetUint64(15680000)
BaseFeePrecision = new(big.Int).SetUint64(1e18)

// scalar and overhead are updated automatically in `Blockchain.writeBlockWithState`.
baseFeeScalar = new(big.Int).SetUint64(34000000000000)
baseFeeOverhead = new(big.Int).SetUint64(15680000)

lock sync.RWMutex
)

func UpdateL2BaseFeeParams(newScalar, newOverhead *big.Int) {
lock.Lock()
defer lock.Unlock()

baseFeeScalar = newScalar
baseFeeOverhead = newOverhead
}

// VerifyEip1559Header verifies some header attributes which were changed in EIP-1559,
// - gas limit check
// - basefee check
Expand Down Expand Up @@ -65,16 +78,9 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, parentL1BaseF
return big.NewInt(10000000) // 0.01 Gwei
}

scalar := config.Scroll.BaseFeeScalar
if scalar == nil {
scalar = DefaultBaseFeeScalar
}
overhead := config.Scroll.BaseFeeOverhead
if overhead == nil {
overhead = DefaultBaseFeeOverhead
}

return calcBaseFee(scalar, overhead, parentL1BaseFee)
lock.RLock()
defer lock.RUnlock()
return calcBaseFee(baseFeeScalar, baseFeeOverhead, parentL1BaseFee)
}

// MinBaseFee calculates the minimum L2 base fee based on the configured coefficients.
Expand Down
6 changes: 3 additions & 3 deletions consensus/misc/eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ func TestCalcBaseFee(t *testing.T) {
}
for i, test := range tests {
config := config()
config.Scroll.BaseFeeScalar = big.NewInt(10000000)
config.Scroll.BaseFeeOverhead = big.NewInt(1)
UpdateL2BaseFeeParams(big.NewInt(10000000), big.NewInt(1))
if have, want := CalcBaseFee(config, nil, big.NewInt(test.parentL1BaseFee)), big.NewInt(test.expectedL2BaseFee); have.Cmp(want) != 0 {
t.Errorf("test %d: have %d want %d, ", i, have, want)
}
Expand All @@ -142,6 +141,7 @@ func TestCalcBaseFee(t *testing.T) {
{644149677419355, 10000000000}, // cap at max L2 base fee
}
for i, test := range testsWithDefaults {
UpdateL2BaseFeeParams(big.NewInt(34000000000000), big.NewInt(15680000))
if have, want := CalcBaseFee(config(), nil, big.NewInt(test.parentL1BaseFee)), big.NewInt(test.expectedL2BaseFee); have.Cmp(want) != 0 {
t.Errorf("test %d: have %d want %d, ", i, have, want)
}
Expand All @@ -150,7 +150,7 @@ func TestCalcBaseFee(t *testing.T) {

// TestMinBaseFee assumes all blocks are 1559-blocks
func TestMinBaseFee(t *testing.T) {
if have, want := MinBaseFee(DefaultBaseFeeScalar, DefaultBaseFeeOverhead), big.NewInt(15680000); have.Cmp(want) != 0 {
if have, want := MinBaseFee(big.NewInt(34000000000000), big.NewInt(15680000)), big.NewInt(15680000); have.Cmp(want) != 0 {
t.Errorf("have %d want %d, ", have, want)
}

Expand Down
24 changes: 23 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/scroll-tech/go-ethereum/common/mclock"
"github.com/scroll-tech/go-ethereum/common/prque"
"github.com/scroll-tech/go-ethereum/consensus"
"github.com/scroll-tech/go-ethereum/consensus/misc"
"github.com/scroll-tech/go-ethereum/core/rawdb"
"github.com/scroll-tech/go-ethereum/core/state"
"github.com/scroll-tech/go-ethereum/core/state/snapshot"
Expand All @@ -45,6 +46,7 @@ import (
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/metrics"
"github.com/scroll-tech/go-ethereum/params"
"github.com/scroll-tech/go-ethereum/rollup/rcfg"
"github.com/scroll-tech/go-ethereum/trie"
)

Expand All @@ -55,7 +57,8 @@ var (
headTimeGapGauge = metrics.NewRegisteredGauge("chain/head/timegap", nil)
headL1MessageGauge = metrics.NewRegisteredGauge("chain/head/l1msg", nil)

l2BaseFeeGauge = metrics.NewRegisteredGauge("chain/fees/l2basefee", nil)
l2BaseFeeGauge = metrics.NewRegisteredGauge("chain/fees/l2basefee", nil)
l2BaseFeeUpdateTimer = metrics.NewRegisteredTimer("chain/fees/updates", nil)

accountReadTimer = metrics.NewRegisteredTimer("chain/account/reads", nil)
accountHashTimer = metrics.NewRegisteredTimer("chain/account/hashes", nil)
Expand Down Expand Up @@ -1269,6 +1272,25 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
l2BaseFeeGauge.Update(0)
}

// Update L2 base fee coefficients.
// Coefficient updates are written into L2 state and emit an event.
// We could use either here; we read from the event to avoid state reads.
// In the future, if the base fee setting becomes part of block validation,
// reading from state will be more appropriate.
l2SystemConfigAddress := bc.Config().Scroll.L2SystemConfigAddress()
start := time.Now()

for _, r := range logs {
if r.Address == l2SystemConfigAddress && r.Topics[0] == rcfg.L2BaseFeeUpdateTopic {
scalar := r.Topics[1].Big()
overhead := r.Topics[2].Big()
misc.UpdateL2BaseFeeParams(scalar, overhead)
log.Info("Updated L2 base fee coefficients", "blockNumber", block.NumberU64(), "blockHash", block.Hash().Hex(), "scalar", scalar, "overhead", overhead)
}
}

l2BaseFeeUpdateTimer.Update(time.Since(start))

// Note the latest relayed L1 message queue index (if any)
updateHeadL1msgGauge(block)

Expand Down
7 changes: 0 additions & 7 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,6 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client l1.Client) (*Ether
if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok {
return nil, genesisErr
}

// Hacky workaround:
// It's hard to pass these fields to `CalcBaseFee`, etc.
// So pass them as part of the genesis config instead.
chainConfig.Scroll.BaseFeeScalar = config.BaseFeeScalar
chainConfig.Scroll.BaseFeeOverhead = config.BaseFeeOverhead

log.Info("Initialised chain configuration", "config", chainConfig)

if err := pruner.RecoverPruning(stack.ResolvePath(""), chainDb, stack.ResolvePath(config.TrieCleanCacheJournal)); err != nil {
Expand Down
4 changes: 0 additions & 4 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ type Config struct {

// DA syncer options
DA da_syncer.Config

// L2 base fee coefficients for the formula: `l2BaseFee = (l1BaseFee * scalar) / PRECISION + overhead`.
BaseFeeScalar *big.Int
BaseFeeOverhead *big.Int
}

// CreateConsensusEngine creates a consensus engine for the given chain configuration.
Expand Down
34 changes: 15 additions & 19 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ var (
L1MessageQueueV2DeploymentBlock: 7773746,
NumL1MessagesPerBlock: 10,
ScrollChainAddress: common.HexToAddress("0x2D567EcE699Eabe5afCd141eDB7A4f2D0D6ce8a0"),
L2SystemConfigAddress: common.Address{}, // TODO
},
GenesisStateRoot: &ScrollSepoliaGenesisState,
},
Expand Down Expand Up @@ -401,6 +402,7 @@ var (
L1MessageQueueV2DeploymentBlock: 22088276,
NumL1MessagesPerBlock: 10,
ScrollChainAddress: common.HexToAddress("0xa13BAF47339d63B743e7Da8741db5456DAc1E556"),
L2SystemConfigAddress: common.Address{}, // TODO
},
GenesisStateRoot: &ScrollMainnetGenesisState,
},
Expand Down Expand Up @@ -704,11 +706,6 @@ type ScrollConfig struct {

// Genesis State Root for MPT clients
GenesisStateRoot *common.Hash `json:"genesisStateRoot,omitempty"`

// L2 base fee coefficients for the formula: `l2BaseFee = (l1BaseFee * scalar) / PRECISION + overhead`.
// These fields are populated from configuration flags, and passed to `CalcBaseFee`.
BaseFeeScalar *big.Int `json:"-"`
BaseFeeOverhead *big.Int `json:"-"`
}

// L1Config contains the l1 parameters needed to sync l1 contract events (e.g., l1 messages, commit/revert/finalize batches) in the sequencer
Expand All @@ -719,15 +716,16 @@ type L1Config struct {
L1MessageQueueV2DeploymentBlock uint64 `json:"l1MessageQueueV2DeploymentBlock,omitempty"`
NumL1MessagesPerBlock uint64 `json:"numL1MessagesPerBlock,string,omitempty"`
ScrollChainAddress common.Address `json:"scrollChainAddress,omitempty"`
L2SystemConfigAddress common.Address `json:"l2SystemConfigAddress,omitempty"`
}

func (c *L1Config) String() string {
if c == nil {
return "<nil>"
}

return fmt.Sprintf("{l1ChainId: %v, l1MessageQueueAddress: %v, l1MessageQueueV2Address: %v, l1MessageQueueV2DeploymentBlock: %v, numL1MessagesPerBlock: %v, ScrollChainAddress: %v}",
c.L1ChainId, c.L1MessageQueueAddress.Hex(), c.L1MessageQueueV2Address.Hex(), c.L1MessageQueueV2DeploymentBlock, c.NumL1MessagesPerBlock, c.ScrollChainAddress.Hex())
return fmt.Sprintf("{l1ChainId: %v, l1MessageQueueAddress: %v, l1MessageQueueV2Address: %v, l1MessageQueueV2DeploymentBlock: %v, numL1MessagesPerBlock: %v, ScrollChainAddress: %v, L2SystemConfigAddress: %v}",
c.L1ChainId, c.L1MessageQueueAddress.Hex(), c.L1MessageQueueV2Address.Hex(), c.L1MessageQueueV2DeploymentBlock, c.NumL1MessagesPerBlock, c.ScrollChainAddress.Hex(), c.L2SystemConfigAddress.Hex())
}

func (s ScrollConfig) FeeVaultEnabled() bool {
Expand Down Expand Up @@ -758,18 +756,8 @@ func (s ScrollConfig) String() string {
genesisStateRoot = fmt.Sprintf("%v", *s.GenesisStateRoot)
}

baseFeeScalar := "<nil>"
if s.BaseFeeScalar != nil {
baseFeeScalar = s.BaseFeeScalar.String()
}

baseFeeOverhead := "<nil>"
if s.BaseFeeOverhead != nil {
baseFeeOverhead = s.BaseFeeOverhead.String()
}

return fmt.Sprintf("{useZktrie: %v, maxTxPerBlock: %v, MaxTxPayloadBytesPerBlock: %v, feeVaultAddress: %v, l1Config: %v, genesisStateRoot: %v, baseFeeScalar: %v, baseFeeOverhead: %v}",
s.UseZktrie, maxTxPerBlock, maxTxPayloadBytesPerBlock, s.FeeVaultAddress, s.L1Config.String(), genesisStateRoot, baseFeeScalar, baseFeeOverhead)
return fmt.Sprintf("{useZktrie: %v, maxTxPerBlock: %v, MaxTxPayloadBytesPerBlock: %v, feeVaultAddress: %v, l1Config: %v, genesisStateRoot: %v}",
s.UseZktrie, maxTxPerBlock, maxTxPayloadBytesPerBlock, s.FeeVaultAddress, s.L1Config.String(), genesisStateRoot)
}

// IsValidTxCount returns whether the given block's transaction count is below the limit.
Expand All @@ -788,6 +776,14 @@ func (s ScrollConfig) IsValidBlockSizeForMining(size common.StorageSize) bool {
return s.IsValidBlockSize(size * (1.0 / 0.95))
}

// L2SystemConfigAddress returns the configured l2 system config address, or the zero address if it is not configured.
func (s ScrollConfig) L2SystemConfigAddress() common.Address {
if s.L1Config == nil {
return common.Address{} // only in tests
}
return s.L1Config.L2SystemConfigAddress
}

// EthashConfig is the consensus engine configs for proof-of-work based sealing.
type EthashConfig struct{}

Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
VersionMajor = 5 // Major version component of the current release
VersionMinor = 8 // Minor version component of the current release
VersionPatch = 49 // Patch version component of the current release
VersionPatch = 50 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)

Expand Down
Loading
Loading