Skip to content

Commit df1d37e

Browse files
refactor(config): consolidate scroll flags (#262)
1 parent 909fe1d commit df1d37e

File tree

19 files changed

+108
-68
lines changed

19 files changed

+108
-68
lines changed

cmd/evm/internal/t8ntool/transition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func Transition(ctx *cli.Context) error {
248248
}
249249
// Sanity check, to not `panic` in state_transition
250250
if chainConfig.IsLondon(big.NewInt(int64(prestate.Env.Number))) {
251-
if prestate.Env.BaseFee == nil && chainConfig.EnableEIP2718 && chainConfig.EnableEIP1559 {
251+
if prestate.Env.BaseFee == nil && chainConfig.Scroll.BaseFeeEnabled() {
252252
return NewError(ErrorConfig, errors.New("EIP-1559 config but missing 'currentBaseFee' in env section"))
253253
}
254254
}

consensus/misc/eip1559.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func VerifyEip1559Header(config *params.ChainConfig, parent, header *types.Heade
3939
return err
4040
}
4141
// Verify the header is not malformed
42-
if header.BaseFee == nil && (config.EnableEIP2718 && config.EnableEIP1559) {
42+
if header.BaseFee == nil && config.Scroll.BaseFeeEnabled() {
4343
return fmt.Errorf("header is missing baseFee")
4444
}
45-
// Now BaseFee can be nil, because !(config.EnableEIP2718 && config.EnableEIP1559)
45+
// Now BaseFee can be nil, because !config.Scroll.BaseFeeEnabled()
4646
if header.BaseFee == nil {
4747
return nil
4848
}
@@ -51,7 +51,7 @@ func VerifyEip1559Header(config *params.ChainConfig, parent, header *types.Heade
5151
var expectedBaseFee *big.Int
5252

5353
// compatible check with the logic in commitNewWork
54-
if config.Clique == nil || (config.EnableEIP2718 && config.EnableEIP1559) {
54+
if config.Clique == nil || config.Scroll.BaseFeeEnabled() {
5555
expectedBaseFee = CalcBaseFee(config, parent)
5656
} else {
5757
expectedBaseFee = big.NewInt(0)
@@ -76,7 +76,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
7676
parentGasTargetBig = new(big.Int).SetUint64(parentGasTarget)
7777
baseFeeChangeDenominator = new(big.Int).SetUint64(params.BaseFeeChangeDenominator)
7878
)
79-
if !config.EnableEIP2718 || !config.EnableEIP1559 {
79+
if !config.Scroll.BaseFeeEnabled() {
8080
return nil
8181
}
8282
// If the parent gasUsed is the same as the target, the baseFee remains unchanged.

core/block_validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
5454
if v.bc.HasBlockAndState(block.Hash(), block.NumberU64()) {
5555
return ErrKnownBlock
5656
}
57-
if !v.config.IsValidTxCount(len(block.Transactions())) {
57+
if !v.config.Scroll.IsValidTxCount(len(block.Transactions())) {
5858
return consensus.ErrInvalidTxCount
5959
}
6060
// Header validity is known at this point, check the uncles and transactions

core/blockchain.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,13 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
231231
txLookupCache, _ := lru.New(txLookupCacheLimit)
232232
futureBlocks, _ := lru.New(maxFutureBlocks)
233233
// override snapshot setting
234-
if chainConfig.Zktrie && cacheConfig.SnapshotLimit > 0 {
234+
if chainConfig.Scroll.ZktrieEnabled() && cacheConfig.SnapshotLimit > 0 {
235235
log.Warn("Snapshot has been disabled by zktrie")
236236
cacheConfig.SnapshotLimit = 0
237237
}
238238

239-
if chainConfig.FeeVaultAddress != nil {
240-
log.Warn("Using fee vault address", "FeeVaultAddress", *chainConfig.FeeVaultAddress)
239+
if chainConfig.Scroll.L1FeeEnabled() {
240+
log.Warn("Using fee vault address", "FeeVaultAddress", *chainConfig.Scroll.FeeVaultAddress)
241241
}
242242

243243
bc := &BlockChain{
@@ -249,7 +249,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
249249
Cache: cacheConfig.TrieCleanLimit,
250250
Journal: cacheConfig.TrieCleanJournal,
251251
Preimages: cacheConfig.Preimages,
252-
Zktrie: chainConfig.Zktrie,
252+
Zktrie: chainConfig.Scroll.ZktrieEnabled(),
253253
}),
254254
quit: make(chan struct{}),
255255
chainmu: syncx.NewClosableMutex(),

core/blockchain_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,7 +3170,7 @@ func TestFeeVault(t *testing.T) {
31703170
}
31713171

31723172
// Ensure that the fee vault received all tx fees
3173-
actual = state.GetBalance(*params.TestChainConfig.FeeVaultAddress)
3173+
actual = state.GetBalance(*params.TestChainConfig.Scroll.FeeVaultAddress)
31743174
expected = new(big.Int).SetUint64(block.GasUsed() * block.Transactions()[0].GasTipCap().Uint64())
31753175

31763176
if actual.Cmp(expected) != 0 {
@@ -3182,8 +3182,8 @@ func TestFeeVault(t *testing.T) {
31823182
func TestTransactionCountLimit(t *testing.T) {
31833183
// Create config that allows at most 1 transaction per block
31843184
config := params.TestChainConfig
3185-
config.MaxTxPerBlock = new(int)
3186-
*config.MaxTxPerBlock = 1
3185+
config.Scroll.MaxTxPerBlock = new(int)
3186+
*config.Scroll.MaxTxPerBlock = 1
31873187

31883188
var (
31893189
engine = ethash.NewFaker()

core/genesis.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
188188
if storedcfg == nil {
189189
log.Warn("Found genesis block without chain config")
190190
} else {
191-
trieCfg = &trie.Config{Zktrie: storedcfg.Zktrie}
191+
trieCfg = &trie.Config{Zktrie: storedcfg.Scroll.ZktrieEnabled()}
192192
}
193193
} else {
194-
trieCfg = &trie.Config{Zktrie: genesis.Config.Zktrie}
194+
trieCfg = &trie.Config{Zktrie: genesis.Config.Scroll.ZktrieEnabled()}
195195
}
196196

197197
if _, err := state.New(header.Root, state.NewDatabaseWithConfig(db, trieCfg), nil); err != nil {
@@ -277,7 +277,7 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
277277
}
278278
var trieCfg *trie.Config
279279
if g.Config != nil {
280-
trieCfg = &trie.Config{Zktrie: g.Config.Zktrie}
280+
trieCfg = &trie.Config{Zktrie: g.Config.Scroll.ZktrieEnabled()}
281281
}
282282
statedb, err := state.New(common.Hash{}, state.NewDatabaseWithConfig(db, trieCfg), nil)
283283
if err != nil {
@@ -315,7 +315,7 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
315315
if g.Config != nil && g.Config.IsLondon(common.Big0) {
316316
if g.BaseFee != nil {
317317
head.BaseFee = g.BaseFee
318-
} else if g.Config.EnableEIP2718 && g.Config.EnableEIP1559 {
318+
} else if g.Config.Scroll.BaseFeeEnabled() {
319319
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
320320
} else {
321321
head.BaseFee = nil

core/state_transition.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation b
166166
// NewStateTransition initialises and returns a new state transition object.
167167
func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition {
168168
l1Fee := new(big.Int)
169-
if evm.ChainConfig().UsingScroll {
169+
if evm.ChainConfig().Scroll.L1FeeEnabled() {
170170
l1Fee, _ = fees.CalculateL1MsgFee(msg, evm.StateDB)
171171
}
172172

@@ -207,7 +207,7 @@ func (st *StateTransition) buyGas() error {
207207
mgval := new(big.Int).SetUint64(st.msg.Gas())
208208
mgval = mgval.Mul(mgval, st.gasPrice)
209209

210-
if st.evm.ChainConfig().UsingScroll {
210+
if st.evm.ChainConfig().Scroll.L1FeeEnabled() {
211211
// always add l1fee, because all tx are L2-to-L1 ATM
212212
log.Debug("Adding L1 fee", "l1_fee", st.l1Fee)
213213
mgval = mgval.Add(mgval, st.l1Fee)
@@ -218,7 +218,7 @@ func (st *StateTransition) buyGas() error {
218218
balanceCheck = new(big.Int).SetUint64(st.msg.Gas())
219219
balanceCheck = balanceCheck.Mul(balanceCheck, st.gasFeeCap)
220220
balanceCheck.Add(balanceCheck, st.value)
221-
if st.evm.ChainConfig().UsingScroll {
221+
if st.evm.ChainConfig().Scroll.L1FeeEnabled() {
222222
// always add l1fee, because all tx are L2-to-L1 ATM
223223
balanceCheck.Add(balanceCheck, st.l1Fee)
224224
}
@@ -370,7 +370,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
370370
}
371371
}
372372

373-
if st.evm.ChainConfig().UsingScroll {
373+
if st.evm.ChainConfig().Scroll.L1FeeEnabled() {
374374
// The L2 Fee is the same as the fee that is charged in the normal geth
375375
// codepath. Add the L1 fee to the L2 fee for the total fee that is sent
376376
// to the sequencer.

core/tx_pool.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
682682
// the sender is marked as local previously, treat it as the local transaction.
683683
isLocal := local || pool.locals.containsTx(tx)
684684

685-
if pool.chainconfig.UsingScroll {
685+
if pool.chainconfig.Scroll.L1FeeEnabled() {
686686
if err := fees.VerifyFee(pool.signer, tx, pool.currentState); err != nil {
687687
log.Trace("Discarding insufficient l1fee transaction", "hash", hash, "err", err)
688688
invalidTxMeter.Mark(1)
@@ -1329,8 +1329,9 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
13291329
// Update all fork indicator by next pending block number.
13301330
next := new(big.Int).Add(newHead.Number, big.NewInt(1))
13311331
pool.istanbul = pool.chainconfig.IsIstanbul(next)
1332-
pool.eip2718 = pool.chainconfig.EnableEIP2718 && pool.chainconfig.IsBerlin(next)
1333-
pool.eip1559 = pool.chainconfig.EnableEIP1559 && pool.chainconfig.IsLondon(next)
1332+
1333+
pool.eip2718 = pool.chainconfig.Scroll.EnableEIP2718 && pool.chainconfig.IsBerlin(next)
1334+
pool.eip1559 = pool.chainconfig.Scroll.EnableEIP1559 && pool.chainconfig.IsLondon(next)
13341335
}
13351336

13361337
// promoteExecutables moves transactions that have become processable from the

core/vm/evm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ func (evm *EVM) ChainConfig() *params.ChainConfig { return evm.chainConfig }
535535

536536
// FeeRecipient returns the environment's transaction fee recipient address.
537537
func (evm *EVM) FeeRecipient() common.Address {
538-
if evm.ChainConfig().FeeVaultAddress != nil {
539-
return *evm.chainConfig.FeeVaultAddress
538+
if evm.ChainConfig().Scroll.L1FeeEnabled() {
539+
return *evm.chainConfig.Scroll.FeeVaultAddress
540540
} else {
541541
return evm.Context.Coinbase
542542
}

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ func (s *Ethereum) BloomIndexer() *core.ChainIndexer { return s.bloomIndexer }
516516
// network protocols to start.
517517
func (s *Ethereum) Protocols() []p2p.Protocol {
518518
protos := eth.MakeProtocols((*ethHandler)(s.handler), s.networkID, s.ethDialCandidates)
519-
if !s.blockchain.Config().Zktrie && s.config.SnapshotCache > 0 {
519+
if !s.blockchain.Config().Scroll.ZktrieEnabled() && s.config.SnapshotCache > 0 {
520520
protos = append(protos, snap.MakeProtocols((*snapHandler)(s.handler), s.snapDialCandidates)...)
521521
}
522522
return protos

0 commit comments

Comments
 (0)