Skip to content

Commit

Permalink
remove command move-partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5459 committed Nov 23, 2023
1 parent 8cee36c commit 9d8c234
Showing 1 changed file with 138 additions and 139 deletions.
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
// },
// }

0 comments on commit 9d8c234

Please sign in to comment.