Check full node version in storageminer init

This commit is contained in:
Łukasz Magiera 2019-07-19 12:15:22 +02:00
parent 0e570c0b19
commit 677f5c3e30
5 changed files with 43 additions and 3 deletions

View File

@ -16,6 +16,12 @@ import (
type Version struct {
Version string
// APIVersion is a binary encoded semver version of the remote implementing
// this api
//
// See APIVersion in build/version.go
APIVersion uint32
// TODO: git commit / os / genesis cid?
}

View File

@ -2,3 +2,20 @@ package build
// Version is the local build version, set by build system
const Version = "0.0.0"
// APIVersion is a hex semver version of the rpc api exposed
//
// M M P
// A I A
// J N T
// O O C
// R R H
// |\vv/|
// vv vv
const APIVersion = 0x000001
const (
MajorMask = 0xff0000
MinorMask = 0xffff00
PatchMask = 0xffffff
)

View File

@ -4,6 +4,7 @@ import (
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-lotus/build"
lcli "github.com/filecoin-project/go-lotus/cli"
"github.com/filecoin-project/go-lotus/node/repo"
)
@ -26,7 +27,7 @@ var initCmd = &cli.Command{
log.Info("Trying to connect to full node RPC")
api, err := lcli.GetAPI(cctx)
api, err := lcli.GetAPI(cctx) // TODO: consider storing full node address in config
if err != nil {
return err
}
@ -34,10 +35,25 @@ var initCmd = &cli.Command{
log.Info("Checking full node version")
v, err := api.Version(ctx)
if err != nil {
return err
}
if v.APIVersion & build.MinorMask != build.APIVersion & build.MinorMask {
return xerrors.Errorf("Remote API version didn't match (local %x, remote %x)", build.APIVersion, v.APIVersion)
}
log.Info("Initializing repo")
if err := r.Init(); err != nil {
return err
}
// create actors and stuff
log.Info("Storage miner successfully created, you can now start it with 'lotus-storage-miner run'")
return nil
},
}

View File

@ -15,7 +15,8 @@ var log = logging.Logger("main")
func main() {
logging.SetLogLevel("*", "INFO")
local := []*cli.Command{
RunCmd,
runCmd,
initCmd,
}
app := &cli.App{

View File

@ -13,7 +13,7 @@ import (
"github.com/filecoin-project/go-lotus/node/repo"
)
var RunCmd = &cli.Command{
var runCmd = &cli.Command{
Name: "run",
Usage: "Start a lotus storage miner process",
Flags: []cli.Flag{