@@ -46,22 +46,20 @@ var startGraphic = strings.ReplaceAll(`
46
46
/___/
47
47
` , "'" , "`" )
48
48
49
- var (
50
- // Keep in sync with contribs/gnogenesis/internal/txs/txs_add_packages.go
51
- genesisDeployAddress = crypto .MustAddressFromString ("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" ) // test1
52
- genesisDeployFee = std .NewFee (50000 , std .MustParseCoin (ugnot .ValueString (1000000 )))
53
- )
49
+ // Keep in sync with contribs/gnogenesis/internal/txs/txs_add_packages.go
50
+ var genesisDeployFee = std .NewFee (50000 , std .MustParseCoin (ugnot .ValueString (1000000 )))
54
51
55
52
type startCfg struct {
56
- gnoRootDir string // TODO: remove as part of https://github.com/gnolang/gno/issues/1952
57
- skipFailingGenesisTxs bool // TODO: remove as part of https://github.com/gnolang/gno/issues/1952
58
- genesisBalancesFile string // TODO: remove as part of https://github.com/gnolang/gno/issues/1952
59
- genesisTxsFile string // TODO: remove as part of https://github.com/gnolang/gno/issues/1952
60
- genesisRemote string // TODO: remove as part of https://github.com/gnolang/gno/issues/1952
61
- genesisFile string
62
- chainID string
63
- dataDir string
64
- lazyInit bool
53
+ gnoRootDir string // TODO: remove as part of https://github.com/gnolang/gno/issues/1952
54
+ skipFailingGenesisTxs bool // TODO: remove as part of https://github.com/gnolang/gno/issues/1952
55
+ skipGenesisSigVerification bool // TODO: remove as part of https://github.com/gnolang/gno/issues/1952
56
+ genesisBalancesFile string // TODO: remove as part of https://github.com/gnolang/gno/issues/1952
57
+ genesisTxsFile string // TODO: remove as part of https://github.com/gnolang/gno/issues/1952
58
+ genesisRemote string // TODO: remove as part of https://github.com/gnolang/gno/issues/1952
59
+ genesisFile string
60
+ chainID string
61
+ dataDir string
62
+ lazyInit bool
65
63
66
64
logLevel string
67
65
logFormat string
@@ -87,7 +85,6 @@ func newStartCmd(io commands.IO) *commands.Command {
87
85
func (c * startCfg ) RegisterFlags (fs * flag.FlagSet ) {
88
86
gnoroot := gnoenv .RootDir ()
89
87
defaultGenesisBalancesFile := filepath .Join (gnoroot , "gno.land" , "genesis" , "genesis_balances.txt" )
90
- defaultGenesisTxsFile := filepath .Join (gnoroot , "gno.land" , "genesis" , "genesis_txs.jsonl" )
91
88
92
89
fs .BoolVar (
93
90
& c .skipFailingGenesisTxs ,
@@ -96,6 +93,13 @@ func (c *startCfg) RegisterFlags(fs *flag.FlagSet) {
96
93
"don't panic when replaying invalid genesis txs" ,
97
94
)
98
95
96
+ fs .BoolVar (
97
+ & c .skipGenesisSigVerification ,
98
+ "skip-genesis-sig-verification" ,
99
+ false ,
100
+ "don't panic when replaying invalidly signed genesis txs" ,
101
+ )
102
+
99
103
fs .StringVar (
100
104
& c .genesisBalancesFile ,
101
105
"genesis-balances-file" ,
@@ -106,7 +110,7 @@ func (c *startCfg) RegisterFlags(fs *flag.FlagSet) {
106
110
fs .StringVar (
107
111
& c .genesisTxsFile ,
108
112
"genesis-txs-file" ,
109
- defaultGenesisTxsFile ,
113
+ "" ,
110
114
"initial txs to replay" ,
111
115
)
112
116
@@ -219,7 +223,7 @@ func execStart(ctx context.Context, c *startCfg, io commands.IO) error {
219
223
)
220
224
221
225
// Init a new genesis.json
222
- if err := lazyInitGenesis (io , c , genesisPath , privateKey .GetPubKey () ); err != nil {
226
+ if err := lazyInitGenesis (io , c , genesisPath , privateKey .Key . PrivKey ); err != nil {
223
227
return fmt .Errorf ("unable to initialize genesis.json, %w" , err )
224
228
}
225
229
}
@@ -239,7 +243,16 @@ func execStart(ctx context.Context, c *startCfg, io commands.IO) error {
239
243
minGasPrices := cfg .Application .MinGasPrices
240
244
241
245
// Create application and node
242
- cfg .LocalApp , err = gnoland .NewApp (nodeDir , c .skipFailingGenesisTxs , evsw , logger , minGasPrices )
246
+ cfg .LocalApp , err = gnoland .NewApp (
247
+ nodeDir ,
248
+ gnoland.GenesisAppConfig {
249
+ SkipFailingTxs : c .skipFailingGenesisTxs ,
250
+ SkipSigVerification : c .skipGenesisSigVerification ,
251
+ },
252
+ evsw ,
253
+ logger ,
254
+ minGasPrices ,
255
+ )
243
256
if err != nil {
244
257
return fmt .Errorf ("unable to create the Gnoland app, %w" , err )
245
258
}
@@ -335,15 +348,15 @@ func lazyInitGenesis(
335
348
io commands.IO ,
336
349
c * startCfg ,
337
350
genesisPath string ,
338
- publicKey crypto.PubKey ,
351
+ privateKey crypto.PrivKey ,
339
352
) error {
340
353
// Check if the genesis.json is present
341
354
if osm .FileExists (genesisPath ) {
342
355
return nil
343
356
}
344
357
345
358
// Generate the new genesis.json file
346
- if err := generateGenesisFile (io , genesisPath , publicKey , c ); err != nil {
359
+ if err := generateGenesisFile (io , genesisPath , privateKey , c ); err != nil {
347
360
return fmt .Errorf ("unable to generate genesis file, %w" , err )
348
361
}
349
362
@@ -368,7 +381,21 @@ func initializeLogger(io io.WriteCloser, logLevel, logFormat string) (*zap.Logge
368
381
return log .GetZapLoggerFn (format )(io , level ), nil
369
382
}
370
383
371
- func generateGenesisFile (io commands.IO , genesisFile string , pk crypto.PubKey , c * startCfg ) error {
384
+ func generateGenesisFile (io commands.IO , genesisFile string , privKey crypto.PrivKey , c * startCfg ) error {
385
+ var (
386
+ pubKey = privKey .PubKey ()
387
+ // There is an active constraint for gno.land transactions:
388
+ //
389
+ // All transaction messages' (MsgSend, MsgAddPkg...) "author" field,
390
+ // specific to the message type ("creator", "sender"...), must match
391
+ // the signature address contained in the transaction itself.
392
+ // This means that if MsgSend is originating from address A,
393
+ // the owner of the private key for address A needs to sign the transaction
394
+ // containing the message. Every message in a transaction needs to
395
+ // originate from the same account that signed the transaction
396
+ txSender = pubKey .Address ()
397
+ )
398
+
372
399
gen := & bft.GenesisDoc {}
373
400
gen .GenesisTime = time .Now ()
374
401
gen .ChainID = c .chainID
@@ -384,8 +411,8 @@ func generateGenesisFile(io commands.IO, genesisFile string, pk crypto.PubKey, c
384
411
385
412
gen .Validators = []bft.GenesisValidator {
386
413
{
387
- Address : pk .Address (),
388
- PubKey : pk ,
414
+ Address : pubKey .Address (),
415
+ PubKey : pubKey ,
389
416
Power : 10 ,
390
417
Name : "testvalidator" ,
391
418
},
@@ -400,22 +427,43 @@ func generateGenesisFile(io commands.IO, genesisFile string, pk crypto.PubKey, c
400
427
// Load examples folder
401
428
examplesDir := filepath .Join (c .gnoRootDir , "examples" )
402
429
loadCfg := & packages.LoadConfig {IO : io , SelfContained : true }
403
- pkgsTxs , err := gnoland .LoadPackagesFromDir (loadCfg , examplesDir , genesisDeployAddress , genesisDeployFee )
430
+ pkgsTxs , err := gnoland .LoadPackagesFromDir (loadCfg , examplesDir , txSender , genesisDeployFee )
404
431
if err != nil {
405
432
return fmt .Errorf ("unable to load examples folder: %w" , err )
406
433
}
407
434
408
435
// Load Genesis TXs
409
- genesisTxs , err := gnoland .LoadGenesisTxsFile (c .genesisTxsFile , c .chainID , c .genesisRemote )
410
- if err != nil {
411
- return fmt .Errorf ("unable to load genesis txs file: %w" , err )
436
+ var genesisTxs []gnoland.TxWithMetadata
437
+
438
+ if c .genesisTxsFile != "" {
439
+ genesisTxs , err = gnoland .LoadGenesisTxsFile (c .genesisTxsFile , c .chainID , c .genesisRemote )
440
+ if err != nil {
441
+ return fmt .Errorf ("unable to load genesis txs file: %w" , err )
442
+ }
412
443
}
413
444
414
445
genesisTxs = append (pkgsTxs , genesisTxs ... )
415
446
447
+ // Sign genesis transactions, with the default key (test1)
448
+ if err = gnoland .SignGenesisTxs (genesisTxs , privKey , c .chainID ); err != nil {
449
+ return fmt .Errorf ("unable to sign genesis txs: %w" , err )
450
+ }
451
+
452
+ // Make sure the genesis transaction author has sufficient
453
+ // balance to cover transaction deployments in genesis.
454
+ //
455
+ // During the init-chainer process, the account that authors the
456
+ // genesis transactions needs to have a sufficient balance
457
+ // to cover outstanding transaction costs.
458
+ // Since the cost can't be estimated upfront at this point, the balance
459
+ // set is an arbitrary value based on a "best guess" basis.
460
+ // There should be a larger discussion if genesis transactions should consume gas, at all
461
+ deployerBalance := int64 (len (genesisTxs )) * 10_000_000 // ~10 GNOT per tx
462
+ balances .Set (txSender , std .NewCoins (std .NewCoin ("ugnot" , deployerBalance )))
463
+
416
464
// Construct genesis AppState.
417
465
defaultGenState := gnoland .DefaultGenState ()
418
- defaultGenState .Balances = balances
466
+ defaultGenState .Balances = balances . List ()
419
467
defaultGenState .Txs = genesisTxs
420
468
gen .AppState = defaultGenState
421
469
0 commit comments