Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add header and comet info service #15850

Merged
merged 38 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
63cc148
experimentation of block info service
tac0turtle Apr 15, 2023
0ed3898
remove nil check
tac0turtle Apr 15, 2023
1d97881
move blockinfo to types
tac0turtle Apr 15, 2023
ef59eb7
define our own types
tac0turtle Apr 16, 2023
0144793
fix build
tac0turtle Apr 16, 2023
947de98
fix build
tac0turtle Apr 16, 2023
d9437f2
address comments
tac0turtle Apr 16, 2023
5f772ce
fix build & lint
tac0turtle Apr 17, 2023
e1f53cc
Merge branch 'main' into marko/block_info
tac0turtle Apr 17, 2023
3f136c0
fix build & lint
tac0turtle Apr 17, 2023
cf9b6d7
minor change
tac0turtle Apr 17, 2023
a5d72fd
fix test
tac0turtle Apr 17, 2023
7ed99df
fix tests
tac0turtle Apr 17, 2023
ec6f5d5
add getblockinfo
tac0turtle Apr 17, 2023
56c340e
implement changes
tac0turtle Apr 17, 2023
5b1cd47
address feedback
tac0turtle Apr 18, 2023
0206cb2
Merge branch 'main' into marko/block_info
tac0turtle Apr 18, 2023
a6d45bf
adjust adr
tac0turtle Apr 18, 2023
6995674
make it structs
tac0turtle Apr 18, 2023
06fcbe5
update docs
tac0turtle Apr 18, 2023
22ae764
add docs
tac0turtle Apr 18, 2023
4b85274
fixxie
tac0turtle Apr 18, 2023
46fee3c
WIP on comet block info (#15889)
aaronc Apr 24, 2023
2cfb91d
fix
tac0turtle Apr 25, 2023
9c509b2
minor changes
tac0turtle Apr 25, 2023
99903f9
adjust changes
tac0turtle Apr 25, 2023
d3b8000
implement voteinfos interface
tac0turtle Apr 26, 2023
f6aafd0
rename comet.Service to comet.InfoService
tac0turtle Apr 28, 2023
a6f68c0
address cosmetic changes
tac0turtle Apr 30, 2023
938b449
fix evidence integration tests
tac0turtle Apr 30, 2023
5d313a1
Merge branch 'main' into marko/block_info
tac0turtle Apr 30, 2023
02e3dde
fix build
tac0turtle May 1, 2023
640086d
Merge branch 'main' into marko/block_info
tac0turtle May 2, 2023
95864c7
fix tests
tac0turtle May 2, 2023
238de6d
Merge branch 'main' into marko/block_info
tac0turtle May 3, 2023
b9f01ea
migrate evidence to use len and get
tac0turtle May 3, 2023
3a692ec
fix lint and test in evidence module
tac0turtle May 3, 2023
abf9ac7
fix integration test and go mod tidy all modules
tac0turtle May 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
WithHeaderHash(req.Hash)
}

// Set blockInfo for module use
app.BlockInfo = NewBlockInfo(req)

if app.beginBlocker != nil {
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
var err error
res, err = app.beginBlocker(app.deliverState.ctx, req)
Expand Down
2 changes: 2 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ type BaseApp struct {
streamingManager storetypes.StreamingManager

chainID string

BlockInfo BlockInfoService
}

// NewBaseApp returns a reference to an initialized BaseApp. It accepts a
Expand Down
65 changes: 65 additions & 0 deletions baseapp/block_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package baseapp

import abci "github.com/cometbft/cometbft/abci/types"

// ======================================================
// BlockInfoService
// ======================================================

// BlockInfoService is the service that runtime will provide to modules which need Comet block information.
type BlockInfoService interface {
GetHeight() int64 // GetHeight returns the height of the block
Misbehavior() []abci.Misbehavior // Misbehavior returns the misbehavior of the block
GetHeaderHash() []byte // GetHeaderHash returns the hash of the block header
// GetValidatorsHash returns the hash of the validators
// For Comet, it is the hash of the next validator set
GetValidatorsHash() []byte
GetProposerAddress() []byte // GetProposerAddress returns the address of the block proposer
GetDecidedLastCommit() abci.CommitInfo // GetDecidedLastCommit returns the last commit info
}

var _ BlockInfoService = (*BlockInfo)(nil)

type BlockInfo struct {
Height int64
Evidence []abci.Misbehavior
HeaderHash []byte
ValidatorsHash []byte
ProposerAddress []byte
DecidedLastCommit abci.CommitInfo
}

func NewBlockInfo(bg abci.RequestBeginBlock) *BlockInfo {
return &BlockInfo{
Height: bg.Header.Height,
Evidence: bg.ByzantineValidators,
HeaderHash: bg.Hash,
ValidatorsHash: bg.Header.NextValidatorsHash,
ProposerAddress: bg.Header.ProposerAddress,
DecidedLastCommit: bg.LastCommitInfo,
}
}

func (bis *BlockInfo) GetHeight() int64 {
return bis.Height
}

func (bis *BlockInfo) Misbehavior() []abci.Misbehavior {
return bis.Evidence
}

func (bis *BlockInfo) GetHeaderHash() []byte {
return bis.HeaderHash
}

func (bis *BlockInfo) GetValidatorsHash() []byte {
return bis.ValidatorsHash
}

func (bis *BlockInfo) GetProposerAddress() []byte {
return bis.ProposerAddress
}

func (bis *BlockInfo) GetDecidedLastCommit() abci.CommitInfo {
return bis.DecidedLastCommit
}
2 changes: 1 addition & 1 deletion runtime/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type BlockInfoService interface {
Misbehavior() []abci.Misbehavior // Misbehavior returns the misbehavior of the block
GetHeaderHash() []byte // GetHeaderHash returns the hash of the block header
// GetValidatorsHash returns the hash of the validators
// For Comet, it is the hash of the next validators
// For Comet, it is the hash of the next validator set
GetValidatorsHash() []byte
GetProposerAddress() []byte // GetProposerAddress returns the address of the block proposer
GetDecidedLastCommit() abci.CommitInfo // GetDecidedLastCommit returns the last commit info
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func NewSimApp(

// create evidence keeper with router
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, keys[evidencetypes.StoreKey], app.StakingKeeper, app.SlashingKeeper, app.AccountKeeper.GetAddressCodec(),
appCodec, keys[evidencetypes.StoreKey], app.StakingKeeper, app.SlashingKeeper, app.AccountKeeper.GetAddressCodec(), app.BlockInfo,
)
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper
Expand Down
6 changes: 4 additions & 2 deletions x/evidence/keeper/abci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"context"
"fmt"
"time"

Expand All @@ -13,10 +14,11 @@ import (

// BeginBlocker iterates through and handles any newly discovered evidence of
// misbehavior submitted by CometBFT. Currently, only equivocation is handled.
func (k Keeper) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) {
func (k Keeper) BeginBlocker(goctx context.Context) {
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)

for _, tmEvidence := range req.ByzantineValidators {
ctx := sdk.UnwrapSDKContext(goctx)
for _, tmEvidence := range k.blockInfo.Misbehavior() {
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
switch tmEvidence.Type {
// It's still ongoing discussion how should we treat and slash attacks with
// premeditation. So for now we agree to treat them in the same way.
Expand Down
6 changes: 5 additions & 1 deletion x/evidence/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand All @@ -28,19 +29,22 @@ type Keeper struct {
stakingKeeper types.StakingKeeper
slashingKeeper types.SlashingKeeper
addressCodec address.Codec

blockInfo baseapp.BlockInfoService
}

// NewKeeper creates a new Keeper object.
func NewKeeper(
cdc codec.BinaryCodec, storeKey storetypes.StoreKey, stakingKeeper types.StakingKeeper,
slashingKeeper types.SlashingKeeper, ac address.Codec,
slashingKeeper types.SlashingKeeper, ac address.Codec, bi baseapp.BlockInfoService,
) *Keeper {
return &Keeper{
cdc: cdc,
storeKey: storeKey,
stakingKeeper: stakingKeeper,
slashingKeeper: slashingKeeper,
addressCodec: ac,
blockInfo: bi,
}
}

Expand Down
17 changes: 11 additions & 6 deletions x/evidence/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"cosmossdk.io/x/evidence/simulation"
"cosmossdk.io/x/evidence/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -31,7 +32,6 @@ import (
)

var (
_ module.BeginBlockAppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
)
Expand Down Expand Up @@ -125,8 +125,9 @@ func NewAppModule(keeper keeper.Keeper) AppModule {
}

var (
_ appmodule.AppModule = AppModule{}
_ appmodule.HasServices = AppModule{}
_ appmodule.AppModule = AppModule{}
_ appmodule.HasServices = AppModule{}
_ appmodule.HasBeginBlocker = AppModule{}
)

// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
Expand Down Expand Up @@ -169,8 +170,10 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
func (AppModule) ConsensusVersion() uint64 { return 1 }

// BeginBlock executes all ABCI BeginBlock logic respective to the evidence module.
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
am.keeper.BeginBlocker(ctx, req)
func (am AppModule) BeginBlock(ctx context.Context) error {
am.keeper.BeginBlocker(ctx)

return nil
}

// AppModuleSimulation functions
Expand Down Expand Up @@ -209,6 +212,8 @@ type ModuleInputs struct {
StakingKeeper types.StakingKeeper
SlashingKeeper types.SlashingKeeper
AddressCodec address.Codec

BlockInfoService baseapp.BlockInfoService
}

type ModuleOutputs struct {
Expand All @@ -219,7 +224,7 @@ type ModuleOutputs struct {
}

func ProvideModule(in ModuleInputs) ModuleOutputs {
k := keeper.NewKeeper(in.Cdc, in.Key, in.StakingKeeper, in.SlashingKeeper, in.AddressCodec)
k := keeper.NewKeeper(in.Cdc, in.Key, in.StakingKeeper, in.SlashingKeeper, in.AddressCodec, in.BlockInfoService)
m := NewAppModule(*k)

return ModuleOutputs{EvidenceKeeper: *k, Module: m}
Expand Down