mukan-sdk/x/consensus/keeper/keeper.go
Mukan Erkin Törük abb1ff956e
Some checks are pending
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
refactor: complete sovereign stack cleanup — all github.com upstream refs purged
2026-05-11 03:46:06 +03:00

114 lines
3 KiB
Go

package keeper
import (
"context"
cmtproto "git.cw.tr/mukan-network/mukan-consensus/proto/tendermint/types"
cmttypes "git.cw.tr/mukan-network/mukan-consensus/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"cosmossdk.io/collections"
"cosmossdk.io/core/event"
storetypes "cosmossdk.io/core/store"
"cosmossdk.io/errors"
"git.cw.tr/mukan-network/mukan-sdk/codec"
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
"git.cw.tr/mukan-network/mukan-sdk/x/consensus/exported"
"git.cw.tr/mukan-network/mukan-sdk/x/consensus/types"
govtypes "git.cw.tr/mukan-network/mukan-sdk/x/gov/types"
)
var StoreKey = "Consensus"
type Keeper struct {
storeService storetypes.KVStoreService
event event.Service
authority string
ParamsStore collections.Item[cmtproto.ConsensusParams]
}
var _ exported.ConsensusParamSetter = Keeper{}.ParamsStore
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,
ParamsStore: collections.NewItem(sb, collections.NewPrefix("Consensus"), "params", codec.CollValue[cmtproto.ConsensusParams](cdc)),
}
}
func (k *Keeper) GetAuthority() string {
return k.authority
}
// Querier
var _ types.QueryServer = Keeper{}
// Params queries params of consensus module
func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
params, err := k.ParamsStore.Get(ctx)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.QueryParamsResponse{Params: &params}, nil
}
// MsgServer
var _ types.MsgServer = Keeper{}
func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.GetAuthority() != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), msg.Authority)
}
consensusParams, err := msg.ToProtoConsensusParams()
if err != nil {
return nil, err
}
paramsProto, err := k.ParamsStore.Get(ctx)
if err != nil {
return nil, err
}
// initialize version params with zero value if not set
if paramsProto.Version == nil {
paramsProto.Version = &cmtproto.VersionParams{}
}
params := cmttypes.ConsensusParamsFromProto(paramsProto)
nextParams := params.Update(&consensusParams)
if err := nextParams.ValidateBasic(); err != nil {
return nil, err
}
sdkCtx := sdk.UnwrapSDKContext(ctx)
if err := params.ValidateUpdate(&consensusParams, sdkCtx.BlockHeader().Height); err != nil {
return nil, err
}
if err := k.ParamsStore.Set(ctx, nextParams.ToProto()); err != nil {
return nil, err
}
if err := k.event.EventManager(ctx).EmitKV(
ctx,
"update_consensus_params",
event.Attribute{Key: "authority", Value: msg.Authority},
event.Attribute{Key: "parameters", Value: consensusParams.String()}); err != nil {
return nil, err
}
return &types.MsgUpdateParamsResponse{}, nil
}