Skip to content

Commit

Permalink
Merge pull request #975 from filecoin-project/feat/cli-slashing
Browse files Browse the repository at this point in the history
chain slash-consensus command
  • Loading branch information
whyrusleeping authored Jan 24, 2020
2 parents 3bf0bd6 + 7711384 commit 7b258ed
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
64 changes: 64 additions & 0 deletions cli/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"gopkg.in/urfave/cli.v2"

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors"
types "github.com/filecoin-project/lotus/chain/types"
)

Expand All @@ -28,6 +29,7 @@ var chainCmd = &cli.Command{
chainListCmd,
chainGetCmd,
chainExportCmd,
slashConsensusFault,
},
}

Expand Down Expand Up @@ -438,3 +440,65 @@ var chainExportCmd = &cli.Command{
return nil
},
}

var slashConsensusFault = &cli.Command{
Name: "slash-consensus",
Usage: "Report consensus fault",
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)

c1, err := cid.Parse(cctx.Args().Get(0))
if err != nil {
return xerrors.Errorf("parsing cid 1: %w", err)
}

b1, err := api.ChainGetBlock(ctx, c1)
if err != nil {
return xerrors.Errorf("getting block 1: %w", err)
}

c2, err := cid.Parse(cctx.Args().Get(0))
if err != nil {
return xerrors.Errorf("parsing cid 2: %w", err)
}

b2, err := api.ChainGetBlock(ctx, c2)
if err != nil {
return xerrors.Errorf("getting block 2: %w", err)
}

def, err := api.WalletDefaultAddress(ctx)
if err != nil {
return err
}

params, err := actors.SerializeParams(&actors.ArbitrateConsensusFaultParams{
Block1: b1,
Block2: b2,
})

msg := &types.Message{
To: actors.StoragePowerAddress,
From: def,
Value: types.NewInt(0),
GasPrice: types.NewInt(1),
GasLimit: types.NewInt(10000000),
Method: actors.SPAMethods.ArbitrateConsensusFault,
Params: params,
}

smsg, err := api.MpoolPushMessage(ctx, msg)
if err != nil {
return err
}

fmt.Println(smsg.Cid())

return nil
},
}
1 change: 1 addition & 0 deletions node/impl/full/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
Expand Down

0 comments on commit 7b258ed

Please sign in to comment.