diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index ce2cc64b9..c8d1b6b7e 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -47,6 +47,11 @@ var DaemonCmd = &cli.Command{ Name: "genesis", Usage: "genesis file to use for first node run", }, + &cli.StringFlag{ + Name: "genesis-timestamp", + Hidden: true, + Usage: "set the timestamp for the genesis block that will be created", + }, &cli.BoolFlag{ Name: "bootstrap", Value: true, @@ -84,7 +89,7 @@ var DaemonCmd = &cli.Command{ if cctx.String(preSealedSectorsFlag) == "" { return xerrors.Errorf("must also pass file with miner preseal info to `--%s`", preSealedSectorsFlag) } - genesis = node.Override(new(modules.Genesis), testing.MakeGenesis(cctx.String(makeGenFlag), cctx.String(preSealedSectorsFlag))) + genesis = node.Override(new(modules.Genesis), testing.MakeGenesis(cctx.String(makeGenFlag), cctx.String(preSealedSectorsFlag), cctx.String("genesis-timestamp"))) } var api api.FullNode diff --git a/node/modules/testing/genesis.go b/node/modules/testing/genesis.go index f0195b639..5efe22382 100644 --- a/node/modules/testing/genesis.go +++ b/node/modules/testing/genesis.go @@ -68,7 +68,7 @@ func MakeGenesisMem(out io.Writer, gmc *gen.GenMinerCfg) func(bs dtypes.ChainBlo } } -func MakeGenesis(outFile, presealInfo string) func(bs dtypes.ChainBlockstore, w *wallet.Wallet) modules.Genesis { +func MakeGenesis(outFile, presealInfo, timestamp string) func(bs dtypes.ChainBlockstore, w *wallet.Wallet) modules.Genesis { return func(bs dtypes.ChainBlockstore, w *wallet.Wallet) modules.Genesis { return func() (*types.BlockHeader, error) { glog.Warn("Generating new random genesis block, note that this SHOULD NOT happen unless you are setting up new network") @@ -119,7 +119,18 @@ func MakeGenesis(outFile, presealInfo string) func(bs dtypes.ChainBlockstore, w addrs[miner.Worker] = types.FromFil(100000) } - b, err := gen.MakeGenesisBlock(bs, addrs, gmc, uint64(time.Now().Unix())) + ts := uint64(time.Now().Unix()) + if timestamp != "" { + t, err := time.Parse(time.RFC3339, timestamp) + if err != nil { + return nil, xerrors.Errorf("parsing input genesis timestamp: %w", err) + } + + glog.Infof("will use %s as the genesis timestamp", t) + ts = uint64(t.Unix()) + } + + b, err := gen.MakeGenesisBlock(bs, addrs, gmc, ts) if err != nil { return nil, err }