From 71dc28af0d359847d88dc29fc69d957659e955ea Mon Sep 17 00:00:00 2001 From: Marko Date: Tue, 12 Sep 2023 12:55:43 +0200 Subject: [PATCH] refactor!: comet_info to struct (#17689) --- core/CHANGELOG.md | 2 ++ core/comet/service.go | 61 ++++++++++++++++++------------------------- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 134d91bcbc..06fdeea319 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -37,6 +37,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] * [#17468](https://github.com/cosmos/cosmos-sdk/pull/17468) Add `appmodule.HasPreBlocker` interface. +* [#17689](https://github.com/cosmos/cosmos-sdk/pull/17689) Move Comet service to return structs instead of interfaces. + * `BlockInfo` was renamed to `Info` and `BlockInfoService` was renamed to `CometInfoService` ## [v0.10.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.10.0) diff --git a/core/comet/service.go b/core/comet/service.go index d2985b2174..8af646e011 100644 --- a/core/comet/service.go +++ b/core/comet/service.go @@ -6,18 +6,18 @@ import ( ) // BlockInfoService is an interface that can be used to get information specific to Comet -type BlockInfoService interface { - GetCometBlockInfo(context.Context) BlockInfo +type CometInfoService interface { + GetCometInfo(context.Context) Info } -// BlockInfo is the information comet provides apps in ABCI -type BlockInfo interface { - GetEvidence() EvidenceList // Evidence misbehavior of the block +// Info is the information comet provides apps in ABCI +type Info struct { + Evidence []Evidence // Evidence misbehavior of the block // ValidatorsHash returns the hash of the validators // For Comet, it is the hash of the next validator set - GetValidatorsHash() []byte - GetProposerAddress() []byte // ProposerAddress returns the address of the block proposer - GetLastCommit() CommitInfo // DecidedLastCommit returns the last commit info + ValidatorsHash []byte + ProposerAddress []byte // ProposerAddress is the address of the block proposer + LastCommit CommitInfo // DecidedLastCommit returns the last commit info } // MisbehaviorType is the type of misbehavior for a validator @@ -29,36 +29,25 @@ const ( LightClientAttack MisbehaviorType = 2 ) -// Validator is the validator information of ABCI -type Validator interface { - Address() []byte - Power() int64 -} - -type EvidenceList interface { - Len() int - Get(int) Evidence -} - // Evidence is the misbehavior information of ABCI -type Evidence interface { - Type() MisbehaviorType - Validator() Validator - Height() int64 - Time() time.Time - TotalVotingPower() int64 +type Evidence struct { + Type MisbehaviorType + Validator Validator + Height int64 + Time time.Time + TotalVotingPower int64 } // CommitInfo is the commit information of ABCI -type CommitInfo interface { - Round() int32 - Votes() VoteInfos +type CommitInfo struct { + Round int32 + Votes []VoteInfo } -// VoteInfos is an interface to get specific votes in a efficient way -type VoteInfos interface { - Len() int - Get(int) VoteInfo +// VoteInfo is the vote information of ABCI +type VoteInfo struct { + Validator Validator + BlockIDFlag BlockIDFlag } // BlockIdFlag indicates which BlockID the signature is for @@ -74,8 +63,8 @@ const ( BlockIDFlagNil BlockIDFlag = 3 ) -// VoteInfo is the vote information of ABCI -type VoteInfo interface { - Validator() Validator - GetBlockIDFlag() BlockIDFlag +// Validator is the validator information of ABCI +type Validator struct { + Address []byte + Power int64 }