github.com/Finschia/finschia-sdk@v0.48.1/x/evidence/spec/01_concepts.md (about) 1 <!-- 2 order: 1 3 --> 4 5 # Concepts 6 7 ## Evidence 8 9 Any concrete type of evidence submitted to the `x/evidence` module must fulfill the 10 `Evidence` contract outlined below. Not all concrete types of evidence will fulfill 11 this contract in the same way and some data may be entirely irrelevant to certain 12 types of evidence. An additional `ValidatorEvidence`, which extends `Evidence`, 13 has also been created to define a contract for evidence against malicious validators. 14 15 ```go 16 // Evidence defines the contract which concrete evidence types of misbehavior 17 // must implement. 18 type Evidence interface { 19 proto.Message 20 21 Route() string 22 Type() string 23 String() string 24 Hash() ostbytes.HexBytes 25 ValidateBasic() error 26 27 // Height at which the infraction occurred 28 GetHeight() int64 29 } 30 31 // ValidatorEvidence extends Evidence interface to define contract 32 // for evidence against malicious validators 33 type ValidatorEvidence interface { 34 Evidence 35 36 // The consensus address of the malicious validator at time of infraction 37 GetConsensusAddress() sdk.ConsAddress 38 39 // The total power of the malicious validator at time of infraction 40 GetValidatorPower() int64 41 42 // The total validator set power at time of infraction 43 GetTotalPower() int64 44 } 45 ``` 46 47 ## Registration & Handling 48 49 The `x/evidence` module must first know about all types of evidence it is expected 50 to handle. This is accomplished by registering the `Route` method in the `Evidence` 51 contract with what is known as a `Router` (defined below). The `Router` accepts 52 `Evidence` and attempts to find the corresponding `Handler` for the `Evidence` 53 via the `Route` method. 54 55 ```go 56 type Router interface { 57 AddRoute(r string, h Handler) Router 58 HasRoute(r string) bool 59 GetRoute(path string) Handler 60 Seal() 61 Sealed() bool 62 } 63 ``` 64 65 The `Handler` (defined below) is responsible for executing the entirety of the 66 business logic for handling `Evidence`. This typically includes validating the 67 evidence, both stateless checks via `ValidateBasic` and stateful checks via any 68 keepers provided to the `Handler`. In addition, the `Handler` may also perform 69 capabilities such as slashing and jailing a validator. All `Evidence` handled 70 by the `Handler` should be persisted. 71 72 ```go 73 // Handler defines an agnostic Evidence handler. The handler is responsible 74 // for executing all corresponding business logic necessary for verifying the 75 // evidence as valid. In addition, the Handler may execute any necessary 76 // slashing and potential jailing. 77 type Handler func(sdk.Context, Evidence) error 78 ```