Skip to content

Commit

Permalink
Merge pull request #5729 from filecoin-project/feat/api-no-dep-build
Browse files Browse the repository at this point in the history
Feat/api no dep build
  • Loading branch information
magik6k authored Mar 9, 2021
2 parents 2642ddc + 05e03dc commit 1c62d7a
Show file tree
Hide file tree
Showing 21 changed files with 116 additions and 117 deletions.
12 changes: 5 additions & 7 deletions api/api_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -72,23 +70,23 @@ 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?

// Seconds
BlockDelay uint64
}

func (v Version) String() string {
func (v APIVersion) String() string {
return fmt.Sprintf("%s+api%s", v.Version, v.APIVersion.String())
}

Expand Down
4 changes: 1 addition & 3 deletions api/api_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions api/apistruct/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion api/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions api/mocks/mock_full.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions api/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
71 changes: 71 additions & 0 deletions api/version.go
Original file line number Diff line number Diff line change
@@ -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
)
70 changes: 0 additions & 70 deletions build/version.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package build

import (
"fmt"

"golang.org/x/xerrors"
)

var CurrentCommit string
var BuildType int

Expand Down Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions cmd/lotus-gateway/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/lotus-seal-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const FlagWorkerRepo = "worker-repo"
const FlagWorkerRepoDeprecation = "workerrepo"

func main() {
build.RunningNodeType = build.NodeWorker
api.RunningNodeType = api.NodeWorker

lotuslog.SetupLogLevels()

Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions cmd/lotus-seal-worker/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-shed/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/lotus-storage-miner/actor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/lotus-storage-miner/allinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 1c62d7a

Please sign in to comment.