Skip to content

Commit 7b258ed

Browse files
Merge pull request #975 from filecoin-project/feat/cli-slashing
chain slash-consensus command
2 parents 3bf0bd6 + 7711384 commit 7b258ed

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

cli/chain.go

+64
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"gopkg.in/urfave/cli.v2"
1414

1515
"github.com/filecoin-project/lotus/api"
16+
"github.com/filecoin-project/lotus/chain/actors"
1617
types "github.com/filecoin-project/lotus/chain/types"
1718
)
1819

@@ -28,6 +29,7 @@ var chainCmd = &cli.Command{
2829
chainListCmd,
2930
chainGetCmd,
3031
chainExportCmd,
32+
slashConsensusFault,
3133
},
3234
}
3335

@@ -438,3 +440,65 @@ var chainExportCmd = &cli.Command{
438440
return nil
439441
},
440442
}
443+
444+
var slashConsensusFault = &cli.Command{
445+
Name: "slash-consensus",
446+
Usage: "Report consensus fault",
447+
Action: func(cctx *cli.Context) error {
448+
api, closer, err := GetFullNodeAPI(cctx)
449+
if err != nil {
450+
return err
451+
}
452+
defer closer()
453+
ctx := ReqContext(cctx)
454+
455+
c1, err := cid.Parse(cctx.Args().Get(0))
456+
if err != nil {
457+
return xerrors.Errorf("parsing cid 1: %w", err)
458+
}
459+
460+
b1, err := api.ChainGetBlock(ctx, c1)
461+
if err != nil {
462+
return xerrors.Errorf("getting block 1: %w", err)
463+
}
464+
465+
c2, err := cid.Parse(cctx.Args().Get(0))
466+
if err != nil {
467+
return xerrors.Errorf("parsing cid 2: %w", err)
468+
}
469+
470+
b2, err := api.ChainGetBlock(ctx, c2)
471+
if err != nil {
472+
return xerrors.Errorf("getting block 2: %w", err)
473+
}
474+
475+
def, err := api.WalletDefaultAddress(ctx)
476+
if err != nil {
477+
return err
478+
}
479+
480+
params, err := actors.SerializeParams(&actors.ArbitrateConsensusFaultParams{
481+
Block1: b1,
482+
Block2: b2,
483+
})
484+
485+
msg := &types.Message{
486+
To: actors.StoragePowerAddress,
487+
From: def,
488+
Value: types.NewInt(0),
489+
GasPrice: types.NewInt(1),
490+
GasLimit: types.NewInt(10000000),
491+
Method: actors.SPAMethods.ArbitrateConsensusFault,
492+
Params: params,
493+
}
494+
495+
smsg, err := api.MpoolPushMessage(ctx, msg)
496+
if err != nil {
497+
return err
498+
}
499+
500+
fmt.Println(smsg.Cid())
501+
502+
return nil
503+
},
504+
}

node/impl/full/chain.go

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"golang.org/x/xerrors"
2525

2626
"github.com/filecoin-project/go-address"
27+
2728
"github.com/filecoin-project/lotus/api"
2829
"github.com/filecoin-project/lotus/chain/store"
2930
"github.com/filecoin-project/lotus/chain/types"

0 commit comments

Comments
 (0)