Skip to content

Commit 49e755e

Browse files
authored
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
1 parent df1d37e commit 49e755e

File tree

15 files changed

+178
-35
lines changed

15 files changed

+178
-35
lines changed

cmd/geth/chaincmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ It expects the genesis file as argument.`,
7070
utils.SepoliaFlag,
7171
utils.RinkebyFlag,
7272
utils.GoerliFlag,
73+
utils.ScrollAlphaFlag,
7374
},
7475
Category: "BLOCKCHAIN COMMANDS",
7576
Description: `

cmd/geth/consolecmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ func remoteConsole(ctx *cli.Context) error {
137137
path = filepath.Join(path, "goerli")
138138
} else if ctx.GlobalBool(utils.SepoliaFlag.Name) {
139139
path = filepath.Join(path, "sepolia")
140+
} else if ctx.GlobalBool(utils.ScrollAlphaFlag.Name) {
141+
path = filepath.Join(path, "scroll-alpha")
140142
}
141143
}
142144
endpoint = fmt.Sprintf("%s/geth.ipc", path)

cmd/geth/dbcmd.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Remove blockchain and state databases`,
8585
utils.SepoliaFlag,
8686
utils.RinkebyFlag,
8787
utils.GoerliFlag,
88+
utils.ScrollAlphaFlag,
8889
},
8990
Usage: "Inspect the storage size for each type of data in the database",
9091
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`,
101102
utils.SepoliaFlag,
102103
utils.RinkebyFlag,
103104
utils.GoerliFlag,
105+
utils.ScrollAlphaFlag,
104106
},
105107
}
106108
dbCompactCmd = cli.Command{
@@ -115,6 +117,7 @@ Remove blockchain and state databases`,
115117
utils.SepoliaFlag,
116118
utils.RinkebyFlag,
117119
utils.GoerliFlag,
120+
utils.ScrollAlphaFlag,
118121
utils.CacheFlag,
119122
utils.CacheDatabaseFlag,
120123
},
@@ -135,6 +138,7 @@ corruption if it is aborted during execution'!`,
135138
utils.SepoliaFlag,
136139
utils.RinkebyFlag,
137140
utils.GoerliFlag,
141+
utils.ScrollAlphaFlag,
138142
},
139143
Description: "This command looks up the specified database key from the database.",
140144
}
@@ -151,6 +155,7 @@ corruption if it is aborted during execution'!`,
151155
utils.SepoliaFlag,
152156
utils.RinkebyFlag,
153157
utils.GoerliFlag,
158+
utils.ScrollAlphaFlag,
154159
},
155160
Description: `This command deletes the specified database key from the database.
156161
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!`,
168173
utils.SepoliaFlag,
169174
utils.RinkebyFlag,
170175
utils.GoerliFlag,
176+
utils.ScrollAlphaFlag,
171177
},
172178
Description: `This command sets a given database key to the given value.
173179
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!`,
185191
utils.SepoliaFlag,
186192
utils.RinkebyFlag,
187193
utils.GoerliFlag,
194+
utils.ScrollAlphaFlag,
188195
},
189196
Description: "This command looks up the specified database key from the database.",
190197
}
@@ -201,6 +208,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
201208
utils.SepoliaFlag,
202209
utils.RinkebyFlag,
203210
utils.GoerliFlag,
211+
utils.ScrollAlphaFlag,
204212
},
205213
Description: "This command displays information about the freezer index.",
206214
}
@@ -216,6 +224,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
216224
utils.RopstenFlag,
217225
utils.RinkebyFlag,
218226
utils.GoerliFlag,
227+
utils.ScrollAlphaFlag,
219228
},
220229
Description: "The import command imports the specific chain data from an RLP encoded stream.",
221230
}
@@ -231,6 +240,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
231240
utils.RopstenFlag,
232241
utils.RinkebyFlag,
233242
utils.GoerliFlag,
243+
utils.ScrollAlphaFlag,
234244
},
235245
Description: "Exports the specified chain data to an RLP encoded stream, optionally gzip-compressed.",
236246
}

cmd/geth/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ var (
145145
utils.SepoliaFlag,
146146
utils.RinkebyFlag,
147147
utils.GoerliFlag,
148+
utils.ScrollAlphaFlag,
148149
utils.VMEnableDebugFlag,
149150
utils.NetworkIdFlag,
150151
utils.EthStatsURLFlag,
@@ -279,6 +280,9 @@ func prepare(ctx *cli.Context) {
279280
case ctx.GlobalIsSet(utils.GoerliFlag.Name):
280281
log.Info("Starting Geth on Görli testnet...")
281282

283+
case ctx.GlobalIsSet(utils.ScrollAlphaFlag.Name):
284+
log.Info("Starting l2geth on Scroll Alpha testnet...")
285+
282286
case ctx.GlobalIsSet(utils.DeveloperFlag.Name):
283287
log.Info("Starting Geth in ephemeral dev mode...")
284288

@@ -288,7 +292,7 @@ func prepare(ctx *cli.Context) {
288292
// If we're a full node on mainnet without --cache specified, bump default cache allowance
289293
if ctx.GlobalString(utils.SyncModeFlag.Name) != "light" && !ctx.GlobalIsSet(utils.CacheFlag.Name) && !ctx.GlobalIsSet(utils.NetworkIdFlag.Name) {
290294
// Make sure we're not on any supported preconfigured testnet either
291-
if !ctx.GlobalIsSet(utils.RopstenFlag.Name) && !ctx.GlobalIsSet(utils.RinkebyFlag.Name) && !ctx.GlobalIsSet(utils.GoerliFlag.Name) && !ctx.GlobalIsSet(utils.DeveloperFlag.Name) {
295+
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) {
292296
// Nope, we're really on mainnet. Bump that cache up!
293297
log.Info("Bumping default cache on mainnet", "provided", ctx.GlobalInt(utils.CacheFlag.Name), "updated", 4096)
294298
ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(4096))

cmd/geth/snapshot.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var (
6666
utils.SepoliaFlag,
6767
utils.RinkebyFlag,
6868
utils.GoerliFlag,
69+
utils.ScrollAlphaFlag,
6970
utils.CacheTrieJournalFlag,
7071
utils.BloomFilterSizeFlag,
7172
},
@@ -97,6 +98,7 @@ the trie clean cache with default directory will be deleted.
9798
utils.SepoliaFlag,
9899
utils.RinkebyFlag,
99100
utils.GoerliFlag,
101+
utils.ScrollAlphaFlag,
100102
},
101103
Description: `
102104
geth snapshot verify-state <state-root>
@@ -118,6 +120,7 @@ In other words, this command does the snapshot to trie conversion.
118120
utils.SepoliaFlag,
119121
utils.RinkebyFlag,
120122
utils.GoerliFlag,
123+
utils.ScrollAlphaFlag,
121124
},
122125
Description: `
123126
geth snapshot traverse-state <state-root>
@@ -141,6 +144,7 @@ It's also usable without snapshot enabled.
141144
utils.SepoliaFlag,
142145
utils.RinkebyFlag,
143146
utils.GoerliFlag,
147+
utils.ScrollAlphaFlag,
144148
},
145149
Description: `
146150
geth snapshot traverse-rawstate <state-root>
@@ -165,6 +169,7 @@ It's also usable without snapshot enabled.
165169
utils.SepoliaFlag,
166170
utils.RinkebyFlag,
167171
utils.GoerliFlag,
172+
utils.ScrollAlphaFlag,
168173
utils.ExcludeCodeFlag,
169174
utils.ExcludeStorageFlag,
170175
utils.StartKeyFlag,

cmd/geth/usage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
4747
utils.RinkebyFlag,
4848
utils.RopstenFlag,
4949
utils.SepoliaFlag,
50+
utils.ScrollAlphaFlag,
5051
utils.SyncModeFlag,
5152
utils.ExitWhenSyncedFlag,
5253
utils.GCModeFlag,

cmd/utils/flags.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ var (
160160
Name: "sepolia",
161161
Usage: "Sepolia network: pre-configured proof-of-work test network",
162162
}
163+
ScrollAlphaFlag = cli.BoolFlag{
164+
Name: "scroll-alpha",
165+
Usage: "Scroll Alpha test network",
166+
}
163167
DeveloperFlag = cli.BoolFlag{
164168
Name: "dev",
165169
Usage: "Ephemeral proof-of-authority network with a pre-funded developer account, mining enabled",
@@ -811,6 +815,9 @@ func MakeDataDir(ctx *cli.Context) string {
811815
if ctx.GlobalBool(SepoliaFlag.Name) {
812816
return filepath.Join(path, "sepolia")
813817
}
818+
if ctx.GlobalBool(ScrollAlphaFlag.Name) {
819+
return filepath.Join(path, "scroll-alpha")
820+
}
814821
return path
815822
}
816823
Fatalf("Cannot determine default data directory, please set manually (--datadir)")
@@ -865,6 +872,8 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
865872
urls = params.RinkebyBootnodes
866873
case ctx.GlobalBool(GoerliFlag.Name):
867874
urls = params.GoerliBootnodes
875+
case ctx.GlobalBool(ScrollAlphaFlag.Name):
876+
urls = params.ScrollAlphaBootnodes
868877
case cfg.BootstrapNodes != nil:
869878
return // already set, don't apply defaults.
870879
}
@@ -1286,6 +1295,8 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) {
12861295
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "goerli")
12871296
case ctx.GlobalBool(SepoliaFlag.Name) && cfg.DataDir == node.DefaultDataDir():
12881297
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "sepolia")
1298+
case ctx.GlobalBool(ScrollAlphaFlag.Name) && cfg.DataDir == node.DefaultDataDir():
1299+
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "scroll-alpha")
12891300
}
12901301
}
12911302

@@ -1471,7 +1482,7 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
14711482
// SetEthConfig applies eth-related command line flags to the config.
14721483
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
14731484
// Avoid conflicting network flags
1474-
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, RopstenFlag, RinkebyFlag, GoerliFlag, SepoliaFlag)
1485+
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, RopstenFlag, RinkebyFlag, GoerliFlag, SepoliaFlag, ScrollAlphaFlag)
14751486
CheckExclusive(ctx, LightServeFlag, SyncModeFlag, "light")
14761487
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
14771488
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) {
16331644
}
16341645
cfg.Genesis = core.DefaultGoerliGenesisBlock()
16351646
SetDNSDiscoveryDefaults(cfg, params.GoerliGenesisHash)
1647+
case ctx.GlobalBool(ScrollAlphaFlag.Name):
1648+
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
1649+
cfg.NetworkId = 534353
1650+
}
1651+
cfg.Genesis = core.DefaultScrollAlphaGenesisBlock()
1652+
// SetDNSDiscoveryDefaults(cfg, params.ScrollAlphaGenesisHash)
16361653
case ctx.GlobalBool(DeveloperFlag.Name):
16371654
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
16381655
cfg.NetworkId = 1337
@@ -1855,6 +1872,8 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis {
18551872
genesis = core.DefaultRinkebyGenesisBlock()
18561873
case ctx.GlobalBool(GoerliFlag.Name):
18571874
genesis = core.DefaultGoerliGenesisBlock()
1875+
case ctx.GlobalBool(ScrollAlphaFlag.Name):
1876+
genesis = core.DefaultScrollAlphaGenesisBlock()
18581877
case ctx.GlobalBool(DeveloperFlag.Name):
18591878
Fatalf("Developer chains are ephemeral")
18601879
}

core/genesis.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,18 @@ func DefaultSepoliaGenesisBlock() *Genesis {
435435
}
436436
}
437437

438+
// DefaultScrollAlphaGenesisBlock returns the Scroll Alpha network genesis block.
439+
func DefaultScrollAlphaGenesisBlock() *Genesis {
440+
return &Genesis{
441+
Config: params.ScrollAlphaChainConfig,
442+
Timestamp: 0x63f67207,
443+
ExtraData: hexutil.MustDecode("0x0000000000000000000000000000000000000000000000000000000000000000b7C0c58702D0781C0e2eB3aaE301E4c340073448Ec9c139eFCBBe6323DA406fffBF4Db02a60A9720589c71deC4302fE718bE62350c174922782Cc6600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
444+
GasLimit: 8000000,
445+
Difficulty: big.NewInt(1),
446+
Alloc: decodePrealloc(scrollAlphaAllocData),
447+
}
448+
}
449+
438450
// DeveloperGenesisBlock returns the 'geth --dev' genesis block.
439451
func DeveloperGenesisBlock(period uint64, gasLimit uint64, faucet common.Address) *Genesis {
440452
// Override the default period to the user requested one
@@ -467,7 +479,40 @@ func DeveloperGenesisBlock(period uint64, gasLimit uint64, faucet common.Address
467479
}
468480
}
469481

482+
// decodePrealloc does not support code and storage in prealloc config,
483+
// so we provide an alternative implementation here.
484+
func decodePreallocScroll(data string) (GenesisAlloc, error) {
485+
var p []struct {
486+
Addr, Balance *big.Int
487+
Code []byte
488+
Storage []struct{ Key, Value *big.Int }
489+
}
490+
491+
if err := rlp.NewStream(strings.NewReader(data), 0).Decode(&p); err != nil {
492+
return nil, err
493+
}
494+
ga := make(GenesisAlloc, len(p))
495+
496+
for _, account := range p {
497+
s := make(map[common.Hash]common.Hash)
498+
for _, entry := range account.Storage {
499+
s[common.BigToHash(entry.Key)] = common.BigToHash(entry.Value)
500+
}
501+
502+
ga[common.BigToAddress(account.Addr)] = GenesisAccount{
503+
Balance: account.Balance,
504+
Code: account.Code,
505+
Storage: s,
506+
}
507+
}
508+
509+
return ga, nil
510+
}
511+
470512
func decodePrealloc(data string) GenesisAlloc {
513+
if ga, err := decodePreallocScroll(data); err == nil {
514+
return ga
515+
}
471516
var p []struct{ Addr, Balance *big.Int }
472517
if err := rlp.NewStream(strings.NewReader(data), 0).Decode(&p); err != nil {
473518
panic(err)

0 commit comments

Comments
 (0)