allow setting genesis timestamp when initializing network

This commit is contained in:
whyrusleeping 2019-12-11 15:36:39 +01:00
parent e6dd471103
commit d6bfbe5a26
2 changed files with 19 additions and 3 deletions

View File

@ -47,6 +47,11 @@ var DaemonCmd = &cli.Command{
Name: "genesis", Name: "genesis",
Usage: "genesis file to use for first node run", 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{ &cli.BoolFlag{
Name: "bootstrap", Name: "bootstrap",
Value: true, Value: true,
@ -84,7 +89,7 @@ var DaemonCmd = &cli.Command{
if cctx.String(preSealedSectorsFlag) == "" { if cctx.String(preSealedSectorsFlag) == "" {
return xerrors.Errorf("must also pass file with miner preseal info to `--%s`", 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 var api api.FullNode

View File

@ -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(bs dtypes.ChainBlockstore, w *wallet.Wallet) modules.Genesis {
return func() (*types.BlockHeader, error) { 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") 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) 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 { if err != nil {
return nil, err return nil, err
} }