Skip to content

Commit

Permalink
Merge pull request #6578 from onflow/ramtin/evm-make-config-concurren…
Browse files Browse the repository at this point in the history
…cy-safe

[EVM] Make chain config concurrency safe
  • Loading branch information
ramtinms authored Oct 21, 2024
2 parents 56dcac7 + aef8c04 commit a3a1295
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
73 changes: 47 additions & 26 deletions fvm/evm/emulator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,50 @@ func (c *Config) ChainRules() gethParams.Rules {
c.BlockContext.Time)
}

// DefaultChainConfig is the default chain config used by the emulator
// considers majority of EVM upgrades (e.g. Cancun update) are already applied
// PreviewNetChainConfig is the chain config used by the previewnet
var PreviewNetChainConfig = MakeChainConfig(types.FlowEVMPreviewNetChainID)

// PreviewNetChainConfig is the chain config used by the testnet
var TestNetChainConfig = MakeChainConfig(types.FlowEVMTestNetChainID)

// MainNetChainConfig is the chain config used by the mainnet
var MainNetChainConfig = MakeChainConfig(types.FlowEVMMainNetChainID)

// DefaultChainConfig is the chain config used by the emulator
var DefaultChainConfig = PreviewNetChainConfig

// MakeChainConfig constructs a chain config
// it considers majority of EVM upgrades (e.g. Cancun update) are already applied
// This has been done through setting the height of these changes
// to zero nad setting the time for some other changes to zero
// For the future changes of EVM, we need to update the EVM go mod version
// and set a proper height for the specific release based on the Flow EVM heights
// so it could gets activated at a desired time.
var DefaultChainConfig = &gethParams.ChainConfig{
ChainID: types.FlowEVMPreviewNetChainID,

// Fork scheduling based on block heights
HomesteadBlock: bigZero,
DAOForkBlock: bigZero,
DAOForkSupport: false,
EIP150Block: bigZero,
EIP155Block: bigZero,
EIP158Block: bigZero,
ByzantiumBlock: bigZero, // already on Byzantium
ConstantinopleBlock: bigZero, // already on Constantinople
PetersburgBlock: bigZero, // already on Petersburg
IstanbulBlock: bigZero, // already on Istanbul
BerlinBlock: bigZero, // already on Berlin
LondonBlock: bigZero, // already on London
MuirGlacierBlock: bigZero, // already on MuirGlacier

// Fork scheduling based on timestamps
ShanghaiTime: &zero, // already on Shanghai
CancunTime: &zero, // already on Cancun
PragueTime: nil, // not on Prague
VerkleTime: nil, // not on Verkle
func MakeChainConfig(chainID *big.Int) *gethParams.ChainConfig {
return &gethParams.ChainConfig{
ChainID: chainID,

// Fork scheduling based on block heights
HomesteadBlock: bigZero,
DAOForkBlock: bigZero,
DAOForkSupport: false,
EIP150Block: bigZero,
EIP155Block: bigZero,
EIP158Block: bigZero,
ByzantiumBlock: bigZero, // already on Byzantium
ConstantinopleBlock: bigZero, // already on Constantinople
PetersburgBlock: bigZero, // already on Petersburg
IstanbulBlock: bigZero, // already on Istanbul
BerlinBlock: bigZero, // already on Berlin
LondonBlock: bigZero, // already on London
MuirGlacierBlock: bigZero, // already on MuirGlacier

// Fork scheduling based on timestamps
ShanghaiTime: &zero, // already on Shanghai
CancunTime: &zero, // already on Cancun
PragueTime: nil, // not on Prague
VerkleTime: nil, // not on Verkle
}
}

// Default config supports the dynamic fee structure (EIP-1559)
Expand Down Expand Up @@ -123,7 +137,14 @@ type Option func(*Config) *Config
// WithChainID sets the evm chain ID
func WithChainID(chainID *big.Int) Option {
return func(c *Config) *Config {
c.ChainConfig.ChainID = chainID
switch chainID.Uint64() {
case types.FlowEVMPreviewNetChainIDInUInt64:
c.ChainConfig = PreviewNetChainConfig
case types.FlowEVMTestNetChainIDInUInt64:
c.ChainConfig = TestNetChainConfig
case types.FlowEVMMainNetChainIDInUInt64:
c.ChainConfig = MainNetChainConfig
}
return c
}
}
Expand Down
4 changes: 4 additions & 0 deletions fvm/evm/types/chainIDs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ var (
FlowEVMPreviewNetChainID = big.NewInt(646)
FlowEVMTestNetChainID = big.NewInt(545)
FlowEVMMainNetChainID = big.NewInt(747)

FlowEVMPreviewNetChainIDInUInt64 = FlowEVMPreviewNetChainID.Uint64()
FlowEVMTestNetChainIDInUInt64 = FlowEVMTestNetChainID.Uint64()
FlowEVMMainNetChainIDInUInt64 = FlowEVMMainNetChainID.Uint64()
)

func EVMChainIDFromFlowChainID(flowChainID flow.ChainID) *big.Int {
Expand Down

0 comments on commit a3a1295

Please sign in to comment.