From 4436c184ed4e4fa591e92c11a9d615f80b1d2c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 16 Apr 2021 00:19:26 +0200 Subject: [PATCH] Fix v0/v1 API versions --- api/docgen/docgen.go | 2 +- api/v0api/v1_wrapper.go | 11 ++++++++ api/version.go | 14 ++++++---- build/openrpc/worker.json.gz | Bin 2577 -> 2577 bytes cmd/lotus-seal-worker/main.go | 4 +-- cmd/lotus-seal-worker/rpc.go | 2 +- cmd/lotus-storage-miner/init.go | 29 ++++++++++++++++++-- cmd/lotus-storage-miner/init_restore.go | 12 +++++--- cmd/lotus-storage-miner/run.go | 22 +++++++++------ documentation/en/api-v0-methods-miner.md | 2 +- documentation/en/api-v0-methods-worker.md | 2 +- documentation/en/api-v0-methods.md | 2 +- documentation/en/api-v1-unstable-methods.md | 2 +- 13 files changed, 75 insertions(+), 29 deletions(-) diff --git a/api/docgen/docgen.go b/api/docgen/docgen.go index 9ce10edfe..8357ff9b5 100644 --- a/api/docgen/docgen.go +++ b/api/docgen/docgen.go @@ -114,7 +114,7 @@ func init() { addExample(network.Connected) addExample(dtypes.NetworkName("lotus")) addExample(api.SyncStateStage(1)) - addExample(api.FullAPIVersion) + addExample(api.FullAPIVersion1) addExample(api.PCHInbound) addExample(time.Minute) addExample(datatransfer.TransferID(3)) diff --git a/api/v0api/v1_wrapper.go b/api/v0api/v1_wrapper.go index bb33fa12a..e977c6b67 100644 --- a/api/v0api/v1_wrapper.go +++ b/api/v0api/v1_wrapper.go @@ -46,4 +46,15 @@ func (w *WrapperV1Full) StateGetReceipt(ctx context.Context, msg cid.Cid, from t return &ml.Receipt, nil } +func (w *WrapperV1Full) Version(ctx context.Context) (api.APIVersion, error) { + ver, err := w.FullNode.Version(ctx) + if err != nil { + return api.APIVersion{}, err + } + + ver.APIVersion = api.FullAPIVersion0 + + return ver, nil +} + var _ FullNode = &WrapperV1Full{} diff --git a/api/version.go b/api/version.go index 17605b518..f419663e6 100644 --- a/api/version.go +++ b/api/version.go @@ -42,11 +42,11 @@ var RunningNodeType NodeType func VersionForType(nodeType NodeType) (Version, error) { switch nodeType { case NodeFull: - return FullAPIVersion, nil + return FullAPIVersion1, nil case NodeMiner: - return MinerAPIVersion, nil + return MinerAPIVersion0, nil case NodeWorker: - return WorkerAPIVersion, nil + return WorkerAPIVersion0, nil default: return Version(0), xerrors.Errorf("unknown node type %d", nodeType) } @@ -54,9 +54,11 @@ func VersionForType(nodeType NodeType) (Version, error) { // semver versions of the rpc api exposed var ( - FullAPIVersion = newVer(1, 1, 0) - MinerAPIVersion = newVer(1, 0, 1) - WorkerAPIVersion = newVer(1, 0, 0) + FullAPIVersion0 = newVer(1, 2, 0) + FullAPIVersion1 = newVer(2, 0, 0) + + MinerAPIVersion0 = newVer(1, 0, 1) + WorkerAPIVersion0 = newVer(1, 0, 0) ) //nolint:varcheck,deadcode diff --git a/build/openrpc/worker.json.gz b/build/openrpc/worker.json.gz index ed8df4b220ff5c0286707875bea30049b969a2c1..eaae7109d1ad5e5613ba22393d60c4a09e07eafd 100644 GIT binary patch delta 100 zcmV-q0Gt1j6p<9LwFz8HHm`TodE2dR^>&qg3bKjc2vz?ID5#1I6vO4R(6gDDBxpY8 z#68f+<@TLK0aMgPY6=1n5rCLEYmrC&`Tg6H#_`F{fd0RR7-oXROq GdH?`;T`v;= delta 100 zcmV-q0Gt1j6p<9LwFz81Ht*#4?YnMmqqnQvQ;kpF1PO_3YelUQd1CshycXQQHw+(U@SbK`9)rPb(xam6Fi^a%>Nqz0RR8MaITn5 GdH?{h)i1>W diff --git a/cmd/lotus-seal-worker/main.go b/cmd/lotus-seal-worker/main.go index 0f0cb88e6..693b833a5 100644 --- a/cmd/lotus-seal-worker/main.go +++ b/cmd/lotus-seal-worker/main.go @@ -210,8 +210,8 @@ var runCmd = &cli.Command{ if err != nil { return err } - if v.APIVersion != api.MinerAPIVersion { - return xerrors.Errorf("lotus-miner API version doesn't match: expected: %s", api.APIVersion{APIVersion: api.MinerAPIVersion}) + if v.APIVersion != api.MinerAPIVersion0 { + return xerrors.Errorf("lotus-miner API version doesn't match: expected: %s", api.APIVersion{APIVersion: api.MinerAPIVersion0}) } log.Infof("Remote version %s", v) diff --git a/cmd/lotus-seal-worker/rpc.go b/cmd/lotus-seal-worker/rpc.go index 3649d6c8f..6a6263671 100644 --- a/cmd/lotus-seal-worker/rpc.go +++ b/cmd/lotus-seal-worker/rpc.go @@ -26,7 +26,7 @@ type worker struct { } func (w *worker) Version(context.Context) (api.Version, error) { - return api.WorkerAPIVersion, nil + return api.WorkerAPIVersion0, nil } func (w *worker) StorageAddLocal(ctx context.Context, path string) error { diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index abb8d3abe..a02520116 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -151,6 +151,10 @@ var initCmd = &cli.Command{ log.Info("Trying to connect to full node RPC") + if err := checkV1ApiSupport(ctx, cctx); err != nil { + return err + } + api, closer, err := lcli.GetFullNodeAPIV1(cctx) // TODO: consider storing full node address in config if err != nil { return err @@ -188,8 +192,8 @@ var initCmd = &cli.Command{ return err } - if !v.APIVersion.EqMajorMinor(lapi.FullAPIVersion) { - return xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", lapi.FullAPIVersion, v.APIVersion) + if !v.APIVersion.EqMajorMinor(lapi.FullAPIVersion1) { + return xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", lapi.FullAPIVersion1, v.APIVersion) } log.Info("Initializing repo") @@ -719,3 +723,24 @@ func createStorageMiner(ctx context.Context, api v1api.FullNode, peerid peer.ID, log.Infof("New miners address is: %s (%s)", retval.IDAddress, retval.RobustAddress) return retval.IDAddress, nil } + +func checkV1ApiSupport(ctx context.Context, cctx *cli.Context) error { + // check v0 api version to make sure it supports v1 api + api0, closer, err := lcli.GetFullNodeAPI(cctx) + if err != nil { + return err + } + + v, err := api0.Version(ctx) + closer() + + if err != nil { + return err + } + + if !v.APIVersion.EqMajorMinor(lapi.FullAPIVersion0) { + return xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", lapi.FullAPIVersion0, v.APIVersion) + } + + return nil +} diff --git a/cmd/lotus-storage-miner/init_restore.go b/cmd/lotus-storage-miner/init_restore.go index 082c45614..eec7b8413 100644 --- a/cmd/lotus-storage-miner/init_restore.go +++ b/cmd/lotus-storage-miner/init_restore.go @@ -54,8 +54,14 @@ var initRestoreCmd = &cli.Command{ return xerrors.Errorf("expected 1 argument") } + ctx := lcli.ReqContext(cctx) + log.Info("Trying to connect to full node RPC") + if err := checkV1ApiSupport(ctx, cctx); err != nil { + return err + } + api, closer, err := lcli.GetFullNodeAPIV1(cctx) // TODO: consider storing full node address in config if err != nil { return err @@ -64,15 +70,13 @@ var initRestoreCmd = &cli.Command{ log.Info("Checking full node version") - ctx := lcli.ReqContext(cctx) - v, err := api.Version(ctx) if err != nil { return err } - if !v.APIVersion.EqMajorMinor(lapi.FullAPIVersion) { - return xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", lapi.FullAPIVersion, v.APIVersion) + if !v.APIVersion.EqMajorMinor(lapi.FullAPIVersion1) { + return xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", lapi.FullAPIVersion1, v.APIVersion) } if !cctx.Bool("nosync") { diff --git a/cmd/lotus-storage-miner/run.go b/cmd/lotus-storage-miner/run.go index f7a4efd1a..5d67cf33d 100644 --- a/cmd/lotus-storage-miner/run.go +++ b/cmd/lotus-storage-miner/run.go @@ -67,19 +67,13 @@ var runCmd = &cli.Command{ } } - nodeApi, ncloser, err := lcli.GetFullNodeAPIV1(cctx) - if err != nil { - return xerrors.Errorf("getting full node api: %w", err) - } - defer ncloser() - ctx, _ := tag.New(lcli.DaemonContext(cctx), tag.Insert(metrics.Version, build.BuildVersion), tag.Insert(metrics.Commit, build.CurrentCommit), tag.Insert(metrics.NodeType, "miner"), ) // Register all metric views - if err = view.Register( + if err := view.Register( metrics.MinerNodeViews..., ); err != nil { log.Fatalf("Cannot register the view: %v", err) @@ -87,6 +81,16 @@ var runCmd = &cli.Command{ // Set the metric to one so it is published to the exporter stats.Record(ctx, metrics.LotusInfo.M(1)) + if err := checkV1ApiSupport(ctx, cctx); err != nil { + return err + } + + nodeApi, ncloser, err := lcli.GetFullNodeAPIV1(cctx) + if err != nil { + return xerrors.Errorf("getting full node api: %w", err) + } + defer ncloser() + v, err := nodeApi.Version(ctx) if err != nil { return err @@ -98,8 +102,8 @@ var runCmd = &cli.Command{ } } - if v.APIVersion != api.FullAPIVersion { - return xerrors.Errorf("lotus-daemon API version doesn't match: expected: %s", api.APIVersion{APIVersion: api.FullAPIVersion}) + if v.APIVersion != api.FullAPIVersion1 { + return xerrors.Errorf("lotus-daemon API version doesn't match: expected: %s", api.APIVersion{APIVersion: api.FullAPIVersion1}) } log.Info("Checking full node sync status") diff --git a/documentation/en/api-v0-methods-miner.md b/documentation/en/api-v0-methods-miner.md index 9d33a55d0..6f1c076a6 100644 --- a/documentation/en/api-v0-methods-miner.md +++ b/documentation/en/api-v0-methods-miner.md @@ -193,7 +193,7 @@ Response: ```json { "Version": "string value", - "APIVersion": 65792, + "APIVersion": 131072, "BlockDelay": 42 } ``` diff --git a/documentation/en/api-v0-methods-worker.md b/documentation/en/api-v0-methods-worker.md index 40300866e..a697258a4 100644 --- a/documentation/en/api-v0-methods-worker.md +++ b/documentation/en/api-v0-methods-worker.md @@ -145,7 +145,7 @@ Perms: admin Inputs: `null` -Response: `65792` +Response: `131072` ## Add diff --git a/documentation/en/api-v0-methods.md b/documentation/en/api-v0-methods.md index a3b956ee7..52f09b163 100644 --- a/documentation/en/api-v0-methods.md +++ b/documentation/en/api-v0-methods.md @@ -276,7 +276,7 @@ Response: ```json { "Version": "string value", - "APIVersion": 65792, + "APIVersion": 131072, "BlockDelay": 42 } ``` diff --git a/documentation/en/api-v1-unstable-methods.md b/documentation/en/api-v1-unstable-methods.md index 4bf57b4f6..bfc4482c3 100644 --- a/documentation/en/api-v1-unstable-methods.md +++ b/documentation/en/api-v1-unstable-methods.md @@ -273,7 +273,7 @@ Response: ```json { "Version": "string value", - "APIVersion": 65792, + "APIVersion": 131072, "BlockDelay": 42 } ```