From 648ac7adaf5daf046682147715b28c8d95111d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 19 Feb 2024 18:08:08 +0100 Subject: [PATCH] lpdeal: Make booster- retrievals work --- cmd/lotus-shed/lpdeal.go | 5 +++- metrics/proxy/proxy.go | 40 ++++++++++++++++++++++++++++++ provider/lpmarket/fakelm/lmimpl.go | 11 ++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/cmd/lotus-shed/lpdeal.go b/cmd/lotus-shed/lpdeal.go index 43d23f597..6fc843069 100644 --- a/cmd/lotus-shed/lpdeal.go +++ b/cmd/lotus-shed/lpdeal.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "github.com/filecoin-project/lotus/metrics/proxy" "io" "net" "net/http" @@ -535,7 +536,9 @@ var lpBoostProxyCmd = &cli.Command{ color.Green("%s served %.3f MiB in %s (%.2f MiB/s)", pieceCid, float64(n)/(1024*1024), took, mbps) } - mh, err := node.MinerHandler(&ast, false) // todo permissioned + finalApi := proxy.LoggingAPI[api.StorageMiner, api.StorageMinerStruct](&ast) + + mh, err := node.MinerHandler(finalApi, false) // todo permissioned if err != nil { return err } diff --git a/metrics/proxy/proxy.go b/metrics/proxy/proxy.go index 6885adfe9..1f0bd9672 100644 --- a/metrics/proxy/proxy.go +++ b/metrics/proxy/proxy.go @@ -2,8 +2,10 @@ package proxy import ( "context" + "fmt" "reflect" + logging "github.com/ipfs/go-log/v2" "go.opencensus.io/tag" "github.com/filecoin-project/lotus/api" @@ -69,3 +71,41 @@ func proxy(in interface{}, outstr interface{}) { } } } + +var log = logging.Logger("api_proxy") + +func LoggingAPI[T, P any](a T) *P { + var out P + logProxy(a, &out) + return &out +} + +func logProxy(in interface{}, outstr interface{}) { + outs := api.GetInternalStructs(outstr) + for _, out := range outs { + rint := reflect.ValueOf(out).Elem() + ra := reflect.ValueOf(in) + + for f := 0; f < rint.NumField(); f++ { + field := rint.Type().Field(f) + fn := ra.MethodByName(field.Name) + + rint.Field(f).Set(reflect.MakeFunc(field.Type, func(args []reflect.Value) (results []reflect.Value) { + var wargs []interface{} + wargs = append(wargs, "method", field.Name) + + for i := 1; i < len(args); i++ { + wargs = append(wargs, fmt.Sprintf("arg%d", i), args[i].Interface()) + } + + res := fn.Call(args) + for i, r := range res { + wargs = append(wargs, fmt.Sprintf("ret%d", i), r.Interface()) + } + + log.Debugw("APICALL", wargs...) + return res + })) + } + } +} diff --git a/provider/lpmarket/fakelm/lmimpl.go b/provider/lpmarket/fakelm/lmimpl.go index 980f1eeab..377a6225f 100644 --- a/provider/lpmarket/fakelm/lmimpl.go +++ b/provider/lpmarket/fakelm/lmimpl.go @@ -3,6 +3,8 @@ package fakelm import ( "context" "encoding/base64" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "net/http" "net/url" @@ -96,6 +98,11 @@ func (l *LMRPCProvider) SectorsStatus(ctx context.Context, sid abi.SectorNumber, } } + spt, err := miner.SealProofTypeFromSectorSize(l.ssize, network.Version20, false) // good enough, just need this for ssize anyways + if err != nil { + return api.SectorInfo{}, err + } + if len(si) == 0 { state := api.SectorState(sealing.UndefinedSectorState) if len(ssip) > 0 { @@ -119,7 +126,7 @@ func (l *LMRPCProvider) SectorsStatus(ctx context.Context, sid abi.SectorNumber, ReplicaUpdateMessage: nil, LastErr: "", Log: nil, - SealProof: 0, + SealProof: spt, Activation: 0, Expiration: 0, DealWeight: big.Zero(), @@ -154,7 +161,7 @@ func (l *LMRPCProvider) SectorsStatus(ctx context.Context, sid abi.SectorNumber, LastErr: "", Log: nil, - SealProof: 0, + SealProof: spt, Activation: 0, Expiration: 0, DealWeight: big.Zero(),