Skip to content

Commit

Permalink
Merge pull request ethereum#110 from OffchainLabs/genesisblock_chainc…
Browse files Browse the repository at this point in the history
…onfig

Genesisblock chainconfig
  • Loading branch information
PlasmaPower authored Jun 15, 2022
2 parents 819647b + ba3fcb9 commit fe17647
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 25 deletions.
22 changes: 2 additions & 20 deletions arbitrum/apibackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (a *APIBackend) FeeHistory(
return nil, nil, nil, nil, errors.New("ArbOS not installed")
}

nitroGenesis := core.NitroGenesisBlock
newestBlock, latestBlock := ClipToPostNitroGenesis(a, newestBlock)
nitroGenesis := rpc.BlockNumber(a.ChainConfig().ArbitrumChainParams.GenesisBlockNum)
newestBlock, latestBlock := a.blockChain().ClipToPostNitroGenesis(newestBlock)

maxFeeHistory := int(a.b.config.FeeHistoryMaxBlockCount)
if blocks > maxFeeHistory {
Expand Down Expand Up @@ -416,21 +416,3 @@ func (a *APIBackend) ChainConfig() *params.ChainConfig {
func (a *APIBackend) Engine() consensus.Engine {
return a.blockChain().Engine()
}

type GetsCurrentBlock interface {
CurrentBlock() *types.Block
}

func ClipToPostNitroGenesis(getter GetsCurrentBlock, blockNum rpc.BlockNumber) (rpc.BlockNumber, rpc.BlockNumber) {
currentBlock := rpc.BlockNumber(getter.CurrentBlock().NumberU64())
if blockNum == rpc.LatestBlockNumber || blockNum == rpc.PendingBlockNumber {
blockNum = currentBlock
}
if blockNum > currentBlock {
blockNum = currentBlock
}
if blockNum < core.NitroGenesisBlock {
blockNum = core.NitroGenesisBlock
}
return blockNum, currentBlock
}
3 changes: 0 additions & 3 deletions core/arbitrum_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ var InterceptRPCMessage func(
// Gets ArbOS's approximation of how quickly compute gas is being burnt relative to the speed limit.
var GetArbOSComputeRate func(statedb *state.StateDB) (float64, error)

// The Nitro genesis block. All blocks before this were imported.
var NitroGenesisBlock rpc.BlockNumber

// Allows ArbOS to update the gas cap so that it ignores the message's specific L1 poster costs.
var InterceptRPCGasCap func(gascap *uint64, msg types.Message, header *types.Header, statedb *state.StateDB)

Expand Down
20 changes: 19 additions & 1 deletion core/blockchain_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
// Package core implements the Ethereum consensus protocol.
package core

import "github.com/ethereum/go-ethereum/core/types"
import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
)

func (bc *BlockChain) ReorgToOldBlock(newHead *types.Block) error {
bc.wg.Add(1)
Expand All @@ -36,3 +39,18 @@ func (bc *BlockChain) ReorgToOldBlock(newHead *types.Block) error {
bc.chainHeadFeed.Send(ChainHeadEvent{Block: newHead})
return nil
}

func (bc *BlockChain) ClipToPostNitroGenesis(blockNum rpc.BlockNumber) (rpc.BlockNumber, rpc.BlockNumber) {
currentBlock := rpc.BlockNumber(bc.CurrentBlock().NumberU64())
nitroGenesis := rpc.BlockNumber(bc.Config().ArbitrumChainParams.GenesisBlockNum)
if blockNum == rpc.LatestBlockNumber || blockNum == rpc.PendingBlockNumber {
blockNum = currentBlock
}
if blockNum > currentBlock {
blockNum = currentBlock
}
if blockNum < nitroGenesis {
blockNum = nitroGenesis
}
return blockNum, currentBlock
}
2 changes: 1 addition & 1 deletion params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
if isForkIncompatible(c.MergeForkBlock, newcfg.MergeForkBlock, head) {
return newCompatError("Merge Start fork block", c.MergeForkBlock, newcfg.MergeForkBlock)
}
return nil
return c.checkArbitrumCompatible(newcfg, head)
}

// isForkIncompatible returns true if a fork scheduled at s1 cannot be rescheduled to
Expand Down
23 changes: 23 additions & 0 deletions params/config_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ArbitrumChainParams struct {
DataAvailabilityCommittee bool
InitialArbOSVersion uint64
InitialChainOwner common.Address
GenesisBlockNum uint64
}

func (c *ChainConfig) IsArbitrum() bool {
Expand All @@ -38,6 +39,28 @@ func (c *ChainConfig) DebugMode() bool {
return c.ArbitrumChainParams.AllowDebugPrecompiles
}

func (c *ChainConfig) checkArbitrumCompatible(newcfg *ChainConfig, head *big.Int) *ConfigCompatError {
boolToBig := func(b bool) *big.Int {
if b {
return common.Big1
}
return common.Big0
}

if c.IsArbitrum() != newcfg.IsArbitrum() {
return newCompatError("isArbitrum", boolToBig(c.IsArbitrum()), boolToBig(newcfg.IsArbitrum()))
}
if !c.IsArbitrum() {
return nil
}
cArb := &c.ArbitrumChainParams
newArb := &newcfg.ArbitrumChainParams
if cArb.GenesisBlockNum != newArb.GenesisBlockNum {
return newCompatError("genesisblocknum", new(big.Int).SetUint64(cArb.GenesisBlockNum), new(big.Int).SetUint64(newArb.GenesisBlockNum))
}
return nil
}

func ArbitrumOneParams() ArbitrumChainParams {
return ArbitrumChainParams{
EnableArbOS: true,
Expand Down

0 comments on commit fe17647

Please sign in to comment.