Skip to content

Commit

Permalink
cmd, common, eth: copy constants after get chain id
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Feb 18, 2025
1 parent 6f22270 commit 2a2711a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
1 change: 0 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.Bool(XDCTestnetFlag.Name) {
cfg.NetworkId = 51
}
common.CopyConstans(cfg.NetworkId)

if ctx.IsSet(CacheFlag.Name) || ctx.IsSet(CacheDatabaseFlag.Name) {
cfg.DatabaseCache = ctx.Int(CacheFlag.Name) * ctx.Int(CacheDatabaseFlag.Name) / 100
Expand Down
11 changes: 6 additions & 5 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ var (
LendingRegistrationSMC = MaintnetConstant.lendingRegistrationSMC
LendingRegistrationSMCTestnet = MaintnetConstant.lendingRegistrationSMCTestnet

ignoreSignerCheckBlockArray = map[uint64]struct{}{}
blacklist = map[Address]struct{}{}
ignoreSignerCheckBlockArray = MaintnetConstant.ignoreSignerCheckBlockArray
blacklist = MaintnetConstant.blacklist
)

func IsIgnoreSignerCheckBlock(blockNumber uint64) bool {
Expand All @@ -160,12 +160,13 @@ func IsInBlacklist(address *Address) bool {
return ok
}

// CopyConstans only handles testnet, devnet, local. It does not
// handles mainnet since the default value is from mainnet.
func CopyConstans(chainID uint64) {
var c *constant
if chainID == MaintnetConstant.chainID {
c = &MaintnetConstant
} else if chainID == TestnetConstant.chainID {
if chainID == TestnetConstant.chainID {
c = &TestnetConstant
IsTestnet = true
} else if chainID == DevnetConstant.chainID {
c = &DevnetConstant
} else if chainID == localConstant.chainID {
Expand Down
11 changes: 6 additions & 5 deletions common/constants/constants.go.devnet
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ var (
LendingRegistrationSMC = MaintnetConstant.lendingRegistrationSMC
LendingRegistrationSMCTestnet = MaintnetConstant.lendingRegistrationSMCTestnet

ignoreSignerCheckBlockArray = map[uint64]struct{}{}
blacklist = map[Address]struct{}{}
ignoreSignerCheckBlockArray = MaintnetConstant.ignoreSignerCheckBlockArray
blacklist = MaintnetConstant.blacklist
)

func IsIgnoreSignerCheckBlock(blockNumber uint64) bool {
Expand All @@ -160,12 +160,13 @@ func IsInBlacklist(address *Address) bool {
return ok
}

// CopyConstans only handles testnet, devnet, local. It does not
// handles mainnet since the default value is from mainnet.
func CopyConstans(chainID uint64) {
var c *constant
if chainID == MaintnetConstant.chainID {
c = &MaintnetConstant
} else if chainID == TestnetConstant.chainID {
if chainID == TestnetConstant.chainID {
c = &TestnetConstant
IsTestnet = true
} else if chainID == DevnetConstant.chainID {
c = &DevnetConstant
} else if chainID == localConstant.chainID {
Expand Down
11 changes: 6 additions & 5 deletions common/constants/constants.go.local
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ var (
LendingRegistrationSMC = MaintnetConstant.lendingRegistrationSMC
LendingRegistrationSMCTestnet = MaintnetConstant.lendingRegistrationSMCTestnet

ignoreSignerCheckBlockArray = map[uint64]struct{}{}
blacklist = map[Address]struct{}{}
ignoreSignerCheckBlockArray = MaintnetConstant.ignoreSignerCheckBlockArray
blacklist = MaintnetConstant.blacklist
)

func IsIgnoreSignerCheckBlock(blockNumber uint64) bool {
Expand All @@ -160,12 +160,13 @@ func IsInBlacklist(address *Address) bool {
return ok
}

// CopyConstans only handles testnet, devnet, local. It does not
// handles mainnet since the default value is from mainnet.
func CopyConstans(chainID uint64) {
var c *constant
if chainID == MaintnetConstant.chainID {
c = &MaintnetConstant
} else if chainID == TestnetConstant.chainID {
if chainID == TestnetConstant.chainID {
c = &TestnetConstant
IsTestnet = true
} else if chainID == DevnetConstant.chainID {
c = &DevnetConstant
} else if chainID == localConstant.chainID {
Expand Down
11 changes: 6 additions & 5 deletions common/constants/constants.go.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ var (
LendingRegistrationSMC = MaintnetConstant.lendingRegistrationSMC
LendingRegistrationSMCTestnet = MaintnetConstant.lendingRegistrationSMCTestnet

ignoreSignerCheckBlockArray = map[uint64]struct{}{}
blacklist = map[Address]struct{}{}
ignoreSignerCheckBlockArray = MaintnetConstant.ignoreSignerCheckBlockArray
blacklist = MaintnetConstant.blacklist
)

func IsIgnoreSignerCheckBlock(blockNumber uint64) bool {
Expand All @@ -160,12 +160,13 @@ func IsInBlacklist(address *Address) bool {
return ok
}

// CopyConstans only handles testnet, devnet, local. It does not
// handles mainnet since the default value is from mainnet.
func CopyConstans(chainID uint64) {
var c *constant
if chainID == MaintnetConstant.chainID {
c = &MaintnetConstant
} else if chainID == TestnetConstant.chainID {
if chainID == TestnetConstant.chainID {
c = &TestnetConstant
IsTestnet = true
} else if chainID == DevnetConstant.chainID {
c = &DevnetConstant
} else if chainID == localConstant.chainID {
Expand Down
10 changes: 6 additions & 4 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,18 @@ func New(ctx *node.ServiceContext, config *ethconfig.Config, XDCXServ *XDCx.XDCX
return nil, genesisErr
}

networkID := config.NetworkId
if networkID == 0 {
networkID = chainConfig.ChainId.Uint64()
}
common.CopyConstans(networkID)

log.Info(strings.Repeat("-", 153))
for _, line := range strings.Split(chainConfig.Description(), "\n") {
log.Info(line)
}
log.Info(strings.Repeat("-", 153))

networkID := config.NetworkId
if networkID == 0 {
networkID = chainConfig.ChainId.Uint64()
}
eth := &Ethereum{
config: config,
chainDb: chainDb,
Expand Down

0 comments on commit 2a2711a

Please sign in to comment.