build: Separate API versions per node type

This commit is contained in:
Łukasz Magiera 2020-09-08 20:54:37 +02:00
parent 3697a1af4d
commit 38863d3025
10 changed files with 58 additions and 12 deletions

View File

@ -105,7 +105,7 @@ func init() {
addExample(network.Connected)
addExample(dtypes.NetworkName("lotus"))
addExample(api.SyncStateStage(1))
addExample(build.APIVersion)
addExample(build.FullAPIVersion)
addExample(api.PCHInbound)
addExample(time.Minute)
addExample(datatransfer.TransferID(3))

View File

@ -65,6 +65,8 @@ func TestApis(t *testing.T, b APIBuilder) {
var OneMiner = []StorageMiner{{Full: 0, Preseal: PresealGenesis}}
func (ts *testSuite) testVersion(t *testing.T) {
build.RunningNodeType = build.NodeFull
ctx := context.Background()
apis, _ := ts.makeNodes(t, 1, OneMiner)
api := apis[0]

View File

@ -1,6 +1,10 @@
package build
import "fmt"
import (
"fmt"
"golang.org/x/xerrors"
)
var CurrentCommit string
var BuildType int
@ -52,8 +56,37 @@ 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, 14, 0)
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(0, 14, 0)
MinerAPIVersion = newVer(0, 14, 0)
WorkerAPIVersion = newVer(0, 14, 0)
)
//nolint:varcheck,deadcode
const (

View File

@ -45,6 +45,8 @@ const FlagWorkerRepo = "worker-repo"
const FlagWorkerRepoDeprecation = "workerrepo"
func main() {
build.RunningNodeType = build.NodeWorker
lotuslog.SetupLogLevels()
local := []*cli.Command{
@ -187,8 +189,8 @@ var runCmd = &cli.Command{
if err != nil {
return err
}
if v.APIVersion != build.APIVersion {
return xerrors.Errorf("lotus-miner API version doesn't match: local: %s", api.Version{APIVersion: build.APIVersion})
if v.APIVersion != build.MinerAPIVersion {
return xerrors.Errorf("lotus-miner API version doesn't match: expected: %s", api.Version{APIVersion: build.MinerAPIVersion})
}
log.Infof("Remote version %s", v)

View File

@ -21,7 +21,7 @@ type worker struct {
}
func (w *worker) Version(context.Context) (build.Version, error) {
return build.APIVersion, nil
return build.WorkerAPIVersion, nil
}
func (w *worker) StorageAddLocal(ctx context.Context, path string) error {

View File

@ -179,8 +179,8 @@ var initCmd = &cli.Command{
return err
}
if !v.APIVersion.EqMajorMinor(build.APIVersion) {
return xerrors.Errorf("Remote API version didn't match (local %s, remote %s)", build.APIVersion, v.APIVersion)
if !v.APIVersion.EqMajorMinor(build.FullAPIVersion) {
return xerrors.Errorf("Remote API version didn't match (expected %s, remote %s)", build.FullAPIVersion, v.APIVersion)
}
log.Info("Initializing repo")

View File

@ -26,6 +26,8 @@ const FlagMinerRepo = "miner-repo"
const FlagMinerRepoDeprecation = "storagerepo"
func main() {
build.RunningNodeType = build.NodeMiner
lotuslog.SetupLogLevels()
local := []*cli.Command{

View File

@ -77,8 +77,8 @@ var runCmd = &cli.Command{
}
}
if v.APIVersion != build.APIVersion {
return xerrors.Errorf("lotus-daemon API version doesn't match: local: %s", api.Version{APIVersion: build.APIVersion})
if v.APIVersion != build.FullAPIVersion {
return xerrors.Errorf("lotus-daemon API version doesn't match: expected: %s", api.Version{APIVersion: build.FullAPIVersion})
}
log.Info("Checking full node sync status")

View File

@ -16,6 +16,8 @@ import (
var AdvanceBlockCmd *cli.Command
func main() {
build.RunningNodeType = build.NodeFull
lotuslog.SetupLogLevels()
local := []*cli.Command{

View File

@ -170,9 +170,14 @@ func (a *CommonAPI) ID(context.Context) (peer.ID, error) {
}
func (a *CommonAPI) Version(context.Context) (api.Version, error) {
v, err := build.VersionForType(build.RunningNodeType)
if err != nil {
return api.Version{}, err
}
return api.Version{
Version: build.UserVersion(),
APIVersion: build.APIVersion,
APIVersion: v,
BlockDelay: build.BlockDelaySecs,
}, nil