From 0ba839a7386d0655f07da7c0910ec9098f23786d Mon Sep 17 00:00:00 2001 From: Marie Gauthier Date: Thu, 7 Jan 2021 17:12:54 +0100 Subject: [PATCH] x/evidence doc general audit & cleanup (#8277) * Update x/evidence doc * Update x/evidence spec --- x/evidence/doc.go | 10 +++++----- x/evidence/spec/01_concepts.md | 4 +++- x/evidence/spec/03_messages.md | 15 +++++++++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/x/evidence/doc.go b/x/evidence/doc.go index 20f907a3b..d68e0e649 100644 --- a/x/evidence/doc.go +++ b/x/evidence/doc.go @@ -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... diff --git a/x/evidence/spec/01_concepts.md b/x/evidence/spec/01_concepts.md index 736e75c9a..78a16523d 100644 --- a/x/evidence/spec/01_concepts.md +++ b/x/evidence/spec/01_concepts.md @@ -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 ``` diff --git a/x/evidence/spec/03_messages.md b/x/evidence/spec/03_messages.md index 85a822890..cd902ec99 100644 --- a/x/evidence/spec/03_messages.md +++ b/x/evidence/spec/03_messages.md @@ -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.