diff --git a/api/api_common.go b/api/api_common.go index 7a44522b5da..fc89f11cd98 100644 --- a/api/api_common.go +++ b/api/api_common.go @@ -11,8 +11,6 @@ import ( "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" protocol "github.com/libp2p/go-libp2p-core/protocol" - - "github.com/filecoin-project/lotus/build" ) type Common interface { @@ -58,7 +56,7 @@ type Common interface { ID(context.Context) (peer.ID, error) // Version provides information about API provider - Version(context.Context) (Version, error) + Version(context.Context) (APIVersion, error) LogList(context.Context) ([]string, error) LogSetLevel(context.Context, string, string) error @@ -72,15 +70,15 @@ type Common interface { Closing(context.Context) (<-chan struct{}, error) } -// Version provides various build-time information -type Version struct { +// APIVersion provides various build-time information +type APIVersion struct { Version string // APIVersion is a binary encoded semver version of the remote implementing // this api // // See APIVersion in build/version.go - APIVersion build.Version + APIVersion Version // TODO: git commit / os / genesis cid? @@ -88,7 +86,7 @@ type Version struct { BlockDelay uint64 } -func (v Version) String() string { +func (v APIVersion) String() string { return fmt.Sprintf("%s+api%s", v.Version, v.APIVersion.String()) } diff --git a/api/api_worker.go b/api/api_worker.go index e85f1e7d41d..999c42680fa 100644 --- a/api/api_worker.go +++ b/api/api_worker.go @@ -9,12 +9,10 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" "github.com/filecoin-project/lotus/extern/sector-storage/stores" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" - - "github.com/filecoin-project/lotus/build" ) type WorkerAPI interface { - Version(context.Context) (build.Version, error) + Version(context.Context) (Version, error) // TODO: Info() (name, ...) ? TaskTypes(context.Context) (map[sealtasks.TaskType]struct{}, error) // TaskType -> Weight diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index b455bbc4212..34b18cd4198 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -33,7 +33,6 @@ import ( "github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/types" @@ -65,8 +64,8 @@ type CommonStruct struct { NetBlockRemove func(ctx context.Context, acl api.NetBlockList) error `perm:"admin"` NetBlockList func(ctx context.Context) (api.NetBlockList, error) `perm:"read"` - ID func(context.Context) (peer.ID, error) `perm:"read"` - Version func(context.Context) (api.Version, error) `perm:"read"` + ID func(context.Context) (peer.ID, error) `perm:"read"` + Version func(context.Context) (api.APIVersion, error) `perm:"read"` LogList func(context.Context) ([]string, error) `perm:"write"` LogSetLevel func(context.Context, string, string) error `perm:"write"` @@ -390,7 +389,7 @@ type WorkerStruct struct { Internal struct { // TODO: lower perms - Version func(context.Context) (build.Version, error) `perm:"admin"` + Version func(context.Context) (api.Version, error) `perm:"admin"` TaskTypes func(context.Context) (map[sealtasks.TaskType]struct{}, error) `perm:"admin"` Paths func(context.Context) ([]stores.StoragePath, error) `perm:"admin"` @@ -551,7 +550,7 @@ func (c *CommonStruct) ID(ctx context.Context) (peer.ID, error) { } // Version implements API.Version -func (c *CommonStruct) Version(ctx context.Context) (api.Version, error) { +func (c *CommonStruct) Version(ctx context.Context) (api.APIVersion, error) { return c.Internal.Version(ctx) } @@ -1615,7 +1614,7 @@ func (c *StorageMinerStruct) CheckProvable(ctx context.Context, pp abi.Registere // WorkerStruct -func (w *WorkerStruct) Version(ctx context.Context) (build.Version, error) { +func (w *WorkerStruct) Version(ctx context.Context) (api.Version, error) { return w.Internal.Version(ctx) } diff --git a/api/docgen/docgen.go b/api/docgen/docgen.go index 487f65706fb..7b6a2725b0f 100644 --- a/api/docgen/docgen.go +++ b/api/docgen/docgen.go @@ -113,7 +113,7 @@ func init() { addExample(network.Connected) addExample(dtypes.NetworkName("lotus")) addExample(api.SyncStateStage(1)) - addExample(build.FullAPIVersion) + addExample(api.FullAPIVersion) addExample(api.PCHInbound) addExample(time.Minute) addExample(datatransfer.TransferID(3)) diff --git a/api/mocks/mock_full.go b/api/mocks/mock_full.go index fa1b98beae2..0b76c784dcd 100644 --- a/api/mocks/mock_full.go +++ b/api/mocks/mock_full.go @@ -2779,10 +2779,10 @@ func (mr *MockFullNodeMockRecorder) SyncValidateTipset(arg0, arg1 interface{}) * } // Version mocks base method -func (m *MockFullNode) Version(arg0 context.Context) (api.Version, error) { +func (m *MockFullNode) Version(arg0 context.Context) (api.APIVersion, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Version", arg0) - ret0, _ := ret[0].(api.Version) + ret0, _ := ret[0].(api.APIVersion) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/api/test/test.go b/api/test/test.go index eaf092a21da..eed760bc24c 100644 --- a/api/test/test.go +++ b/api/test/test.go @@ -155,13 +155,13 @@ var MineNext = miner.MineReq{ } func (ts *testSuite) testVersion(t *testing.T) { - build.RunningNodeType = build.NodeFull + api.RunningNodeType = api.NodeFull ctx := context.Background() apis, _ := ts.makeNodes(t, OneFull, OneMiner) - api := apis[0] + napi := apis[0] - v, err := api.Version(ctx) + v, err := napi.Version(ctx) if err != nil { t.Fatal(err) } diff --git a/api/version.go b/api/version.go new file mode 100644 index 00000000000..17605b518a6 --- /dev/null +++ b/api/version.go @@ -0,0 +1,71 @@ +package api + +import ( + "fmt" + + xerrors "golang.org/x/xerrors" +) + +type Version uint32 + +func newVer(major, minor, patch uint8) Version { + return Version(uint32(major)<<16 | uint32(minor)<<8 | uint32(patch)) +} + +// Ints returns (major, minor, patch) versions +func (ve Version) Ints() (uint32, uint32, uint32) { + v := uint32(ve) + return (v & majorOnlyMask) >> 16, (v & minorOnlyMask) >> 8, v & patchOnlyMask +} + +func (ve Version) String() string { + vmj, vmi, vp := ve.Ints() + return fmt.Sprintf("%d.%d.%d", vmj, vmi, vp) +} + +func (ve Version) EqMajorMinor(v2 Version) bool { + return ve&minorMask == v2&minorMask +} + +type NodeType int + +const ( + NodeUnknown NodeType = iota + + NodeFull + NodeMiner + NodeWorker +) + +var RunningNodeType NodeType + +func VersionForType(nodeType NodeType) (Version, error) { + switch nodeType { + case NodeFull: + return FullAPIVersion, nil + case NodeMiner: + return MinerAPIVersion, nil + case NodeWorker: + return WorkerAPIVersion, nil + default: + return Version(0), xerrors.Errorf("unknown node type %d", nodeType) + } +} + +// semver versions of the rpc api exposed +var ( + FullAPIVersion = newVer(1, 1, 0) + MinerAPIVersion = newVer(1, 0, 1) + WorkerAPIVersion = newVer(1, 0, 0) +) + +//nolint:varcheck,deadcode +const ( + majorMask = 0xff0000 + minorMask = 0xffff00 + patchMask = 0xffffff + + majorOnlyMask = 0xff0000 + minorOnlyMask = 0x00ff00 + patchOnlyMask = 0x0000ff +) diff --git a/build/version.go b/build/version.go index 55b8d6b90eb..7ca51a9f5d3 100644 --- a/build/version.go +++ b/build/version.go @@ -1,11 +1,5 @@ package build -import ( - "fmt" - - "golang.org/x/xerrors" -) - var CurrentCommit string var BuildType int @@ -40,67 +34,3 @@ const BuildVersion = "1.5.0" func UserVersion() string { return BuildVersion + buildType() + CurrentCommit } - -type Version uint32 - -func newVer(major, minor, patch uint8) Version { - return Version(uint32(major)<<16 | uint32(minor)<<8 | uint32(patch)) -} - -// Ints returns (major, minor, patch) versions -func (ve Version) Ints() (uint32, uint32, uint32) { - v := uint32(ve) - return (v & majorOnlyMask) >> 16, (v & minorOnlyMask) >> 8, v & patchOnlyMask -} - -func (ve Version) String() string { - vmj, vmi, vp := ve.Ints() - return fmt.Sprintf("%d.%d.%d", vmj, vmi, vp) -} - -func (ve Version) EqMajorMinor(v2 Version) bool { - return ve&minorMask == v2&minorMask -} - -type NodeType int - -const ( - NodeUnknown NodeType = iota - - NodeFull - NodeMiner - NodeWorker -) - -var RunningNodeType NodeType - -func VersionForType(nodeType NodeType) (Version, error) { - switch nodeType { - case NodeFull: - return FullAPIVersion, nil - case NodeMiner: - return MinerAPIVersion, nil - case NodeWorker: - return WorkerAPIVersion, nil - default: - return Version(0), xerrors.Errorf("unknown node type %d", nodeType) - } -} - -// semver versions of the rpc api exposed -var ( - FullAPIVersion = newVer(1, 1, 0) - MinerAPIVersion = newVer(1, 0, 1) - WorkerAPIVersion = newVer(1, 0, 0) -) - -//nolint:varcheck,deadcode -const ( - majorMask = 0xff0000 - minorMask = 0xffff00 - patchMask = 0xffffff - - majorOnlyMask = 0xff0000 - minorOnlyMask = 0x00ff00 - patchOnlyMask = 0x0000ff -) diff --git a/cmd/lotus-gateway/api.go b/cmd/lotus-gateway/api.go index 11e78a606e4..6f6cf27e673 100644 --- a/cmd/lotus-gateway/api.go +++ b/cmd/lotus-gateway/api.go @@ -34,7 +34,7 @@ var ( // gatewayDepsAPI defines the API methods that the GatewayAPI depends on // (to make it easy to mock for tests) type gatewayDepsAPI interface { - Version(context.Context) (api.Version, error) + Version(context.Context) (api.APIVersion, error) ChainGetBlockMessages(context.Context, cid.Cid) (*api.BlockMessages, error) ChainGetMessage(ctx context.Context, mc cid.Cid) (*types.Message, error) ChainGetNode(ctx context.Context, p string) (*api.IpldObject, error) @@ -130,7 +130,7 @@ func (a *GatewayAPI) checkTimestamp(at time.Time) error { return nil } -func (a *GatewayAPI) Version(ctx context.Context) (api.Version, error) { +func (a *GatewayAPI) Version(ctx context.Context) (api.APIVersion, error) { return a.api.Version(ctx) } diff --git a/cmd/lotus-seal-worker/main.go b/cmd/lotus-seal-worker/main.go index d5ebf891853..24918e52a39 100644 --- a/cmd/lotus-seal-worker/main.go +++ b/cmd/lotus-seal-worker/main.go @@ -50,7 +50,7 @@ const FlagWorkerRepo = "worker-repo" const FlagWorkerRepoDeprecation = "workerrepo" func main() { - build.RunningNodeType = build.NodeWorker + api.RunningNodeType = api.NodeWorker lotuslog.SetupLogLevels() @@ -211,8 +211,8 @@ var runCmd = &cli.Command{ if err != nil { return err } - if v.APIVersion != build.MinerAPIVersion { - return xerrors.Errorf("lotus-miner API version doesn't match: expected: %s", api.Version{APIVersion: build.MinerAPIVersion}) + if v.APIVersion != api.MinerAPIVersion { + return xerrors.Errorf("lotus-miner API version doesn't match: expected: %s", api.APIVersion{APIVersion: api.MinerAPIVersion}) } log.Infof("Remote version %s", v) diff --git a/cmd/lotus-seal-worker/rpc.go b/cmd/lotus-seal-worker/rpc.go index f4e8494d07d..f69129c5022 100644 --- a/cmd/lotus-seal-worker/rpc.go +++ b/cmd/lotus-seal-worker/rpc.go @@ -8,7 +8,7 @@ import ( "github.com/mitchellh/go-homedir" "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/api" sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" "github.com/filecoin-project/lotus/extern/sector-storage/stores" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" @@ -23,8 +23,8 @@ type worker struct { disabled int64 } -func (w *worker) Version(context.Context) (build.Version, error) { - return build.WorkerAPIVersion, nil +func (w *worker) Version(context.Context) (api.Version, error) { + return api.WorkerAPIVersion, nil } func (w *worker) StorageAddLocal(ctx context.Context, path string) error { diff --git a/cmd/lotus-shed/consensus.go b/cmd/lotus-shed/consensus.go index 1fe7756c1fa..c78c9c00f03 100644 --- a/cmd/lotus-shed/consensus.go +++ b/cmd/lotus-shed/consensus.go @@ -36,7 +36,7 @@ type consensusItem struct { targetTipset *types.TipSet headTipset *types.TipSet peerID peer.ID - version api.Version + version api.APIVersion api api.FullNode } diff --git a/cmd/lotus-storage-miner/actor_test.go b/cmd/lotus-storage-miner/actor_test.go index 1816c1eab93..02b41202cb1 100644 --- a/cmd/lotus-storage-miner/actor_test.go +++ b/cmd/lotus-storage-miner/actor_test.go @@ -17,6 +17,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/test" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/policy" @@ -70,7 +71,7 @@ func TestWorkerKeyChange(t *testing.T) { "testnode-storage": sn[0], } app.Writer = output - build.RunningNodeType = build.NodeMiner + api.RunningNodeType = api.NodeMiner fs := flag.NewFlagSet("", flag.ContinueOnError) for _, f := range cmd.Flags { diff --git a/cmd/lotus-storage-miner/allinfo_test.go b/cmd/lotus-storage-miner/allinfo_test.go index 51aba14a913..6fa3136d330 100644 --- a/cmd/lotus-storage-miner/allinfo_test.go +++ b/cmd/lotus-storage-miner/allinfo_test.go @@ -11,8 +11,8 @@ import ( "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/test" - "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/lib/lotuslog" "github.com/filecoin-project/lotus/node/repo" @@ -55,7 +55,7 @@ func TestMinerAllInfo(t *testing.T) { "testnode-full": n[0], "testnode-storage": sn[0], } - build.RunningNodeType = build.NodeMiner + api.RunningNodeType = api.NodeMiner cctx := cli.NewContext(app, flag.NewFlagSet("", flag.ContinueOnError), nil) diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index 13f946d78eb..2e38dcc06ca 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -186,8 +186,8 @@ var initCmd = &cli.Command{ return err } - if !v.APIVersion.EqMajorMinor(build.FullAPIVersion) { - return xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", build.FullAPIVersion, v.APIVersion) + if !v.APIVersion.EqMajorMinor(lapi.FullAPIVersion) { + return xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", lapi.FullAPIVersion, v.APIVersion) } log.Info("Initializing repo") diff --git a/cmd/lotus-storage-miner/init_restore.go b/cmd/lotus-storage-miner/init_restore.go index 9591129b8d6..12358e63a75 100644 --- a/cmd/lotus-storage-miner/init_restore.go +++ b/cmd/lotus-storage-miner/init_restore.go @@ -18,6 +18,7 @@ import ( paramfetch "github.com/filecoin-project/go-paramfetch" "github.com/filecoin-project/go-state-types/big" + lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" @@ -68,8 +69,8 @@ var initRestoreCmd = &cli.Command{ return err } - if !v.APIVersion.EqMajorMinor(build.FullAPIVersion) { - return xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", build.FullAPIVersion, v.APIVersion) + if !v.APIVersion.EqMajorMinor(lapi.FullAPIVersion) { + return xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", lapi.FullAPIVersion, v.APIVersion) } if !cctx.Bool("nosync") { diff --git a/cmd/lotus-storage-miner/main.go b/cmd/lotus-storage-miner/main.go index 671f75cf0fc..84654d7899b 100644 --- a/cmd/lotus-storage-miner/main.go +++ b/cmd/lotus-storage-miner/main.go @@ -26,7 +26,7 @@ const FlagMinerRepo = "miner-repo" const FlagMinerRepoDeprecation = "storagerepo" func main() { - build.RunningNodeType = build.NodeMiner + api.RunningNodeType = api.NodeMiner lotuslog.SetupLogLevels() diff --git a/cmd/lotus-storage-miner/run.go b/cmd/lotus-storage-miner/run.go index 741a18eb6be..cdcc4d88f59 100644 --- a/cmd/lotus-storage-miner/run.go +++ b/cmd/lotus-storage-miner/run.go @@ -95,8 +95,8 @@ var runCmd = &cli.Command{ } } - if v.APIVersion != build.FullAPIVersion { - return xerrors.Errorf("lotus-daemon API version doesn't match: expected: %s", api.Version{APIVersion: build.FullAPIVersion}) + if v.APIVersion != api.FullAPIVersion { + return xerrors.Errorf("lotus-daemon API version doesn't match: expected: %s", api.APIVersion{APIVersion: api.FullAPIVersion}) } log.Info("Checking full node sync status") diff --git a/cmd/lotus/main.go b/cmd/lotus/main.go index eb97045eeb1..af9c567357e 100644 --- a/cmd/lotus/main.go +++ b/cmd/lotus/main.go @@ -6,6 +6,7 @@ import ( "github.com/urfave/cli/v2" "go.opencensus.io/trace" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/lib/lotuslog" @@ -16,7 +17,7 @@ import ( var AdvanceBlockCmd *cli.Command func main() { - build.RunningNodeType = build.NodeFull + api.RunningNodeType = api.NodeFull lotuslog.SetupLogLevels() diff --git a/cmd/tvx/simulate.go b/cmd/tvx/simulate.go index 7a33707dc11..da9a034e923 100644 --- a/cmd/tvx/simulate.go +++ b/cmd/tvx/simulate.go @@ -154,7 +154,7 @@ func runSimulateCmd(_ *cli.Context) error { version, err := FullAPI.Version(ctx) if err != nil { log.Printf("failed to get node version: %s; falling back to unknown", err) - version = api.Version{} + version = api.APIVersion{} } nv, err := FullAPI.StateNetworkVersion(ctx, ts.Key()) diff --git a/node/impl/common/common.go b/node/impl/common/common.go index 0a7e01eca8f..389e2fbc621 100644 --- a/node/impl/common/common.go +++ b/node/impl/common/common.go @@ -211,13 +211,13 @@ func (a *CommonAPI) ID(context.Context) (peer.ID, error) { return a.Host.ID(), nil } -func (a *CommonAPI) Version(context.Context) (api.Version, error) { - v, err := build.VersionForType(build.RunningNodeType) +func (a *CommonAPI) Version(context.Context) (api.APIVersion, error) { + v, err := api.VersionForType(api.RunningNodeType) if err != nil { - return api.Version{}, err + return api.APIVersion{}, err } - return api.Version{ + return api.APIVersion{ Version: build.UserVersion(), APIVersion: v,