Merge pull request #909 from filecoin-project/feat/version2
Refactor versions
This commit is contained in:
commit
e2fd292ead
@ -4,10 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/libp2p/go-libp2p-core/network"
|
"github.com/libp2p/go-libp2p-core/network"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Permission = string
|
type Permission = string
|
||||||
@ -40,7 +39,7 @@ type Version struct {
|
|||||||
// this api
|
// this api
|
||||||
//
|
//
|
||||||
// See APIVersion in build/version.go
|
// See APIVersion in build/version.go
|
||||||
APIVersion uint32
|
APIVersion build.Version
|
||||||
|
|
||||||
// TODO: git commit / os / genesis cid?
|
// TODO: git commit / os / genesis cid?
|
||||||
|
|
||||||
@ -49,6 +48,5 @@ type Version struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v Version) String() string {
|
func (v Version) String() string {
|
||||||
vM, vm, vp := build.VersionInts(v.APIVersion)
|
return fmt.Sprintf("%s+api%s", v.Version, v.APIVersion.String())
|
||||||
return fmt.Sprintf("%s+api%d.%d.%d", v.Version, vM, vm, vp)
|
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func (ts *testSuite) testVersion(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if v.Version != build.Version {
|
if v.Version != build.BuildVersion {
|
||||||
t.Error("Version didn't work properly")
|
t.Error("Version didn't work properly")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,44 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
var CurrentCommit string
|
var CurrentCommit string
|
||||||
|
|
||||||
// Version is the local build version, set by build system
|
// BuildVersion is the local build version, set by build system
|
||||||
const Version = "0.1.2"
|
const BuildVersion = "0.1.2"
|
||||||
|
|
||||||
var UserVersion = Version + CurrentCommit
|
var UserVersion = BuildVersion + CurrentCommit
|
||||||
|
|
||||||
// APIVersion is a hex semver version of the rpc api exposed
|
type Version uint32
|
||||||
//
|
|
||||||
// M M P
|
func newVer(major, minor, patch uint8) Version {
|
||||||
// A I A
|
return Version(uint32(major)<<16 | uint32(minor)<<8 | uint32(patch))
|
||||||
// J N T
|
}
|
||||||
// O O C
|
|
||||||
// R R H
|
// Ints returns (major, minor, patch) versions
|
||||||
// |\vv/|
|
func (ve Version) Ints() (uint32, uint32, uint32) {
|
||||||
// vv vv
|
v := uint32(ve)
|
||||||
const APIVersion = 0x000102
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// APIVersion is a semver version of the rpc api exposed
|
||||||
|
var APIVersion Version = newVer(0, 1, 2)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MajorMask = 0xff0000
|
majorMask = 0xff0000
|
||||||
MinorMask = 0xffff00
|
minorMask = 0xffff00
|
||||||
PatchMask = 0xffffff
|
patchMask = 0xffffff
|
||||||
|
|
||||||
MajorOnlyMask = 0xff0000
|
majorOnlyMask = 0xff0000
|
||||||
MinorOnlyMask = 0x00ff00
|
minorOnlyMask = 0x00ff00
|
||||||
PatchOnlyMask = 0x0000ff
|
patchOnlyMask = 0x0000ff
|
||||||
)
|
)
|
||||||
|
|
||||||
// VersionInts returns (major, minor, patch) versions
|
|
||||||
func VersionInts(version uint32) (uint32, uint32, uint32) {
|
|
||||||
return (version & MajorOnlyMask) >> 16, (version & MinorOnlyMask) >> 8, version & PatchOnlyMask
|
|
||||||
}
|
|
||||||
|
@ -25,7 +25,7 @@ func main() {
|
|||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "lotus-shed",
|
Name: "lotus-shed",
|
||||||
Usage: "A place for all the lotus tools",
|
Usage: "A place for all the lotus tools",
|
||||||
Version: build.Version,
|
Version: build.BuildVersion,
|
||||||
Commands: local,
|
Commands: local,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ var initCmd = &cli.Command{
|
|||||||
return err
|
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)
|
return xerrors.Errorf("Remote API version didn't match (local %x, remote %x)", build.APIVersion, v.APIVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package impl
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/gbrlsnchs/jwt/v3"
|
"github.com/gbrlsnchs/jwt/v3"
|
||||||
"github.com/libp2p/go-libp2p-core/host"
|
"github.com/libp2p/go-libp2p-core/host"
|
||||||
"github.com/libp2p/go-libp2p-core/network"
|
"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) {
|
func (a *CommonAPI) Version(context.Context) (api.Version, error) {
|
||||||
return api.Version{
|
return api.Version{
|
||||||
Version: build.Version,
|
Version: build.UserVersion,
|
||||||
APIVersion: build.APIVersion,
|
APIVersion: build.APIVersion,
|
||||||
|
|
||||||
BlockDelay: build.BlockDelay,
|
BlockDelay: build.BlockDelay,
|
||||||
|
Loading…
Reference in New Issue
Block a user