Skip to content

Commit

Permalink
move genesis loading to build pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Oct 2, 2019
1 parent 05878f4 commit 713f08e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions build/genesis.go
Original file line number Diff line number Diff line change
@@ -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
}
36 changes: 18 additions & 18 deletions build/paramfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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()

outf, err := os.Create(out)
if err != nil {
return err
}
defer outf.Close()

bar := pb.New64(resp.ContentLength)
if err != nil {
return err
}
defer resp.Body.Close()

outf, err := os.Create(out)
if err != nil {
return err
}
defer outf.Close()

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
}
3 changes: 2 additions & 1 deletion cmd/lotus-storage-miner/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 3 additions & 11 deletions cmd/lotus/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit 713f08e

Please sign in to comment.