Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-vball committed May 25, 2022
1 parent ef4a44c commit fcdf64a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
18 changes: 16 additions & 2 deletions cmd/lotus-miner/sectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2112,7 +2112,7 @@ var sectorsCompactPartitionsCmd = &cli.Command{
},
&cli.StringFlag{
Name: "actor",
Usage: "TODO",
Usage: "Specify the address of the minor to run this command",
},
},
Action: func(cctx *cli.Context) error {
Expand Down Expand Up @@ -2140,6 +2140,9 @@ var sectorsCompactPartitionsCmd = &cli.Command{
}

deadline := cctx.Uint64("deadline")
if deadline < 0 || deadline > miner.WPoStPeriodDeadlines {
return fmt.Errorf("deadline %d out of range", deadline)
}

parts := cctx.Int64Slice("partitions")
if len(parts) <= 0 {
Expand Down Expand Up @@ -2173,7 +2176,18 @@ var sectorsCompactPartitionsCmd = &cli.Command{
return xerrors.Errorf("mpool push: %w", err)
}

fmt.Println("Message CID:", smsg.Cid())
fmt.Printf("Requested compact partitions in message %s\n", smsg.Cid())

wait, err := api.StateWaitMsg(ctx, smsg.Cid(), 0)
if err != nil {
return err
}

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

return nil
},
Expand Down
60 changes: 33 additions & 27 deletions cmd/lotus-shed/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/ipfs/go-cid"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
Expand All @@ -22,7 +23,6 @@ import (

"github.com/docker/go-units"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
Expand Down Expand Up @@ -374,7 +374,7 @@ var sendInvalidWindowPoStCmd = &cli.Command{
},
&cli.Int64SliceFlag{
Name: "partitions",
Usage: "list of partitions to compact sectors in",
Usage: "list of partitions to submit invalid post for",
Required: true,
},
&cli.StringFlag{
Expand Down Expand Up @@ -469,7 +469,18 @@ var sendInvalidWindowPoStCmd = &cli.Command{
return xerrors.Errorf("mpool push: %w", err)
}

fmt.Println("Message CID:", smsg.Cid())
fmt.Printf("Invalid PoST in message %s\n", smsg.Cid())

wait, err := api.StateWaitMsg(ctx, smsg.Cid(), 0)
if err != nil {
return err
}

// check it executed successfully
if wait.Receipt.ExitCode != 0 {
fmt.Println(cctx.App.Writer, "Invalid PoST message failed!")
return err
}

return nil
},
Expand All @@ -479,23 +490,8 @@ var generateAndSendConsensusFaultCmd = &cli.Command{
Name: "generate-and-send-consensus-fault",
Usage: "Provided a block CID mined by the miner, will create another block at the same height, and send both block headers to generate a consensus fault.",
Description: `Note: This is meant for testing purposes and should NOT be used on mainnet or you will be slashed`,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "really-do-it",
Usage: "Actually send transaction performing the action",
Value: false,
},
&cli.StringFlag{
Name: "actor",
Usage: "TODO",
},
},
Action: func(cctx *cli.Context) error {
if !cctx.Bool("really-do-it") {
return xerrors.Errorf("Pass --really-do-it to actually execute this action")
}

if cctx.Args().Len() != 1 {
if cctx.NArg() != 1 {
return xerrors.Errorf("expected 1 arg (blockCID)")
}

Expand All @@ -512,21 +508,20 @@ var generateAndSendConsensusFaultCmd = &cli.Command{

ctx := lcli.ReqContext(cctx)

maddr, err := address.NewFromString(cctx.String("actor"))
blockHeader, err := api.ChainGetBlock(ctx, blockCid)
if err != nil {
return xerrors.Errorf("getting actor address: %w", err)
return xerrors.Errorf("getting block header: %w", err)
}

maddr := blockHeader.Miner

minfo, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
if err != nil {
return xerrors.Errorf("getting miner info: %w", err)
}

blockHeader, err := api.ChainGetBlock(ctx, blockCid)
if err != nil {
return xerrors.Errorf("getting block header: %w", err)
}

// We are changing one field in the block header, then resigning the new block.
// This gives two different blocks signed by the same miner at the same height which will result in a consensus fault.
blockHeaderCopy := *blockHeader
blockHeaderCopy.ForkSignaling = blockHeader.ForkSignaling + 1

Expand Down Expand Up @@ -573,7 +568,18 @@ var generateAndSendConsensusFaultCmd = &cli.Command{
return xerrors.Errorf("mpool push: %w", err)
}

fmt.Println("Message CID:", smsg.Cid())
fmt.Printf("Consensus fault reported in message %s\n", smsg.Cid())

wait, err := api.StateWaitMsg(ctx, smsg.Cid(), 0)
if err != nil {
return err
}

// check it executed successfully
if wait.Receipt.ExitCode != 0 {
fmt.Println(cctx.App.Writer, "Report consensus fault failed!")
return err
}

return nil
},
Expand Down
2 changes: 1 addition & 1 deletion documentation/en/cli-lotus-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@ OPTIONS:
--deadline value the deadline to compact the partitions in (default: 0)
--partitions value list of partitions to compact sectors in
--really-do-it Actually send transaction performing the action (default: false)
--actor value TODO
--actor value Specify the address of the minor to run this command
--help, -h show help (default: false)
```
Expand Down

0 comments on commit fcdf64a

Please # to comment.