diff --git a/cmd/XDC/chaincmd.go b/cmd/XDC/chaincmd.go index 84dac53598..d41d8aab9e 100644 --- a/cmd/XDC/chaincmd.go +++ b/cmd/XDC/chaincmd.go @@ -45,7 +45,9 @@ var ( utils.DataDirFlag, utils.XDCXDataDirFlag, utils.LightModeFlag, - utils.XDCTestnetFlag, + utils.MainnetFlag, + utils.TestnetFlag, + utils.DevnetFlag, }, Description: ` The init command initializes a new genesis block and definition for the network. @@ -154,11 +156,23 @@ Use "ethereum dump 0" to dump the genesis block.`, // initGenesis will initialise the given JSON format genesis file and writes it as // the zero'd block (i.e. genesis) or will fail hard if it can't succeed. func initGenesis(ctx *cli.Context) error { + utils.CheckExclusive(ctx, utils.MainnetFlag, utils.TestnetFlag, utils.DevnetFlag) + var err error genesis := new(core.Genesis) - if ctx.Bool(utils.XDCTestnetFlag.Name) { + if ctx.Bool(utils.MainnetFlag.Name) { if ctx.Args().Len() > 0 { - utils.Fatalf("Flags --apothem and genesis file can't be used at the same time") + utils.Fatalf("The mainnet flag and genesis file can't be used at the same time") + } + err = json.Unmarshal(xdc_genesis.TestnetGenesis, &genesis) + } else if ctx.Bool(utils.TestnetFlag.Name) { + if ctx.Args().Len() > 0 { + utils.Fatalf("The testnet flag and genesis file can't be used at the same time") + } + err = json.Unmarshal(xdc_genesis.TestnetGenesis, &genesis) + } else if ctx.Bool(utils.DevnetFlag.Name) { + if ctx.Args().Len() > 0 { + utils.Fatalf("The devnet flag and genesis file can't be used at the same time") } err = json.Unmarshal(xdc_genesis.TestnetGenesis, &genesis) } else { @@ -166,9 +180,9 @@ func initGenesis(ctx *cli.Context) error { utils.Fatalf("need the genesis.json file or the network name [ mainnet | testnet | devnet ] as the only argument") } genesisPath := ctx.Args().First() - if genesisPath == "mainnet" { + if genesisPath == "mainnet" || genesisPath == "xinfin" { err = json.Unmarshal(xdc_genesis.MainnetGenesis, &genesis) - } else if genesisPath == "testnet" { + } else if genesisPath == "testnet" || genesisPath == "apothem" { err = json.Unmarshal(xdc_genesis.TestnetGenesis, &genesis) } else if genesisPath == "devnet" { err = json.Unmarshal(xdc_genesis.DevnetGenesis, &genesis) diff --git a/cmd/XDC/config.go b/cmd/XDC/config.go index 38ff730bdf..b5e22c12e9 100644 --- a/cmd/XDC/config.go +++ b/cmd/XDC/config.go @@ -157,7 +157,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, XDCConfig) { } // Check testnet is enable. - if ctx.Bool(utils.XDCTestnetFlag.Name) { + if ctx.Bool(utils.TestnetFlag.Name) { common.IsTestnet = true common.TRC21IssuerSMC = common.TRC21IssuerSMCTestNet cfg.Eth.NetworkId = 51 diff --git a/cmd/XDC/consolecmd.go b/cmd/XDC/consolecmd.go index 8fb64a99c9..fb5b7de77d 100644 --- a/cmd/XDC/consolecmd.go +++ b/cmd/XDC/consolecmd.go @@ -125,8 +125,8 @@ func remoteConsole(ctx *cli.Context) error { if path != "" { if ctx.Bool(utils.TestnetFlag.Name) { path = filepath.Join(path, "testnet") - } else if ctx.Bool(utils.RinkebyFlag.Name) { - path = filepath.Join(path, "rinkeby") + } else if ctx.Bool(utils.DevnetFlag.Name) { + path = filepath.Join(path, "devnet") } } endpoint = fmt.Sprintf("%s/XDC.ipc", path) diff --git a/cmd/XDC/main.go b/cmd/XDC/main.go index d87f5e2b61..bd1c10f04c 100644 --- a/cmd/XDC/main.go +++ b/cmd/XDC/main.go @@ -117,10 +117,10 @@ var ( utils.NodeKeyHexFlag, //utils.DeveloperFlag, //utils.DeveloperPeriodFlag, - //utils.TestnetFlag, - //utils.RinkebyFlag, + utils.MainnetFlag, + utils.TestnetFlag, + utils.DevnetFlag, //utils.VMEnableDebugFlag, - utils.XDCTestnetFlag, utils.Enable0xPrefixFlag, utils.EnableXDCPrefixFlag, utils.RewoundFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 569144c246..c337100f0a 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -104,19 +104,21 @@ var ( Value: ethconfig.Defaults.NetworkId, Category: flags.EthCategory, } + MainnetFlag = &cli.BoolFlag{ + Name: "mainnet", + Aliases: []string{"xinfin"}, + Usage: "XDC xinfin network", + Category: flags.EthCategory, + } TestnetFlag = &cli.BoolFlag{ Name: "testnet", - Usage: "Ropsten network: pre-configured proof-of-work test network", + Aliases: []string{"apothem"}, + Usage: "XDC apothem network", Category: flags.EthCategory, } - XDCTestnetFlag = &cli.BoolFlag{ - Name: "apothem", - Usage: "XDC Apothem Network", - Category: flags.EthCategory, - } - RinkebyFlag = &cli.BoolFlag{ - Name: "rinkeby", - Usage: "Rinkeby network: pre-configured proof-of-authority test network", + DevnetFlag = &cli.BoolFlag{ + Name: "devnet", + Usage: "XDC develop network", Category: flags.EthCategory, } @@ -823,8 +825,8 @@ func MakeDataDir(ctx *cli.Context) string { if ctx.Bool(TestnetFlag.Name) { return filepath.Join(path, "testnet") } - if ctx.Bool(RinkebyFlag.Name) { - return filepath.Join(path, "rinkeby") + if ctx.Bool(DevnetFlag.Name) { + return filepath.Join(path, "devnet") } return path } @@ -883,14 +885,11 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) { if cfg.BootstrapNodes != nil { return // Already set by config file, don't apply defaults. } - networkID := uint64(0) - if ctx.IsSet(NetworkIdFlag.Name) { - networkID = ctx.Uint64(NetworkIdFlag.Name) - } + networkID := ctx.Uint64(NetworkIdFlag.Name) switch { - case ctx.Bool(XDCTestnetFlag.Name) || networkID == params.TestnetChainConfig.ChainId.Uint64(): + case ctx.Bool(TestnetFlag.Name) || networkID == 51: urls = params.TestnetBootnodes - case networkID == params.DevnetChainConfig.ChainId.Uint64(): + case ctx.Bool(DevnetFlag.Name) || networkID == 551: urls = params.DevnetBootnodes } } @@ -921,8 +920,10 @@ func setBootstrapNodesV5(ctx *cli.Context, cfg *p2p.Config) { urls = SplitAndTrim(ctx.String(BootnodesFlag.Name)) case ctx.IsSet(BootnodesV5Flag.Name): urls = SplitAndTrim(ctx.String(BootnodesV5Flag.Name)) - case ctx.Bool(XDCTestnetFlag.Name): + case ctx.Bool(TestnetFlag.Name): urls = params.TestnetBootnodes + case ctx.Bool(DevnetFlag.Name): + urls = params.DevnetBootnodes case cfg.BootstrapNodesV5 != nil: return // already set, don't apply defaults. } @@ -1200,8 +1201,8 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) { cfg.DataDir = "" // unless explicitly requested, use memory databases case ctx.Bool(TestnetFlag.Name): cfg.DataDir = filepath.Join(node.DefaultDataDir(), "testnet") - case ctx.Bool(RinkebyFlag.Name): - cfg.DataDir = filepath.Join(node.DefaultDataDir(), "rinkeby") + case ctx.Bool(DevnetFlag.Name): + cfg.DataDir = filepath.Join(node.DefaultDataDir(), "devnet") } if ctx.IsSet(KeyStoreDirFlag.Name) { @@ -1393,7 +1394,7 @@ func SetXDCXConfig(ctx *cli.Context, cfg *XDCx.Config, XDCDataDir string) { // SetEthConfig applies eth-related command line flags to the config. func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { // Avoid conflicting network flags - CheckExclusive(ctx, DeveloperFlag, TestnetFlag, RinkebyFlag) + CheckExclusive(ctx, MainnetFlag, TestnetFlag, DevnetFlag, DeveloperFlag) CheckExclusive(ctx, FastSyncFlag, LightModeFlag, SyncModeFlag) CheckExclusive(ctx, LightServFlag, LightModeFlag) CheckExclusive(ctx, LightServFlag, SyncModeFlag, "light") @@ -1443,9 +1444,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if ctx.IsSet(NetworkIdFlag.Name) { cfg.NetworkId = ctx.Uint64(NetworkIdFlag.Name) } - if ctx.Bool(XDCTestnetFlag.Name) { - cfg.NetworkId = 51 - } if ctx.IsSet(CacheFlag.Name) || ctx.IsSet(CacheDatabaseFlag.Name) { cfg.DatabaseCache = ctx.Int(CacheFlag.Name) * ctx.Int(CacheDatabaseFlag.Name) / 100 @@ -1499,16 +1497,21 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { } // Override any default configs for hard coded networks. switch { + case ctx.Bool(MainnetFlag.Name): + if !ctx.IsSet(NetworkIdFlag.Name) { + cfg.NetworkId = 50 + } + cfg.Genesis = core.DefaultGenesisBlock() case ctx.Bool(TestnetFlag.Name): if !ctx.IsSet(NetworkIdFlag.Name) { - cfg.NetworkId = 3 + cfg.NetworkId = 51 } cfg.Genesis = core.DefaultTestnetGenesisBlock() - case ctx.Bool(RinkebyFlag.Name): + case ctx.Bool(DevnetFlag.Name): if !ctx.IsSet(NetworkIdFlag.Name) { - cfg.NetworkId = 4 + cfg.NetworkId = 551 } - cfg.Genesis = core.DefaultRinkebyGenesisBlock() + cfg.Genesis = core.DefaultDevnetGenesisBlock() case ctx.Bool(DeveloperFlag.Name): // Create new developer account or reuse existing one var ( @@ -1628,10 +1631,12 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly bool) ethdb. func MakeGenesis(ctx *cli.Context) *core.Genesis { var genesis *core.Genesis switch { + case ctx.Bool(MainnetFlag.Name): + genesis = core.DefaultGenesisBlock() case ctx.Bool(TestnetFlag.Name): genesis = core.DefaultTestnetGenesisBlock() - case ctx.Bool(RinkebyFlag.Name): - genesis = core.DefaultRinkebyGenesisBlock() + case ctx.Bool(DevnetFlag.Name): + genesis = core.DefaultDevnetGenesisBlock() case ctx.Bool(DeveloperFlag.Name): Fatalf("Developer chains are ephemeral") } diff --git a/common/constants.local.go b/common/constants.local.go index 737b609182..5626c97a08 100644 --- a/common/constants.local.go +++ b/common/constants.local.go @@ -28,7 +28,7 @@ var localConstant = constant{ TIPV2SwitchBlock: big.NewInt(0), tipXDCXMinerDisable: big.NewInt(0), tipXDCXReceiverDisable: big.NewInt(0), - eip1559Block: big.NewInt(9999999999), + eip1559Block: big.NewInt(0), cancunBlock: big.NewInt(9999999999), trc21IssuerSMCTestNet: HexToAddress("0x0E2C88753131CE01c7551B726b28BFD04e44003F"), diff --git a/core/genesis.go b/core/genesis.go index 2540b99afb..689d7d0979 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "math/big" - "strings" "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common/hexutil" @@ -33,7 +32,6 @@ import ( "github.com/XinFinOrg/XDPoSChain/ethdb" "github.com/XinFinOrg/XDPoSChain/log" "github.com/XinFinOrg/XDPoSChain/params" - "github.com/XinFinOrg/XDPoSChain/rlp" ) //go:generate go run github.com/fjl/gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go @@ -267,11 +265,10 @@ func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big return g.MustCommit(db) } -// DefaultGenesisBlock returns the Ethereum main net genesis block. +// DefaultGenesisBlock returns the XDC mainnet genesis block. func DefaultGenesisBlock() *Genesis { - config := params.XDCMainnetChainConfig return &Genesis{ - Config: config, + Config: params.XDCMainnetChainConfig, Nonce: 0, ExtraData: hexutil.MustDecode("0x000000000000000000000000000000000000000000000000000000000000000025c65b4b379ac37cf78357c4915f73677022eaffc7d49d0a2cf198deebd6ce581af465944ec8b2bbcfccdea1006a5cfa7d9484b5b293b46964c265c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), GasLimit: 4700000, @@ -281,10 +278,8 @@ func DefaultGenesisBlock() *Genesis { } } -// DefaultTestnetGenesisBlock returns the Ropsten network genesis block. +// DefaultTestnetGenesisBlock returns the XDC testnet genesis block. func DefaultTestnetGenesisBlock() *Genesis { - config := params.TestnetChainConfig - config.XDPoS.V2 = nil return &Genesis{ Config: params.TestnetChainConfig, Nonce: 0, @@ -296,15 +291,16 @@ func DefaultTestnetGenesisBlock() *Genesis { } } -// DefaultRinkebyGenesisBlock returns the Rinkeby network genesis block. -func DefaultRinkebyGenesisBlock() *Genesis { +// DefaultDevnetGenesisBlock returns the XDC devnet genesis block. +func DefaultDevnetGenesisBlock() *Genesis { return &Genesis{ - Config: params.RinkebyChainConfig, - Timestamp: 1492009146, - ExtraData: hexutil.MustDecode("0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), + Config: params.DevnetChainConfig, + Nonce: 0, + ExtraData: hexutil.MustDecode("0x0000000000000000000000000000000000000000000000000000000000000000311bdf9066246e68559816e7f636435867f824ef442a44a6fc20f5b8dfa8b304d7137581f7e6bef347318441696e9ae962633c16e04d53935272639d537fc89618edae86950e12687a612e15c4786b8473898cc3c5beca5841306b26fdb4e30411392a6a74826141342a4dc33a1045cefa4182b6212ec0317bc30fbeb7208192d1474b5f87ffbc056de43c11888c073313b36cf03cf1f739f39443551ff12bbe8d993351c0e2db739f9bcbfdeda94d73b50b16d3a242960b7ca1937e826bda6c397df74d9f9ab01aa89af636787499e81362e815e36f28763eac120babebf5a6cbe6113780cbe489e3eb0db882381aebaf81190100d82f41ad2c95898195c7a47dc59115bb5ec85408683795da2f604a5c0464868eabfcb6da489a1b4304f49aafaec938c7adc48539470624e1f9c75ce33e568d8fa3ace90497ee0c60dc921eefea93e384a6ccaaf28e33790a2d1b2625bf964dfc087e2622b02b0bb78713e872c02796ef64c8f10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), GasLimit: 4700000, Difficulty: big.NewInt(1), - Alloc: decodePrealloc(""), + Alloc: DecodeAllocJson(DevnetAllocData), + Timestamp: 1735513074, } } @@ -336,18 +332,6 @@ func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis { } } -func decodePrealloc(data string) types.GenesisAlloc { - var p []struct{ Addr, Balance *big.Int } - if err := rlp.NewStream(strings.NewReader(data), 0).Decode(&p); err != nil { - panic(err) - } - ga := make(types.GenesisAlloc, len(p)) - for _, account := range p { - ga[common.BigToAddress(account.Addr)] = types.Account{Balance: account.Balance} - } - return ga -} - func DecodeAllocJson(s string) types.GenesisAlloc { alloc := types.GenesisAlloc{} json.Unmarshal([]byte(s), &alloc) diff --git a/eth/handler.go b/eth/handler.go index 7ac5c633f7..0abf711fe2 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -1080,7 +1080,7 @@ func (pm *ProtocolManager) lendingTxBroadcastLoop() { // NodeInfo represents a short summary of the Ethereum sub-protocol metadata // known about the host peer. type NodeInfo struct { - Network uint64 `json:"network"` // Ethereum network ID (1=Frontier, 2=Morden, Ropsten=3, Rinkeby=4) + Network uint64 `json:"network"` // XDC network ID (50=xinfin, 51=apothem, 551=devnet) Difficulty *big.Int `json:"difficulty"` // Total difficulty of the host's blockchain Genesis common.Hash `json:"genesis"` // SHA3 hash of the host's genesis block Config *params.ChainConfig `json:"config"` // Chain configuration for the fork rules diff --git a/les/backend.go b/les/backend.go index 0f250f5181..3b0f6bed41 100644 --- a/les/backend.go +++ b/les/backend.go @@ -92,6 +92,12 @@ func New(ctx *node.ServiceContext, config *ethconfig.Config) (*LightEthereum, er 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) @@ -101,10 +107,6 @@ func New(ctx *node.ServiceContext, config *ethconfig.Config) (*LightEthereum, er peers := newPeerSet() quitSync := make(chan struct{}) - networkID := config.NetworkId - if networkID == 0 { - networkID = chainConfig.ChainId.Uint64() - } leth := &LightEthereum{ config: config, chainConfig: chainConfig, diff --git a/les/handler.go b/les/handler.go index bef0fd6467..d988101004 100644 --- a/les/handler.go +++ b/les/handler.go @@ -1184,7 +1184,7 @@ func (pm *ProtocolManager) txStatus(hashes []common.Hash) []txStatus { // NodeInfo represents a short summary of the Ethereum sub-protocol metadata // known about the host peer. type NodeInfo struct { - Network uint64 `json:"network"` // Ethereum network ID (1=Frontier, 2=Morden, Ropsten=3, Rinkeby=4) + Network uint64 `json:"network"` // XDC network ID (50=xinfin, 51=apothem, 551=devnet) Difficulty *big.Int `json:"difficulty"` // Total difficulty of the host's blockchain Genesis common.Hash `json:"genesis"` // SHA3 hash of the host's genesis block Config *params.ChainConfig `json:"config"` // Chain configuration for the fork rules diff --git a/params/config.go b/params/config.go index 971892bc13..67007c7871 100644 --- a/params/config.go +++ b/params/config.go @@ -240,29 +240,6 @@ var ( }, } - // RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network. - RinkebyChainConfig = &ChainConfig{ - ChainId: big.NewInt(4), - HomesteadBlock: big.NewInt(1), - DAOForkBlock: nil, - DAOForkSupport: true, - EIP150Block: big.NewInt(2), - EIP155Block: big.NewInt(3), - EIP158Block: big.NewInt(3), - ByzantiumBlock: big.NewInt(1035301), - ConstantinopleBlock: nil, - XDPoS: &XDPoSConfig{ - Period: 15, - Epoch: 900, - V2: &V2{ - SwitchEpoch: 9999999999 / 900, - SwitchBlock: big.NewInt(9999999999), - CurrentConfig: MainnetV2Configs[0], - AllConfigs: MainnetV2Configs, - }, - }, - } - // AllEthashProtocolChanges contains every protocol change (EIPs) introduced // and accepted by the Ethereum core developers into the Ethash consensus. //