keeper

package
v0.5.1-t2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MaxChallengeIndexBackfillPerBlock = 256

MaxChallengeIndexBackfillPerBlock bounds how many challenge records one EndBlocker pass converts into index entries. A chain whose history predates the indexes therefore converges over a few blocks instead of one slow block.

This is a wall-clock bound, not a gas bound: Begin/EndBlock run with an infinite block gas meter (baseapp sets NewInfiniteGasMeter before them), so a large chunk would not be rejected, it would only delay the round.

View Source
const MaxExpiredChallengesPerBlock = 64

MaxExpiredChallengesPerBlock bounds how many challenges a single EndBlocker pass settles. A large backlog therefore degrades into "a few more blocks" instead of one oversized block; the rest keep their (earlier) buckets and are picked up on the next block. Normal operation settles zero per block.

View Source
const SettlementTriggerAutomatic = "endblocker"

SettlementTriggerAutomatic is the submitter recorded when the EndBlocker — not a transaction — settled a challenge. Distinguishes "the window expired and the chain closed it" from "someone paid gas to close it" in events and queries, without implying any party decided the outcome.

Variables

This section is empty.

Functions

func ChallengeIndexInvariant

func ChallengeIndexInvariant(k Keeper) sdk.Invariant

ChallengeIndexInvariant checks that every V1 challenge record is reachable through the candidate index and that every OPEN record sits in the timeout bucket (and settled records do not).

Those two structures are derived state: if they drift, an OPEN challenge becomes invisible to approve (which would release funds it must block) or stops being swept. Migration 1→2 is the only writer that can legitimately leave them stale while it runs, so any break outside an upgrade is a real fault. Run with: uptickd query crisis invariant appmining challenge-index-consistent

func EntitlementPoolInvariant

func EntitlementPoolInvariant(k Keeper) sdk.Invariant

EntitlementPoolInvariant checks funded = available + reserved + paid per pool and, per denom, module balance >= Σ(available + reserved) across all pools sharing that denom (UGE doc15: unpaid liability must be fully backed).

func EpochSpentInvariant

func EpochSpentInvariant(k Keeper) sdk.Invariant

EpochSpentInvariant checks spent <= limit for every epoch budget.

func GasCreditConservationInvariant

func GasCreditConservationInvariant(k Keeper) sdk.Invariant

GasCreditConservationInvariant checks balance + total_consumed == total_issued.

func NewMsgServerImpl

func NewMsgServerImpl(k Keeper) types.MsgServer

NewMsgServerImpl returns a MsgServer implementation.

func OneSettlementInvariant

func OneSettlementInvariant(k Keeper) sdk.Invariant

OneSettlementInvariant is a structural check: settlement keys are unique by construction.

func OpenBudgetPoolInvariant

func OpenBudgetPoolInvariant(k Keeper) sdk.Invariant

OpenBudgetPoolInvariant checks sum(limit-spent) over open budgets per denom does not exceed the reward pool balance (vector: released/commitment vs pool).

func OpenChallengeEscrowInvariant

func OpenChallengeEscrowInvariant(k Keeper) sdk.Invariant

OpenChallengeEscrowInvariant checks challenge escrow balance covers sum of OPEN attestation bonds plus OPEN V1 entitlement challenge deposits per denom.

func RegisterInvariants

func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper)

RegisterInvariants registers appmining ledger invariants.

func SettlementAttestationInvariant

func SettlementAttestationInvariant(k Keeper) sdk.Invariant

SettlementAttestationInvariant checks each settlement references a FINALIZED attestation.

Types

type ChallengeIndexState

type ChallengeIndexState struct {
	Done   bool
	Cursor string // last challenge_id converted; empty when unstarted or done
}

ChallengeIndexState is the persisted progress of the one-time index rebuild. A single record is enough: the rebuild is a linear walk over the challenge table, so "done" plus "where we stopped" fully describes it.

type Keeper

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

Keeper of the appmining store.

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey storetypes.StoreKey,
	bank types.BankKeeper,
	ak types.AccountKeeper,
) Keeper

NewKeeper creates a new appmining Keeper.

func (Keeper) AutoConsumeForTx

func (k Keeper) AutoConsumeForTx(ctx sdk.Context, feePayer sdk.AccAddress, gasUsed uint64, sourceTxHash []byte) error

AutoConsumeForTx debits gas credit for an enrolled fee payer after a Cosmos tx. Not enrolled → no-op. Insufficient/paused/inactive → skip event, no error (ledger path must not roll back an otherwise-valid Cosmos tx until fee replacement lands). Unexpected store errors are returned.

func (Keeper) BackfillChallengeIndexes

func (k Keeper) BackfillChallengeIndexes(ctx sdk.Context) (int, error)

BackfillChallengeIndexes rebuilds both derived structures from the record table. It is idempotent and is run once from Migrate1to2 so chains that already hold V1 challenges before this change keep correct per-candidate reads. Returns the number of records visited.

func (Keeper) Candidate

func (Keeper) Challenge

func (Keeper) ChallengeIndexesReady

func (k Keeper) ChallengeIndexesReady(ctx sdk.Context) bool

ChallengeIndexesReady reports whether every stored challenge record is guaranteed to be reachable through the candidate index and the timeout buckets. Until it is true, per-candidate reads must fall back to the record table: a partially rebuilt index is worse than no index, because a candidate with two legacy challenges would look "indexed" after only one of them was converted.

func (Keeper) ConsumeGasCredit

func (k Keeper) ConsumeGasCredit(
	ctx sdk.Context,
	appID []byte,
	gasPayer string,
	amount string,
	sourceTxHash []byte,
) (remaining string, err error)

ConsumeGasCredit debits gas credit for an authorized payer. Shared by Msg server and Cosmos PostHandler auto-consume.

Storage note (P1-2): GasCreditConsumption records grow unboundedly by design and are NOT prunable. Each record is the only thing binding a source tx hash to exactly one debit; deleting one would let the same sourceTxHash be debited again (MsgConsumeGasCredit is a separate tx from the source tx, so cometbft dedup does not protect it). Growth is bounded in rate: one ~110B record per actual gas consumption, same order as the tx index itself. AuthNonce (the other append-only set) IS pruned -- see store.pruneAuthNonces -- because wire proofs carry expires_at.

func (Keeper) DeleteGasPayerIndex

func (k Keeper) DeleteGasPayerIndex(ctx sdk.Context, payer string)

DeleteGasPayerIndex removes the reverse index entry.

func (Keeper) DeleteOpenChallengeIndex

func (k Keeper) DeleteOpenChallengeIndex(ctx sdk.Context, appID []byte, epoch, challengeID uint64)

func (Keeper) DeleteOpenEntitlementChallenge

func (k Keeper) DeleteOpenEntitlementChallenge(ctx sdk.Context, entitlementID, challenger string)

func (Keeper) EnsureChallengeIndexes

func (k Keeper) EnsureChallengeIndexes(ctx sdk.Context) int

EnsureChallengeIndexes advances the index rebuild by at most MaxChallengeIndexBackfillPerBlock records and returns how many it visited.

It exists so a binary swap that does NOT run a store migration still ends up with correct per-candidate reads. Without it, challenges written by a v1 binary have neither a candidate index entry nor a timeout bucket, which makes an OPEN challenge invisible to approve (an approval could then release funds that an unresolved challenge should still block) and makes the sweeper never see it.

Properties:

  • Deterministic: reads only module state and params, walks the table in key order, so every validator performs byte-identical writes.
  • Idempotent and resumable: the cursor is persisted; re-running after a restart continues where it stopped, and re-processing a record rewrites the same bytes.
  • Cheap in steady state: one key read per block once Done is set.
  • Writes only records with an actual gap (missing index entry, or an OPEN record still missing its sealed deadline), so the cost tracks real backlog rather than total history.

func (Keeper) EntitlementChallenges

EntitlementChallenges lists V1 challenges with optional candidate_id and status filters. Legacy attestation challenges live in a different store and are served by OpenChallenges/Challenges.

With candidate_id it walks the per-candidate index, so the cost is O(challenges of that candidate) — the same structure approve relies on. Only the unfiltered listing (operator/explorer use, no tx path) scans everything.

func (Keeper) ExportGenesis

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

ExportGenesis exports full module state (BLOCK-2 fix).

func (Keeper) GasCredit

func (Keeper) GetAppIDByGasPayer

func (k Keeper) GetAppIDByGasPayer(ctx sdk.Context, payer string) ([]byte, bool)

GetAppIDByGasPayer returns the app bound to this gas payer, if any.

func (Keeper) GetApplication

func (k Keeper) GetApplication(ctx sdk.Context, appID []byte) (types.Application, bool)

func (Keeper) GetAssessmentSigner

func (k Keeper) GetAssessmentSigner(ctx sdk.Context, keyID string) (types.AssessmentSigner, bool)

func (Keeper) GetAttestation

func (k Keeper) GetAttestation(ctx sdk.Context, appID []byte, epoch uint64) (types.AttestationCommitment, bool)

func (Keeper) GetCandidate

func (k Keeper) GetCandidate(ctx sdk.Context, entitlementID string) (types.Candidate, bool)

func (Keeper) GetChallenge

func (k Keeper) GetChallenge(ctx sdk.Context, id uint64) (types.Challenge, bool)

func (Keeper) GetChallengeIndexState

func (k Keeper) GetChallengeIndexState(ctx sdk.Context) ChallengeIndexState

GetChallengeIndexState reads the rebuild state. A missing record means the indexes were never built, which is exactly the pre-upgrade situation.

func (Keeper) GetCredentialEntitlement

func (k Keeper) GetCredentialEntitlement(ctx sdk.Context, credentialID string) (string, bool)

func (Keeper) GetEntitlement

func (k Keeper) GetEntitlement(ctx sdk.Context, entitlementID string) (types.Entitlement, bool)

func (Keeper) GetEntitlementChallenge

func (k Keeper) GetEntitlementChallenge(ctx sdk.Context, challengeID string) (types.EntitlementChallenge, bool)

func (Keeper) GetEntitlementPool

func (k Keeper) GetEntitlementPool(ctx sdk.Context, poolID string) (types.Pool, bool)

func (Keeper) GetEpochBudget

func (k Keeper) GetEpochBudget(ctx sdk.Context, epoch uint64) (types.EpochBudget, bool)

func (Keeper) GetGasCredit

func (k Keeper) GetGasCredit(ctx sdk.Context, appID []byte) (types.GasCreditAccount, bool)

func (Keeper) GetNextChallengeID

func (k Keeper) GetNextChallengeID(ctx sdk.Context) uint64

func (Keeper) GetOpenEntitlementChallenge

func (k Keeper) GetOpenEntitlementChallenge(ctx sdk.Context, entitlementID, challenger string) (string, bool)

func (Keeper) GetOrCreateGasCredit

func (k Keeper) GetOrCreateGasCredit(ctx sdk.Context, appID []byte) types.GasCreditAccount

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) types.Params

func (Keeper) GetRoleKey

func (k Keeper) GetRoleKey(ctx sdk.Context, role types.EntitlementRole, keyID string) (types.RoleKey, bool)

func (Keeper) GetSettlement

func (k Keeper) GetSettlement(ctx sdk.Context, appID []byte, epoch uint64) (types.Settlement, bool)

func (Keeper) HasAnyEntitlementChallenge

func (k Keeper) HasAnyEntitlementChallenge(ctx sdk.Context, entitlementID string) bool

HasAnyEntitlementChallenge reports whether the candidate has any stored challenge record (any status). Used by the no-challenge approve path (UGE DEC-01 scheme C): empty challenge_resolution_hash requires zero challenges.

It goes through the same accessor as the status predicates so it inherits the pre-backfill fallback; a direct index lookup here would report "no challenge" for legacy records and silently enable the empty-hash approval path.

func (Keeper) HasAuthNonce

func (k Keeper) HasAuthNonce(ctx sdk.Context, role types.EntitlementRole, keyID, nonce string) bool

HasAuthNonce reports whether the wire-v1 nonce was already consumed.

func (Keeper) HasCredentialID

func (k Keeper) HasCredentialID(ctx sdk.Context, credentialID string) bool

HasCredentialID reports whether credential_id was consumed. Index entries are never deleted — including after candidate REJECTED (D-A permanent one-shot).

func (Keeper) HasGasCreditConsumption

func (k Keeper) HasGasCreditConsumption(ctx sdk.Context, appID, sourceTx []byte) bool

func (Keeper) HasOpenChallenge

func (k Keeper) HasOpenChallenge(ctx sdk.Context, appID []byte, epoch uint64) bool

func (Keeper) HasOpenOrUpheldEntitlementChallenge

func (k Keeper) HasOpenOrUpheldEntitlementChallenge(ctx sdk.Context, entitlementID string) bool

HasOpenOrUpheldEntitlementChallenge reports whether any challenge for the candidate is OPEN or UPHELD (blocks approval). DISMISSED/EXPIRED do not.

func (Keeper) HasSettledEntitlementChallengeResolution

func (k Keeper) HasSettledEntitlementChallengeResolution(ctx sdk.Context, entitlementID, digest string) bool

HasSettledEntitlementChallengeResolution reports whether the candidate has a settled challenge (DISMISSED by a reviewer, or EXPIRED by timeout) whose stored ResolutionDigest equals digest. Both are "no allegation proven" states that unblock approval; OPEN and UPHELD are not accepted here.

func (Keeper) InitGenesis

func (k Keeper) InitGenesis(ctx sdk.Context, gs types.GenesisState)

InitGenesis imports genesis state.

func (Keeper) IsEntitlementFlowEnabled

func (k Keeper) IsEntitlementFlowEnabled(ctx sdk.Context, pool types.Pool) bool

IsEntitlementFlowEnabled reports whether V1 business msgs may run for pool: per-pool pause/min-funded gates, plus denom-aggregated available+reserved <= module balance (covers multi-pool / genesis skew).

func (Keeper) IterateAssessmentSigners

func (k Keeper) IterateAssessmentSigners(ctx sdk.Context, fn func(types.AssessmentSigner) bool)

func (Keeper) IterateAuthNonces

func (k Keeper) IterateAuthNonces(ctx sdk.Context, fn func(string) bool)

IterateAuthNonces walks consumed wire-v1 nonces ("role/key_id/nonce"), reconstructing the identity from the store key so the value format stays free to evolve.

func (Keeper) IterateEntitlementChallenges

func (k Keeper) IterateEntitlementChallenges(ctx sdk.Context, fn func(types.EntitlementChallenge) bool)

IterateEntitlementChallenges walks every entitlement challenge record.

NOT for tx paths: use IterateEntitlementChallengesByCandidate there. This is the O(history) walk kept for ExportGenesis, the 1→2 backfill and crisis invariants.

func (Keeper) IterateEntitlementChallengesByCandidate

func (k Keeper) IterateEntitlementChallengesByCandidate(ctx sdk.Context, candidateID string, fn func(types.EntitlementChallenge) bool)

IterateEntitlementChallengesByCandidate is the exported per-candidate walk.

func (Keeper) IterateRoleKeys

func (k Keeper) IterateRoleKeys(ctx sdk.Context, role types.EntitlementRole, fn func(types.RoleKey) bool)

IterateRoleKeys walks every registered key of one role (key order = key_id).

func (Keeper) ListOpenChallengeIDs

func (k Keeper) ListOpenChallengeIDs(ctx sdk.Context, appID []byte, epoch uint64) []uint64

ListOpenChallengeIDs returns open challenge ids for (app, epoch).

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

Logger returns a module-specific logger.

func (Keeper) MarkChallengeIndexesReady

func (k Keeper) MarkChallengeIndexesReady(ctx sdk.Context)

MarkChallengeIndexesReady declares the indexes complete. Used by the 1→2 migration after its full backfill, so the EndBlocker rebuild becomes a no-op.

func (Keeper) Params

func (Keeper) Pool

Pool returns the entitlement pool record, module balance and flow status.

func (Keeper) Roles

Roles returns registered role keys, optionally filtered by role and status.

func (Keeper) SetApplication

func (k Keeper) SetApplication(ctx sdk.Context, app types.Application)

func (Keeper) SetAssessmentSigner

func (k Keeper) SetAssessmentSigner(ctx sdk.Context, s types.AssessmentSigner)

func (Keeper) SetAttestation

func (k Keeper) SetAttestation(ctx sdk.Context, a types.AttestationCommitment)

func (Keeper) SetAuthNonce

func (k Keeper) SetAuthNonce(ctx sdk.Context, role types.EntitlementRole, keyID, nonce string, expiresAt int64)

SetAuthNonce consumes the wire-v1 nonce. The value is the proof's expires_at as 8-byte big-endian, used only for pruning; the genesis string ("role_wire/key_id/nonce") is reconstructed from the key, which carries the full identity. Legacy entries written before the expiry format keep their old string values -- they are never pruned and export identically.

func (Keeper) SetCandidate

func (k Keeper) SetCandidate(ctx sdk.Context, c types.Candidate)

func (Keeper) SetChallenge

func (k Keeper) SetChallenge(ctx sdk.Context, c types.Challenge)

func (Keeper) SetCredentialIndex

func (k Keeper) SetCredentialIndex(ctx sdk.Context, credentialID, entitlementID string)

func (Keeper) SetEntitlement

func (k Keeper) SetEntitlement(ctx sdk.Context, e types.Entitlement)

func (Keeper) SetEntitlementChallenge

func (k Keeper) SetEntitlementChallenge(ctx sdk.Context, c types.EntitlementChallenge)

SetEntitlementChallenge is the ONLY write path for V1 challenge records. Besides the record itself it maintains two derived structures so that per-candidate reads never scan the whole history:

  • candidate index: candidate_id | 0x00 | challenge_id -> challenge_id
  • timeout bucket: be(resolution_deadline) | challenge_id -> challenge_id

Keeping maintenance here (rather than in each handler) means open, resolve, expire and genesis cannot drift apart. Both writes are idempotent.

func (Keeper) SetEntitlementPool

func (k Keeper) SetEntitlementPool(ctx sdk.Context, p types.Pool)

func (Keeper) SetGasCredit

func (k Keeper) SetGasCredit(ctx sdk.Context, a types.GasCreditAccount)

func (Keeper) SetGasCreditConsumption

func (k Keeper) SetGasCreditConsumption(ctx sdk.Context, c types.GasCreditConsumption)

func (Keeper) SetGasPayerIndex

func (k Keeper) SetGasPayerIndex(ctx sdk.Context, payer string, appID []byte) error

SetGasPayerIndex binds payer -> app_id. Rejects cross-app rebind.

func (Keeper) SetNextChallengeID

func (k Keeper) SetNextChallengeID(ctx sdk.Context, id uint64)

func (Keeper) SetOpenChallengeIndex

func (k Keeper) SetOpenChallengeIndex(ctx sdk.Context, appID []byte, epoch, challengeID uint64)

func (Keeper) SetOpenEntitlementChallenge

func (k Keeper) SetOpenEntitlementChallenge(ctx sdk.Context, entitlementID, challenger, challengeID string)

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, p types.Params) error

func (Keeper) SetRoleKey

func (k Keeper) SetRoleKey(ctx sdk.Context, rk types.RoleKey)

func (Keeper) SetSettlement

func (k Keeper) SetSettlement(ctx sdk.Context, s types.Settlement)

func (Keeper) Settlement

func (Keeper) StoreEpochBudget

func (k Keeper) StoreEpochBudget(ctx sdk.Context, b types.EpochBudget)

func (Keeper) SweepExpiredChallenges

func (k Keeper) SweepExpiredChallenges(ctx sdk.Context) int

SweepExpiredChallenges settles every OPEN challenge whose sealed resolution deadline has elapsed. It is the automatic counterpart of MsgExpireEntitlementChallenge: same settlement helper, so the outcome (EXPIRED + full deposit refund, candidate stays PUBLISHED) is identical either way.

Design notes:

  • Bucket order is big-endian deadline, so the walk stops at the first deadline still in the future. Cost is O(entries actually due), normally 0, and never scales with settled history.
  • It never returns an error and never panics: an EndBlocker failure halts the chain, so per-entry problems are logged and skipped.
  • Only block time and module-local state are read, so it is deterministic across validators.
  • It deliberately does not gate on requireEntitlementFlow: releasing a stranded deposit must keep working while the pool is paused. No pool money moves — the deposit only returns to the challenger that paid it.

type Migrator

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

Migrator is a helper for in-place store migrations.

func NewMigrator

func NewMigrator(k Keeper) Migrator

NewMigrator returns a new Migrator.

func (Migrator) Migrate1to2

func (m Migrator) Migrate1to2(ctx sdk.Context) error

Migrate1to2 pauses the legacy attestation / GasCredit / Finalize settlement flow for audit-only retention, ensures the V1 entitlement pool module account exists, and rebuilds the V1 challenge derived indexes. It does NOT convert POC settlements into Entitlements.

The index backfill is why this migration must run before any per-candidate read is trusted: Read paths (approve's OPEN/UPHELD gate, the settled-digest check, the timeout sweeper) only look at the candidate index and the deadline buckets. A challenge written by a v1 binary has neither, so skipping the backfill would make an existing OPEN challenge invisible to approve.

Jump to

Keyboard shortcuts

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