x/evidence doc general audit & cleanup (#8277)

* Update x/evidence doc

* Update x/evidence spec
This commit is contained in:
Marie Gauthier 2021-01-07 17:12:54 +01:00 committed by GitHub
parent 1895831641
commit 0ba839a738
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 10 deletions

View File

@ -20,13 +20,11 @@ A full setup of the evidence module may look something as follows:
evidence.AppModuleBasic{},
)
// First, create the keeper's subspace for parameters and the keeper itself.
evidenceParamspace := app.ParamsKeeper.Subspace(evidence.ModuleName)
// First, create the keeper
evidenceKeeper := evidence.NewKeeper(
app.cdc, keys[evidence.StoreKey], evidenceParamspace, evidence.DefaultCodespace,
appCodec, keys[evidence.StoreKey], &app.StakingKeeper, app.SlashingKeeper,
)
// Second, create the evidence Handler and register all desired routes.
evidenceRouter := evidence.NewRouter().
AddRoute(evidenceRoute, evidenceHandler).
@ -34,9 +32,11 @@ A full setup of the evidence module may look something as follows:
evidenceKeeper.SetRouter(evidenceRouter)
app.EvidenceKeeper = *evidenceKeeper
app.mm = module.NewManager(
// ...
evidence.NewAppModule(evidenceKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
)
// Remaining application bootstrapping...

View File

@ -16,6 +16,8 @@ has also been created to define a contract for evidence against malicious valida
// Evidence defines the contract which concrete evidence types of misbehavior
// must implement.
type Evidence interface {
proto.Message
Route() string
Type() string
String() string
@ -71,5 +73,5 @@ capabilities such as slashing and jailing a validator.
// for executing all corresponding business logic necessary for verifying the
// evidence as valid. In addition, the Handler may execute any necessary
// slashing and potential jailing.
type Handler func(Context, Evidence) error
type Handler func(sdk.Context, Evidence) error
```

View File

@ -27,17 +27,24 @@ as follows:
```go
func SubmitEvidence(ctx Context, evidence Evidence) error {
if _, ok := GetEvidence(ctx, evidence.Hash()); ok {
return ErrEvidenceExists(codespace, evidence.Hash().String())
return sdkerrors.Wrap(types.ErrEvidenceExists, evidence.Hash().String())
}
if !router.HasRoute(evidence.Route()) {
return ErrNoEvidenceHandlerExists(codespace, evidence.Route())
return sdkerrors.Wrap(types.ErrNoEvidenceHandlerExists, evidence.Route())
}
handler := router.GetRoute(evidence.Route())
if err := handler(ctx, evidence); err != nil {
return ErrInvalidEvidence(codespace, err.Error())
return sdkerrors.Wrap(types.ErrInvalidEvidence, err.Error())
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeSubmitEvidence,
sdk.NewAttribute(types.AttributeKeyEvidenceHash, evidence.Hash().String()),
),
)
SetEvidence(ctx, evidence)
return nil
}
@ -45,4 +52,4 @@ func SubmitEvidence(ctx Context, evidence Evidence) error {
First, there must not already exist valid submitted `Evidence` of the exact same
type. Secondly, the `Evidence` is routed to the `Handler` and executed. Finally,
if there is no error in handling the `Evidence`, it is persisted to state.
if there is no error in handling the `Evidence`, an event is emitted and it is persisted to state.