Skip to content

Commit

Permalink
feat: curio: sectors UI (#11869)
Browse files Browse the repository at this point in the history
* cfg edit 1

* jsonschema deps

* feat: lp mig - first few steps

* lp mig: default tasks

* code comments

* docs

* lp-mig-progress

* shared

* comments and todos

* fix: curio: rename lotus-provider to curio (#11645)

* rename provider to curio

* install gotext

* fix lint errors, mod tidy

* fix typo

* fix API_INFO and add gotext to circleCI

* add back gotext

* add gotext after remerge

* lp: channels doc

* finish easy-migration TODOs

* out generate

* merging and more renames

* avoid make-all

* minor doc stuff

* cu: make gen

* make gen fix

* make gen

* tryfix

* go mod tidy

* minor ez migration fixes

* ez setup - ui cleanups

* better error message

* guided setup colors

* better path to saveconfigtolayer

* loadconfigwithupgrades fix

* readMiner oops

* guided - homedir

* err if miner is running

* prompt error should exit

* process already running, miner_id sectors in migration

* dont prompt for language a second time

* check miner stopped

* unlock repo

* render and sql oops

* curio easyMig - some fixes

* easyMigration runs successfully

* lint

* part 2 of last

* message

* merge addtl

* fixing guided setup for myself

* warn-on-no-post

* EditorLoads

* cleanups and styles

* create info

* fix tests

* make gen

* sector early bird

* sectors v2

* sector termination v1

* terminate2

* mjs

* minor things

* flag bad sectors

* fix errors

* add dealweight and deals

* change column width

* refactor sql, handle sealing sectors

* fix estimates

---------

Co-authored-by: LexLuthr <88259624+LexLuthr@users.noreply.github.com>
Co-authored-by: LexLuthr <lexluthr@protocol.ai>
Co-authored-by: LexLuthr <lexluthr@curiostorage.org>
  • Loading branch information
4 people authored Apr 18, 2024
1 parent edd9c82 commit 6b3e9b1
Show file tree
Hide file tree
Showing 8 changed files with 608 additions and 52 deletions.
122 changes: 74 additions & 48 deletions cli/spcli/sectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package spcli

import (
"bufio"
"context"
"encoding/csv"
"encoding/json"
"errors"
Expand All @@ -16,6 +17,7 @@ import (

"github.com/fatih/color"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/samber/lo"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"

Expand Down Expand Up @@ -1353,44 +1355,20 @@ func TerminateSectorCmd(getActorAddress ActorAddressGetter) *cli.Command {
}
}

mi, err := nodeApi.StateMinerInfo(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}

terminationDeclarationParams := []miner2.TerminationDeclaration{}

for _, sn := range cctx.Args().Slice() {
sectorNum, err := strconv.ParseUint(sn, 10, 64)
var outerErr error
sectorNumbers := lo.Map(cctx.Args().Slice(), func(sn string, _ int) int {
sectorNum, err := strconv.Atoi(sn)
if err != nil {
return fmt.Errorf("could not parse sector number: %w", err)
outerErr = fmt.Errorf("could not parse sector number: %w", err)
return 0
}

sectorbit := bitfield.New()
sectorbit.Set(sectorNum)

loca, err := nodeApi.StateSectorPartition(ctx, maddr, abi.SectorNumber(sectorNum), types.EmptyTSK)
if err != nil {
return fmt.Errorf("get state sector partition %s", err)
}

para := miner2.TerminationDeclaration{
Deadline: loca.Deadline,
Partition: loca.Partition,
Sectors: sectorbit,
}

terminationDeclarationParams = append(terminationDeclarationParams, para)
}

terminateSectorParams := &miner2.TerminateSectorsParams{
Terminations: terminationDeclarationParams,
return sectorNum
})
if outerErr != nil {
return outerErr
}

sp, err := actors.SerializeParams(terminateSectorParams)
if err != nil {
return xerrors.Errorf("serializing params: %w", err)
}
confidence := uint64(cctx.Int("confidence"))

var fromAddr address.Address
if from := cctx.String("from"); from != "" {
Expand All @@ -1400,33 +1378,81 @@ func TerminateSectorCmd(getActorAddress ActorAddressGetter) *cli.Command {
return fmt.Errorf("parsing address %s: %w", from, err)
}
} else {
mi, err := nodeApi.StateMinerInfo(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}

fromAddr = mi.Worker
}

smsg, err := nodeApi.MpoolPushMessage(ctx, &types.Message{
From: fromAddr,
To: maddr,
Method: builtin.MethodsMiner.TerminateSectors,

Value: big.Zero(),
Params: sp,
}, nil)
smsg, err := TerminateSectors(ctx, nodeApi, maddr, sectorNumbers, fromAddr)
if err != nil {
return xerrors.Errorf("mpool push message: %w", err)
return err
}

fmt.Println("sent termination message:", smsg.Cid())

wait, err := nodeApi.StateWaitMsg(ctx, smsg.Cid(), uint64(cctx.Int("confidence")))
wait, err := nodeApi.StateWaitMsg(ctx, smsg.Cid(), confidence)
if err != nil {
return err
}

if wait.Receipt.ExitCode.IsError() {
return fmt.Errorf("terminate sectors message returned exit %d", wait.Receipt.ExitCode)
}

return nil
},
}
}

type TerminatorNode interface {
StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error)
MpoolPushMessage(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec) (*types.SignedMessage, error)
}

func TerminateSectors(ctx context.Context, full TerminatorNode, maddr address.Address, sectorNumbers []int, fromAddr address.Address) (*types.SignedMessage, error) {

terminationDeclarationParams := []miner2.TerminationDeclaration{}

for _, sectorNum := range sectorNumbers {

sectorbit := bitfield.New()
sectorbit.Set(uint64(sectorNum))

loca, err := full.StateSectorPartition(ctx, maddr, abi.SectorNumber(sectorNum), types.EmptyTSK)
if err != nil {
return nil, fmt.Errorf("get state sector partition %s", err)
}

para := miner2.TerminationDeclaration{
Deadline: loca.Deadline,
Partition: loca.Partition,
Sectors: sectorbit,
}

terminationDeclarationParams = append(terminationDeclarationParams, para)
}

terminateSectorParams := &miner2.TerminateSectorsParams{
Terminations: terminationDeclarationParams,
}

sp, errA := actors.SerializeParams(terminateSectorParams)
if errA != nil {
return nil, xerrors.Errorf("serializing params: %w", errA)
}

smsg, err := full.MpoolPushMessage(ctx, &types.Message{
From: fromAddr,
To: maddr,
Method: builtin.MethodsMiner.TerminateSectors,

Value: big.Zero(),
Params: sp,
}, nil)
if err != nil {
return nil, xerrors.Errorf("mpool push message: %w", err)
}

fmt.Println("sent termination message:", smsg.Cid())

return smsg, nil
}
1 change: 0 additions & 1 deletion curiosrc/web/api/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func getSch(w http.ResponseWriter, r *http.Request) {
},
}
sch := ref.Reflect(config.CurioConfig{})
//sch := jsonschema.Reflect(config.CurioConfig{})
// add comments
for k, doc := range config.Doc {
item, ok := sch.Definitions[k]
Expand Down
2 changes: 2 additions & 0 deletions curiosrc/web/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"github.com/filecoin-project/lotus/cmd/curio/deps"
"github.com/filecoin-project/lotus/curiosrc/web/api/config"
"github.com/filecoin-project/lotus/curiosrc/web/api/debug"
"github.com/filecoin-project/lotus/curiosrc/web/api/sector"
)

func Routes(r *mux.Router, deps *deps.Deps) {
debug.Routes(r.PathPrefix("/debug").Subrouter(), deps)
config.Routes(r.PathPrefix("/config").Subrouter(), deps)
sector.Routes(r.PathPrefix("/sector").Subrouter(), deps)
}
Loading

0 comments on commit 6b3e9b1

Please sign in to comment.