Add Scroll bootnode config (#261)

* add Scroll bootnode config

* expose scroll networks on node CLI

* add alpha genesis config

* fix scroll genesis config

* update default sync mode

* address todos

* remove scroll staging network

* bump version

* update genesis config

* bump version
This commit is contained in:
Péter Garamvölgyi 2023-04-19 04:40:52 +02:00 committed by GitHub
parent df1d37e097
commit 49e755e334
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 178 additions and 35 deletions

View file

@ -70,6 +70,7 @@ It expects the genesis file as argument.`,
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `

View file

@ -137,6 +137,8 @@ func remoteConsole(ctx *cli.Context) error {
path = filepath.Join(path, "goerli")
} else if ctx.GlobalBool(utils.SepoliaFlag.Name) {
path = filepath.Join(path, "sepolia")
} else if ctx.GlobalBool(utils.ScrollAlphaFlag.Name) {
path = filepath.Join(path, "scroll-alpha")
}
}
endpoint = fmt.Sprintf("%s/geth.ipc", path)

View file

@ -85,6 +85,7 @@ Remove blockchain and state databases`,
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
Usage: "Inspect the storage size for each type of data in the database",
Description: `This commands iterates the entire database. If the optional 'prefix' and 'start' arguments are provided, then the iteration is limited to the given subset of data.`,
@ -101,6 +102,7 @@ Remove blockchain and state databases`,
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
}
dbCompactCmd = cli.Command{
@ -115,6 +117,7 @@ Remove blockchain and state databases`,
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
utils.CacheFlag,
utils.CacheDatabaseFlag,
},
@ -135,6 +138,7 @@ corruption if it is aborted during execution'!`,
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
Description: "This command looks up the specified database key from the database.",
}
@ -151,6 +155,7 @@ corruption if it is aborted during execution'!`,
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
Description: `This command deletes the specified database key from the database.
WARNING: This is a low-level operation which may cause database corruption!`,
@ -168,6 +173,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
Description: `This command sets a given database key to the given value.
WARNING: This is a low-level operation which may cause database corruption!`,
@ -185,6 +191,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
Description: "This command looks up the specified database key from the database.",
}
@ -201,6 +208,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
Description: "This command displays information about the freezer index.",
}
@ -216,6 +224,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
Description: "The import command imports the specific chain data from an RLP encoded stream.",
}
@ -231,6 +240,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
Description: "Exports the specified chain data to an RLP encoded stream, optionally gzip-compressed.",
}

View file

@ -145,6 +145,7 @@ var (
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
utils.VMEnableDebugFlag,
utils.NetworkIdFlag,
utils.EthStatsURLFlag,
@ -279,6 +280,9 @@ func prepare(ctx *cli.Context) {
case ctx.GlobalIsSet(utils.GoerliFlag.Name):
log.Info("Starting Geth on Görli testnet...")
case ctx.GlobalIsSet(utils.ScrollAlphaFlag.Name):
log.Info("Starting l2geth on Scroll Alpha testnet...")
case ctx.GlobalIsSet(utils.DeveloperFlag.Name):
log.Info("Starting Geth in ephemeral dev mode...")
@ -288,7 +292,7 @@ func prepare(ctx *cli.Context) {
// If we're a full node on mainnet without --cache specified, bump default cache allowance
if ctx.GlobalString(utils.SyncModeFlag.Name) != "light" && !ctx.GlobalIsSet(utils.CacheFlag.Name) && !ctx.GlobalIsSet(utils.NetworkIdFlag.Name) {
// Make sure we're not on any supported preconfigured testnet either
if !ctx.GlobalIsSet(utils.RopstenFlag.Name) && !ctx.GlobalIsSet(utils.RinkebyFlag.Name) && !ctx.GlobalIsSet(utils.GoerliFlag.Name) && !ctx.GlobalIsSet(utils.DeveloperFlag.Name) {
if !ctx.GlobalIsSet(utils.RopstenFlag.Name) && !ctx.GlobalIsSet(utils.RinkebyFlag.Name) && !ctx.GlobalIsSet(utils.GoerliFlag.Name) && !ctx.GlobalIsSet(utils.ScrollAlphaFlag.Name) && !ctx.GlobalIsSet(utils.DeveloperFlag.Name) {
// Nope, we're really on mainnet. Bump that cache up!
log.Info("Bumping default cache on mainnet", "provided", ctx.GlobalInt(utils.CacheFlag.Name), "updated", 4096)
ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(4096))

View file

@ -66,6 +66,7 @@ var (
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
utils.CacheTrieJournalFlag,
utils.BloomFilterSizeFlag,
},
@ -97,6 +98,7 @@ the trie clean cache with default directory will be deleted.
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
Description: `
geth snapshot verify-state <state-root>
@ -118,6 +120,7 @@ In other words, this command does the snapshot to trie conversion.
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
Description: `
geth snapshot traverse-state <state-root>
@ -141,6 +144,7 @@ It's also usable without snapshot enabled.
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
},
Description: `
geth snapshot traverse-rawstate <state-root>
@ -165,6 +169,7 @@ It's also usable without snapshot enabled.
utils.SepoliaFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.ScrollAlphaFlag,
utils.ExcludeCodeFlag,
utils.ExcludeStorageFlag,
utils.StartKeyFlag,

View file

@ -47,6 +47,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.RinkebyFlag,
utils.RopstenFlag,
utils.SepoliaFlag,
utils.ScrollAlphaFlag,
utils.SyncModeFlag,
utils.ExitWhenSyncedFlag,
utils.GCModeFlag,

View file

@ -160,6 +160,10 @@ var (
Name: "sepolia",
Usage: "Sepolia network: pre-configured proof-of-work test network",
}
ScrollAlphaFlag = cli.BoolFlag{
Name: "scroll-alpha",
Usage: "Scroll Alpha test network",
}
DeveloperFlag = cli.BoolFlag{
Name: "dev",
Usage: "Ephemeral proof-of-authority network with a pre-funded developer account, mining enabled",
@ -811,6 +815,9 @@ func MakeDataDir(ctx *cli.Context) string {
if ctx.GlobalBool(SepoliaFlag.Name) {
return filepath.Join(path, "sepolia")
}
if ctx.GlobalBool(ScrollAlphaFlag.Name) {
return filepath.Join(path, "scroll-alpha")
}
return path
}
Fatalf("Cannot determine default data directory, please set manually (--datadir)")
@ -865,6 +872,8 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls = params.RinkebyBootnodes
case ctx.GlobalBool(GoerliFlag.Name):
urls = params.GoerliBootnodes
case ctx.GlobalBool(ScrollAlphaFlag.Name):
urls = params.ScrollAlphaBootnodes
case cfg.BootstrapNodes != nil:
return // already set, don't apply defaults.
}
@ -1286,6 +1295,8 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) {
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "goerli")
case ctx.GlobalBool(SepoliaFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "sepolia")
case ctx.GlobalBool(ScrollAlphaFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "scroll-alpha")
}
}
@ -1471,7 +1482,7 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
// 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, MainnetFlag, DeveloperFlag, RopstenFlag, RinkebyFlag, GoerliFlag, SepoliaFlag)
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, RopstenFlag, RinkebyFlag, GoerliFlag, SepoliaFlag, ScrollAlphaFlag)
CheckExclusive(ctx, LightServeFlag, SyncModeFlag, "light")
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
if ctx.GlobalString(GCModeFlag.Name) == "archive" && ctx.GlobalUint64(TxLookupLimitFlag.Name) != 0 {
@ -1633,6 +1644,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}
cfg.Genesis = core.DefaultGoerliGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.GoerliGenesisHash)
case ctx.GlobalBool(ScrollAlphaFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 534353
}
cfg.Genesis = core.DefaultScrollAlphaGenesisBlock()
// SetDNSDiscoveryDefaults(cfg, params.ScrollAlphaGenesisHash)
case ctx.GlobalBool(DeveloperFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 1337
@ -1855,6 +1872,8 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis {
genesis = core.DefaultRinkebyGenesisBlock()
case ctx.GlobalBool(GoerliFlag.Name):
genesis = core.DefaultGoerliGenesisBlock()
case ctx.GlobalBool(ScrollAlphaFlag.Name):
genesis = core.DefaultScrollAlphaGenesisBlock()
case ctx.GlobalBool(DeveloperFlag.Name):
Fatalf("Developer chains are ephemeral")
}

View file

@ -435,6 +435,18 @@ func DefaultSepoliaGenesisBlock() *Genesis {
}
}
// DefaultScrollAlphaGenesisBlock returns the Scroll Alpha network genesis block.
func DefaultScrollAlphaGenesisBlock() *Genesis {
return &Genesis{
Config: params.ScrollAlphaChainConfig,
Timestamp: 0x63f67207,
ExtraData: hexutil.MustDecode("0x0000000000000000000000000000000000000000000000000000000000000000b7C0c58702D0781C0e2eB3aaE301E4c340073448Ec9c139eFCBBe6323DA406fffBF4Db02a60A9720589c71deC4302fE718bE62350c174922782Cc6600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
GasLimit: 8000000,
Difficulty: big.NewInt(1),
Alloc: decodePrealloc(scrollAlphaAllocData),
}
}
// DeveloperGenesisBlock returns the 'geth --dev' genesis block.
func DeveloperGenesisBlock(period uint64, gasLimit uint64, faucet common.Address) *Genesis {
// Override the default period to the user requested one
@ -467,7 +479,40 @@ func DeveloperGenesisBlock(period uint64, gasLimit uint64, faucet common.Address
}
}
// decodePrealloc does not support code and storage in prealloc config,
// so we provide an alternative implementation here.
func decodePreallocScroll(data string) (GenesisAlloc, error) {
var p []struct {
Addr, Balance *big.Int
Code []byte
Storage []struct{ Key, Value *big.Int }
}
if err := rlp.NewStream(strings.NewReader(data), 0).Decode(&p); err != nil {
return nil, err
}
ga := make(GenesisAlloc, len(p))
for _, account := range p {
s := make(map[common.Hash]common.Hash)
for _, entry := range account.Storage {
s[common.BigToHash(entry.Key)] = common.BigToHash(entry.Value)
}
ga[common.BigToAddress(account.Addr)] = GenesisAccount{
Balance: account.Balance,
Code: account.Code,
Storage: s,
}
}
return ga, nil
}
func decodePrealloc(data string) GenesisAlloc {
if ga, err := decodePreallocScroll(data); err == nil {
return ga
}
var p []struct{ Addr, Balance *big.Int }
if err := rlp.NewStream(strings.NewReader(data), 0).Decode(&p); err != nil {
panic(err)

File diff suppressed because one or more lines are too long

View file

@ -161,29 +161,30 @@ func TestSetupGenesis(t *testing.T) {
}
}
// // TestGenesisHashes checks the congruity of default genesis data to
// // corresponding hardcoded genesis hash values.
// func TestGenesisHashes(t *testing.T) {
// for i, c := range []struct {
// genesis *Genesis
// want common.Hash
// }{
// {DefaultGenesisBlock(), params.MainnetGenesisHash},
// {DefaultGoerliGenesisBlock(), params.GoerliGenesisHash},
// {DefaultRopstenGenesisBlock(), params.RopstenGenesisHash},
// {DefaultRinkebyGenesisBlock(), params.RinkebyGenesisHash},
// {DefaultSepoliaGenesisBlock(), params.SepoliaGenesisHash},
// } {
// // Test via MustCommit
// if have := c.genesis.MustCommit(rawdb.NewMemoryDatabase()).Hash(); have != c.want {
// t.Errorf("case: %d a), want: %s, got: %s", i, c.want.Hex(), have.Hex())
// }
// // Test via ToBlock
// if have := c.genesis.ToBlock(nil).Hash(); have != c.want {
// t.Errorf("case: %d a), want: %s, got: %s", i, c.want.Hex(), have.Hex())
// }
// }
// }
// TestGenesisHashes checks the congruity of default genesis data to
// corresponding hardcoded genesis hash values.
func TestGenesisHashes(t *testing.T) {
for i, c := range []struct {
genesis *Genesis
want common.Hash
}{
// {DefaultGenesisBlock(), params.MainnetGenesisHash},
// {DefaultGoerliGenesisBlock(), params.GoerliGenesisHash},
// {DefaultRopstenGenesisBlock(), params.RopstenGenesisHash},
// {DefaultRinkebyGenesisBlock(), params.RinkebyGenesisHash},
// {DefaultSepoliaGenesisBlock(), params.SepoliaGenesisHash},
{DefaultScrollAlphaGenesisBlock(), params.ScrollAlphaGenesisHash},
} {
// Test via MustCommit
if have := c.genesis.MustCommit(rawdb.NewMemoryDatabase()).Hash(); have != c.want {
t.Errorf("case: %d a), want: %s, got: %s", i, c.want.Hex(), have.Hex())
}
// Test via ToBlock
if have := c.genesis.ToBlock(nil).Hash(); have != c.want {
t.Errorf("case: %d a), want: %s, got: %s", i, c.want.Hex(), have.Hex())
}
}
}
func TestGenesis_Commit(t *testing.T) {
genesis := &Genesis{

View file

@ -37,7 +37,14 @@ import (
"github.com/scroll-tech/go-ethereum/rlp"
)
type allocItem struct{ Addr, Balance *big.Int }
type storageItem struct{ Key, Value *big.Int }
type storageList []storageItem
type allocItem struct {
Addr, Balance *big.Int
Code []byte
Storage storageList
}
type allocList []allocItem
@ -48,11 +55,17 @@ func (a allocList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func makelist(g *core.Genesis) allocList {
a := make(allocList, 0, len(g.Alloc))
for addr, account := range g.Alloc {
if len(account.Storage) > 0 || len(account.Code) > 0 || account.Nonce != 0 {
if account.Nonce != 0 {
panic(fmt.Sprintf("can't encode account %x", addr))
}
bigAddr := new(big.Int).SetBytes(addr.Bytes())
a = append(a, allocItem{bigAddr, account.Balance})
s := make(storageList, 0, len(account.Storage))
for key, value := range account.Storage {
s = append(s, storageItem{Key: new(big.Int).SetBytes(key.Bytes()), Value: new(big.Int).SetBytes(value.Bytes())})
}
a = append(a, allocItem{bigAddr, account.Balance, account.Code, s})
}
sort.Sort(a)
return a

View file

@ -61,7 +61,7 @@ var LightClientGPO = gasprice.Config{
// Defaults contains default settings for use on the Ethereum main net.
var Defaults = Config{
SyncMode: downloader.SnapSync,
SyncMode: downloader.FullSync,
Ethash: ethash.Config{
CacheDir: "ethash",
CachesInMem: 2,

View file

@ -76,6 +76,13 @@ var GoerliBootnodes = []string{
"enode://a59e33ccd2b3e52d578f1fbd70c6f9babda2650f0760d6ff3b37742fdcdfdb3defba5d56d315b40c46b70198c7621e63ffa3f987389c7118634b0fefbbdfa7fd@51.15.119.157:40303",
}
// ScrollAlphaBootnodes are the enode URLs of the P2P bootstrap nodes running on the Scroll Alpha test network.
var ScrollAlphaBootnodes = []string{
"enode://996a655365e731321ca35636f5a62fdf37c0b75dc56a8832c472d077da5af47effe45874196268f6083b8f65e1a9589ed25015f68f47598c7bcc93ac8ea29e8a@35.85.116.190:30303",
"enode://a4e90d8108bbcd8b13066567c786f800812a9b6b3eeb92947e64edd19ac9231bf371da1a86796af2ccd7b7e781218ebbe2d04130d63f7b3f25d6372a706fc022@44.224.134.190:30303",
"enode://cf85bfa5828239b1f6b21758579ee8aaaba2a1fb4c658d6967c5f7ed4f040d95dee5b5cef0c77d656a191f6b0875dd03f05b30a3b2b3e15bfcf18b500d8f634c@35.155.117.77:30303",
}
var V5Bootnodes = []string{
// Teku team's bootnode
"enr:-KG4QOtcP9X1FbIMOe17QNMKqDxCpm14jcX5tiOE4_TyMrFqbmhPZHK_ZPG2Gxb1GE2xdtodOfx9-cgvNtxnRyHEmC0ghGV0aDKQ9aX9QgAAAAD__________4JpZIJ2NIJpcIQDE8KdiXNlY3AyNTZrMaEDhpehBDbZjM_L9ek699Y7vhUJ-eAdMyQW_Fil522Y0fODdGNwgiMog3VkcIIjKA",

View file

@ -28,11 +28,12 @@ import (
// Genesis hashes to enforce below configs on.
var (
MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
RopstenGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d")
SepoliaGenesisHash = common.HexToHash("0x25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9")
RinkebyGenesisHash = common.HexToHash("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177")
GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a")
MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
RopstenGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d")
SepoliaGenesisHash = common.HexToHash("0x25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9")
RinkebyGenesisHash = common.HexToHash("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177")
GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a")
ScrollAlphaGenesisHash = common.HexToHash("0xa4fc62b9b0643e345bdcebe457b3ae898bef59c7203c3db269200055e037afda")
)
// TrustedCheckpoints associates each known checkpoint with the genesis hash of
@ -253,6 +254,39 @@ var (
Threshold: 2,
}
// ScrollAlphaChainConfig contains the chain parameters to run a node on the Scroll Alpha test network.
ScrollFeeVaultAddress = common.HexToAddress("0x5300000000000000000000000000000000000005")
ScrollMaxTxPerBlock = 44
ScrollAlphaChainConfig = &ChainConfig{
ChainID: big.NewInt(534353),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: nil,
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ArrowGlacierBlock: nil,
Clique: &CliqueConfig{
Period: 3,
Epoch: 30000,
},
Scroll: ScrollConfig{
UseZktrie: true,
MaxTxPerBlock: &ScrollMaxTxPerBlock,
FeeVaultAddress: &ScrollFeeVaultAddress,
EnableEIP2718: false,
EnableEIP1559: false,
},
}
// AllEthashProtocolChanges contains every protocol change (EIPs) introduced
// and accepted by the Ethereum core developers into the Ethash consensus.
//

View file

@ -24,7 +24,7 @@ import (
const (
VersionMajor = 3 // Major version component of the current release
VersionMinor = 1 // Minor version component of the current release
VersionPatch = 3 // Patch version component of the current release
VersionPatch = 4 // Patch version component of the current release
VersionMeta = "alpha" // Version metadata to append to the version string
)