Merge pull request #6052 from filecoin-project/fix/miner-v1api-check
Fix v0/v1 API versions
This commit is contained in:
commit
5e71bcedc2
@ -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))
|
||||
|
@ -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{}
|
||||
|
@ -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
|
||||
|
Binary file not shown.
@ -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)
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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") {
|
||||
|
@ -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")
|
||||
|
@ -193,7 +193,7 @@ Response:
|
||||
```json
|
||||
{
|
||||
"Version": "string value",
|
||||
"APIVersion": 65792,
|
||||
"APIVersion": 131072,
|
||||
"BlockDelay": 42
|
||||
}
|
||||
```
|
||||
|
@ -145,7 +145,7 @@ Perms: admin
|
||||
|
||||
Inputs: `null`
|
||||
|
||||
Response: `65792`
|
||||
Response: `131072`
|
||||
|
||||
## Add
|
||||
|
||||
|
@ -276,7 +276,7 @@ Response:
|
||||
```json
|
||||
{
|
||||
"Version": "string value",
|
||||
"APIVersion": 65792,
|
||||
"APIVersion": 131072,
|
||||
"BlockDelay": 42
|
||||
}
|
||||
```
|
||||
|
@ -273,7 +273,7 @@ Response:
|
||||
```json
|
||||
{
|
||||
"Version": "string value",
|
||||
"APIVersion": 65792,
|
||||
"APIVersion": 131072,
|
||||
"BlockDelay": 42
|
||||
}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user