feat: add header and comet info service (#15850)

Co-authored-by: Aaron Craelius <aaron@regen.network>
This commit is contained in:
Marko
2023-05-03 13:32:25 +00:00
committed by GitHub
co-authored by Aaron Craelius
parent 1d03f419f7
commit 1705615ef0
27 changed files with 659 additions and 107 deletions
+8 -6
View File
@@ -194,12 +194,14 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
WithBlockGasMeter(gasMeter).
WithHeaderHash(req.Hash).
WithConsensusParams(app.GetConsensusParams(app.deliverState.ctx)).
WithVoteInfos(req.LastCommitInfo.GetVotes())
WithVoteInfos(req.LastCommitInfo.GetVotes()).
WithCometInfo(cometInfo{Misbehavior: req.ByzantineValidators, ValidatorsHash: req.Header.ValidatorsHash, ProposerAddress: req.Header.ProposerAddress, LastCommit: req.LastCommitInfo})
if app.checkState != nil {
app.checkState.ctx = app.checkState.ctx.
WithBlockGasMeter(gasMeter).
WithHeaderHash(req.Hash)
WithHeaderHash(req.Hash).
WithCometInfo(cometInfo{Misbehavior: req.ByzantineValidators, ValidatorsHash: req.Header.ValidatorsHash, ProposerAddress: req.Header.ProposerAddress, LastCommit: req.LastCommitInfo})
}
if app.beginBlocker != nil {
@@ -210,8 +212,6 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
}
res.Events = sdk.MarkEventsToIndex(res.Events, app.indexEvents)
}
// set the signed validators for addition to context in deliverTx
app.voteInfos = req.LastCommitInfo.GetVotes()
// call the streaming service hook with the BeginBlock messages
for _, abciListener := range app.streamingManager.ABCIListeners {
@@ -287,7 +287,8 @@ func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) (resp abci.
WithVoteInfos(toVoteInfo(req.LocalLastCommit.Votes)). // this is a set of votes that are not finalized yet, wait for commit
WithBlockHeight(req.Height).
WithBlockTime(req.Time).
WithProposer(req.ProposerAddress)
WithProposer(req.ProposerAddress).
WithCometInfo(prepareProposalInfo{req})
app.prepareProposalState.ctx = app.prepareProposalState.ctx.
WithConsensusParams(app.GetConsensusParams(app.prepareProposalState.ctx)).
@@ -345,7 +346,8 @@ func (app *BaseApp) ProcessProposal(req abci.RequestProcessProposal) (resp abci.
WithBlockHeight(req.Height).
WithBlockTime(req.Time).
WithHeaderHash(req.Hash).
WithProposer(req.ProposerAddress)
WithProposer(req.ProposerAddress).
WithCometInfo(cometInfo{ProposerAddress: req.ProposerAddress, ValidatorsHash: req.NextValidatorsHash, Misbehavior: req.Misbehavior, LastCommit: req.ProposedLastCommit})
app.processProposalState.ctx = app.processProposalState.ctx.
WithConsensusParams(app.GetConsensusParams(app.processProposalState.ctx)).
+3 -6
View File
@@ -51,7 +51,7 @@ var _ abci.Application = (*BaseApp)(nil)
type BaseApp struct {
// initialized on creation
logger log.Logger
name string // application name from abci.Info
name string // application name from abci.BlockInfo
db dbm.DB // common DB backend
cms storetypes.CommitMultiStore // Main (uncached) state
qms storetypes.MultiStore // Optional alternative multistore for querying only.
@@ -91,9 +91,6 @@ type BaseApp struct {
// an inter-block write-through cache provided to the context during deliverState
interBlockCache storetypes.MultiStorePersistentCache
// absent validators from begin block
voteInfos []abci.VoteInfo
// paramStore is used to query for ABCI consensus parameters from an
// application parameter store.
paramStore ParamStore
@@ -573,8 +570,8 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) sdk.Context
panic(fmt.Sprintf("state is nil for mode %v", mode))
}
ctx := modeState.ctx.
WithTxBytes(txBytes).
WithVoteInfos(app.voteInfos)
WithTxBytes(txBytes)
// WithVoteInfos(app.voteInfos) // TODO: identify if this is needed
ctx = ctx.WithConsensusParams(app.GetConsensusParams(ctx))
+197
View File
@@ -0,0 +1,197 @@
package baseapp
import (
"time"
abci "github.com/cometbft/cometbft/abci/types"
"cosmossdk.io/core/comet"
)
var _ comet.BlockInfo = (*cometInfo)(nil)
// CometInfo defines the properties provided by comet to the application
type cometInfo struct {
Misbehavior []abci.Misbehavior
ValidatorsHash []byte
ProposerAddress []byte
LastCommit abci.CommitInfo
}
func (r cometInfo) GetEvidence() comet.EvidenceList {
return evidenceWrapper{evidence: r.Misbehavior}
}
func (r cometInfo) GetValidatorsHash() []byte {
return r.ValidatorsHash
}
func (r cometInfo) GetProposerAddress() []byte {
return r.ProposerAddress
}
func (r cometInfo) GetLastCommit() comet.CommitInfo {
return commitInfoWrapper{r.LastCommit}
}
type evidenceWrapper struct {
evidence []abci.Misbehavior
}
func (e evidenceWrapper) Len() int {
return len(e.evidence)
}
func (e evidenceWrapper) Get(i int) comet.Evidence {
return misbehaviorWrapper{e.evidence[i]}
}
// commitInfoWrapper is a wrapper around abci.CommitInfo that implements CommitInfo interface
type commitInfoWrapper struct {
abci.CommitInfo
}
var _ comet.CommitInfo = (*commitInfoWrapper)(nil)
func (c commitInfoWrapper) Round() int32 {
return c.CommitInfo.Round
}
func (c commitInfoWrapper) Votes() comet.VoteInfos {
return abciVoteInfoWrapper{c.CommitInfo.Votes}
}
// abciVoteInfoWrapper is a wrapper around abci.VoteInfo that implements VoteInfos interface
type abciVoteInfoWrapper struct {
votes []abci.VoteInfo
}
var _ comet.VoteInfos = (*abciVoteInfoWrapper)(nil)
func (e abciVoteInfoWrapper) Len() int {
return len(e.votes)
}
func (e abciVoteInfoWrapper) Get(i int) comet.VoteInfo {
return voteInfoWrapper{e.votes[i]}
}
// voteInfoWrapper is a wrapper around abci.VoteInfo that implements VoteInfo interface
type voteInfoWrapper struct {
abci.VoteInfo
}
var _ comet.VoteInfo = (*voteInfoWrapper)(nil)
func (v voteInfoWrapper) SignedLastBlock() bool {
return v.VoteInfo.SignedLastBlock
}
func (v voteInfoWrapper) Validator() comet.Validator {
return validatorWrapper{v.VoteInfo.Validator}
}
// validatorWrapper is a wrapper around abci.Validator that implements Validator interface
type validatorWrapper struct {
abci.Validator
}
var _ comet.Validator = (*validatorWrapper)(nil)
func (v validatorWrapper) Address() []byte {
return v.Validator.Address
}
func (v validatorWrapper) Power() int64 {
return v.Validator.Power
}
type misbehaviorWrapper struct {
abci.Misbehavior
}
func (m misbehaviorWrapper) Type() comet.MisbehaviorType {
return comet.MisbehaviorType(m.Misbehavior.Type)
}
func (m misbehaviorWrapper) Height() int64 {
return m.Misbehavior.Height
}
func (m misbehaviorWrapper) Validator() comet.Validator {
return validatorWrapper{m.Misbehavior.Validator}
}
func (m misbehaviorWrapper) Time() time.Time {
return m.Misbehavior.Time
}
func (m misbehaviorWrapper) TotalVotingPower() int64 {
return m.Misbehavior.TotalVotingPower
}
type prepareProposalInfo struct {
abci.RequestPrepareProposal
}
var _ comet.BlockInfo = (*prepareProposalInfo)(nil)
func (r prepareProposalInfo) GetEvidence() comet.EvidenceList {
return evidenceWrapper{r.Misbehavior}
}
func (r prepareProposalInfo) GetValidatorsHash() []byte {
return r.NextValidatorsHash
}
func (r prepareProposalInfo) GetProposerAddress() []byte {
return r.RequestPrepareProposal.ProposerAddress
}
func (r prepareProposalInfo) GetLastCommit() comet.CommitInfo {
return extendedCommitInfoWrapper{r.RequestPrepareProposal.LocalLastCommit}
}
var _ comet.BlockInfo = (*prepareProposalInfo)(nil)
type extendedCommitInfoWrapper struct {
abci.ExtendedCommitInfo
}
var _ comet.CommitInfo = (*extendedCommitInfoWrapper)(nil)
func (e extendedCommitInfoWrapper) Round() int32 {
return e.ExtendedCommitInfo.Round
}
func (e extendedCommitInfoWrapper) Votes() comet.VoteInfos {
return extendedVoteInfoWrapperList{e.ExtendedCommitInfo.Votes}
}
type extendedVoteInfoWrapperList struct {
votes []abci.ExtendedVoteInfo
}
var _ comet.VoteInfos = (*extendedVoteInfoWrapperList)(nil)
func (e extendedVoteInfoWrapperList) Len() int {
return len(e.votes)
}
func (e extendedVoteInfoWrapperList) Get(i int) comet.VoteInfo {
return extendedVoteInfoWrapper{e.votes[i]}
}
type extendedVoteInfoWrapper struct {
abci.ExtendedVoteInfo
}
var _ comet.VoteInfo = (*extendedVoteInfoWrapper)(nil)
func (e extendedVoteInfoWrapper) SignedLastBlock() bool {
return e.ExtendedVoteInfo.SignedLastBlock
}
func (e extendedVoteInfoWrapper) Validator() comet.Validator {
return validatorWrapper{e.ExtendedVoteInfo.Validator}
}