Skip to content

Commit

Permalink
Merge pull request #1033 from ipfs-force-community/cherry-pick-pr-103…
Browse files Browse the repository at this point in the history
…2-to-release-v0.9

Release v0.9.0
  • Loading branch information
0x5459 authored Nov 23, 2023
2 parents 497ceb9 + 9d8c234 commit 9f87e20
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 207 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.zh.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

## v0.9.0

## v0.9.0-rc7
- damocles-manager
- 暂时移除 `move partition` 相关的命令 [#1022](https://github.com/ipfs-force-community/damocles/pull/1022)
Expand Down
277 changes: 138 additions & 139 deletions damocles-manager/cmd/damocles-manager/internal/util_sealer_sectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
specpolicy "github.com/filecoin-project/venus/venus-shared/actors/policy"
"github.com/filecoin-project/venus/venus-shared/types"

minerV12 "github.com/filecoin-project/go-state-types/builtin/v12/miner"
"github.com/filecoin-project/lotus/api"
"github.com/ipfs-force-community/damocles/damocles-manager/core"
"github.com/ipfs-force-community/damocles/damocles-manager/modules/policy"
Expand Down Expand Up @@ -2636,141 +2635,141 @@ var utilSealerSectorsUnsealCmd = &cli.Command{
},
}

var utilSealerSectorsMovePartitionsCmd = &cli.Command{
Name: "move-partitions",
Usage: "move deadline of specified partitions from one to another",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "miner",
Usage: "miner address",
Required: true,
},
&cli.Int64SliceFlag{
Name: "partition-indices",
Usage: "Indices of partitions to update, separated by comma",
},
&cli.Uint64Flag{
Name: "orig-deadline",
Usage: "Deadline to move partition from",
},
&cli.Uint64Flag{
Name: "dest-deadline",
Usage: "Deadline to move partition to",
},
&cli.BoolFlag{
Name: "really-do-it",
Usage: "Actually send transaction performing the action",
Value: false,
},
&cli.IntFlag{
Name: "confidence",
Usage: "Number of epochs to wait for message confidence",
Value: 5,
},
},
Action: func(cctx *cli.Context) error {
if !cctx.Bool("really-do-it") {
fmt.Println("Pass --really-do-it to actually execute this action")
return nil
}

if cctx.Args().Present() {
return fmt.Errorf("please use flags to provide arguments")
}

maddr, err := ShouldAddress(cctx.String("miner"), false, true)
if err != nil {
return err
}

fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr))

api, ctx, stop, err := extractAPI(cctx)
if err != nil {
return err
}
defer stop()

minfo, err := api.Chain.StateMinerInfo(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}

origDeadline := cctx.Uint64("orig-deadline")
if origDeadline > miner.WPoStPeriodDeadlines {
return fmt.Errorf("orig-deadline %d out of range", origDeadline)
}
destDeadline := cctx.Uint64("dest-deadline")
if destDeadline > miner.WPoStPeriodDeadlines {
return fmt.Errorf("dest-deadline %d out of range", destDeadline)
}
if origDeadline == destDeadline {
return fmt.Errorf("dest-desdline cannot be the same as orig-deadline")
}

partitions := cctx.Int64Slice("partition-indices")
if len(partitions) == 0 {
return fmt.Errorf("must include at least one partition to move")
}

curPartitions, err := api.Chain.StateMinerPartitions(ctx, maddr, origDeadline, types.EmptyTSK)
if err != nil {
return fmt.Errorf("getting partitions for deadline %d: %w", origDeadline, err)
}
if len(partitions) > len(curPartitions) {
return fmt.Errorf("partition size(%d) cannot be bigger than current partition size(%d) for deadline %d", len(partitions), len(curPartitions), origDeadline)
}

fmt.Printf("Moving %d paritions\n", len(partitions))

partitionsBf := bitfield.New()
for _, partition := range partitions {
if partition >= int64(len(curPartitions)) {
return fmt.Errorf("partition index(%d) doesn't exist", partition)
}
partitionsBf.Set(uint64(partition))
}

params := minerV12.MovePartitionsParams{
OrigDeadline: origDeadline,
DestDeadline: destDeadline,
Partitions: partitionsBf,
}

serializedParams, err := actors.SerializeParams(&params)
if err != nil {
return fmt.Errorf("serializing params: %w", err)
}

mid, err := api.Messager.PushMessage(ctx, &types.Message{
From: minfo.Worker,
To: maddr,
Method: builtin.MethodsMiner.MovePartitions,
Value: big.Zero(),
Params: serializedParams,
}, nil)
if err != nil {
return err
}

fmt.Printf("MovePartitions Message CID: %s\n", mid)

// wait for it to get mined into a block
fmt.Printf("waiting for %d epochs for confirmation..\n", uint64(cctx.Int("confidence")))

wait, err := api.Messager.WaitMessage(ctx, mid, uint64(cctx.Int("confidence")))
if err != nil {
return err
}

// check it executed successfully
if wait.Receipt.ExitCode != 0 {
fmt.Println("Moving partitions failed!")
return err
}

fmt.Println("Move partition confirmed")

return nil
},
}
// var utilSealerSectorsMovePartitionsCmd = &cli.Command{
// Name: "move-partitions",
// Usage: "move deadline of specified partitions from one to another",
// Flags: []cli.Flag{
// &cli.StringFlag{
// Name: "miner",
// Usage: "miner address",
// Required: true,
// },
// &cli.Int64SliceFlag{
// Name: "partition-indices",
// Usage: "Indices of partitions to update, separated by comma",
// },
// &cli.Uint64Flag{
// Name: "orig-deadline",
// Usage: "Deadline to move partition from",
// },
// &cli.Uint64Flag{
// Name: "dest-deadline",
// Usage: "Deadline to move partition to",
// },
// &cli.BoolFlag{
// Name: "really-do-it",
// Usage: "Actually send transaction performing the action",
// Value: false,
// },
// &cli.IntFlag{
// Name: "confidence",
// Usage: "Number of epochs to wait for message confidence",
// Value: 5,
// },
// },
// Action: func(cctx *cli.Context) error {
// if !cctx.Bool("really-do-it") {
// fmt.Println("Pass --really-do-it to actually execute this action")
// return nil
// }

// if cctx.Args().Present() {
// return fmt.Errorf("please use flags to provide arguments")
// }

// maddr, err := ShouldAddress(cctx.String("miner"), false, true)
// if err != nil {
// return err
// }

// fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr))

// api, ctx, stop, err := extractAPI(cctx)
// if err != nil {
// return err
// }
// defer stop()

// minfo, err := api.Chain.StateMinerInfo(ctx, maddr, types.EmptyTSK)
// if err != nil {
// return err
// }

// origDeadline := cctx.Uint64("orig-deadline")
// if origDeadline > miner.WPoStPeriodDeadlines {
// return fmt.Errorf("orig-deadline %d out of range", origDeadline)
// }
// destDeadline := cctx.Uint64("dest-deadline")
// if destDeadline > miner.WPoStPeriodDeadlines {
// return fmt.Errorf("dest-deadline %d out of range", destDeadline)
// }
// if origDeadline == destDeadline {
// return fmt.Errorf("dest-desdline cannot be the same as orig-deadline")
// }

// partitions := cctx.Int64Slice("partition-indices")
// if len(partitions) == 0 {
// return fmt.Errorf("must include at least one partition to move")
// }

// curPartitions, err := api.Chain.StateMinerPartitions(ctx, maddr, origDeadline, types.EmptyTSK)
// if err != nil {
// return fmt.Errorf("getting partitions for deadline %d: %w", origDeadline, err)
// }
// if len(partitions) > len(curPartitions) {
// return fmt.Errorf("partition size(%d) cannot be bigger than current partition size(%d) for deadline %d", len(partitions), len(curPartitions), origDeadline)
// }

// fmt.Printf("Moving %d paritions\n", len(partitions))

// partitionsBf := bitfield.New()
// for _, partition := range partitions {
// if partition >= int64(len(curPartitions)) {
// return fmt.Errorf("partition index(%d) doesn't exist", partition)
// }
// partitionsBf.Set(uint64(partition))
// }

// params := minerV12.MovePartitionsParams{
// OrigDeadline: origDeadline,
// DestDeadline: destDeadline,
// Partitions: partitionsBf,
// }

// serializedParams, err := actors.SerializeParams(&params)
// if err != nil {
// return fmt.Errorf("serializing params: %w", err)
// }

// mid, err := api.Messager.PushMessage(ctx, &types.Message{
// From: minfo.Worker,
// To: maddr,
// Method: builtin.MethodsMiner.MovePartitions,
// Value: big.Zero(),
// Params: serializedParams,
// }, nil)
// if err != nil {
// return err
// }

// fmt.Printf("MovePartitions Message CID: %s\n", mid)

// // wait for it to get mined into a block
// fmt.Printf("waiting for %d epochs for confirmation..\n", uint64(cctx.Int("confidence")))

// wait, err := api.Messager.WaitMessage(ctx, mid, uint64(cctx.Int("confidence")))
// if err != nil {
// return err
// }

// // check it executed successfully
// if wait.Receipt.ExitCode != 0 {
// fmt.Println("Moving partitions failed!")
// return err
// }

// fmt.Println("Move partition confirmed")

// return nil
// },
// }
30 changes: 18 additions & 12 deletions damocles-manager/cmd/damocles-manager/internal/util_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var utilWorkerCmd = &cli.Command{
utilWorkerInfoCmd,
utilWorkerPauseCmd,
utilWorkerResumeCmd,
utilWdPostCmd,
utilWorkerWdPostCmd,
},
}

Expand Down Expand Up @@ -306,18 +306,18 @@ func resolveWorkerDest(ctx context.Context, a *APIClient, name string) (string,
return addr.String(), nil
}

var utilWdPostCmd = &cli.Command{
var utilWorkerWdPostCmd = &cli.Command{
Name: "wdpost",
Usage: "manager wdpost jobs if the jobs is handle by worker",
Subcommands: []*cli.Command{
utilWdPostListCmd,
utilWdPostResetCmd,
utilWdPostRemoveCmd,
utilWdPostRemoveAllCmd,
utilWorkerWdPostListCmd,
utilWorkerWdPostResetCmd,
utilWorkerWdPostRemoveCmd,
utilWorkerWdPostRemoveAllCmd,
},
}

var utilWdPostListCmd = &cli.Command{
var utilWorkerWdPostListCmd = &cli.Command{
Name: "list",
Usage: "list all wdpost job",
Flags: []cli.Flag{
Expand Down Expand Up @@ -354,12 +354,18 @@ var utilWdPostListCmd = &cli.Command{
if err != nil {
return err
}

formatDateTime := func(unix_secs uint64) string {
if unix_secs == 0 {
return "-"
}
return time.Unix(int64(unix_secs), 0).Format("01-02 15:04:05")
}

formatPartitions := func(partitions []uint64) string {
return "[" + strings.Join(partitions, ", ") + "]"
}

for _, job := range allJobs.Jobs {
if !cctx.Bool("all") && job.Succeed() {
continue
Expand All @@ -375,7 +381,7 @@ var utilWdPostListCmd = &cli.Command{
job.State,
job.Input.MinerID,
job.DeadlineIdx,
strings.Join(job.Partitions, ","),
formatPartitions(job.Partitions),
job.Sectors,
job.WorkerName,
job.DisplayState(),
Expand Down Expand Up @@ -406,7 +412,7 @@ var utilWdPostListCmd = &cli.Command{
job.ID,
job.Input.MinerID,
job.DeadlineIdx,
strings.Join(job.Partitions, ","),
formatPartitions(job.Partitions),
job.Sectors,
job.WorkerName,
job.DisplayState(),
Expand All @@ -424,7 +430,7 @@ var utilWdPostListCmd = &cli.Command{
},
}

var utilWdPostResetCmd = &cli.Command{
var utilWorkerWdPostResetCmd = &cli.Command{
Name: "reset",
Usage: "reset the job status to allow new workers can pick it up",
ArgsUsage: "<job id>...",
Expand All @@ -451,7 +457,7 @@ var utilWdPostResetCmd = &cli.Command{
},
}

var utilWdPostRemoveCmd = &cli.Command{
var utilWorkerWdPostRemoveCmd = &cli.Command{
Name: "remove",
Usage: "remove wdpost job",
ArgsUsage: "<job id>...",
Expand All @@ -477,7 +483,7 @@ var utilWdPostRemoveCmd = &cli.Command{
},
}

var utilWdPostRemoveAllCmd = &cli.Command{
var utilWorkerWdPostRemoveAllCmd = &cli.Command{
Name: "remove-all",
Usage: "remove all wdpost jobs",
Flags: []cli.Flag{
Expand Down
Loading

0 comments on commit 9f87e20

Please sign in to comment.