From 867cba610b92aacf13ed766731a16cdee1d99c6e Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Fri, 13 Dec 2019 18:20:55 +0100 Subject: [PATCH 1/3] Refactor versions Signed-off-by: Jakub Sztandera --- api/api_common.go | 8 ++--- build/version.go | 53 ++++++++++++++++++++++++--------- cmd/lotus-storage-miner/init.go | 2 +- node/impl/common.go | 3 +- 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/api/api_common.go b/api/api_common.go index ee99f6d76..81608c59e 100644 --- a/api/api_common.go +++ b/api/api_common.go @@ -4,10 +4,9 @@ import ( "context" "fmt" + "github.com/filecoin-project/lotus/build" "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" - - "github.com/filecoin-project/lotus/build" ) type Permission = string @@ -40,7 +39,7 @@ type Version struct { // this api // // See APIVersion in build/version.go - APIVersion uint32 + APIVersion build.Version // TODO: git commit / os / genesis cid? @@ -49,6 +48,5 @@ type Version struct { } func (v Version) String() string { - vM, vm, vp := build.VersionInts(v.APIVersion) - return fmt.Sprintf("%s+api%d.%d.%d", v.Version, vM, vm, vp) + return fmt.Sprintf("%s+api%s", v.Version, v.APIVersion.String()) } diff --git a/build/version.go b/build/version.go index 095ce8d0c..05ca42c48 100644 --- a/build/version.go +++ b/build/version.go @@ -1,11 +1,35 @@ package build +import "fmt" + var CurrentCommit string -// Version is the local build version, set by build system -const Version = "0.1.2" +// BuildVersion is the local build version, set by build system +const BuildVersion = "0.1.2" -var UserVersion = Version + CurrentCommit +var UserVersion = BuildVersion + 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) +} +>>>>>>> 4041819c... Refactor versions + +func (ve Version) EqMajorMinor(v2 Version) bool { + return ve&minorMask == v2&minorMask +} // APIVersion is a hex semver version of the rpc api exposed // @@ -16,19 +40,20 @@ var UserVersion = Version + CurrentCommit // R R H // |\vv/| // vv vv +<<<<<<< HEAD const APIVersion = 0x000102 +||||||| parent of 4041819c... Refactor versions +const APIVersion = 0x000101 +======= +var APIVersion Version = newVer(0, 1, 1) +>>>>>>> 4041819c... Refactor versions const ( - MajorMask = 0xff0000 - MinorMask = 0xffff00 - PatchMask = 0xffffff + majorMask = 0xff0000 + minorMask = 0xffff00 + patchMask = 0xffffff - MajorOnlyMask = 0xff0000 - MinorOnlyMask = 0x00ff00 - PatchOnlyMask = 0x0000ff + majorOnlyMask = 0xff0000 + minorOnlyMask = 0x00ff00 + patchOnlyMask = 0x0000ff ) - -// VersionInts returns (major, minor, patch) versions -func VersionInts(version uint32) (uint32, uint32, uint32) { - return (version & MajorOnlyMask) >> 16, (version & MinorOnlyMask) >> 8, version & PatchOnlyMask -} diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index c6845d2b5..6cc836f98 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -136,7 +136,7 @@ var initCmd = &cli.Command{ return err } - if v.APIVersion&build.MinorMask != build.APIVersion&build.MinorMask { + if v.APIVersion.EqMajorMinor(build.APIVersion) { return xerrors.Errorf("Remote API version didn't match (local %x, remote %x)", build.APIVersion, v.APIVersion) } diff --git a/node/impl/common.go b/node/impl/common.go index 990a46a8a..c77535779 100644 --- a/node/impl/common.go +++ b/node/impl/common.go @@ -2,6 +2,7 @@ package impl import ( "context" + "github.com/gbrlsnchs/jwt/v3" "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/network" @@ -84,7 +85,7 @@ func (a *CommonAPI) ID(context.Context) (peer.ID, error) { func (a *CommonAPI) Version(context.Context) (api.Version, error) { return api.Version{ - Version: build.Version, + Version: build.UserVersion, APIVersion: build.APIVersion, BlockDelay: build.BlockDelay, From 17d0fe96a48eea97b4b86b09fe4f25f6479dc774 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 17 Dec 2019 00:44:56 +0100 Subject: [PATCH 2/3] Fix version references Signed-off-by: Jakub Sztandera --- api/test/test.go | 2 +- cmd/lotus-shed/main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/test/test.go b/api/test/test.go index 8ade6d981..7925300be 100644 --- a/api/test/test.go +++ b/api/test/test.go @@ -50,7 +50,7 @@ func (ts *testSuite) testVersion(t *testing.T) { if err != nil { t.Fatal(err) } - if v.Version != build.Version { + if v.Version != build.BuildVersion { t.Error("Version didn't work properly") } } diff --git a/cmd/lotus-shed/main.go b/cmd/lotus-shed/main.go index 5b402152a..79be74d31 100644 --- a/cmd/lotus-shed/main.go +++ b/cmd/lotus-shed/main.go @@ -25,7 +25,7 @@ func main() { app := &cli.App{ Name: "lotus-shed", Usage: "A place for all the lotus tools", - Version: build.Version, + Version: build.BuildVersion, Commands: local, } From 5c64859a9baa2242484b35cdf16966c3bf42480f Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 17 Dec 2019 02:50:52 +0100 Subject: [PATCH 3/3] Fix merge conflict Signed-off-by: Jakub Sztandera --- build/version.go | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/build/version.go b/build/version.go index 05ca42c48..1a4f5bfd5 100644 --- a/build/version.go +++ b/build/version.go @@ -25,28 +25,13 @@ func (ve Version) String() string { vmj, vmi, vp := ve.Ints() return fmt.Sprintf("%d.%d.%d", vmj, vmi, vp) } ->>>>>>> 4041819c... Refactor versions func (ve Version) EqMajorMinor(v2 Version) bool { return ve&minorMask == v2&minorMask } -// 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 -<<<<<<< HEAD -const APIVersion = 0x000102 -||||||| parent of 4041819c... Refactor versions -const APIVersion = 0x000101 -======= -var APIVersion Version = newVer(0, 1, 1) ->>>>>>> 4041819c... Refactor versions +// APIVersion is a semver version of the rpc api exposed +var APIVersion Version = newVer(0, 1, 2) const ( majorMask = 0xff0000