feat: add event core api to runtime (#15547)
Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
This commit is contained in:
parent
51f3e70a12
commit
9a09f8656b
@ -55,6 +55,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* (mempool) [#14484](https://github.com/cosmos/cosmos-sdk/pull/14484) Add priority nonce mempool option for transaction replacement.
|
||||
* (x/bank) [#14894](https://github.com/cosmos/cosmos-sdk/pull/14894) Return a human readable denomination for IBC vouchers when querying bank balances. Added a `ResolveDenom` parameter to `types.QueryAllBalancesRequest` and `--resolve-denom` flag to `GetBalancesCmd()`.
|
||||
* (x/gov) [#15151](https://github.com/cosmos/cosmos-sdk/pull/15151) Add `burn_vote_quorum`, `burn_proposal_deposit_prevote` and `burn_vote_veto` params to allow applications to decide if they would like to burn deposits
|
||||
* (runtime) [#15547](https://github.com/cosmos/cosmos-sdk/pull/15547) Allow runtime to pass event core api service to modules
|
||||
|
||||
### Improvements
|
||||
|
||||
|
||||
59
runtime/events.go
Normal file
59
runtime/events.go
Normal file
@ -0,0 +1,59 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cosmossdk.io/core/event"
|
||||
"google.golang.org/protobuf/runtime/protoiface"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var _ event.Service = (*EventService)(nil)
|
||||
|
||||
type EventService struct {
|
||||
Events
|
||||
}
|
||||
|
||||
func (es EventService) EventManager(ctx context.Context) event.Manager {
|
||||
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
||||
return &Events{sdkCtx.EventManager()}
|
||||
}
|
||||
|
||||
var _ event.Manager = (*Events)(nil)
|
||||
|
||||
type Events struct {
|
||||
sdk.EventManagerI
|
||||
}
|
||||
|
||||
func NewEventManager(ctx context.Context) event.Manager {
|
||||
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
||||
return &Events{sdkCtx.EventManager()}
|
||||
}
|
||||
|
||||
// Emit emits an typed event that is defined in the protobuf file.
|
||||
// In the future these events will be added to consensus
|
||||
func (e Events) Emit(ctx context.Context, event protoiface.MessageV1) error {
|
||||
return e.EventManagerI.EmitTypedEvent(event)
|
||||
}
|
||||
|
||||
// EmitKV emits a key value pair event
|
||||
func (e Events) EmitKV(ctx context.Context, eventType string, attrs ...event.Attribute) error {
|
||||
attributes := make([]sdk.Attribute, 0, len(attrs))
|
||||
|
||||
for _, attr := range attrs {
|
||||
attributes = append(attributes, sdk.NewAttribute(attr.Key, attr.Value))
|
||||
}
|
||||
|
||||
events := sdk.Events{
|
||||
sdk.NewEvent(eventType, attributes...),
|
||||
}
|
||||
e.EventManagerI.EmitEvents(events)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Emit emits an typed event that is defined in the protobuf file.
|
||||
// In the future these events will be added to consensus
|
||||
func (e Events) EmitNonConsensus(ctx context.Context, event protoiface.MessageV1) error {
|
||||
return e.EventManagerI.EmitTypedEvent(event)
|
||||
}
|
||||
@ -13,6 +13,7 @@ import (
|
||||
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
|
||||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/core/event"
|
||||
"cosmossdk.io/depinject"
|
||||
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
@ -63,6 +64,7 @@ func init() {
|
||||
ProvideKVStoreService,
|
||||
ProvideMemoryStoreService,
|
||||
ProvideTransientStoreService,
|
||||
ProvideEventService,
|
||||
),
|
||||
appmodule.Invoke(SetupAppBuilder),
|
||||
)
|
||||
@ -202,3 +204,7 @@ func ProvideTransientStoreService(key depinject.ModuleKey, app *AppBuilder) stor
|
||||
storeKey := ProvideTransientStoreKey(key, app)
|
||||
return transientStoreService{key: storeKey}
|
||||
}
|
||||
|
||||
func ProvideEventService() event.Service {
|
||||
return EventService{}
|
||||
}
|
||||
|
||||
@ -285,7 +285,7 @@ func NewSimApp(
|
||||
app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
|
||||
|
||||
// set the BaseApp's parameter store
|
||||
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String())
|
||||
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String(), runtime.EventService{})
|
||||
bApp.SetParamStore(app.ConsensusParamsKeeper.Params)
|
||||
|
||||
// add keepers
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/event"
|
||||
storetypes "cosmossdk.io/core/store"
|
||||
"cosmossdk.io/errors"
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
@ -20,16 +21,18 @@ var StoreKey = "Consensus"
|
||||
|
||||
type Keeper struct {
|
||||
storeService storetypes.KVStoreService
|
||||
event event.Service
|
||||
|
||||
authority string
|
||||
Params collections.Item[cmtproto.ConsensusParams]
|
||||
}
|
||||
|
||||
func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, authority string) Keeper {
|
||||
func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, authority string, em event.Service) Keeper {
|
||||
sb := collections.NewSchemaBuilder(storeService)
|
||||
return Keeper{
|
||||
storeService: storeService,
|
||||
authority: authority,
|
||||
event: em,
|
||||
Params: collections.NewItem(sb, collections.NewPrefix("Consensus"), "params", codec.CollValue[cmtproto.ConsensusParams](cdc)),
|
||||
}
|
||||
}
|
||||
@ -70,5 +73,13 @@ func (k Keeper) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := k.event.EventManager(ctx).EmitKV(
|
||||
ctx,
|
||||
"update_consensus_params",
|
||||
event.Attribute{Key: "authority", Value: req.Authority},
|
||||
event.Attribute{Key: "parameters", Value: consensusParams.String()}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.MsgUpdateParamsResponse{}, nil
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ func (s *KeeperTestSuite) SetupTest() {
|
||||
encCfg := moduletestutil.MakeTestEncodingConfig()
|
||||
storeService := runtime.NewKVStoreService(key)
|
||||
|
||||
keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, storeService, authtypes.NewModuleAddress(govtypes.ModuleName).String())
|
||||
keeper := consensusparamkeeper.NewKeeper(encCfg.Codec, storeService, authtypes.NewModuleAddress(govtypes.ModuleName).String(), runtime.EventService{})
|
||||
|
||||
s.ctx = ctx
|
||||
s.consensusParamsKeeper = &keeper
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
|
||||
modulev1 "cosmossdk.io/api/cosmos/consensus/module/v1"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/core/event"
|
||||
"cosmossdk.io/depinject"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
@ -147,6 +148,7 @@ type ConsensusInputs struct {
|
||||
Config *modulev1.Module
|
||||
Cdc codec.Codec
|
||||
StoreService storetypes.KVStoreService
|
||||
EventManager event.Service
|
||||
}
|
||||
|
||||
//nolint:revive
|
||||
@ -165,7 +167,7 @@ func ProvideModule(in ConsensusInputs) ConsensusOutputs {
|
||||
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
|
||||
}
|
||||
|
||||
k := keeper.NewKeeper(in.Cdc, in.StoreService, authority.String())
|
||||
k := keeper.NewKeeper(in.Cdc, in.StoreService, authority.String(), in.EventManager)
|
||||
m := NewAppModule(in.Cdc, k)
|
||||
baseappOpt := func(app *baseapp.BaseApp) {
|
||||
app.SetParamStore(k.Params)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user