From 77113844a2ffbae9efd18be7358a3e646df7bba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 18 Dec 2019 16:37:47 +0100 Subject: [PATCH] chain slash-consensus command --- cli/chain.go | 64 +++++++++++++++++++++++++++++++++++++++++ node/impl/full/chain.go | 1 + 2 files changed, 65 insertions(+) diff --git a/cli/chain.go b/cli/chain.go index 48854d217..aed541f8c 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -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" ) @@ -28,6 +29,7 @@ var chainCmd = &cli.Command{ chainListCmd, chainGetCmd, chainExportCmd, + slashConsensusFault, }, } @@ -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 + }, +} diff --git a/node/impl/full/chain.go b/node/impl/full/chain.go index fdcf2962c..7656ce19d 100644 --- a/node/impl/full/chain.go +++ b/node/impl/full/chain.go @@ -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"