Skip to content

Commit

Permalink
[config] remove EVMNetworkID() and SetEVMNetworkID() (#3503)
Browse files Browse the repository at this point in the history
Co-authored-by: dustinxie <dahuaxie@gmail.com>
  • Loading branch information
millken and dustinxie committed Jul 6, 2022
1 parent 9347fed commit e956ca6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 26 deletions.
19 changes: 0 additions & 19 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"math/big"
"os"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/iotexproject/go-pkgs/crypto"
Expand All @@ -34,11 +32,6 @@ import (
// IMPORTANT: to define a config, add a field or a new config type to the existing config types. In addition, provide
// the default value in Default var.

var (
_evmNetworkID uint32
_loadChainID sync.Once
)

const (
// RollDPoSScheme means randomized delegated proof of stake
RollDPoSScheme = "ROLLDPOS"
Expand Down Expand Up @@ -463,18 +456,6 @@ func NewSub(configPaths []string, validates ...Validate) (Config, error) {
return cfg, nil
}

// SetEVMNetworkID sets the extern chain ID
func SetEVMNetworkID(id uint32) {
_loadChainID.Do(func() {
_evmNetworkID = id
})
}

// EVMNetworkID returns the extern chain ID
func EVMNetworkID() uint32 {
return atomic.LoadUint32(&_evmNetworkID)
}

// ProducerAddress returns the configured producer address derived from key
func (cfg Config) ProducerAddress() address.Address {
sk := cfg.ProducerPrivateKey()
Expand Down
2 changes: 0 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ func TestStrs_String(t *testing.T) {
func TestNewDefaultConfig(t *testing.T) {
cfg, err := New([]string{}, []string{})
require.NoError(t, err)
SetEVMNetworkID(cfg.Chain.EVMNetworkID)
require.Equal(t, cfg.Chain.EVMNetworkID, EVMNetworkID())
genesis.SetGenesisTimestamp(cfg.Genesis.Timestamp)
require.Equal(t, cfg.Genesis.Timestamp, genesis.Timestamp())
}
Expand Down
9 changes: 4 additions & 5 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,17 @@ func main() {
}
defer recovery.Recover()

// populdate chain ID
config.SetEVMNetworkID(cfg.Chain.EVMNetworkID)
if config.EVMNetworkID() == 0 {
glog.Fatalln("EVM Network ID is not set, call config.New() first")
// check EVM network ID and chain ID
if cfg.Chain.EVMNetworkID == 0 || cfg.Chain.ID == 0 {
glog.Fatalln("EVM Network ID or Chain ID is not set, call config.New() first")
}

cfg.Genesis = genesisCfg
cfgToLog := cfg
cfgToLog.Chain.ProducerPrivKey = ""
cfgToLog.Network.MasterKey = ""
log.S().Infof("Config in use: %+v", cfgToLog)
log.S().Infof("EVM Network ID: %d, Chain ID: %d", config.EVMNetworkID(), cfg.Chain.ID)
log.S().Infof("EVM Network ID: %d, Chain ID: %d", cfg.Chain.EVMNetworkID, cfg.Chain.ID)
log.S().Infof("Genesis timestamp: %d", genesisCfg.Timestamp)
log.S().Infof("Genesis hash: %x", block.GenesisHash())

Expand Down

0 comments on commit e956ca6

Please sign in to comment.