diff --git a/cometmock/abci_client/client.go b/cometmock/abci_client/client.go index 99ead85..c020af0 100644 --- a/cometmock/abci_client/client.go +++ b/cometmock/abci_client/client.go @@ -88,6 +88,31 @@ func (a *AbciClient) IncrementTimeOffset(additionalOffset time.Duration) error { return nil } +func (a *AbciClient) CauseLightClientAttack(address string, misbehaviourType string) error { + a.Logger.Info("Causing double sign", "address", address) + + validator, err := a.GetValidatorFromAddress(address) + if err != nil { + return err + } + + // get the misbehaviour type from the string + var misbehaviour MisbehaviourType + switch misbehaviourType { + case "Lunatic": + misbehaviour = Lunatic + case "Amnesia": + misbehaviour = Amnesia + case "Equivocation": + misbehaviour = Equivocation + default: + return fmt.Errorf("unknown misbehaviour type %s, possible types are: Equivocation, Lunatic, Amnesia", misbehaviourType) + } + + _, _, _, _, _, err = a.RunBlockWithEvidence(nil, map[*types.Validator]MisbehaviourType{validator: misbehaviour}) + return err +} + func (a *AbciClient) CauseDoubleSign(address string) error { a.Logger.Info("Causing double sign", "address", address) @@ -96,7 +121,7 @@ func (a *AbciClient) CauseDoubleSign(address string) error { return err } - _, _, _, _, _, err = a.RunBlockWithEvidence(nil, []*types.Validator{validator}) + _, _, _, _, _, err = a.RunBlockWithEvidence(nil, map[*types.Validator]MisbehaviourType{validator: DuplicateVote}) return err } diff --git a/cometmock/rpc_server/routes.go b/cometmock/rpc_server/routes.go index ca4c30c..5b83aec 100644 --- a/cometmock/rpc_server/routes.go +++ b/cometmock/rpc_server/routes.go @@ -57,13 +57,13 @@ var Routes = map[string]*rpc.RPCFunc{ "set_signing_status": rpc.NewRPCFunc(SetSigningStatus, "private_key_address,status"), "advance_time": rpc.NewRPCFunc(AdvanceTime, "duration_in_seconds"), "cause_double_sign": rpc.NewRPCFunc(CauseDoubleSign, "private_key_address"), - "cause_light_client_attack": rpc.NewRPCFunc(CauseLightClientAttack, "private_key_address"), + "cause_light_client_attack": rpc.NewRPCFunc(CauseLightClientAttack, "private_key_address, misbehaviour_type"), } type ResultCauseLightClientAttack struct{} -func CauseLightClientAttack(ctx *rpctypes.Context, privateKeyAddress string) (*ResultCauseLightClientAttack, error) { - err := abci_client.GlobalClient.CauseLightClientAttack(privateKeyAddress) +func CauseLightClientAttack(ctx *rpctypes.Context, privateKeyAddress, misbehaviourType string) (*ResultCauseLightClientAttack, error) { + err := abci_client.GlobalClient.CauseLightClientAttack(privateKeyAddress, misbehaviourType) return &ResultCauseLightClientAttack{}, err }