Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenRPC Support #5843

Merged
merged 61 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4980369
main: init implement rpc.Discover RPC method
meowsbits Oct 27, 2020
9d84fd4
main,go.mod,go.sum: init example with go-openrpc-reflect lib
meowsbits Jul 6, 2020
64ff7ef
main: make variable name human-friendly
meowsbits Jul 6, 2020
0f278a3
main,go.mod,go.sum: init impl of go-openrp-reflect printing document
meowsbits Jul 6, 2020
5af03c5
go.mod,go.sum: use go-openrpc-reflect and open-rpc/meta-schema hackforks
meowsbits Oct 27, 2020
9805c16
main,openrpc,main: refactor openrpc supporting code to own package
meowsbits Oct 27, 2020
116898e
main: add rpc.Discover to openrpc document
meowsbits Oct 27, 2020
bf78ff6
openrpc: fix rpc.discover method name casing
meowsbits Oct 27, 2020
de2569b
Revert "main: add rpc.Discover to openrpc document"
meowsbits Oct 27, 2020
1100dad
main: fix document creation method name
meowsbits Oct 27, 2020
f90ee85
main,docgen,openrpc: refactor to share api parsing, etc as docgen exp…
meowsbits Oct 28, 2020
0fcceff
openrpc: add schema.examples to app reflector
meowsbits Oct 28, 2020
d11db31
openrpc: init method pairing examples
meowsbits Oct 29, 2020
3ccacf2
go.mod,go.sum: bump go.mod to use latest meta-schema and openrpc-refl…
meowsbits Oct 30, 2020
377f000
openrpc: init SchemaType mapper function
meowsbits Oct 30, 2020
b381ca1
Merge remote-tracking branch 'origin/master' into feat/openrpc
meowsbits Nov 3, 2020
413d02f
go.mod,go.sum: tame dependencies by bumping etclabscore/go-openrpc-re…
meowsbits Nov 21, 2020
b2d623e
main: add 'miner' arg to openrpc gen cmd
meowsbits Nov 21, 2020
89536c5
docgen: add missing examples for Miner API
meowsbits Nov 21, 2020
fc5a4e6
build/openrpc/full.json,build/openrpc/miner.json: add build/openrpc/[…
meowsbits Nov 21, 2020
4cbee1a
build: init go-rice openrpc static assets
meowsbits Nov 21, 2020
a63eeef
main: remove rpc.discover implementation from runtime plugin
meowsbits Nov 21, 2020
630fa60
api,apistruct,common: add Discover(ctx) method to CommonAPI interface…
meowsbits Nov 21, 2020
d20a497
main: use rpc server method aliasing for rpc.discover
meowsbits Nov 21, 2020
e391954
api,apistruct,build,common: rpc.discover: return json object instead …
meowsbits Nov 21, 2020
d81b8ef
Merge branch 'master' into feat/openrpc
meowsbits Nov 22, 2020
5968b36
Makefile: merge resolve: docsgen command path
meowsbits Nov 22, 2020
b4a45a2
apistruct,main,docgen,openrpc: merge resolve: fix func exporteds, sig…
meowsbits Nov 22, 2020
598cefb
go.mod,go.sum: 'get get' auto-bumps version
meowsbits Nov 22, 2020
2879538
Makefile,docgen,main,build/openrpc: refactor openrpc documentation ge…
meowsbits Nov 22, 2020
88fbef9
main,docgen_openrpc: rename api/openrpc -> api/docgen-openrpc
meowsbits Nov 22, 2020
bd710a0
api,apistruct,docgen,build,build/openrpc: use typed Discover response
meowsbits Nov 22, 2020
584e4a0
apistruct,build,main,impl: implement Discover method for Worker and S…
meowsbits Nov 22, 2020
9904a8b
docgen_openrpc,build/openrpc: remove timestamping from openrpc doc info
meowsbits Nov 22, 2020
85ae23b
main,docgen_openrpc,main,build: fix lint issues
meowsbits Nov 22, 2020
0836ac7
docgenopenrpc: fix: don't use an underscore in package name (golint)
meowsbits Nov 22, 2020
1f8a9f8
go.sum: fix: mod-tidy-check (run 'go mod tidy')
meowsbits Nov 22, 2020
76e6fd2
go.mod,go.sum: bump filecoin-project/go-jsonrpc dep to latest
meowsbits Nov 23, 2020
145e8bb
Makefile,main,build,build/openrpc: init gzipped openrpc static docs
meowsbits Nov 24, 2020
503e079
build: refactor gzip reading
meowsbits Nov 24, 2020
bb410a4
build: add basic test for openrpc doc from static assets
meowsbits Nov 24, 2020
bbe144e
build: handle reader Close error
meowsbits Nov 24, 2020
b1ebe83
go.sum: run 'go mod tidy'
meowsbits Nov 24, 2020
6ed76d6
Merge branch 'master' into feat/openrpc
meowsbits Nov 24, 2020
a67efba
go.mod,go.sum: go mod tidy
meowsbits Nov 24, 2020
0d6041f
go.mod,go.sum: bump filecoin-project/go-jsonrpc to latest
meowsbits Nov 24, 2020
8764a77
docgenopenrpc,build/openrpc: remove method example pairings, improve …
meowsbits Nov 27, 2020
c48a894
docgenopenrpc: use generic number jsonschema for number types
meowsbits Dec 15, 2020
dcdd0f0
Merge branch 'master' into feat/openrpc
meowsbits Jan 19, 2021
f4a953b
cmd/lotus,go.mod,go.sum: maybe fix straggling merge resolution conflicts
meowsbits Jan 19, 2021
8ec6f16
build/openrpc/full.json.gz,build/openrpc/miner.json.gz,build/openrpc/…
meowsbits Jan 19, 2021
fa889ad
api/apistruct,node/impl: (lint) gofmt
meowsbits Jan 19, 2021
7686435
api/docgen: maybe fix parse error: open ./api: no such file or direc…
meowsbits Jan 19, 2021
7b7cd4f
api/docgen,build/openrpc: maybe fix no such file error and run 'make …
meowsbits Jan 19, 2021
549125d
api/docgen: return if AST comment/groupdoc parsing encounters any error
meowsbits Jan 19, 2021
b9ea12f
Merge branch 'feat/openrpc' of github.com:etclabscore/lotus into etcl…
magik6k Mar 19, 2021
c8669ab
api: Don't depend on build/
magik6k Mar 19, 2021
d56b2eb
make: support parallel docsgen
magik6k Mar 19, 2021
5630003
openrpc gen: Use simple build version
magik6k Mar 19, 2021
ad50f2b
methodgen
magik6k Mar 19, 2021
a569954
goimports
magik6k Mar 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
/lotus-pcr
/lotus-wallet
/lotus-keygen
/docgen-md
/docgen-openrpc
/bench.json
/lotuspond/front/node_modules
/lotuspond/front/build
Expand Down
30 changes: 26 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,32 @@ method-gen:

gen: type-gen method-gen

docsgen:
go run ./api/docgen "api/api_full.go" "FullNode" > documentation/en/api-methods.md
go run ./api/docgen "api/api_storage.go" "StorageMiner" > documentation/en/api-methods-miner.md
go run ./api/docgen "api/api_worker.go" "WorkerAPI" > documentation/en/api-methods-worker.md
docsgen: docsgen-md docsgen-openrpc

docsgen-md-bin:
go build $(GOFLAGS) -o docgen-md ./api/docgen/cmd
docsgen-openrpc-bin:
go build $(GOFLAGS) -o docgen-openrpc ./api/docgen-openrpc/cmd

docsgen-md: docsgen-md-full docsgen-md-storage docsgen-md-worker

docsgen-md-full: docsgen-md-bin
./docgen-md "api/api_full.go" "FullNode" > documentation/en/api-methods.md
docsgen-md-storage: docsgen-md-bin
./docgen-md "api/api_storage.go" "StorageMiner" > documentation/en/api-methods-miner.md
docsgen-md-worker: docsgen-md-bin
./docgen-md "api/api_worker.go" "WorkerAPI" > documentation/en/api-methods-worker.md

docsgen-openrpc: docsgen-openrpc-full docsgen-openrpc-storage docsgen-openrpc-worker

docsgen-openrpc-full: docsgen-openrpc-bin
./docgen-openrpc "api/api_full.go" "FullNode" -gzip > build/openrpc/full.json.gz
docsgen-openrpc-storage: docsgen-openrpc-bin
./docgen-openrpc "api/api_storage.go" "StorageMiner" -gzip > build/openrpc/miner.json.gz
docsgen-openrpc-worker: docsgen-openrpc-bin
./docgen-openrpc "api/api_worker.go" "WorkerAPI" -gzip > build/openrpc/worker.json.gz

.PHONY: docsgen docsgen-md-bin docsgen-openrpc-bin

print-%:
@echo $*=$($*)
5 changes: 5 additions & 0 deletions api/api_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
protocol "github.com/libp2p/go-libp2p-core/protocol"

apitypes "github.com/filecoin-project/lotus/api/types"
)

type Common interface {
Expand Down Expand Up @@ -52,6 +54,9 @@ type Common interface {

// MethodGroup: Common

// Discover returns an OpenRPC document describing an RPC API.
Discover(ctx context.Context) (apitypes.OpenRPCDocument, error)

// ID returns peerID of libp2p node backing this API
ID(context.Context) (peer.ID, error)

Expand Down
12 changes: 12 additions & 0 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ func TestDoesntDependOnFFI(t *testing.T) {
}
}

func TestDoesntDependOnBuild(t *testing.T) {
deps, err := exec.Command(goCmd(), "list", "-deps", "github.com/filecoin-project/lotus/api").Output()
if err != nil {
t.Fatal(err)
}
for _, pkg := range strings.Fields(string(deps)) {
if pkg == "github.com/filecoin-project/build" {
t.Fatal("api depends on filecoin-ffi")
}
}
}

func TestReturnTypes(t *testing.T) {
errType := reflect.TypeOf(new(error)).Elem()
bareIface := reflect.TypeOf(new(interface{})).Elem()
Expand Down
22 changes: 20 additions & 2 deletions api/apistruct/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
"io"
"time"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
"github.com/google/uuid"
"github.com/ipfs/go-cid"
metrics "github.com/libp2p/go-libp2p-core/metrics"
"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/go-address"
"github.com/filecoin-project/go-bitfield"
datatransfer "github.com/filecoin-project/go-data-transfer"
"github.com/filecoin-project/go-fil-markets/piecestore"
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
Expand All @@ -33,6 +33,7 @@ import (
"github.com/filecoin-project/specs-storage/storage"

"github.com/filecoin-project/lotus/api"
apitypes "github.com/filecoin-project/lotus/api/types"
"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 @@ -63,6 +64,7 @@ type CommonStruct struct {
NetBlockAdd func(ctx context.Context, acl api.NetBlockList) error `perm:"admin"`
NetBlockRemove func(ctx context.Context, acl api.NetBlockList) error `perm:"admin"`
NetBlockList func(ctx context.Context) (api.NetBlockList, error) `perm:"read"`
Discover func(ctx context.Context) (map[string]interface{}, error) `perm:"read"`

ID func(context.Context) (peer.ID, error) `perm:"read"`
Version func(context.Context) (api.APIVersion, error) `perm:"read"`
Expand Down Expand Up @@ -382,6 +384,8 @@ type StorageMinerStruct struct {
CreateBackup func(ctx context.Context, fpath string) error `perm:"admin"`

CheckProvable func(ctx context.Context, pp abi.RegisteredPoStProof, sectors []storage.SectorRef, expensive bool) (map[abi.SectorNumber]string, error) `perm:"admin"`

Discover func(ctx context.Context) (apitypes.OpenRPCDocument, error) `perm:"read"`
}
}

Expand Down Expand Up @@ -420,6 +424,8 @@ type WorkerStruct struct {

ProcessSession func(context.Context) (uuid.UUID, error) `perm:"admin"`
Session func(context.Context) (uuid.UUID, error) `perm:"admin"`

Discover func(ctx context.Context) (apitypes.OpenRPCDocument, error) `perm:"read"`
}
}

Expand Down Expand Up @@ -544,6 +550,10 @@ func (c *CommonStruct) NetPeerInfo(ctx context.Context, p peer.ID) (*api.Extende
return c.Internal.NetPeerInfo(ctx, p)
}

func (c *CommonStruct) Discover(ctx context.Context) (apitypes.OpenRPCDocument, error) {
return c.Internal.Discover(ctx)
}

// ID implements API.ID
func (c *CommonStruct) ID(ctx context.Context) (peer.ID, error) {
return c.Internal.ID(ctx)
Expand Down Expand Up @@ -1612,6 +1622,10 @@ func (c *StorageMinerStruct) CheckProvable(ctx context.Context, pp abi.Registere
return c.Internal.CheckProvable(ctx, pp, sectors, expensive)
}

func (c *StorageMinerStruct) Discover(ctx context.Context) (apitypes.OpenRPCDocument, error) {
return c.Internal.Discover(ctx)
}

// WorkerStruct

func (w *WorkerStruct) Version(ctx context.Context) (api.Version, error) {
Expand Down Expand Up @@ -1710,6 +1724,10 @@ func (w *WorkerStruct) Session(ctx context.Context) (uuid.UUID, error) {
return w.Internal.Session(ctx)
}

func (c *WorkerStruct) Discover(ctx context.Context) (apitypes.OpenRPCDocument, error) {
return c.Internal.Discover(ctx)
}

func (g GatewayStruct) ChainGetBlockMessages(ctx context.Context, c cid.Cid) (*api.BlockMessages, error) {
return g.Internal.ChainGetBlockMessages(ctx, c)
}
Expand Down
77 changes: 77 additions & 0 deletions api/docgen-openrpc/cmd/docgen_openrpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package main

import (
"compress/gzip"
"encoding/json"
"io"
"log"
"os"

"github.com/filecoin-project/lotus/api/apistruct"
docgen_openrpc "github.com/filecoin-project/lotus/api/docgen-openrpc"
)

/*
main defines a small program that writes an OpenRPC document describing
a Lotus API to stdout.

If the first argument is "miner", the document will describe the StorageMiner API.
If not (no, or any other args), the document will describe the Full API.

Use:

go run ./api/openrpc/cmd ["api/api_full.go"|"api/api_storage.go"|"api/api_worker.go"] ["FullNode"|"StorageMiner"|"WorkerAPI"]

With gzip compression: a '-gzip' flag is made available as an optional third argument. Note that position matters.

go run ./api/openrpc/cmd ["api/api_full.go"|"api/api_storage.go"|"api/api_worker.go"] ["FullNode"|"StorageMiner"|"WorkerAPI"] -gzip

*/

func main() {
doc := docgen_openrpc.NewLotusOpenRPCDocument()

switch os.Args[2] {
case "FullNode":
doc.RegisterReceiverName("Filecoin", &apistruct.FullNodeStruct{})
case "StorageMiner":
doc.RegisterReceiverName("Filecoin", &apistruct.StorageMinerStruct{})
case "WorkerAPI":
doc.RegisterReceiverName("Filecoin", &apistruct.WorkerStruct{})
}

out, err := doc.Discover()
if err != nil {
log.Fatalln(err)
}

var jsonOut []byte
var writer io.WriteCloser

// Use os.Args to handle a somewhat hacky flag for the gzip option.
// Could use flags package to handle this more cleanly, but that requires changes elsewhere
// the scope of which just isn't warranted by this one use case which will usually be run
// programmatically anyways.
if len(os.Args) > 3 && os.Args[3] == "-gzip" {
jsonOut, err = json.Marshal(out)
if err != nil {
log.Fatalln(err)
}
writer = gzip.NewWriter(os.Stdout)
} else {
jsonOut, err = json.MarshalIndent(out, "", " ")
if err != nil {
log.Fatalln(err)
}
writer = os.Stdout
}

_, err = writer.Write(jsonOut)
if err != nil {
log.Fatalln(err)
}
err = writer.Close()
if err != nil {
log.Fatalln(err)
}
}
Loading