Fix v0/v1 API versions

This commit is contained in:
Łukasz Magiera
2021-04-16 00:20:13 +02:00
parent 35cf83d519
commit 4436c184ed
13 changed files with 75 additions and 29 deletions
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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 {
+27 -2
View File
@@ -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
}
+8 -4
View File
@@ -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") {
+13 -9
View File
@@ -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")