From d01d440c4ad79d209ed48fc63dd5bd547ad29d0f Mon Sep 17 00:00:00 2001 From: Will Scott Date: Wed, 7 Oct 2020 13:36:12 -0700 Subject: [PATCH 1/6] first pass at an in-process lotus lens --- commands/setup.go | 15 ++++++++-- lens/interface.go | 2 ++ lens/lotus/lotus.go | 9 +++--- lens/lotusrepo/repo.go | 63 ++++++++++++++++++++++++++++++++++++++++++ main.go | 5 ++++ 5 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 lens/lotusrepo/repo.go diff --git a/commands/setup.go b/commands/setup.go index d17f6c2e5..c6dfe5601 100644 --- a/commands/setup.go +++ b/commands/setup.go @@ -17,8 +17,8 @@ import ( "golang.org/x/xerrors" lens "github.com/filecoin-project/sentinel-visor/lens" - lotuslens "github.com/filecoin-project/sentinel-visor/lens/lotus" vapi "github.com/filecoin-project/sentinel-visor/lens/lotus" + repoapi "github.com/filecoin-project/sentinel-visor/lens/lotusrepo" "github.com/filecoin-project/sentinel-visor/storage" ) @@ -26,12 +26,21 @@ var log = logging.Logger("visor") type RunContext struct { api lens.API - closer lotuslens.APICloser + closer lens.APICloser db *storage.Database } func setupStorageAndAPI(cctx *cli.Context) (context.Context, *RunContext, error) { - ctx, api, closer, err := vapi.GetFullNodeAPI(cctx) + var ctx context.Context + var api lens.API + var closer lens.APICloser + var err error + + if cctx.String("lens") == "lotus" { + ctx, api, closer, err = vapi.GetFullNodeAPI(cctx) + } else if cctx.String("lens") == "lotusrepo" { + ctx, api, closer, err = repoapi.GetAPI(cctx) + } if err != nil { return nil, nil, xerrors.Errorf("get node api: %w", err) } diff --git a/lens/interface.go b/lens/interface.go index 94e2946da..ddf4325c3 100644 --- a/lens/interface.go +++ b/lens/interface.go @@ -12,3 +12,5 @@ type API interface { api.FullNode ComputeGasOutputs(gasUsed, gasLimit int64, baseFee, feeCap, gasPremium abi.TokenAmount) vm.GasOutputs } + +type APICloser func() diff --git a/lens/lotus/lotus.go b/lens/lotus/lotus.go index ac9994ce2..3439a6fc8 100644 --- a/lens/lotus/lotus.go +++ b/lens/lotus/lotus.go @@ -3,10 +3,11 @@ package lotus import ( "context" "fmt" - "github.com/filecoin-project/sentinel-visor/lens" "net/http" "strings" + "github.com/filecoin-project/sentinel-visor/lens" + logging "github.com/ipfs/go-log/v2" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" @@ -21,9 +22,7 @@ import ( var log = logging.Logger("visor/lens/lotus") -type APICloser jsonrpc.ClientCloser - -func GetFullNodeAPI(cctx *cli.Context) (context.Context, lens.API, APICloser, error) { +func GetFullNodeAPI(cctx *cli.Context) (context.Context, lens.API, lens.APICloser, error) { var api lotus_api.FullNode var closer jsonrpc.ClientCloser var err error @@ -60,7 +59,7 @@ func GetFullNodeAPI(cctx *cli.Context) (context.Context, lens.API, APICloser, er lensAPI := NewAPIWrapper(api, cacheStore) - return ctx, lensAPI, APICloser(closer), nil + return ctx, lensAPI, lens.APICloser(closer), nil } func getFullNodeAPIUsingCredentials(ctx context.Context, listenAddr, token string) (lotus_api.FullNode, jsonrpc.ClientCloser, error) { diff --git a/lens/lotusrepo/repo.go b/lens/lotusrepo/repo.go new file mode 100644 index 000000000..415f7b8f3 --- /dev/null +++ b/lens/lotusrepo/repo.go @@ -0,0 +1,63 @@ +package lotusrepo + +import ( + "context" + "fmt" + + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/sentinel-visor/lens" + "github.com/urfave/cli/v2" + + "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/chain/vm" + "github.com/filecoin-project/lotus/node/" + "github.com/filecoin-project/lotus/node/impl" + "github.com/filecoin-project/lotus/node/repo" + "github.com/filecoin-project/specs-actors/actors/util/adt" + cbor "github.com/ipfs/go-ipld-cbor" +) + +type RepoAPI struct { + api.FullNode + context.Context +} + +func (ra *RepoAPI) ComputeGasOutputs(gasUsed, gasLimit int64, baseFee, feeCap, gasPremium abi.TokenAmount) vm.GasOutputs { + return vm.ComputeGasOutputs(gasUsed, gasLimit, baseFee, feeCap, gasPremium) +} + +func (ra *RepoAPI) Store() adt.Store { + i, ok := ra.FullNode.(*impl.FullNodeAPI) + if !ok { + return nil + } + store := i.ChainAPI.Chain.Blockstore() + cs := cbor.NewCborStore(store) + adtStore := adt.WrapStore(ra.Context, cs) + return adtStore +} + +func GetAPI(c *cli.Context) (context.Context, lens.API, lens.APICloser, error) { + rapi := RepoAPI{} + + r, err := repo.NewFS(c.String("repo")) + if err != nil { + return c.Context, nil, nil, err + } + + options := []node.Option{ + node.FullAPI(&rapi.FullNode), + node.Repo(r), + } + stop, err := node.New(c.Context, options...) + if err != nil { + return c.Context, nil, nil, err + } + + sf := func() { + fmt.Printf("%v", stop(c.Context)) + } + + rapi.Context = c.Context + return c.Context, &rapi, sf, nil +} diff --git a/main.go b/main.go index e53fc4703..767d2d01d 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,11 @@ func main() { Usage: "Filecoin Chain Monitoring Utility", Version: version.String(), Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "lens", + EnvVars: []string{"VISOR_LENS"}, + Value: "lotus", + }, &cli.StringFlag{ Name: "repo", EnvVars: []string{"LOTUS_PATH"}, From 86fb11a964e7bd4baf2c3bf9938a08f3a0768574 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Wed, 7 Oct 2020 15:38:18 -0700 Subject: [PATCH 2/6] fix import --- go.mod | 1 + lens/lotusrepo/repo.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 791606d14..444b2b835 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/go-pg/pgext v0.1.4 github.com/hashicorp/golang-lru v0.5.4 github.com/ipfs/go-cid v0.0.7 + github.com/ipfs/go-ipld-cbor v0.0.5-0.20200428170625-a0bd04d3cbdf github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4 github.com/lib/pq v1.8.0 github.com/mattn/go-isatty v0.0.12 // indirect diff --git a/lens/lotusrepo/repo.go b/lens/lotusrepo/repo.go index 415f7b8f3..1be06963f 100644 --- a/lens/lotusrepo/repo.go +++ b/lens/lotusrepo/repo.go @@ -10,7 +10,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/vm" - "github.com/filecoin-project/lotus/node/" + "github.com/filecoin-project/lotus/node" "github.com/filecoin-project/lotus/node/impl" "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/specs-actors/actors/util/adt" From 996c7a5d50b6d15c411d0eda79960f499a62c257 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Wed, 7 Oct 2020 15:41:44 -0700 Subject: [PATCH 3/6] caching --- lens/lotusrepo/repo.go | 10 +++++++--- main.go | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lens/lotusrepo/repo.go b/lens/lotusrepo/repo.go index 1be06963f..ba65e5f49 100644 --- a/lens/lotusrepo/repo.go +++ b/lens/lotusrepo/repo.go @@ -10,6 +10,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/vm" + "github.com/filecoin-project/lotus/lib/cachebs" "github.com/filecoin-project/lotus/node" "github.com/filecoin-project/lotus/node/impl" "github.com/filecoin-project/lotus/node/repo" @@ -20,6 +21,7 @@ import ( type RepoAPI struct { api.FullNode context.Context + cacheSize int } func (ra *RepoAPI) ComputeGasOutputs(gasUsed, gasLimit int64, baseFee, feeCap, gasPremium abi.TokenAmount) vm.GasOutputs { @@ -32,7 +34,8 @@ func (ra *RepoAPI) Store() adt.Store { return nil } store := i.ChainAPI.Chain.Blockstore() - cs := cbor.NewCborStore(store) + cachedStore := cachebs.NewBufferedBstore(store, ra.cacheSize) + cs := cbor.NewCborStore(cachedStore) adtStore := adt.WrapStore(ra.Context, cs) return adtStore } @@ -42,7 +45,7 @@ func GetAPI(c *cli.Context) (context.Context, lens.API, lens.APICloser, error) { r, err := repo.NewFS(c.String("repo")) if err != nil { - return c.Context, nil, nil, err + return nil, nil, nil, err } options := []node.Option{ @@ -51,7 +54,7 @@ func GetAPI(c *cli.Context) (context.Context, lens.API, lens.APICloser, error) { } stop, err := node.New(c.Context, options...) if err != nil { - return c.Context, nil, nil, err + return nil, nil, nil, err } sf := func() { @@ -59,5 +62,6 @@ func GetAPI(c *cli.Context) (context.Context, lens.API, lens.APICloser, error) { } rapi.Context = c.Context + rapi.cacheSize = c.Int("lens-cache-hint") return c.Context, &rapi, sf, nil } diff --git a/main.go b/main.go index 767d2d01d..6d9ff806c 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,11 @@ func main() { EnvVars: []string{"LOTUS_DB_POOL_SIZE"}, Value: 75, }, + &cli.IntFlag{ + Name: "lens-cache-hint", + EnvVars: []string{"VISOR_LENS_CACHE_HINT"}, + Value: 1024 * 1024, + }, &cli.StringFlag{ Name: "log-level", EnvVars: []string{"GOLOG_LOG_LEVEL"}, From 51e3c8937194a14bb311861420b32c43ac0be6b6 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Mon, 12 Oct 2020 10:02:55 -0700 Subject: [PATCH 4/6] use lighter weight repo path --- go.mod | 7 ++ go.sum | 27 ++++++++ lens/lotusrepo/repo.go | 148 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 169 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index e05e914ae..8f84e9bc9 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,13 @@ go 1.14 require ( contrib.go.opencensus.io/exporter/prometheus v0.1.0 github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect + github.com/cskr/pubsub v1.0.2 github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect github.com/filecoin-project/go-address v0.0.4 github.com/filecoin-project/go-bitfield v0.2.1 + github.com/filecoin-project/go-fil-markets v0.7.0 github.com/filecoin-project/go-jsonrpc v0.1.2-0.20200822201400-474f4fdccc52 + github.com/filecoin-project/go-multistore v0.0.3 github.com/filecoin-project/go-state-types v0.0.0-20200928172055-2df22083d8ab github.com/filecoin-project/lotus v0.9.0 github.com/filecoin-project/specs-actors v0.9.12 @@ -18,9 +21,13 @@ require ( github.com/go-pg/pgext v0.1.4 github.com/hashicorp/golang-lru v0.5.4 github.com/ipfs/go-cid v0.0.7 + github.com/ipfs/go-ipfs-blockstore v1.0.1 github.com/ipfs/go-ipld-cbor v0.0.5-0.20200428170625-a0bd04d3cbdf github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4 github.com/lib/pq v1.8.0 + github.com/libp2p/go-libp2p-core v0.6.1 + github.com/libp2p/go-libp2p-host v0.0.3 + github.com/libp2p/go-libp2p-peer v0.2.0 github.com/mattn/go-isatty v0.0.12 // indirect github.com/multiformats/go-multiaddr v0.3.1 github.com/multiformats/go-multihash v0.0.14 diff --git a/go.sum b/go.sum index 18aaf6961..1d89d5868 100644 --- a/go.sum +++ b/go.sum @@ -158,6 +158,7 @@ github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= @@ -230,12 +231,16 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fatih/color v1.8.0 h1:5bzFgL+oy7JITMTxUPJ00n7VxmYd/PdMp5mHFX40/RY= github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8= github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E= +github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0= github.com/filecoin-project/go-address v0.0.3/go.mod h1:jr8JxKsYx+lQlQZmF5i2U0Z+cGQ59wMIps/8YW/lDj8= github.com/filecoin-project/go-address v0.0.4 h1:gSNMv0qWwH16fGQs7ycOUrDjY6YCSsgLUl0I0KLjo8w= github.com/filecoin-project/go-address v0.0.4/go.mod h1:jr8JxKsYx+lQlQZmF5i2U0Z+cGQ59wMIps/8YW/lDj8= +github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e/go.mod h1:boRtQhzmxNocrMxOXo1NYn4oUc1NGvR8tEa79wApNXg= github.com/filecoin-project/go-amt-ipld/v2 v2.1.0/go.mod h1:nfFPoGyX0CU9SkXX8EoCcSuHN1XcbN0c6KBh7yvP5fs= github.com/filecoin-project/go-amt-ipld/v2 v2.1.1-0.20201006184820-924ee87a1349 h1:pIuR0dnMD0i+as8wNnjjHyQrnhP5O5bmba/lmgQeRgU= github.com/filecoin-project/go-amt-ipld/v2 v2.1.1-0.20201006184820-924ee87a1349/go.mod h1:vgmwKBkx+ca5OIeEvstiQgzAZnb7R6QaqE1oEDSqa6g= +github.com/filecoin-project/go-bitfield v0.0.0-20200416002808-b3ee67ec9060/go.mod h1:iodsLxOFZnqKtjj2zkgqzoGNrv6vUqj69AT/J8DKXEw= +github.com/filecoin-project/go-bitfield v0.1.2/go.mod h1:CNl9WG8hgR5mttCnUErjcQjGvuiZjRqK9rHVBsQF4oM= github.com/filecoin-project/go-bitfield v0.2.0/go.mod h1:CNl9WG8hgR5mttCnUErjcQjGvuiZjRqK9rHVBsQF4oM= github.com/filecoin-project/go-bitfield v0.2.1 h1:S6Uuqcspqu81sWJ0He4OAfFLm1tSwPdVjtKTkl5m/xQ= github.com/filecoin-project/go-bitfield v0.2.1/go.mod h1:CNl9WG8hgR5mttCnUErjcQjGvuiZjRqK9rHVBsQF4oM= @@ -261,6 +266,7 @@ github.com/filecoin-project/go-multistore v0.0.3 h1:vaRBY4YiA2UZFPK57RNuewypB8u0 github.com/filecoin-project/go-multistore v0.0.3/go.mod h1:kaNqCC4IhU4B1uyr7YWFHd23TL4KM32aChS0jNkyUvQ= github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20 h1:+/4aUeUoKr6AKfPE3mBhXA5spIV6UcKdTYDPNU2Tdmg= github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20/go.mod h1:mPn+LRRd5gEKNAtc+r3ScpW2JRU/pj4NBKdADYWHiak= +github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663/go.mod h1:fZzmf4tftbwf9S37XRifoJlz7nCjRdIrMGLR07dKLCc= github.com/filecoin-project/go-paramfetch v0.0.2-0.20200701152213-3e0f0afdc261 h1:A256QonvzRaknIIAuWhe/M2dpV2otzs3NBhi5TWa/UA= github.com/filecoin-project/go-paramfetch v0.0.2-0.20200701152213-3e0f0afdc261/go.mod h1:fZzmf4tftbwf9S37XRifoJlz7nCjRdIrMGLR07dKLCc= github.com/filecoin-project/go-state-types v0.0.0-20200903145444-247639ffa6ad/go.mod h1:IQ0MBPnonv35CJHtWSN3YY1Hz2gkPru1Q9qoaYLxx9I= @@ -277,12 +283,17 @@ github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b/go.mod h1:Q0GQOBtKf1oE10eSXSlhN45kDBdGvEcVOqMiffqX+N8= github.com/filecoin-project/lotus v0.9.0 h1:AWgKRtYJP5uQTycQQqdy0dsuoinABBxuX2wKKiQFvYA= github.com/filecoin-project/lotus v0.9.0/go.mod h1:8Qg5wmvHgCvxq2gCq9iziPlcNHl58dtzozf4StZ68Kk= +github.com/filecoin-project/sector-storage v0.0.0-20200810171746-eac70842d8e0 h1:E1fZ27fhKK05bhZItfTwqr1i05vXnEZJznQFEYwEEUU= +github.com/filecoin-project/sector-storage v0.0.0-20200810171746-eac70842d8e0/go.mod h1:oOawOl9Yk+qeytLzzIryjI8iRbqo+qzS6EEeElP4PWA= +github.com/filecoin-project/specs-actors v0.3.0/go.mod h1:nQYnFbQ7Y0bHZyq6HDEuVlCPR+U3z5Q3wMOQ+2aiV+Y= +github.com/filecoin-project/specs-actors v0.8.2/go.mod h1:Q3ACV5kBLvqPaYbthc/J1lGMJ5OwogmD9pzdtPRMdCw= github.com/filecoin-project/specs-actors v0.9.4/go.mod h1:BStZQzx5x7TmCkLv0Bpa07U6cPKol6fd3w9KjMPZ6Z4= github.com/filecoin-project/specs-actors v0.9.7/go.mod h1:wM2z+kwqYgXn5Z7scV1YHLyd1Q1cy0R8HfTIWQ0BFGU= github.com/filecoin-project/specs-actors v0.9.12 h1:iIvk58tuMtmloFNHhAOQHG+4Gci6Lui0n7DYQGi3cJk= github.com/filecoin-project/specs-actors v0.9.12/go.mod h1:TS1AW/7LbG+615j4NsjMK1qlpAwaFsG9w0V2tg2gSao= github.com/filecoin-project/specs-actors/v2 v2.0.1 h1:bf08x6tqCDfClzrv2q/rmt/A/UbBOy1KgaoogQEcLhU= github.com/filecoin-project/specs-actors/v2 v2.0.1/go.mod h1:v2NZVYinNIKA9acEMBm5wWXxqv5+frFEbekBFemYghY= +github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k= github.com/filecoin-project/specs-storage v0.1.1-0.20200907031224-ed2e5cd13796 h1:dJsTPWpG2pcTeojO2pyn0c6l+x/3MZYCBgo/9d11JEk= github.com/filecoin-project/specs-storage v0.1.1-0.20200907031224-ed2e5cd13796/go.mod h1:nJRRM7Aa9XVvygr3W9k6xGF46RWzr2zxF/iGoAIfA/g= github.com/filecoin-project/test-vectors/schema v0.0.3/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E= @@ -559,6 +570,7 @@ github.com/ipfs/go-fs-lock v0.0.6/go.mod h1:OTR+Rj9sHiRubJh3dRhD15Juhd/+w6VPOY28 github.com/ipfs/go-graphsync v0.1.0/go.mod h1:jMXfqIEDFukLPZHqDPp8tJMbHO9Rmeb9CEGevngQbmE= github.com/ipfs/go-graphsync v0.2.1 h1:MdehhqBSuTI2LARfKLkpYnt0mUrqHs/mtuDnESXHBfU= github.com/ipfs/go-graphsync v0.2.1/go.mod h1:gEBvJUNelzMkaRPJTpg/jaKN4AQW/7wDWu0K92D8o10= +github.com/ipfs/go-hamt-ipld v0.0.15-0.20200131012125-dd88a59d3f2e/go.mod h1:9aQJu/i/TaRDW6jqB5U217dLIDopn50wxLdHXM2CTfE= github.com/ipfs/go-hamt-ipld v0.1.1/go.mod h1:1EZCr2v0jlCnhpa+aZ0JZYp8Tt2w16+JJOAVz17YcDk= github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08= github.com/ipfs/go-ipfs-blockstore v0.1.0/go.mod h1:5aD0AvHPi7mZc6Ci1WCAhiBQu2IsfTduLl+422H6Rqw= @@ -589,6 +601,7 @@ github.com/ipfs/go-ipfs-exchange-offline v0.0.1/go.mod h1:WhHSFCVYX36H/anEKQboAz github.com/ipfs/go-ipfs-files v0.0.2/go.mod h1:INEFm0LL2LWXBhNJ2PMIIb2w45hpXgPjNoE7yA8Y1d4= github.com/ipfs/go-ipfs-files v0.0.3/go.mod h1:INEFm0LL2LWXBhNJ2PMIIb2w45hpXgPjNoE7yA8Y1d4= github.com/ipfs/go-ipfs-files v0.0.4/go.mod h1:INEFm0LL2LWXBhNJ2PMIIb2w45hpXgPjNoE7yA8Y1d4= +github.com/ipfs/go-ipfs-files v0.0.7/go.mod h1:wiN/jSG8FKyk7N0WyctKSvq3ljIa2NNTiZB55kpTdOs= github.com/ipfs/go-ipfs-files v0.0.8 h1:8o0oFJkJ8UkO/ABl8T6ac6tKF3+NIpj67aAB6ZpusRg= github.com/ipfs/go-ipfs-files v0.0.8/go.mod h1:wiN/jSG8FKyk7N0WyctKSvq3ljIa2NNTiZB55kpTdOs= github.com/ipfs/go-ipfs-flags v0.0.1/go.mod h1:RnXBb9WV53GSfTrSDVK61NLTFKvWc60n+K9EgCDh+rA= @@ -839,6 +852,7 @@ github.com/libp2p/go-libp2p-core v0.6.1 h1:XS+Goh+QegCDojUZp00CaPMfiEADCrLjNZskW github.com/libp2p/go-libp2p-core v0.6.1/go.mod h1:FfewUH/YpvWbEB+ZY9AQRQ4TAD8sJBt/G1rVvhz5XT8= github.com/libp2p/go-libp2p-crypto v0.0.1/go.mod h1:yJkNyDmO341d5wwXxDUGO0LykUVT72ImHNUqh5D/dBE= github.com/libp2p/go-libp2p-crypto v0.0.2/go.mod h1:eETI5OUfBnvARGOHrJz2eWNyTUxEGZnBxMcbUjfIj4I= +github.com/libp2p/go-libp2p-crypto v0.1.0 h1:k9MFy+o2zGDNGsaoZl0MA3iZ75qXxr9OOoAZF+sD5OQ= github.com/libp2p/go-libp2p-crypto v0.1.0/go.mod h1:sPUokVISZiy+nNuTTH/TY+leRSxnFj/2GLjtOTW90hI= github.com/libp2p/go-libp2p-daemon v0.2.2/go.mod h1:kyrpsLB2JeNYR2rvXSVWyY0iZuRIMhqzWR3im9BV6NQ= github.com/libp2p/go-libp2p-discovery v0.0.1/go.mod h1:ZkkF9xIFRLA1xCc7bstYFkd80gBGK8Fc1JqGoU2i+zI= @@ -850,9 +864,11 @@ github.com/libp2p/go-libp2p-discovery v0.4.0/go.mod h1:bZ0aJSrFc/eX2llP0ryhb1kpg github.com/libp2p/go-libp2p-discovery v0.5.0 h1:Qfl+e5+lfDgwdrXdu4YNCWyEo3fWuP+WgN9mN0iWviQ= github.com/libp2p/go-libp2p-discovery v0.5.0/go.mod h1:+srtPIU9gDaBNu//UHvcdliKBIcr4SfDcm0/PfPJLug= github.com/libp2p/go-libp2p-host v0.0.1/go.mod h1:qWd+H1yuU0m5CwzAkvbSjqKairayEHdR5MMl7Cwa7Go= +github.com/libp2p/go-libp2p-host v0.0.3 h1:BB/1Z+4X0rjKP5lbQTmjEjLbDVbrcmLOlA6QDsN5/j4= github.com/libp2p/go-libp2p-host v0.0.3/go.mod h1:Y/qPyA6C8j2coYyos1dfRm0I8+nvd4TGrDGt4tA7JR8= github.com/libp2p/go-libp2p-interface-connmgr v0.0.1/go.mod h1:GarlRLH0LdeWcLnYM/SaBykKFl9U5JFnbBGruAk/D5k= github.com/libp2p/go-libp2p-interface-connmgr v0.0.4/go.mod h1:GarlRLH0LdeWcLnYM/SaBykKFl9U5JFnbBGruAk/D5k= +github.com/libp2p/go-libp2p-interface-connmgr v0.0.5 h1:KG/KNYL2tYzXAfMvQN5K1aAGTYSYUMJ1prgYa2/JI1E= github.com/libp2p/go-libp2p-interface-connmgr v0.0.5/go.mod h1:GarlRLH0LdeWcLnYM/SaBykKFl9U5JFnbBGruAk/D5k= github.com/libp2p/go-libp2p-interface-pnet v0.0.1/go.mod h1:el9jHpQAXK5dnTpKA4yfCNBZXvrzdOU75zz+C6ryp3k= github.com/libp2p/go-libp2p-kad-dht v0.2.1/go.mod h1:k7ONOlup7HKzQ68dE6lSnp07cdxdkmnRa+6B4Fh9/w0= @@ -878,6 +894,7 @@ github.com/libp2p/go-libp2p-nat v0.0.5/go.mod h1:1qubaE5bTZMJE+E/uu2URroMbzdubFz github.com/libp2p/go-libp2p-nat v0.0.6 h1:wMWis3kYynCbHoyKLPBEMu4YRLltbm8Mk08HGSfvTkU= github.com/libp2p/go-libp2p-nat v0.0.6/go.mod h1:iV59LVhB3IkFvS6S6sauVTSOrNEANnINbI/fkaLimiw= github.com/libp2p/go-libp2p-net v0.0.1/go.mod h1:Yt3zgmlsHOgUWSXmt5V/Jpz9upuJBE8EgNU9DrCcR8c= +github.com/libp2p/go-libp2p-net v0.0.2 h1:qP06u4TYXfl7uW/hzqPhlVVTSA2nw1B/bHBJaUnbh6M= github.com/libp2p/go-libp2p-net v0.0.2/go.mod h1:Yt3zgmlsHOgUWSXmt5V/Jpz9upuJBE8EgNU9DrCcR8c= github.com/libp2p/go-libp2p-netutil v0.0.1/go.mod h1:GdusFvujWZI9Vt0X5BKqwWWmZFxecf9Gt03cKxm2f/Q= github.com/libp2p/go-libp2p-netutil v0.1.0 h1:zscYDNVEcGxyUpMd0JReUZTrpMfia8PmLKcKF72EAMQ= @@ -886,6 +903,7 @@ github.com/libp2p/go-libp2p-noise v0.1.1 h1:vqYQWvnIcHpIoWJKC7Al4D6Hgj0H012TuXRh github.com/libp2p/go-libp2p-noise v0.1.1/go.mod h1:QDFLdKX7nluB7DEnlVPbz7xlLHdwHFA9HiohJRr3vwM= github.com/libp2p/go-libp2p-peer v0.0.1/go.mod h1:nXQvOBbwVqoP+T5Y5nCjeH4sP9IX/J0AMzcDUVruVoo= github.com/libp2p/go-libp2p-peer v0.1.1/go.mod h1:jkF12jGB4Gk/IOo+yomm+7oLWxF278F7UnrYUQ1Q8es= +github.com/libp2p/go-libp2p-peer v0.2.0 h1:EQ8kMjaCUwt/Y5uLgjT8iY2qg0mGUT0N1zUjer50DsY= github.com/libp2p/go-libp2p-peer v0.2.0/go.mod h1:RCffaCvUyW2CJmG2gAWVqwePwW7JMgxjsHm7+J5kjWY= github.com/libp2p/go-libp2p-peerstore v0.0.1/go.mod h1:RabLyPVJLuNQ+GFyoEkfi8H4Ti6k/HtZJ7YKgtSq+20= github.com/libp2p/go-libp2p-peerstore v0.0.6/go.mod h1:RabLyPVJLuNQ+GFyoEkfi8H4Ti6k/HtZJ7YKgtSq+20= @@ -902,6 +920,7 @@ github.com/libp2p/go-libp2p-peerstore v0.2.6/go.mod h1:ss/TWTgHZTMpsU/oKVVPQCGuD github.com/libp2p/go-libp2p-pnet v0.2.0 h1:J6htxttBipJujEjz1y0a5+eYoiPcFHhSYHH6na5f0/k= github.com/libp2p/go-libp2p-pnet v0.2.0/go.mod h1:Qqvq6JH/oMZGwqs3N1Fqhv8NVhrdYcO0BW4wssv21LA= github.com/libp2p/go-libp2p-protocol v0.0.1/go.mod h1:Af9n4PiruirSDjHycM1QuiMi/1VZNHYcK8cLgFJLZ4s= +github.com/libp2p/go-libp2p-protocol v0.1.0 h1:HdqhEyhg0ToCaxgMhnOmUO8snQtt/kQlcjVk3UoJU3c= github.com/libp2p/go-libp2p-protocol v0.1.0/go.mod h1:KQPHpAabB57XQxGrXCNvbL6UEXfQqUgC/1adR2Xtflk= github.com/libp2p/go-libp2p-pubsub v0.1.1/go.mod h1:ZwlKzRSe1eGvSIdU5bD7+8RZN/Uzw0t1Bp9R1znpR/Q= github.com/libp2p/go-libp2p-pubsub v0.3.2-0.20200527132641-c0712c6e92cf/go.mod h1:TxPOBuo1FPdsTjFnv+FGZbNbWYsp74Culx+4ViQpato= @@ -1008,6 +1027,7 @@ github.com/libp2p/go-sockaddr v0.0.2/go.mod h1:syPvOmNs24S3dFVGJA1/mrqdeijPxLV2L github.com/libp2p/go-sockaddr v0.1.0 h1:Y4s3/jNoryVRKEBrkJ576F17CPOaMIzUeCsg7dlTDj0= github.com/libp2p/go-sockaddr v0.1.0/go.mod h1:syPvOmNs24S3dFVGJA1/mrqdeijPxLV2Le3BRLKd68k= github.com/libp2p/go-stream-muxer v0.0.1/go.mod h1:bAo8x7YkSpadMTbtTaxGVHWUQsR/l5MEaHbKaliuT14= +github.com/libp2p/go-stream-muxer v0.1.0 h1:3ToDXUzx8pDC6RfuOzGsUYP5roMDthbUKRdMRRhqAqY= github.com/libp2p/go-stream-muxer v0.1.0/go.mod h1:8JAVsjeRBCWwPoZeH0W1imLOcriqXJyFvB0mR4A04sQ= github.com/libp2p/go-stream-muxer-multistream v0.1.1/go.mod h1:zmGdfkQ1AzOECIAcccoL8L//laqawOsO03zX8Sa+eGw= github.com/libp2p/go-stream-muxer-multistream v0.2.0/go.mod h1:j9eyPol/LLRqT+GPLSxvimPhNph4sfYfMoDPd7HkzIc= @@ -1068,6 +1088,7 @@ github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= @@ -1296,6 +1317,7 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI= github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= +github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -1402,6 +1424,7 @@ github.com/uber/jaeger-lib v2.2.0+incompatible h1:MxZXOiR2JuoANZ3J6DE/U0kSFv/eJ/ github.com/uber/jaeger-lib v2.2.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.0.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= @@ -1561,6 +1584,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200317142112-1b76d66859c6/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -1715,6 +1739,7 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190902133755-9109b7679e13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1739,6 +1764,7 @@ golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1812,6 +1838,7 @@ golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200318150045-ba25ddc85566/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= diff --git a/lens/lotusrepo/repo.go b/lens/lotusrepo/repo.go index ba65e5f49..b7a8cd14c 100644 --- a/lens/lotusrepo/repo.go +++ b/lens/lotusrepo/repo.go @@ -3,23 +3,34 @@ package lotusrepo import ( "context" "fmt" + "io" + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-fil-markets/storagemarket" + "github.com/filecoin-project/go-multistore" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/sentinel-visor/lens" + peer "github.com/libp2p/go-libp2p-peer" "github.com/urfave/cli/v2" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/vm" + "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/lotus/lib/cachebs" - "github.com/filecoin-project/lotus/node" + "github.com/filecoin-project/lotus/lib/ulimit" + marketevents "github.com/filecoin-project/lotus/markets/loggers" "github.com/filecoin-project/lotus/node/impl" "github.com/filecoin-project/lotus/node/repo" + "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/filecoin-project/specs-actors/actors/util/adt" + "github.com/ipfs/go-cid" + blockstore "github.com/ipfs/go-ipfs-blockstore" cbor "github.com/ipfs/go-ipld-cbor" ) type RepoAPI struct { - api.FullNode + impl.FullNodeAPI context.Context cacheSize int } @@ -29,17 +40,82 @@ func (ra *RepoAPI) ComputeGasOutputs(gasUsed, gasLimit int64, baseFee, feeCap, g } func (ra *RepoAPI) Store() adt.Store { - i, ok := ra.FullNode.(*impl.FullNodeAPI) - if !ok { - return nil - } - store := i.ChainAPI.Chain.Blockstore() - cachedStore := cachebs.NewBufferedBstore(store, ra.cacheSize) + bs := ra.FullNodeAPI.ChainAPI.Chain.Blockstore() + cachedStore := cachebs.NewBufferedBstore(bs, ra.cacheSize) cs := cbor.NewCborStore(cachedStore) adtStore := adt.WrapStore(ra.Context, cs) return adtStore } +func (ra *RepoAPI) ClientStartDeal(ctx context.Context, params *api.StartDealParams) (*cid.Cid, error) { + return nil, fmt.Errorf("unsupported") +} + +func (ra *RepoAPI) ClientListDeals(ctx context.Context) ([]api.DealInfo, error) { + return nil, fmt.Errorf("unsupported") +} + +func (ra *RepoAPI) ClientGetDealInfo(ctx context.Context, d cid.Cid) (*api.DealInfo, error) { + return nil, fmt.Errorf("unsupported") +} + +func (ra *RepoAPI) ClientGetDealUpdates(ctx context.Context) (<-chan api.DealInfo, error) { + return nil, fmt.Errorf("unsupported") +} + +func (ra *RepoAPI) ClientHasLocal(ctx context.Context, root cid.Cid) (bool, error) { + return false, fmt.Errorf("unsupported") +} + +func (ra *RepoAPI) ClientFindData(ctx context.Context, root cid.Cid, piece *cid.Cid) ([]api.QueryOffer, error) { + return nil, fmt.Errorf("unsupported") +} + +func (ra *RepoAPI) ClientMinerQueryOffer(ctx context.Context, miner address.Address, root cid.Cid, piece *cid.Cid) (api.QueryOffer, error) { + return api.QueryOffer{}, fmt.Errorf("unsupported") +} + +func (ra *RepoAPI) ClientImport(ctx context.Context, ref api.FileRef) (*api.ImportRes, error) { + return nil, fmt.Errorf("unsupported") +} + +func (ra *RepoAPI) ClientRemoveImport(ctx context.Context, importID multistore.StoreID) error { + return fmt.Errorf("unsupported") +} +func (ra *RepoAPI) ClientImportLocal(ctx context.Context, f io.Reader) (cid.Cid, error) { + return cid.Undef, fmt.Errorf("unsupported") +} +func (ra *RepoAPI) ClientListImports(ctx context.Context) ([]api.Import, error) { + return nil, fmt.Errorf("unsupported") +} +func (ra *RepoAPI) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, ref *api.FileRef) error { + return fmt.Errorf("unsupported") +} +func (ra *RepoAPI) ClientRetrieveWithEvents(ctx context.Context, order api.RetrievalOrder, ref *api.FileRef) (<-chan marketevents.RetrievalEvent, error) { + return nil, fmt.Errorf("unsupported") +} +func (ra *RepoAPI) ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.StorageAsk, error) { + return nil, fmt.Errorf("unsupported") +} +func (ra *RepoAPI) ClientCalcCommP(ctx context.Context, inpath string) (*api.CommPRet, error) { + return nil, fmt.Errorf("unsupported") +} +func (ra *RepoAPI) ClientDealSize(ctx context.Context, root cid.Cid) (api.DataSize, error) { + return api.DataSize{}, fmt.Errorf("unsupported") +} +func (ra *RepoAPI) ClientGenCar(ctx context.Context, ref api.FileRef, outputPath string) error { + return fmt.Errorf("unsupported") +} +func (ra *RepoAPI) ClientListDataTransfers(ctx context.Context) ([]api.DataTransferChannel, error) { + return nil, fmt.Errorf("unsupported") +} +func (ra *RepoAPI) ClientDataTransferUpdates(ctx context.Context) (<-chan api.DataTransferChannel, error) { + return nil, fmt.Errorf("unsupported") +} +func (ra *RepoAPI) ClientRetrieveTryRestartInsufficientFunds(ctx context.Context, paymentChannel address.Address) error { + return fmt.Errorf("unsupported") +} + func GetAPI(c *cli.Context) (context.Context, lens.API, lens.APICloser, error) { rapi := RepoAPI{} @@ -48,20 +124,66 @@ func GetAPI(c *cli.Context) (context.Context, lens.API, lens.APICloser, error) { return nil, nil, nil, err } - options := []node.Option{ - node.FullAPI(&rapi.FullNode), - node.Repo(r), + exists, err := r.Exists() + if err != nil { + return nil, nil, nil, err + } + if !exists { + return nil, nil, nil, fmt.Errorf("lotus repo doesn't exist") } - stop, err := node.New(c.Context, options...) + + lr, err := r.Lock(repo.FullNode) if err != nil { return nil, nil, nil, err } + ds, err := lr.Datastore("/chain") + if err != nil { + return nil, nil, nil, err + } + + mds, err := lr.Datastore("/metadata") + if err != nil { + return nil, nil, nil, err + } + + if _, _, err := ulimit.ManageFdLimit(); err != nil { + return nil, nil, nil, fmt.Errorf("setting file descriptor limit: %s", err) + } + + cs := store.NewChainStore(blockstore.NewBlockstore(ds), mds, vm.Syscalls(&fakeVerifier{})) + if err := cs.Load(); err != nil { + return nil, nil, nil, err + } + + rapi.FullNodeAPI.ChainAPI.Chain = cs + sf := func() { - fmt.Printf("%v", stop(c.Context)) + lr.Close() } rapi.Context = c.Context rapi.cacheSize = c.Int("lens-cache-hint") return c.Context, &rapi, sf, nil } + +// From https://github.com/ribasushi/ltsh/blob/5b0211033020570217b0ae37b50ee304566ac218/cmd/lotus-shed/deallifecycles.go#L41-L171 +type fakeVerifier struct{} + +var _ ffiwrapper.Verifier = (*fakeVerifier)(nil) + +func (m fakeVerifier) VerifySeal(svi proof.SealVerifyInfo) (bool, error) { + return true, nil +} + +func (m fakeVerifier) VerifyWinningPoSt(ctx context.Context, info proof.WinningPoStVerifyInfo) (bool, error) { + return true, nil +} + +func (m fakeVerifier) VerifyWindowPoSt(ctx context.Context, info proof.WindowPoStVerifyInfo) (bool, error) { + return true, nil +} + +func (m fakeVerifier) GenerateWinningPoStSectorChallenge(ctx context.Context, proof abi.RegisteredPoStProof, id abi.ActorID, randomness abi.PoStRandomness, u uint64) ([]uint64, error) { + panic("GenerateWinningPoStSectorChallenge not supported") +} From 98e63100538aac7155f7fb5c184328e67de7f727 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Mon, 12 Oct 2020 10:19:28 -0700 Subject: [PATCH 5/6] ulimit earlier --- lens/lotusrepo/repo.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lens/lotusrepo/repo.go b/lens/lotusrepo/repo.go index b7a8cd14c..5821063ce 100644 --- a/lens/lotusrepo/repo.go +++ b/lens/lotusrepo/repo.go @@ -119,6 +119,10 @@ func (ra *RepoAPI) ClientRetrieveTryRestartInsufficientFunds(ctx context.Context func GetAPI(c *cli.Context) (context.Context, lens.API, lens.APICloser, error) { rapi := RepoAPI{} + if _, _, err := ulimit.ManageFdLimit(); err != nil { + return nil, nil, nil, fmt.Errorf("setting file descriptor limit: %s", err) + } + r, err := repo.NewFS(c.String("repo")) if err != nil { return nil, nil, nil, err @@ -147,10 +151,6 @@ func GetAPI(c *cli.Context) (context.Context, lens.API, lens.APICloser, error) { return nil, nil, nil, err } - if _, _, err := ulimit.ManageFdLimit(); err != nil { - return nil, nil, nil, fmt.Errorf("setting file descriptor limit: %s", err) - } - cs := store.NewChainStore(blockstore.NewBlockstore(ds), mds, vm.Syscalls(&fakeVerifier{})) if err := cs.Load(); err != nil { return nil, nil, nil, err From 2023d690c01257ec1457903eb1975065aa60a76f Mon Sep 17 00:00:00 2001 From: Will Scott Date: Mon, 12 Oct 2020 10:34:54 -0700 Subject: [PATCH 6/6] populate both chain and state modules of API --- lens/lotusrepo/repo.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lens/lotusrepo/repo.go b/lens/lotusrepo/repo.go index 5821063ce..67376a803 100644 --- a/lens/lotusrepo/repo.go +++ b/lens/lotusrepo/repo.go @@ -14,6 +14,7 @@ import ( "github.com/urfave/cli/v2" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/vm" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" @@ -156,7 +157,11 @@ func GetAPI(c *cli.Context) (context.Context, lens.API, lens.APICloser, error) { return nil, nil, nil, err } + sm := stmgr.NewStateManager(cs) + rapi.FullNodeAPI.ChainAPI.Chain = cs + rapi.FullNodeAPI.StateAPI.Chain = cs + rapi.FullNodeAPI.StateAPI.StateManager = sm sf := func() { lr.Close()