@@ -40,15 +40,40 @@ import Control.Retry
40
40
-- -------------------------------------------------------------------------- --
41
41
-- Main
42
42
43
+ -- | This program generates chain-spec files, genesis blocks, and the respective
44
+ -- block hashes for EVMs on Chainweb networks.
45
+ --
46
+ -- The results can be used to define the genesis information for the respective
47
+ -- networks in the chainweb-node code basis.
48
+ --
43
49
main :: IO ()
44
50
main = do
45
- cids <- traverse (fromText . T. pack) =<< getArgs
51
+
52
+ -- parse command line
53
+ (n, cids, spec) <- getArgs >>= \ case
54
+ [] -> error " No argument for the chainweb version provided. The version must be one of: 'mainnet', 'testnet', 'evm-testnet', or 'evm-development'."
55
+ [" mainnet" ] -> do
56
+ let cids = [20 .. 25 ]
57
+ return (" mainnet" , cids, mainnetSpecFile)
58
+ [" testnet" ] -> do
59
+ let cids = [20 .. 25 ]
60
+ return (" testnet" , cids, testnetSpecFile)
61
+ [" evm-testnet" ] -> do
62
+ let cids = [20 .. 25 ]
63
+ return (" evm-testnet" , cids, evmTestnetSpecFile)
64
+ [" evm-development" ] -> do
65
+ let cids = [20 .. 25 ]
66
+ return (" evm-development" , cids, evmDevnetSpecFile)
67
+ _ -> error " Invalid argument for the chainweb version provided. The version must be one of: 'mainnet', 'testnet', 'evm-testnet', or 'evm-development'."
68
+
46
69
hdrs <- forM cids $ \ cid -> do
47
- createDirectoryIfMissing True " ./chain-specs"
48
- let specFileName = " ./chain-specs/chain-spec-" <> show cid <> " .json"
49
- encodeFile specFileName $ specFile cid
70
+ let specFileDir = " ./chain-specs/" <> n
71
+ createDirectoryIfMissing True specFileDir
72
+ let specFileName = specFileDir <> " /chain-spec-" <> show cid <> " .json"
73
+ encodeFile specFileName $ spec cid
50
74
hdr <- queryNode cid specFileName
51
75
return (cid, hdr)
76
+
52
77
T. putStrLn $ encodeToText
53
78
[ object
54
79
[ " chainId" .= cid
@@ -128,8 +153,23 @@ mkRpcCtx u = do
128
153
-- -------------------------------------------------------------------------- --
129
154
-- Spec File For EVM Devnet
130
155
131
- specFile :: Natural -> Value
132
- specFile cid = object [
156
+ -- | Intended only for local development and testing. It is not intended for use
157
+ -- with public networks.
158
+ --
159
+ -- The keys for all allocations are publicly known.
160
+ --
161
+ -- The Ethereum network chain ids are not officially registered and overlap with
162
+ -- the chain ids of other networks.
163
+ --
164
+ -- The configuration of the network may change at any time.
165
+ --
166
+ -- EVMs are available at block height 0.
167
+ --
168
+ evmDevnetSpecFile
169
+ :: Natural
170
+ -- numeric chainweb chain id
171
+ -> Value
172
+ evmDevnetSpecFile cid = object [
133
173
" config" .= object [
134
174
" chainId" .= (1789 + cid - 20 ),
135
175
" daoForkSupport" .= True ,
@@ -166,6 +206,7 @@ specFile cid = object [
166
206
" 0x0000000000000000000000000000000000000000000000000000000000000000" .= (printf " 0x%064x" cid :: String )
167
207
]
168
208
],
209
+ -- TODO: add native-x-chain system contract
169
210
" 0x8849BAbdDcfC1327Ad199877861B577cEBd8A7b6" .= object [
170
211
" balance" .= t " 0xd3c21bcecceda1000000"
171
212
],
@@ -240,3 +281,226 @@ specFile cid = object [
240
281
i :: Natural -> Natural
241
282
i = id
242
283
284
+ -- -------------------------------------------------------------------------- --
285
+ -- Spec File For EVM Testnet
286
+
287
+ -- | Used with the public Kadena EVM testnet. This is a temporary feature
288
+ -- testnet in preparation for the launch of EVM chains on the Kadena mainet and
289
+ -- the regular permanent Kadena testnet.
290
+ --
291
+ -- The network is expected to be decommissioned after EVM chains have been
292
+ -- launched on the Kadena mainnet.
293
+ --
294
+ -- Funds on the network have no economic value.
295
+ --
296
+ -- The keys for the genesis allocations are held by the Kadena team.
297
+ --
298
+ -- The EVM chains are available at block height 0.
299
+ --
300
+ evmTestnetSpecFile
301
+ :: Natural
302
+ -- ^ numeric chainweb chain id
303
+ -> Value
304
+ evmTestnetSpecFile cid = object [
305
+ " config" .= object [
306
+ " chainId" .= (1789 + cid - 20 ),
307
+ " daoForkSupport" .= True ,
308
+ " terminalTotalDifficultyPassed" .= True ,
309
+ " terminalTotalDifficulty" .= i 0 ,
310
+ " daoForkBlock" .= i 0 ,
311
+ " homesteadBlock" .= i 0 ,
312
+ " eip150Block" .= i 0 ,
313
+ " eip155Block" .= i 0 ,
314
+ " eip158Block" .= i 0 ,
315
+ " byzantiumBlock" .= i 0 ,
316
+ " constantinopleBlock" .= i 0 ,
317
+ " petersburgBlock" .= i 0 ,
318
+ " istanbulBlock" .= i 0 ,
319
+ " muirGlacierBlock" .= i 0 ,
320
+ " berlinBlock" .= i 0 ,
321
+ " londonBlock" .= i 0 ,
322
+ " arrowGlacierBlock" .= i 0 ,
323
+ " graphGlacierBlock" .= i 0 ,
324
+ " mergeForkBlock" .= i 0 ,
325
+ " mergeNetsplitBlock" .= i 0 ,
326
+ " shanghaiTime" .= i 0 ,
327
+ " cancunTime" .= i 0 ,
328
+ " pragueTime" .= i 0
329
+ ],
330
+ " timestamp" .= t " 0x6490fdd2" ,
331
+ " extraData" .= t " 0x" ,
332
+ " gasLimit" .= t " 0x1c9c380" ,
333
+ " alloc" .= object [
334
+ " 0x9b02c3e2df42533e0fd166798b5a616f59dbd2cc" .= object [
335
+ " balance" .= t " 0x0" ,
336
+ " code" .= t " 0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063973e55d414602d575b600080fd5b600054603c9063ffffffff1681565b60405163ffffffff909116815260200160405180910390f3fea2646970667358221220b716cf70992d0b5a77124b3da9b37629f5625bf265c121cfb76f9714f249119b64736f6c634300081c0033" ,
337
+ " storage" .= object [
338
+ " 0x0000000000000000000000000000000000000000000000000000000000000000" .= (printf " 0x%064x" cid :: String )
339
+ ]
340
+ ]
341
+ -- TODO: Native-X-Chain System contract
342
+ -- TODO: funding of faucet
343
+ -- TODO: other allocations.
344
+ ],
345
+
346
+ " number" .= t " 0x0" ,
347
+ " nonce" .= t " 0x0" ,
348
+ " difficulty" .= t " 0x0" ,
349
+ " mixHash" .= t " 0x0000000000000000000000000000000000000000000000000000000000000000" ,
350
+ " coinbase" .= t " 0x0000000000000000000000000000000000000000"
351
+ ]
352
+ where
353
+ t :: T. Text -> T. Text
354
+ t = id
355
+
356
+ i :: Natural -> Natural
357
+ i = id
358
+
359
+ -- -------------------------------------------------------------------------- --
360
+ -- Spec File For Kadena Mainnet
361
+
362
+ -- | Used with the public Kadena Mainnet.
363
+ --
364
+ -- Allocations are funded out of the platform share of the Kadena mainnet.
365
+ -- The keys for the Allocations are not publicly known.
366
+ --
367
+ -- The EVM chains are launched at block height TODO.
368
+ --
369
+ -- TODO
370
+ --
371
+ mainnetSpecFile
372
+ :: Natural
373
+ -- ^ numeric chainweb chain id
374
+ -> Value
375
+ mainnetSpecFile cid = object [
376
+ " config" .= object [
377
+ " chainId" .= (3789 + cid - 20 ),
378
+ " daoForkSupport" .= True ,
379
+ " terminalTotalDifficultyPassed" .= True ,
380
+ " terminalTotalDifficulty" .= i 0 ,
381
+ " daoForkBlock" .= i 0 ,
382
+ " homesteadBlock" .= i 0 ,
383
+ " eip150Block" .= i 0 ,
384
+ " eip155Block" .= i 0 ,
385
+ " eip158Block" .= i 0 ,
386
+ " byzantiumBlock" .= i 0 ,
387
+ " constantinopleBlock" .= i 0 ,
388
+ " petersburgBlock" .= i 0 ,
389
+ " istanbulBlock" .= i 0 ,
390
+ " muirGlacierBlock" .= i 0 ,
391
+ " berlinBlock" .= i 0 ,
392
+ " londonBlock" .= i 0 ,
393
+ " arrowGlacierBlock" .= i 0 ,
394
+ " graphGlacierBlock" .= i 0 ,
395
+ " mergeForkBlock" .= i 0 ,
396
+ " mergeNetsplitBlock" .= i 0 ,
397
+ " shanghaiTime" .= i 0 ,
398
+ " cancunTime" .= i 0 ,
399
+ " pragueTime" .= i 0
400
+ ],
401
+ " timestamp" .= t " 0x6490fdd2" ,
402
+ " extraData" .= t " 0x" ,
403
+ " gasLimit" .= t " 0x1c9c380" ,
404
+ " alloc" .= object [
405
+ " 0x9b02c3e2df42533e0fd166798b5a616f59dbd2cc" .= object [
406
+ " balance" .= t " 0x0" ,
407
+ " code" .= t " 0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063973e55d414602d575b600080fd5b600054603c9063ffffffff1681565b60405163ffffffff909116815260200160405180910390f3fea2646970667358221220b716cf70992d0b5a77124b3da9b37629f5625bf265c121cfb76f9714f249119b64736f6c634300081c0033" ,
408
+ " storage" .= object [
409
+ " 0x0000000000000000000000000000000000000000000000000000000000000000" .= (printf " 0x%064x" cid :: String )
410
+ ]
411
+ ],
412
+ error " mainnetSpecFile: the EVM genesis allocations for mainnet are TBD"
413
+ -- TODO: Native-X-Chain System contract
414
+ -- TODO: other allocations.
415
+ ],
416
+
417
+ " number" .= error @ _ @ () " mainnetSpecFile: the initial block height is TBD" , -- t "0x0",
418
+ " nonce" .= t " 0x0" ,
419
+ " difficulty" .= t " 0x0" ,
420
+ " mixHash" .= t " 0x0000000000000000000000000000000000000000000000000000000000000000" ,
421
+ " coinbase" .= t " 0x0000000000000000000000000000000000000000"
422
+ ]
423
+ where
424
+ t :: T. Text -> T. Text
425
+ t = id
426
+
427
+ i :: Natural -> Natural
428
+ i = id
429
+
430
+
431
+ -- -------------------------------------------------------------------------- --
432
+ -- Spec File For Kadena Testnet
433
+
434
+ -- | Used with the public Kadena testnet. This is a permament testnet that
435
+ -- has the same features and properties of the Kadena mainnet. It has the
436
+ -- purpose to facilitate testing of services and applications under the same
437
+ -- conditions as on the Kadena mainnet.
438
+ --
439
+ -- Funds on the network have no economic value.
440
+ --
441
+ -- The keys for the genesis allocations are held by the Kadena team.
442
+ --
443
+ -- The EVM chains are launched at block height TODO.
444
+ --
445
+ -- TODO
446
+ --
447
+ testnetSpecFile
448
+ :: Natural
449
+ -- ^ numeric chainweb chain id
450
+ -> Value
451
+ testnetSpecFile cid = object [
452
+ " config" .= object [
453
+ " chainId" .= (2789 + cid - 20 ),
454
+ " daoForkSupport" .= True ,
455
+ " terminalTotalDifficultyPassed" .= True ,
456
+ " terminalTotalDifficulty" .= i 0 ,
457
+ " daoForkBlock" .= i 0 ,
458
+ " homesteadBlock" .= i 0 ,
459
+ " eip150Block" .= i 0 ,
460
+ " eip155Block" .= i 0 ,
461
+ " eip158Block" .= i 0 ,
462
+ " byzantiumBlock" .= i 0 ,
463
+ " constantinopleBlock" .= i 0 ,
464
+ " petersburgBlock" .= i 0 ,
465
+ " istanbulBlock" .= i 0 ,
466
+ " muirGlacierBlock" .= i 0 ,
467
+ " berlinBlock" .= i 0 ,
468
+ " londonBlock" .= i 0 ,
469
+ " arrowGlacierBlock" .= i 0 ,
470
+ " graphGlacierBlock" .= i 0 ,
471
+ " mergeForkBlock" .= i 0 ,
472
+ " mergeNetsplitBlock" .= i 0 ,
473
+ " shanghaiTime" .= i 0 ,
474
+ " cancunTime" .= i 0 ,
475
+ " pragueTime" .= i 0
476
+ ],
477
+ " timestamp" .= t " 0x6490fdd2" ,
478
+ " extraData" .= t " 0x" ,
479
+ " gasLimit" .= t " 0x1c9c380" ,
480
+ " alloc" .= object [
481
+ " 0x9b02c3e2df42533e0fd166798b5a616f59dbd2cc" .= object [
482
+ " balance" .= t " 0x0" ,
483
+ " code" .= t " 0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063973e55d414602d575b600080fd5b600054603c9063ffffffff1681565b60405163ffffffff909116815260200160405180910390f3fea2646970667358221220b716cf70992d0b5a77124b3da9b37629f5625bf265c121cfb76f9714f249119b64736f6c634300081c0033" ,
484
+ " storage" .= object [
485
+ " 0x0000000000000000000000000000000000000000000000000000000000000000" .= (printf " 0x%064x" cid :: String )
486
+ ]
487
+ ],
488
+ error " mainnetSpecFile: the EVM genesis allocations for mainnet are TBD"
489
+ -- TODO: Native-X-Chain System contract
490
+ -- TODO: other allocations.
491
+ ],
492
+
493
+ " number" .= error @ _ @ () " mainnetSpecFile: the initial block height is TBD" , -- t "0x0",
494
+ " nonce" .= t " 0x0" ,
495
+ " difficulty" .= t " 0x0" ,
496
+ " mixHash" .= t " 0x0000000000000000000000000000000000000000000000000000000000000000" ,
497
+ " coinbase" .= t " 0x0000000000000000000000000000000000000000"
498
+ ]
499
+ where
500
+ t :: T. Text -> T. Text
501
+ t = id
502
+
503
+ i :: Natural -> Natural
504
+ i = id
505
+
506
+
0 commit comments