keeper

package
v0.0.41 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

NewMsgServerImpl returns an implementation of the module MsgServer interface.

Types

type Hooks added in v0.0.40

type Hooks struct {
	Validator types.UValidatorHooks
	Ballot    types.BallotHooks
}

Hooks bundles every external-module callback surface that x/uvalidator exposes. Each field is independently optional — nil means "don't register that surface."

  • Validator: validator-lifecycle callbacks (AfterValidatorAdded, AfterValidatorRemoved, AfterValidatorStatusChanged). Today consumed by x/utss + x/uexecutor (typically wrapped in a MultiUValidatorHooks for fan-out).

  • Ballot: ballot-lifecycle terminal callbacks (AfterBallotTerminal). Today consumed by x/uexecutor only — for the F-2026-16642 per-variant audit-trail cleanup. If a future module needs to react to ballot terminals, introduce a MultiBallotHooks wrapper following the MultiUValidatorHooks pattern.

type Keeper

type Keeper struct {

	// state management
	Params collections.Item[types.Params]
	// TODO: write the migration from sdk.ValAddress to current structure
	UniversalValidatorSet collections.Map[sdk.ValAddress, types.UniversalValidator] // Set of all registered Universal Validator addresses

	// Ballots management
	Ballots            collections.Map[string, types.Ballot] // stores the actual ballot object, keyed by ballot ID
	ActiveBallotIDs    collections.KeySet[string]            // set of ballot IDs currently collecting votes
	ExpiredBallotIDs   collections.KeySet[string]            // set of ballot IDs that have expired (not yet pruned)
	FinalizedBallotIDs collections.KeySet[string]            // set of ballot IDs that are PASSED or REJECTED

	StakingKeeper      types.StakingKeeper
	SlashingKeeper     types.SlashingKeeper
	UtssKeeper         types.UtssKeeper
	BankKeeper         types.BankKeeper
	AuthKeeper         types.AccountKeeper
	DistributionKeeper types.DistributionKeeper
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeService storetypes.KVStoreService,
	logger log.Logger,
	authority string,
	bankKeeper types.BankKeeper,
	authKeeper types.AccountKeeper,
	distributionKeeper types.DistributionKeeper,
	stakingKeeper types.StakingKeeper,
	slashingKeeper types.SlashingKeeper,
	utssKeeper types.UtssKeeper,
) Keeper

NewKeeper creates a new Keeper instance

func (Keeper) AddUniversalValidator

func (k Keeper) AddUniversalValidator(
	ctx context.Context,
	coreValidatorAddr string,
	networkInfo types.NetworkInfo,
) error

new validator -> added as a PENDING_JOIN status if existing: inactive -> added as a PENDING_JOIN status any other status -> revert AddUniversalValidator registers or reactivates a core validator as a universal validator. It ensures the core validator exists, is bonded, and handles lifecycle reactivation.

func (Keeper) AddVoteToBallot

func (k Keeper) AddVoteToBallot(
	ctx context.Context,
	ballot types.Ballot,
	address string,
	voteResult types.VoteResult,
) (types.Ballot, error)

func (Keeper) AllActiveBallotIDs

AllActiveBallotIDs implements types.QueryServer.

func (Keeper) CheckIfFinalizingVote

func (k Keeper) CheckIfFinalizingVote(ctx context.Context, b types.Ballot) (types.Ballot, bool, error)

CheckIfFinalizingVote inspects whether the just-cast vote pushes the ballot over its threshold and, if so, drives the finalization through MarkBallotFinalized — the single canonical write path for terminal status transitions, which applies CEI-style ordering on the secondary indexes.

func (Keeper) CreateBallot

func (k Keeper) CreateBallot(
	ctx context.Context,
	id string,
	ballotType types.BallotObservationType,
	eligibleVoters []string,
	votingThreshold int64,
	expiryAfterBlocks int64,
) (types.Ballot, error)

CreateBallot creates a new ballot with the given parameters, stores it, and marks it as active.

func (Keeper) DeleteBallot

func (k Keeper) DeleteBallot(ctx context.Context, id string) error

DeleteBallot removes a ballot and its ID from all collections

func (Keeper) ExpireBallotsBeforeHeight

func (k Keeper) ExpireBallotsBeforeHeight(ctx context.Context, currentHeight int64) error

ExpireBallotsBeforeHeight checks active ballots and marks expired ones. It uses a two-phase approach: first collect IDs to expire, then mutate, to avoid modifying the ActiveBallotIDs collection during iteration.

func (*Keeper) ExportGenesis

func (k *Keeper) ExportGenesis(ctx context.Context) *types.GenesisState

ExportGenesis exports the module's state to a genesis state.

func (Keeper) GetAdmin added in v0.0.40

func (k Keeper) GetAdmin(ctx context.Context) (string, error)

GetAdmin returns the Params.Admin address. Used by other modules' admin-gated paths.

func (Keeper) GetAllUniversalValidators

func (k Keeper) GetAllUniversalValidators(ctx context.Context) ([]types.UniversalValidator, error)

GetAllUniversalValidators returns all validators in the UniversalValidatorSet.

func (Keeper) GetBallot

func (k Keeper) GetBallot(ctx context.Context, id string) (types.Ballot, error)

GetBallot retrieves a ballot by ID

func (Keeper) GetBlockHeight

func (k Keeper) GetBlockHeight(ctx context.Context) (int64, error)

func (Keeper) GetEligibleVoters

func (k Keeper) GetEligibleVoters(ctx context.Context) ([]types.UniversalValidator, error)

GetEligibleVoters returns all validators that are eligible to vote on external transactions.

Eligibility requires BOTH:

  • UV lifecycle status is ACTIVE or PENDING_JOIN; AND
  • the underlying Cosmos staking validator is bonded and not tombstoned.

The staking-state filter prevents stranded UVs (still ACTIVE on paper but unbonded/jailed/tombstoned on the base chain) from inflating the ballot quorum denominator. Vote admission already rejects such signers, so without this filter the ballot threshold can become unreachable and finalization deadlocks.

func (Keeper) GetOrCreateBallot

func (k Keeper) GetOrCreateBallot(
	ctx context.Context,
	id string,
	ballotType types.BallotObservationType,
	voters []string,
	votesNeeded int64,
	expiryAfterBlocks int64,
) (types.Ballot, bool, error)

GetOrCreateBallot returns the ballot if it exists, otherwise creates it.

func (Keeper) GetUniversalValidator

func (k Keeper) GetUniversalValidator(
	ctx context.Context,
	addr sdk.ValAddress,
) (types.UniversalValidator, bool, error)

GetUniversalValidator returns a single UniversalValidator by address.

func (Keeper) GetValidatorsByStatus

func (k Keeper) GetValidatorsByStatus(ctx context.Context, status types.UVStatus) ([]types.UniversalValidator, error)

GetValidatorsByStatus returns a list of validators filtered by status (ACTIVE, PENDING_JOIN, etc.).

func (Keeper) HandleBaseValidatorBonded added in v0.0.40

func (k Keeper) HandleBaseValidatorBonded(ctx sdk.Context, valAddr sdk.ValAddress)

HandleBaseValidatorBonded auto-revives a UV when the base validator returns to bonded state, but only if the latest lifecycle event was STAKING_HOOK- driven. PENDING_LEAVE → ACTIVE, INACTIVE → PENDING_JOIN; admin-driven removals stay put until operator reactivates. Errors are logged and swallowed.

func (Keeper) HandleBaseValidatorUnbonding added in v0.0.40

func (k Keeper) HandleBaseValidatorUnbonding(ctx sdk.Context, valAddr sdk.ValAddress)

HandleBaseValidatorUnbonding transitions the UV out of voting eligibility when the base validator begins unbonding. ACTIVE → PENDING_LEAVE, PENDING_JOIN → INACTIVE; other states no-op. Bypasses admin TSS guards since the base chain has already invalidated the validator. Records STAKING_HOOK reason for later auto-revival on re-bond. Errors are logged and swallowed so staking EndBlocker is never blocked.

func (Keeper) HasUniversalValidatorInSet

func (k Keeper) HasUniversalValidatorInSet(ctx context.Context, uvAddr sdk.ValAddress) (bool, error)

func (*Keeper) InitGenesis

func (k *Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) error

InitGenesis initializes the module's state from a genesis state.

func (Keeper) IsActiveUniversalValidator added in v0.0.13

func (k Keeper) IsActiveUniversalValidator(
	ctx context.Context,
	validatorOperatorAddr string,
) (bool, error)

IsActiveUniversalValidator returns true if the given validator address is currently registered as an active universal validator.

func (Keeper) IsBondedUniversalValidator

func (k Keeper) IsBondedUniversalValidator(ctx context.Context, universalValidator string) (bool, error)

func (Keeper) IsTombstonedUniversalValidator

func (k Keeper) IsTombstonedUniversalValidator(ctx context.Context, universalValidator string) (bool, error)

func (Keeper) Logger

func (k Keeper) Logger() log.Logger

func (Keeper) MarkBallotExpired

func (k Keeper) MarkBallotExpired(ctx context.Context, id string) error

MarkBallotExpired moves a ballot from active to expired. Side-effect ordering: secondary indexes are updated before the canonical ballot record is rewritten, so the status field is only persisted once the active/expired set membership is in its final shape (defensive CEI-style ordering; collections.KeySet.Remove is a no-op on absent keys, so retries remain safe).

Fires the BallotHooks terminal callback (if registered) AFTER all writes have committed. Hook errors are logged but do NOT block the terminal transition — the terminal status is the desired outcome regardless of secondary-index side-effect failure.

func (Keeper) MarkBallotFinalized

func (k Keeper) MarkBallotFinalized(ctx context.Context, id string, status types.BallotStatus) error

MarkBallotFinalized moves a ballot from active to finalized (PASSED or REJECTED). Side-effect ordering matches MarkBallotExpired: secondary indexes are updated before the canonical ballot record is rewritten with its final status.

Fires the BallotHooks terminal callback (if registered) AFTER all writes have committed. Hook errors are logged but do NOT block the terminal transition.

func (Keeper) RecomputeBallotQuorum added in v0.0.40

func (k Keeper) RecomputeBallotQuorum(ctx context.Context, ballotID string) (
	oldEligibleCount, newEligibleCount, oldThreshold, newThreshold int64,
	newStatus types.BallotStatus,
	err error,
)

RecomputeBallotQuorum rebuilds a pending ballot's eligible-voter list and voting threshold against the current eligible-voter set, preserving votes from voters still eligible and dropping votes from voters no longer eligible.

If the recomputed eligible count is zero, the ballot is marked EXPIRED (no path to finalization). Otherwise it stays PENDING with the new parameters; downstream UVs must re-vote on the same ballot to trigger finalize+execute via the normal flow.

Returns the old/new counts and threshold for the response.

func (Keeper) RemoveUniversalValidator

func (k Keeper) RemoveUniversalValidator(
	ctx context.Context,
	universalValidatorAddr string,
) error

RemoveUniversalValidator handles universal validator removal lifecycle:

  • ACTIVE -> PENDING_LEAVE
  • PENDING_JOIN ->
  • if in current TSS process (ongoing) → revert (keygen ongoing)
  • if not in current TSS process (ongoing) → INACTIVE

It ensures the validator exists before removal and triggers hooks on status change.

func (Keeper) RemoveUniversalValidatorFromSet

func (k Keeper) RemoveUniversalValidatorFromSet(ctx context.Context, addr sdk.ValAddress) error

func (Keeper) SchemaBuilder

func (k Keeper) SchemaBuilder() *collections.SchemaBuilder

func (Keeper) SetBallot

func (k Keeper) SetBallot(ctx context.Context, ballot types.Ballot) error

SetBallot updates an existing ballot

func (*Keeper) SetHooks

func (k *Keeper) SetHooks(h Hooks) *Keeper

SetHooks registers the external-module hook implementations on this keeper. Each Hooks field is independently optional; nil means the corresponding surface is not registered. Calling SetHooks twice panics — all hook wiring must happen in a single registration call (typically inside app.go after every keeper has been constructed).

func (Keeper) StakingHooks added in v0.0.40

func (k Keeper) StakingHooks() StakingHooks

func (Keeper) UpdateParams

func (k Keeper) UpdateParams(ctx context.Context, params types.Params) error

updateParams is for updating params collections of the module

func (Keeper) UpdateUniversalValidator

func (k Keeper) UpdateUniversalValidator(
	ctx context.Context,
	coreValidatorAddr string,
	networkInfo types.NetworkInfo,
) error

UpdateUniversalValidator updates the metadata of the registered universal validator

func (Keeper) UpdateUniversalValidatorStatus

func (k Keeper) UpdateUniversalValidatorStatus(
	ctx context.Context,
	coreValidatorAddr string,
	newStatus types.UVStatus,
) error

UpdateUniversalValidatorStatus updates the UV status from PENDING_LEAVE to ACTIVE any other case of status change must fail

func (Keeper) UpdateValidatorStatus

func (k Keeper) UpdateValidatorStatus(ctx context.Context, addr sdk.ValAddress, newStatus types.UVStatus, reason types.TransitionReason) error

UpdateValidatorStatus appends a lifecycle event and persists the new status. The reason is consulted by HandleBaseValidatorBonded to decide auto-revival.

func (Keeper) VoteOnBallot

func (k Keeper) VoteOnBallot(
	ctx context.Context,
	id string,
	ballotType types.BallotObservationType,
	voter string,
	voteResult types.VoteResult,
	voters []string,
	votesNeeded int64,
	expiryAfterBlocks int64,
) (
	ballot types.Ballot,
	isFinalized bool,
	isNew bool,
	err error)

type MultiUValidatorHooks

type MultiUValidatorHooks []types.UValidatorHooks

MultiUValidatorHooks allows multiple modules to listen to the same events.

func NewMultiUValidatorHooks

func NewMultiUValidatorHooks(hooks ...types.UValidatorHooks) MultiUValidatorHooks

NewMultiUValidatorHooks creates a new combined hook instance.

func (MultiUValidatorHooks) AfterValidatorAdded

func (mh MultiUValidatorHooks) AfterValidatorAdded(ctx sdk.Context, valAddr sdk.ValAddress)

AfterValidatorAdded calls every hook in the list.

func (MultiUValidatorHooks) AfterValidatorRemoved

func (mh MultiUValidatorHooks) AfterValidatorRemoved(ctx sdk.Context, valAddr sdk.ValAddress)

AfterValidatorRemoved calls every hook in the list.

func (MultiUValidatorHooks) AfterValidatorStatusChanged

func (mh MultiUValidatorHooks) AfterValidatorStatusChanged(ctx sdk.Context, valAddr sdk.ValAddress, oldStatus, newStatus types.UVStatus)

AfterValidatorStatusChanged calls every hook in the list.

type Querier

type Querier struct {
	Keeper
}

func NewQuerier

func NewQuerier(keeper Keeper) Querier

func (Querier) AllActiveBallots

ActiveBallots implements types.QueryServer.

func (Querier) AllBallots

AllBallots implements types.QueryServer.

func (Querier) AllExpiredBallotIDs

AllExpiredBallotIDs implements types.QueryServer.

func (Querier) AllExpiredBallots

AllExpiredBallots implements types.QueryServer.

func (Querier) AllFinalizedBallotIDs

FinalizedBallotIDs implements types.QueryServer.

func (Querier) AllFinalizedBallots

FinalizedBallots implements types.QueryServer.

func (Querier) Ballot

Ballot implements types.QueryServer.

func (Querier) Params

type StakingHooks added in v0.0.40

type StakingHooks struct {
	// contains filtered or unexported fields
}

StakingHooks implements stakingtypes.StakingHooks. AfterValidatorBeginUnbonding and AfterValidatorBonded keep UV lifecycle in sync with base-chain state; the rest are no-op stubs.

func (StakingHooks) AfterDelegationModified added in v0.0.40

func (h StakingHooks) AfterDelegationModified(_ context.Context, _ sdk.AccAddress, _ sdk.ValAddress) error

func (StakingHooks) AfterUnbondingInitiated added in v0.0.40

func (h StakingHooks) AfterUnbondingInitiated(_ context.Context, _ uint64) error

func (StakingHooks) AfterValidatorBeginUnbonding added in v0.0.40

func (h StakingHooks) AfterValidatorBeginUnbonding(ctx context.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) error

func (StakingHooks) AfterValidatorBonded added in v0.0.40

func (h StakingHooks) AfterValidatorBonded(ctx context.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) error

func (StakingHooks) AfterValidatorCreated added in v0.0.40

func (h StakingHooks) AfterValidatorCreated(_ context.Context, _ sdk.ValAddress) error

func (StakingHooks) AfterValidatorRemoved added in v0.0.40

func (h StakingHooks) AfterValidatorRemoved(_ context.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error

func (StakingHooks) BeforeDelegationCreated added in v0.0.40

func (h StakingHooks) BeforeDelegationCreated(_ context.Context, _ sdk.AccAddress, _ sdk.ValAddress) error

func (StakingHooks) BeforeDelegationRemoved added in v0.0.40

func (h StakingHooks) BeforeDelegationRemoved(_ context.Context, _ sdk.AccAddress, _ sdk.ValAddress) error

func (StakingHooks) BeforeDelegationSharesModified added in v0.0.40

func (h StakingHooks) BeforeDelegationSharesModified(_ context.Context, _ sdk.AccAddress, _ sdk.ValAddress) error

func (StakingHooks) BeforeValidatorModified added in v0.0.40

func (h StakingHooks) BeforeValidatorModified(_ context.Context, _ sdk.ValAddress) error

func (StakingHooks) BeforeValidatorSlashed added in v0.0.40

func (h StakingHooks) BeforeValidatorSlashed(_ context.Context, _ sdk.ValAddress, _ math.LegacyDec) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL