Merge pull request #11301 from filecoin-project/move-partition

Feat: Lotus cli: actor: Support move partition command to move partitions' deadline
This commit is contained in:
Jie Hou 2023-10-02 09:27:26 -07:00 committed by GitHub
commit e81e5a751c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 163 additions and 5 deletions

View File

@ -2,6 +2,9 @@
# UNRELEASED
## New features
- feat: Add move-partition command ([filecoin-project/lotus#11290](https://github.com/filecoin-project/lotus/pull/11290))
# v1.23.3 / 2023-08-01
This feature release of Lotus includes numerous improvements and enhancements for node operators, ETH RPC-providers and storage providers.

View File

@ -21,6 +21,7 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin"
minerV12 "github.com/filecoin-project/go-state-types/builtin/v12/miner"
"github.com/filecoin-project/go-state-types/builtin/v9/miner"
"github.com/filecoin-project/go-state-types/network"
@ -49,6 +50,7 @@ var actorCmd = &cli.Command{
actorProposeChangeWorker,
actorConfirmChangeWorker,
actorCompactAllocatedCmd,
actorMovePartitionsCmd,
actorProposeChangeBeneficiary,
actorConfirmChangeBeneficiary,
},
@ -1286,13 +1288,149 @@ var actorConfirmChangeBeneficiary = &cli.Command{
},
}
var actorMovePartitionsCmd = &cli.Command{
Name: "move-partitions",
Usage: "move deadline of specified partitions from one to another",
Flags: []cli.Flag{
&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,
},
},
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")
}
ctx := lcli.ReqContext(cctx)
minerApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
maddr, err := minerApi.ActorAddress(ctx)
if err != nil {
return err
}
fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr))
fullNodeApi, acloser, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer acloser()
minfo, err := fullNodeApi.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 := fullNodeApi.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)
}
smsg, err := fullNodeApi.MpoolPushMessage(ctx, &types.Message{
From: minfo.Worker,
To: maddr,
Method: builtin.MethodsMiner.MovePartitions,
Value: big.Zero(),
Params: serializedParams,
}, nil)
if err != nil {
return fmt.Errorf("mpool push: %w", err)
}
fmt.Println("MovePartitions Message CID:", smsg.Cid())
// wait for it to get mined into a block
fmt.Println("Waiting for block confirmation...")
wait, err := fullNodeApi.StateWaitMsg(ctx, smsg.Cid(), build.MessageConfidence)
if err != nil {
return err
}
// check it executed successfully
if wait.Receipt.ExitCode.IsError() {
fmt.Println("Moving partitions failed!")
return err
}
fmt.Println("Move partition confirmed")
return nil
},
}
var actorCompactAllocatedCmd = &cli.Command{
Name: "compact-allocated",
Usage: "compact allocated sectors bitfield",
Flags: []cli.Flag{
&cli.Uint64Flag{
Name: "mask-last-offset",
Usage: "Mask sector IDs from 0 to 'higest_allocated - offset'",
Usage: "Mask sector IDs from 0 to 'highest_allocated - offset'",
},
&cli.Uint64Flag{
Name: "mask-upto-n",

View File

@ -223,6 +223,7 @@ COMMANDS:
propose-change-worker Propose a worker address change
confirm-change-worker Confirm a worker address change
compact-allocated compact allocated sectors bitfield
move-partitions move deadline of specified partitions from one to another
propose-change-beneficiary Propose a beneficiary address change
confirm-change-beneficiary Confirm a beneficiary address change
help, h Shows a list of commands or help for one command
@ -366,12 +367,28 @@ USAGE:
lotus-miner actor compact-allocated [command options] [arguments...]
OPTIONS:
--mask-last-offset value Mask sector IDs from 0 to 'higest_allocated - offset' (default: 0)
--mask-last-offset value Mask sector IDs from 0 to 'highest_allocated - offset' (default: 0)
--mask-upto-n value Mask sector IDs from 0 to 'n' (default: 0)
--really-do-it Actually send transaction performing the action (default: false)
--help, -h show help
```
### lotus-miner actor move-partitions
```
NAME:
lotus-miner actor move-partitions - move deadline of specified partitions from one to another
USAGE:
lotus-miner actor move-partitions [command options] [arguments...]
OPTIONS:
--partition-indices value [ --partition-indices value ] Indices of partitions to update, separated by comma
--orig-deadline value Deadline to move partition from (default: 0)
--dest-deadline value Deadline to move partition to (default: 0)
--really-do-it Actually send transaction performing the action (default: false)
--help, -h show help
```
### lotus-miner actor propose-change-beneficiary
```
NAME:

2
go.mod
View File

@ -45,7 +45,7 @@ require (
github.com/filecoin-project/go-jsonrpc v0.3.1
github.com/filecoin-project/go-padreader v0.0.1
github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.12.3
github.com/filecoin-project/go-state-types v0.12.4-0.20231002153316-c656c180c4d2
github.com/filecoin-project/go-statemachine v1.0.3
github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/go-storedcounter v0.1.0

4
go.sum
View File

@ -338,8 +338,8 @@ github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psS
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.11.2-0.20230712101859-8f37624fa540/go.mod h1:SyNPwTsU7I22gL2r0OAPcImvLoTVfgRwdK/Y5rR1zz8=
github.com/filecoin-project/go-state-types v0.12.3 h1:tPljjwrmLUT+b/H0R0yWZQVjVEso7ld9JBh4mpF6c8c=
github.com/filecoin-project/go-state-types v0.12.3/go.mod h1:iJTqGdWDvzXhuVf64Lw0hzt4TIoitMo0VgHdxdjNDZI=
github.com/filecoin-project/go-state-types v0.12.4-0.20231002153316-c656c180c4d2 h1:eZvCTWl1Z3FxKB45gKN4RdDbaI0qBt+w2mG/lFEE3rs=
github.com/filecoin-project/go-state-types v0.12.4-0.20231002153316-c656c180c4d2/go.mod h1:iJTqGdWDvzXhuVf64Lw0hzt4TIoitMo0VgHdxdjNDZI=
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statemachine v1.0.3 h1:N07o6alys+V1tNoSTi4WuuoeNC4erS/6jE74+NsgQuk=
github.com/filecoin-project/go-statemachine v1.0.3/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=