move genesis loading to build pkg

This commit is contained in:
Łukasz Magiera 2019-10-02 22:29:40 +02:00
parent 05878f4320
commit 713f08e9bf
5 changed files with 39 additions and 29 deletions

View File

@ -75,7 +75,7 @@ build: $(BUILD_DEPS)
rm -f lotus lotus-storage-miner
go build -o lotus ./cmd/lotus
go build -o lotus-storage-miner ./cmd/lotus-storage-miner
rice append --exec lotus -i ./cmd/lotus -i ./build
rice append --exec lotus -i ./build
rice append --exec lotus-storage-miner -i ./build
.PHONY: build

17
build/genesis.go Normal file
View File

@ -0,0 +1,17 @@
package build
import rice "github.com/GeertJohan/go.rice"
func MaybeGenesis() []byte {
builtinGen, err := rice.FindBox("genesis")
if err != nil {
log.Warn("loading built-in genesis: %s", err)
return nil
}
genBytes, err := builtinGen.Bytes("devnet.car")
if err != nil {
log.Warn("loading built-in genesis: %s", err)
}
return genBytes
}

View File

@ -15,14 +15,14 @@ import (
pb "gopkg.in/cheggaaa/pb.v1"
)
var log = logging.Logger("miner")
var log = logging.Logger("build")
const gateway = "http://198.211.99.118/ipfs/"
const paramdir = "/var/tmp/filecoin-proof-parameters"
type paramFile struct{
Cid string `json:"cid"`
Digest string `json:"digest"`
type paramFile struct {
Cid string `json:"cid"`
Digest string `json:"digest"`
SectorSize uint64 `json:"sector_size"`
}
@ -79,25 +79,25 @@ func doFetch(out string, info paramFile) error {
log.Infof("Fetching %s", out)
resp, err := http.Get(gateway + info.Cid)
if err != nil {
return err
}
defer resp.Body.Close()
if err != nil {
return err
}
defer resp.Body.Close()
outf, err := os.Create(out)
if err != nil {
return err
}
defer outf.Close()
outf, err := os.Create(out)
if err != nil {
return err
}
defer outf.Close()
bar := pb.New64(resp.ContentLength)
bar := pb.New64(resp.ContentLength)
bar.Units = pb.U_BYTES
bar.ShowSpeed = true
bar.Start()
_, err = io.Copy(outf, bar.NewProxyReader(resp.Body))
_, err = io.Copy(outf, bar.NewProxyReader(resp.Body))
bar.Finish()
bar.Finish()
return err
}

View File

@ -47,13 +47,14 @@ var initCmd = &cli.Command{
},
Action: func(cctx *cli.Context) error {
log.Info("Initializing lotus storage miner")
log.Info("Checking if repo exists")
log.Info("Checking proof parameters")
if err := build.GetParams(true); err != nil {
return xerrors.Errorf("fetching proof parameters: %w", err)
}
log.Info("Checking if repo exists")
r, err := repo.NewFS(cctx.String(FlagStorageRepo))
if err != nil {
return err

View File

@ -4,15 +4,14 @@ package main
import (
"context"
"github.com/filecoin-project/go-lotus/build"
"golang.org/x/xerrors"
"io/ioutil"
rice "github.com/GeertJohan/go.rice"
"github.com/multiformats/go-multiaddr"
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/build"
"github.com/filecoin-project/go-lotus/node"
"github.com/filecoin-project/go-lotus/node/modules"
"github.com/filecoin-project/go-lotus/node/modules/testing"
@ -57,14 +56,7 @@ var DaemonCmd = &cli.Command{
return xerrors.Errorf("fetching proof parameters: %w", err)
}
builtinGen, err := rice.FindBox("../../build/genesis")
if err != nil {
log.Warn("loading built-in genesis: %s", err)
}
genBytes, err := builtinGen.Bytes("devnet.car")
if err != nil {
log.Warn("loading built-in genesis: %s", err)
}
genBytes := build.MaybeGenesis()
if cctx.String("genesis") != "" {
genBytes, err = ioutil.ReadFile(cctx.String("genesis"))