Skip to content

Commit

Permalink
Update call to light client evidence method
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt committed Aug 30, 2023
1 parent f0a488e commit 4fe458e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
27 changes: 26 additions & 1 deletion cometmock/abci_client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions cometmock/rpc_server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4fe458e

Please sign in to comment.