lpdeal: Make booster- retrievals work

This commit is contained in:
Łukasz Magiera 2024-02-19 18:08:08 +01:00
parent e0f84087ac
commit 648ac7adaf
3 changed files with 53 additions and 3 deletions

View File

@ -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
}

View File

@ -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
}))
}
}
}

View File

@ -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(),