diff --git a/api/api.go b/api/api.go index ee5d3ea6b..25309b592 100644 --- a/api/api.go +++ b/api/api.go @@ -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? } diff --git a/build/version.go b/build/version.go index 39e2ca1e2..d9c45d991 100644 --- a/build/version.go +++ b/build/version.go @@ -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 +) \ No newline at end of file diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index 618e5de1e..4e8e6503b 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -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 }, } diff --git a/cmd/lotus-storage-miner/main.go b/cmd/lotus-storage-miner/main.go index a6122ff9c..cf32da73d 100644 --- a/cmd/lotus-storage-miner/main.go +++ b/cmd/lotus-storage-miner/main.go @@ -15,7 +15,8 @@ var log = logging.Logger("main") func main() { logging.SetLogLevel("*", "INFO") local := []*cli.Command{ - RunCmd, + runCmd, + initCmd, } app := &cli.App{ diff --git a/cmd/lotus-storage-miner/run.go b/cmd/lotus-storage-miner/run.go index be870378f..89174a815 100644 --- a/cmd/lotus-storage-miner/run.go +++ b/cmd/lotus-storage-miner/run.go @@ -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{