2019-11-25 04:45:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-02-12 21:41:59 +00:00
|
|
|
"encoding/hex"
|
2020-02-06 19:56:35 +00:00
|
|
|
"encoding/json"
|
2019-12-08 18:35:44 +00:00
|
|
|
"fmt"
|
2019-11-25 04:45:13 +00:00
|
|
|
"os"
|
|
|
|
|
2020-05-14 02:32:04 +00:00
|
|
|
"github.com/docker/go-units"
|
2020-01-08 19:10:57 +00:00
|
|
|
logging "github.com/ipfs/go-log/v2"
|
2019-11-25 04:45:13 +00:00
|
|
|
"github.com/mitchellh/go-homedir"
|
2020-06-02 18:12:53 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-11-26 13:52:59 +00:00
|
|
|
|
2019-12-19 20:13:17 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
2020-02-06 19:56:35 +00:00
|
|
|
|
2019-11-26 13:52:59 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2020-11-05 12:43:05 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
2020-02-12 21:41:59 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2019-11-27 14:18:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
|
2019-12-08 18:35:44 +00:00
|
|
|
"github.com/filecoin-project/lotus/genesis"
|
2019-11-25 04:45:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var log = logging.Logger("lotus-seed")
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
logging.SetLogLevel("*", "INFO")
|
|
|
|
|
|
|
|
local := []*cli.Command{
|
2020-02-21 20:56:30 +00:00
|
|
|
genesisCmd,
|
|
|
|
|
2019-11-25 04:45:13 +00:00
|
|
|
preSealCmd,
|
2019-12-08 18:35:44 +00:00
|
|
|
aggregateManifestsCmd,
|
2019-11-25 04:45:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app := &cli.App{
|
|
|
|
Name: "lotus-seed",
|
|
|
|
Usage: "Seal sectors for genesis miner",
|
2020-06-01 18:43:51 +00:00
|
|
|
Version: build.UserVersion(),
|
2019-11-25 04:45:13 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
2020-03-26 19:34:38 +00:00
|
|
|
Name: "sector-dir",
|
2019-11-25 04:45:13 +00:00
|
|
|
Value: "~/.genesis-sectors",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Commands: local,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
log.Warn(err)
|
2020-02-21 20:56:30 +00:00
|
|
|
os.Exit(1)
|
2019-11-25 04:45:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var preSealCmd = &cli.Command{
|
|
|
|
Name: "pre-seal",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "miner-addr",
|
2020-02-21 20:56:30 +00:00
|
|
|
Value: "t01000",
|
2019-11-25 04:45:13 +00:00
|
|
|
Usage: "specify the future address of your miner",
|
|
|
|
},
|
2020-03-15 20:42:44 +00:00
|
|
|
&cli.StringFlag{
|
2019-11-25 04:45:13 +00:00
|
|
|
Name: "sector-size",
|
2020-03-15 20:42:44 +00:00
|
|
|
Value: "2KiB",
|
2019-11-25 04:45:13 +00:00
|
|
|
Usage: "specify size of sectors to pre-seal",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "ticket-preimage",
|
|
|
|
Value: "lotus is fire",
|
|
|
|
Usage: "set the ticket preimage for sealing randomness",
|
|
|
|
},
|
2019-11-30 23:17:50 +00:00
|
|
|
&cli.IntFlag{
|
2019-11-25 04:45:13 +00:00
|
|
|
Name: "num-sectors",
|
|
|
|
Value: 1,
|
|
|
|
Usage: "select number of sectors to pre-seal",
|
|
|
|
},
|
2019-12-06 17:55:46 +00:00
|
|
|
&cli.Uint64Flag{
|
2019-12-06 17:53:33 +00:00
|
|
|
Name: "sector-offset",
|
|
|
|
Value: 0,
|
2019-12-06 21:49:44 +00:00
|
|
|
Usage: "how many sector ids to skip when starting to seal",
|
2019-12-06 17:53:33 +00:00
|
|
|
},
|
2020-02-12 21:41:59 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "key",
|
|
|
|
Value: "",
|
|
|
|
Usage: "(optional) Key to use for signing / owner/worker addresses",
|
|
|
|
},
|
2020-07-03 01:29:06 +00:00
|
|
|
&cli.BoolFlag{
|
2020-07-03 18:52:40 +00:00
|
|
|
Name: "fake-sectors",
|
2020-07-03 01:29:06 +00:00
|
|
|
Value: false,
|
|
|
|
},
|
2021-09-08 19:26:37 +00:00
|
|
|
&cli.UintFlag{
|
2021-05-15 01:11:23 +00:00
|
|
|
Name: "network-version",
|
|
|
|
Usage: "specify network version",
|
2022-05-30 16:58:00 +00:00
|
|
|
Value: uint(build.GenesisNetworkVersion),
|
2021-05-15 01:11:23 +00:00
|
|
|
},
|
2019-11-25 04:45:13 +00:00
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) error {
|
2020-03-26 19:34:38 +00:00
|
|
|
sdir := c.String("sector-dir")
|
2019-11-25 04:45:13 +00:00
|
|
|
sbroot, err := homedir.Expand(sdir)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
maddr, err := address.NewFromString(c.String("miner-addr"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-12 21:41:59 +00:00
|
|
|
var k *types.KeyInfo
|
|
|
|
if c.String("key") != "" {
|
|
|
|
k = new(types.KeyInfo)
|
2023-03-29 19:24:07 +00:00
|
|
|
kh, err := os.ReadFile(c.String("key"))
|
2020-02-12 21:41:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
kb, err := hex.DecodeString(string(kh))
|
2020-08-20 04:49:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-12 21:41:59 +00:00
|
|
|
if err := json.Unmarshal(kb, k); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-15 20:42:44 +00:00
|
|
|
sectorSizeInt, err := units.RAMInBytes(c.String("sector-size"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
sectorSize := abi.SectorSize(sectorSizeInt)
|
|
|
|
|
2022-05-30 16:58:00 +00:00
|
|
|
nv := build.GenesisNetworkVersion
|
2021-05-26 16:40:13 +00:00
|
|
|
if c.IsSet("network-version") {
|
|
|
|
nv = network.Version(c.Uint64("network-version"))
|
|
|
|
}
|
|
|
|
|
2023-05-29 22:05:42 +00:00
|
|
|
var synthetic = false // there's little reason to have this for a seed.
|
|
|
|
|
|
|
|
spt, err := miner.SealProofTypeFromSectorSize(sectorSize, nv, synthetic)
|
2020-02-27 00:42:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-05 12:43:05 +00:00
|
|
|
gm, key, err := seed.PreSeal(maddr, spt, abi.SectorNumber(c.Uint64("sector-offset")), c.Int("num-sectors"), sbroot, []byte(c.String("ticket-preimage")), k, c.Bool("fake-sectors"))
|
2019-11-29 03:38:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-12 21:41:59 +00:00
|
|
|
return seed.WriteGenesisMiner(maddr, sbroot, gm, key)
|
2019-11-25 04:45:13 +00:00
|
|
|
},
|
|
|
|
}
|
2019-12-08 18:35:44 +00:00
|
|
|
|
|
|
|
var aggregateManifestsCmd = &cli.Command{
|
|
|
|
Name: "aggregate-manifests",
|
|
|
|
Usage: "aggregate a set of preseal manifests into a single file",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2020-02-12 21:41:59 +00:00
|
|
|
var inputs []map[string]genesis.Miner
|
2019-12-08 18:35:44 +00:00
|
|
|
for _, infi := range cctx.Args().Slice() {
|
|
|
|
fi, err := os.Open(infi)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-12 21:41:59 +00:00
|
|
|
var val map[string]genesis.Miner
|
2019-12-08 18:35:44 +00:00
|
|
|
if err := json.NewDecoder(fi).Decode(&val); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
inputs = append(inputs, val)
|
2020-07-23 10:21:13 +00:00
|
|
|
if err := fi.Close(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-12-08 18:35:44 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 21:41:59 +00:00
|
|
|
output := make(map[string]genesis.Miner)
|
2019-12-08 18:35:44 +00:00
|
|
|
for _, in := range inputs {
|
|
|
|
for maddr, val := range in {
|
|
|
|
if gm, ok := output[maddr]; ok {
|
|
|
|
output[maddr] = mergeGenMiners(gm, val)
|
|
|
|
} else {
|
|
|
|
output[maddr] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
blob, err := json.MarshalIndent(output, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(string(blob))
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-12 21:41:59 +00:00
|
|
|
func mergeGenMiners(a, b genesis.Miner) genesis.Miner {
|
2019-12-08 18:35:44 +00:00
|
|
|
if a.SectorSize != b.SectorSize {
|
|
|
|
panic("sector sizes mismatch")
|
|
|
|
}
|
|
|
|
|
2020-02-12 21:41:59 +00:00
|
|
|
return genesis.Miner{
|
2020-02-14 20:33:41 +00:00
|
|
|
Owner: a.Owner,
|
|
|
|
Worker: a.Worker,
|
2020-04-22 02:05:35 +00:00
|
|
|
PeerId: a.PeerId,
|
2020-02-14 20:33:41 +00:00
|
|
|
MarketBalance: big.Zero(),
|
|
|
|
PowerBalance: big.Zero(),
|
|
|
|
SectorSize: a.SectorSize,
|
|
|
|
Sectors: append(a.Sectors, b.Sectors...),
|
2019-12-08 18:35:44 +00:00
|
|
|
}
|
|
|
|
}
|