From f8183a712299970529b7d2c402af80217d1ac833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sun, 11 Feb 2024 13:40:25 +0100 Subject: [PATCH] fakelm: deals in SectorStatus --- cmd/lotus-shed/lpdeal.go | 7 ++++- node/modules/storageminer_svc.go | 2 +- provider/lpmarket/fakelm/lmimpl.go | 50 +++++++++++++++++++++++++----- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/cmd/lotus-shed/lpdeal.go b/cmd/lotus-shed/lpdeal.go index bac3f167a..9b46da72a 100644 --- a/cmd/lotus-shed/lpdeal.go +++ b/cmd/lotus-shed/lpdeal.go @@ -380,7 +380,7 @@ var lpBoostProxyCmd = &cli.Command{ return xerrors.Errorf("getting miner info: %w", err) } - lp := fakelm.NewLMRPCProvider(si, maddr, abi.ActorID(mid), mi.SectorSize, pin, db, cctx.String("layers")) + lp := fakelm.NewLMRPCProvider(si, full, maddr, abi.ActorID(mid), mi.SectorSize, pin, db, cctx.String("layers")) laddr, err := net.ResolveTCPAddr("tcp", cctx.String("listen")) if err != nil { @@ -489,6 +489,11 @@ var lpBoostProxyCmd = &cli.Command{ return } + if r.Method != http.MethodGet { + http.Error(w, "bad method", http.StatusMethodNotAllowed) + return + } + fmt.Printf("%s request for piece from %s\n", pieceCid, r.RemoteAddr) pieceInfoLk.Lock() diff --git a/node/modules/storageminer_svc.go b/node/modules/storageminer_svc.go index eace506be..f642c2ed4 100644 --- a/node/modules/storageminer_svc.go +++ b/node/modules/storageminer_svc.go @@ -83,7 +83,7 @@ func connectHarmony(apiInfo string, fapi v1api.FullNode, mctx helpers.MetricsCtx return nil, xerrors.Errorf("getting miner info: %w", err) } - lp := fakelm.NewLMRPCProvider(si, maddr, abi.ActorID(mid), mi.SectorSize, pin, db, parts[1]) + lp := fakelm.NewLMRPCProvider(si, fapi, maddr, abi.ActorID(mid), mi.SectorSize, pin, db, parts[1]) ast := api.StorageMinerStruct{} diff --git a/provider/lpmarket/fakelm/lmimpl.go b/provider/lpmarket/fakelm/lmimpl.go index 65c57d13b..5b84ffa95 100644 --- a/provider/lpmarket/fakelm/lmimpl.go +++ b/provider/lpmarket/fakelm/lmimpl.go @@ -6,6 +6,7 @@ import ( "github.com/BurntSushi/toml" "github.com/filecoin-project/go-jsonrpc/auth" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/harmony/harmonydb" "github.com/filecoin-project/lotus/node/config" "github.com/gbrlsnchs/jwt/v3" @@ -26,7 +27,8 @@ import ( ) type LMRPCProvider struct { - si paths.SectorIndex + si paths.SectorIndex + full api.FullNode maddr address.Address // lotus-miner RPC is single-actor minerID abi.ActorID @@ -38,9 +40,10 @@ type LMRPCProvider struct { confLayer string } -func NewLMRPCProvider(si paths.SectorIndex, maddr address.Address, minerID abi.ActorID, ssize abi.SectorSize, pi lpmarket.Ingester, db *harmonydb.DB, confLayer string) *LMRPCProvider { +func NewLMRPCProvider(si paths.SectorIndex, full api.FullNode, maddr address.Address, minerID abi.ActorID, ssize abi.SectorSize, pi lpmarket.Ingester, db *harmonydb.DB, confLayer string) *LMRPCProvider { return &LMRPCProvider{ si: si, + full: full, maddr: maddr, minerID: minerID, ssize: ssize, @@ -65,14 +68,47 @@ func (l *LMRPCProvider) SectorsStatus(ctx context.Context, sid abi.SectorNumber, return api.SectorInfo{}, err } + var ssip []struct { + PieceCID *string `db:"piece_cid"` + DealID *int64 `db:"f05_deal_id"` + } + + err = l.db.Select(ctx, &ssip, "select ssip.piece_cid, ssip.f05_deal_id from sectors_sdr_pipeline p left join sectors_sdr_initial_pieces ssip on p.sp_id = ssip.sp_id and p.sector_number = ssip.sector_number where p.sp_id = $1 and p.sector_number = $2", l.minerID, sid) + if err != nil { + return api.SectorInfo{}, err + } + + var deals []abi.DealID + if len(ssip) > 0 { + for _, d := range ssip { + if d.DealID != nil { + deals = append(deals, abi.DealID(*d.DealID)) + } + } + } else { + osi, err := l.full.StateSectorGetInfo(ctx, l.maddr, sid, types.EmptyTSK) + if err != nil { + return api.SectorInfo{}, err + } + + if osi != nil { + deals = osi.DealIDs + } + } + if len(si) == 0 { + state := api.SectorState(sealing.UndefinedSectorState) + if len(ssip) > 0 { + state = api.SectorState(sealing.PreCommit1) + } + return api.SectorInfo{ SectorID: sid, - State: api.SectorState(sealing.UndefinedSectorState), + State: state, CommD: nil, CommR: nil, Proof: nil, - Deals: nil, + Deals: deals, Pieces: nil, Ticket: api.SealTicket{}, Seed: api.SealSeed{}, @@ -94,9 +130,9 @@ func (l *LMRPCProvider) SectorsStatus(ctx context.Context, sid abi.SectorNumber, }, nil } - var state api.SectorState = api.SectorState(sealing.Proving) + var state = api.SectorState(sealing.Proving) if !si[0].CanStore { - state = api.SectorState(sealing.PreCommit1) + state = api.SectorState(sealing.PreCommit2) } // todo improve this with on-chain info @@ -106,7 +142,7 @@ func (l *LMRPCProvider) SectorsStatus(ctx context.Context, sid abi.SectorNumber, CommD: nil, CommR: nil, Proof: nil, - Deals: nil, + Deals: deals, Pieces: nil, Ticket: api.SealTicket{}, Seed: api.SealSeed{},