Skip to content

Commit

Permalink
params: use rialto to test builtin network logic (#2106)
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh0 authored Dec 28, 2023
1 parent 8e56d6b commit a6befb5
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 260 deletions.
2 changes: 1 addition & 1 deletion cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func initGenesis(ctx *cli.Context) error {
if err != nil {
utils.Fatalf("Failed to write genesis block: %v", err)
}
log.Info("Successfully wrote genesis state", "database", name, "hash", hash)
log.Info(fmt.Sprintf("Successfully wrote genesis state database=%v hash=%v", name, hash))
}
return nil
}
Expand Down
14 changes: 14 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/scwallet"
"github.com/ethereum/go-ethereum/accounts/usbwallet"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/internal/flags"
Expand Down Expand Up @@ -171,6 +172,19 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
// makeFullNode loads geth configuration and creates the Ethereum backend.
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
stack, cfg := makeConfigNode(ctx)
if ctx.IsSet(utils.RialtoHash.Name) {
v := ctx.String(utils.RialtoHash.Name)
params.RialtoGenesisHash = common.HexToHash(v)
}

if ctx.IsSet(utils.OverrideShanghai.Name) {
v := ctx.Uint64(utils.OverrideShanghai.Name)
cfg.Eth.OverrideShanghai = &v
}
if ctx.IsSet(utils.OverrideKepler.Name) {
v := ctx.Uint64(utils.OverrideKepler.Name)
cfg.Eth.OverrideKepler = &v
}
if ctx.IsSet(utils.OverrideCancun.Name) {
v := ctx.Uint64(utils.OverrideCancun.Name)
cfg.Eth.OverrideCancun = &v
Expand Down
3 changes: 3 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ var (
utils.RangeLimitFlag,
utils.USBFlag,
utils.SmartCardDaemonPathFlag,
utils.RialtoHash,
utils.OverrideShanghai,
utils.OverrideKepler,
utils.OverrideCancun,
utils.OverrideVerkle,
utils.EnablePersonal,
Expand Down
15 changes: 15 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,21 @@ var (
Value: &defaultVerifyMode,
Category: flags.FastNodeCategory,
}
RialtoHash = &cli.StringFlag{
Name: "rialtohash",
Usage: "Manually specify the Rialto Genesis Hash, to trigger builtin network logic",
Category: flags.EthCategory,
}
OverrideShanghai = &cli.Uint64Flag{
Name: "override.shanghai",
Usage: "Manually specify the Shanghai fork timestamp, overriding the bundled setting",
Category: flags.EthCategory,
}
OverrideKepler = &cli.Uint64Flag{
Name: "override.kepler",
Usage: "Manually specify the Kepler fork timestamp, overriding the bundled setting",
Category: flags.EthCategory,
}
OverrideCancun = &cli.Uint64Flag{
Name: "override.cancun",
Usage: "Manually specify the Cancun fork timestamp, overriding the bundled setting",
Expand Down
15 changes: 12 additions & 3 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,13 @@ func (e *GenesisMismatchError) Error() string {
return fmt.Sprintf("database contains incompatible genesis (have %x, new %x)", e.Stored, e.New)
}

// ChainOverrides contains the changes to chain config.
// ChainOverrides contains the changes to chain config
// Typically, these modifications involve hardforks that are not enabled on the BSC mainnet, intended for testing purposes.
type ChainOverrides struct {
OverrideCancun *uint64
OverrideVerkle *uint64
OverrideShanghai *uint64
OverrideKepler *uint64
OverrideCancun *uint64
OverrideVerkle *uint64
}

// SetupGenesisBlock writes or updates the genesis block in db.
Expand All @@ -303,6 +306,12 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen
}
applyOverrides := func(config *params.ChainConfig) {
if config != nil {
if overrides != nil && overrides.OverrideShanghai != nil {
config.ShanghaiTime = overrides.OverrideShanghai
}
if overrides != nil && overrides.OverrideKepler != nil {
config.KeplerTime = overrides.OverrideKepler
}
if overrides != nil && overrides.OverrideCancun != nil {
config.CancunTime = overrides.OverrideCancun
}
Expand Down
213 changes: 0 additions & 213 deletions core/systemcontracts/upgrade.go

Large diffs are not rendered by default.

26 changes: 18 additions & 8 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,24 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
// Override the chain config with provided settings.
var overrides core.ChainOverrides
if config.OverrideShanghai != nil {
chainConfig.ShanghaiTime = config.OverrideShanghai
overrides.OverrideShanghai = config.OverrideShanghai
}
if config.OverrideKepler != nil {
chainConfig.KeplerTime = config.OverrideKepler
overrides.OverrideKepler = config.OverrideKepler
}
if config.OverrideCancun != nil {
chainConfig.CancunTime = config.OverrideCancun
overrides.OverrideCancun = config.OverrideCancun
}
if config.OverrideVerkle != nil {
chainConfig.VerkleTime = config.OverrideVerkle
overrides.OverrideVerkle = config.OverrideVerkle
}

eth := &Ethereum{
config: config,
Expand Down Expand Up @@ -241,14 +259,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {

peers := newPeerSet()
bcOps = append(bcOps, core.EnableBlockValidator(chainConfig, eth.engine, config.TriesVerifyMode, peers))
// Override the chain config with provided settings.
var overrides core.ChainOverrides
if config.OverrideCancun != nil {
overrides.OverrideCancun = config.OverrideCancun
}
if config.OverrideVerkle != nil {
overrides.OverrideVerkle = config.OverrideVerkle
}
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TransactionHistory, bcOps...)
if err != nil {
return nil, err
Expand Down
6 changes: 6 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ type Config struct {
// send-transaction variants. The unit is ether.
RPCTxFeeCap float64

// OverrideShanghai (TODO: remove after the fork)
OverrideShanghai *uint64 `toml:",omitempty"`

// OverrideKepler (TODO: remove after the fork)
OverrideKepler *uint64 `toml:",omitempty"`

// OverrideCancun (TODO: remove after the fork)
OverrideCancun *uint64 `toml:",omitempty"`

Expand Down
12 changes: 12 additions & 0 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions les/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
return nil, err
}
var overrides core.ChainOverrides
if config.OverrideShanghai != nil {
overrides.OverrideShanghai = config.OverrideShanghai
}
if config.OverrideKepler != nil {
overrides.OverrideKepler = config.OverrideKepler
}
if config.OverrideCancun != nil {
overrides.OverrideCancun = config.OverrideCancun
}
Expand Down
53 changes: 18 additions & 35 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,6 @@ var (
Ethash: new(EthashConfig),
}

// just for prysm compile pass
// RopstenChainConfig contains the chain parameters to run a node on the Ropsten test network.
RopstenChainConfig = &ChainConfig{
ChainID: big.NewInt(3),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(10),
EIP158Block: big.NewInt(10),
ByzantiumBlock: big.NewInt(1_700_000),
ConstantinopleBlock: big.NewInt(4_230_000),
PetersburgBlock: big.NewInt(4_939_394),
IstanbulBlock: big.NewInt(6_485_846),
MuirGlacierBlock: big.NewInt(7_117_117),
BerlinBlock: big.NewInt(9_812_189),
LondonBlock: big.NewInt(10_499_401),
TerminalTotalDifficulty: new(big.Int).SetUint64(50_000_000_000_000_000),
Ethash: new(EthashConfig),
}

// just for prysm compile pass
// SepoliaChainConfig contains the chain parameters to run a node on the Sepolia test network.
SepoliaChainConfig = &ChainConfig{
Expand Down Expand Up @@ -211,8 +190,9 @@ var (
},
}

// used to test hard fork upgrade, following https://github.com/bnb-chain/bsc-genesis-contract/blob/master/genesis.json
RialtoChainConfig = &ChainConfig{
ChainID: big.NewInt(1417),
ChainID: big.NewInt(714),
HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
Expand All @@ -222,20 +202,23 @@ var (
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
RamanujanBlock: big.NewInt(400),
RamanujanBlock: big.NewInt(0),
NielsBlock: big.NewInt(0),
MirrorSyncBlock: big.NewInt(400),
BrunoBlock: big.NewInt(400),
EulerBlock: big.NewInt(400),
GibbsBlock: big.NewInt(400),
NanoBlock: nil,
MoranBlock: nil,
PlanckBlock: nil,
LubanBlock: nil,
PlatoBlock: nil,
BerlinBlock: nil,
HertzBlock: nil,
HertzfixBlock: nil,
MirrorSyncBlock: big.NewInt(1),
BrunoBlock: big.NewInt(1),
EulerBlock: big.NewInt(2),
NanoBlock: big.NewInt(3),
MoranBlock: big.NewInt(3),
GibbsBlock: big.NewInt(4),
PlanckBlock: big.NewInt(5),
LubanBlock: big.NewInt(6),
PlatoBlock: big.NewInt(7),
BerlinBlock: big.NewInt(8),
LondonBlock: big.NewInt(8),
HertzBlock: big.NewInt(8),
HertzfixBlock: big.NewInt(8),
ShanghaiTime: newUint64(0),
KeplerTime: newUint64(0),

Parlia: &ParliaConfig{
Period: 3,
Expand Down

0 comments on commit a6befb5

Please sign in to comment.