keeper

package
v0.0.0-...-3cdce6e Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: MIT Imports: 67 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChainedCustomQuerier

func ChainedCustomQuerier(k viewKeeper, sk slashingKeeper, next wasmkeeper.WasmVMQueryHandler) wasmkeeper.WasmVMQueryHandler

ChainedCustomQuerier implements the mesh-security custom query handler. The given WasmVMQueryHandler is receiving all unhandled queries and must therefore not be nil.

This CustomQuerier is designed as an extension point. See the NewQueryDecorator impl how to set this up for wasmd.

func ConvertSdkValidatorToWasm

func ConvertSdkValidatorToWasm(v stakingtypes.Validator) wasmvmtypes.Validator

ConvertSdkValidatorToWasm helper method

func FetchAllStoredOperations

func FetchAllStoredOperations(t *testing.T, ctx sdk.Context, msKeeper *Keeper) map[string][]types.PipedValsetOperation

FetchAllStoredOperations load all ops from temp db

func MinValidatorFixture

func MinValidatorFixture(t *testing.T) stakingtypes.Validator

MinValidatorFixture creates minimal sdk validator object

func ModuleLogger

func ModuleLogger(ctx sdk.Context) log.Logger

ModuleLogger returns logger with module attribute

func NewIntegrityHandler

func NewIntegrityHandler(k maxCapSource) wasmkeeper.MessageHandlerFunc

NewIntegrityHandler prevents any contract with max cap set to use staking or stargate messages. This ensures that staked "virtual" tokens are not bypassing the instant undelegate and burn mechanism provided by mesh-security.

This handler should be chained before any other.

func NewMsgServer

func NewMsgServer(k *Keeper) *msgServer

NewMsgServer constructor

func NewQuerier

func NewQuerier(cdc codec.Codec, k *Keeper) *querier

NewQuerier constructor

func NewQueryDecorator

func NewQueryDecorator(k viewKeeper, sk slashingKeeper) func(wasmkeeper.WasmVMQueryHandler) wasmkeeper.WasmVMQueryHandler

NewQueryDecorator constructor to build a chained custom querier. The mesh-security custom query handler is placed at the first position and delegates to the next in chain for any queries that do not match the mesh-security custom query namespace.

To be used with `wasmkeeper.WithQueryHandlerDecorator(meshseckeeper.NewQueryDecorator(app.MeshSecKeeper)))`

Types

type AuthSource

type AuthSource interface {
	// IsAuthorized returns if the contract authorized to execute a virtual stake message
	IsAuthorized(ctx sdk.Context, contractAddr sdk.AccAddress) bool
}

AuthSource abstract type that provides contract authorization. This is an extension point for custom implementations.

type AuthSourceFn

type AuthSourceFn func(ctx sdk.Context, contractAddr sdk.AccAddress) bool

AuthSourceFn is helper for simple AuthSource types

func (AuthSourceFn) IsAuthorized

func (a AuthSourceFn) IsAuthorized(ctx sdk.Context, contractAddr sdk.AccAddress) bool

IsAuthorized returns if the contract authorized to execute a virtual stake message

type BankKeeperAdapter

type BankKeeperAdapter struct {
	types.SDKBankKeeper
}

BankKeeperAdapter adapter to vanilla SDK bank keeper

func NewBankKeeperAdapter

func NewBankKeeperAdapter(k types.SDKBankKeeper) *BankKeeperAdapter

NewBankKeeperAdapter constructor

func (BankKeeperAdapter) AddSupplyOffset

func (b BankKeeperAdapter) AddSupplyOffset(ctx sdk.Context, denom string, offsetAmount math.Int)

AddSupplyOffset noop

type CustomMsgHandler

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

func NewCustomMsgHandler

func NewCustomMsgHandler(k msKeeper, auth AuthSource) *CustomMsgHandler

NewCustomMsgHandler constructor to set up CustomMsgHandler with an individual auth source. This is an extension point for non default contract authorization logic.

func NewDefaultCustomMsgHandler

func NewDefaultCustomMsgHandler(k *Keeper) *CustomMsgHandler

NewDefaultCustomMsgHandler constructor to set up the CustomMsgHandler with default max cap authorization

func (CustomMsgHandler) DispatchMsg

func (h CustomMsgHandler) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress, _ string, msg wasmvmtypes.CosmosMsg) ([]sdk.Event, [][]byte, error)

DispatchMsg handle contract message of type Custom in the mesh-security namespace

type ExecResult

type ExecResult struct {
	Contract      sdk.AccAddress
	ExecErr       error
	RescheduleErr error
	DeleteTaskErr error
	GasUsed       sdk.Gas
	GasLimit      sdk.Gas
	NextRunHeight uint64
}

ExecResult are the results of a task execution

type Hooks

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

Hooks wrapper struct for slashing keeper

func (Hooks) AfterDelegationModified

func (h Hooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error

AfterDelegationModified noop

func (Hooks) AfterUnbondingInitiated

func (h Hooks) AfterUnbondingInitiated(ctx sdk.Context, id uint64) error

func (Hooks) AfterValidatorBeginUnbonding

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

func (Hooks) AfterValidatorBonded

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

func (Hooks) AfterValidatorCreated

func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) error

AfterValidatorCreated noop

func (Hooks) AfterValidatorRemoved

func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error

AfterValidatorRemoved noop

func (Hooks) BeforeDelegationCreated

func (h Hooks) BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error

BeforeDelegationCreated noop

func (Hooks) BeforeDelegationRemoved

func (h Hooks) BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error

BeforeDelegationRemoved noop

func (Hooks) BeforeDelegationSharesModified

func (h Hooks) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error

BeforeDelegationSharesModified noop

func (Hooks) BeforeValidatorModified

func (h Hooks) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) error

func (Hooks) BeforeValidatorSlashed

func (h Hooks) BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, fraction sdk.Dec) error

type Keeper

type Keeper struct {
	Staking types.XStakingKeeper
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(
	cdc codec.Codec,
	storeKey storetypes.StoreKey,
	memoryStoreKey storetypes.StoreKey,
	bank types.SDKBankKeeper,
	staking types.SDKStakingKeeper,
	wasm types.WasmKeeper,
	authority string,
	opts ...Option,
) *Keeper

NewKeeper constructor with vanilla sdk keepers

func NewKeeperX

func NewKeeperX(
	cdc codec.Codec,
	storeKey storetypes.StoreKey,
	memoryStoreKey storetypes.StoreKey,
	bank types.XBankKeeper,
	staking types.XStakingKeeper,
	wasm types.WasmKeeper,
	authority string,
	opts ...Option,
) *Keeper

NewKeeperX constructor with extended Osmosis SDK keepers

func (Keeper) ClearPipedValsetOperations

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

ClearPipedValsetOperations delete all entries from the temporary store that contains the valset updates.

func (Keeper) Delegate

func (k Keeper) Delegate(pCtx sdk.Context, actor sdk.AccAddress, valAddr sdk.ValAddress, amt sdk.Coin) (sdk.Dec, error)

Delegate mints new "virtual" bonding tokens and delegates them to the given validator. The amount minted is removed from the SupplyOffset (so that it will become negative), when supported. Authorization of the actor should be handled before entering this method.

func (Keeper) DeleteAllScheduledTasks

func (k Keeper) DeleteAllScheduledTasks(ctx sdk.Context, tp types.SchedulerTaskType, contract sdk.AccAddress) error

DeleteAllScheduledTasks deletes all tasks of given type for the contract.

func (Keeper) ExecScheduledTasks

func (k Keeper) ExecScheduledTasks(pCtx sdk.Context, tp types.SchedulerTaskType, epochLength uint64, cb executor) ([]ExecResult, error)

ExecScheduledTasks execute scheduled task at current height The executor function is called within the scope of a new cached store. Any failure on execution reverts the state of this sub call. Rescheduling or other state changes due to the scheduler provisioning are not affected. The result type contains more details information of execution or provisioning errors. The given epoch length is used for re-scheduling the task, when set on the task and value >0

func (Keeper) ExportGenesis

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

func (Keeper) GetAuthority

func (k Keeper) GetAuthority() string

GetAuthority returns the module's authority.

func (Keeper) GetMaxCapLimit

func (k Keeper) GetMaxCapLimit(ctx sdk.Context, actor sdk.AccAddress) sdk.Coin

GetMaxCapLimit the cap limit is set per consumer contract. Different providers can have different limits Returns zero amount when no limit is stored.

func (Keeper) GetMaxSudoGas

func (k Keeper) GetMaxSudoGas(ctx sdk.Context) sdk.Gas

func (Keeper) GetNextScheduledTaskHeight

func (k Keeper) GetNextScheduledTaskHeight(ctx sdk.Context, tp types.SchedulerTaskType, contract sdk.AccAddress) (height uint64, found bool)

GetNextScheduledTaskHeight returns height for task to execute

func (Keeper) GetParams

func (k Keeper) GetParams(clientCtx sdk.Context) (params types.Params)

GetParams gets the module's parameters.

func (Keeper) GetRebalanceEpochLength

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

func (Keeper) GetTotalContractsMaxCap

func (k Keeper) GetTotalContractsMaxCap(ctx sdk.Context) sdk.Coin

func (Keeper) GetTotalDelegated

func (k Keeper) GetTotalDelegated(ctx sdk.Context, actor sdk.AccAddress) sdk.Coin

GetTotalDelegated returns the total amount delegated by the given consumer contract. This amount can be 0 is never negative.

func (Keeper) HasMaxCapLimit

func (k Keeper) HasMaxCapLimit(ctx sdk.Context, actor sdk.AccAddress) bool

HasMaxCapLimit returns true when any max cap limit was set. The amount is not taken into account for the result. A 0 value would be true as well.

func (Keeper) HasScheduledTask

func (k Keeper) HasScheduledTask(ctx sdk.Context, tp types.SchedulerTaskType, contract sdk.AccAddress, repeat bool) bool

HasScheduledTask returns true if the contract has a task scheduled of the given type and repeat setting

func (Keeper) Hooks

func (k Keeper) Hooks() Hooks

Hooks return the mesh-security hooks

func (Keeper) InitGenesis

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

func (Keeper) IterateMaxCapLimit

func (k Keeper) IterateMaxCapLimit(ctx sdk.Context, cb func(sdk.AccAddress, math.Int) bool)

IterateMaxCapLimit iterate over contract addresses with max cap limit set Callback can return true to stop early

func (Keeper) IterateScheduledTasks

func (k Keeper) IterateScheduledTasks(ctx sdk.Context, tp types.SchedulerTaskType, maxHeight uint64, cb func(addr sdk.AccAddress, height uint64, repeat bool) bool) error

IterateScheduledTasks iterate of all scheduled task executions for the given type up to given block height (included)

func (Keeper) ScheduleBonded

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

ScheduleBonded store a validator update to bonded status for the valset update report

func (Keeper) ScheduleJailed

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

ScheduleJailed store a validator update to jailed status for the valset update report

func (Keeper) ScheduleModified

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

ScheduleModified store a validator metadata update for the valset update report

func (Keeper) ScheduleOneShotTask

func (k Keeper) ScheduleOneShotTask(ctx sdk.Context, tp types.SchedulerTaskType, contract sdk.AccAddress, execBlockHeight uint64) error

ScheduleOneShotTask register a new task to be executed at given block height. The task is not repeating and registered only once for a given contract and height. Duplicates are silently ignored

func (Keeper) ScheduleRegularRebalanceTask

func (k Keeper) ScheduleRegularRebalanceTask(ctx sdk.Context, contract sdk.AccAddress) error

ScheduleRegularRebalanceTask schedule a rebalance task for the given virtual staking contract using params defined epoch length

func (Keeper) ScheduleRepeatingTask

func (k Keeper) ScheduleRepeatingTask(ctx sdk.Context, tp types.SchedulerTaskType, contract sdk.AccAddress, execBlockHeight uint64) error

ScheduleRepeatingTask register a recurring task to be executed at given block height. Duplicates are overwritten

func (Keeper) ScheduleSlashed

func (k Keeper) ScheduleSlashed(ctx sdk.Context, addr sdk.ValAddress, power int64, height int64, totalSlashAmount math.Int, slashRatio sdk.Dec) error

ScheduleSlashed store a validator slash event / data for the valset update report

func (Keeper) ScheduleTombstoned

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

ScheduleTombstoned store a validator update to tombstoned status for the valset update report

func (Keeper) ScheduleUnbonded

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

ScheduleUnbonded store a validator update to unbonded status for the valset update report

func (Keeper) ScheduleUnjailed

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

ScheduleUnjailed store a validator update to unjailed status for the valset update report

func (Keeper) SendHandleEpoch

func (k Keeper) SendHandleEpoch(ctx sdk.Context, contractAddr sdk.AccAddress) error

SendHandleEpoch send epoch handling message to virtual staking contract via sudo

func (Keeper) SendValsetUpdate

func (k Keeper) SendValsetUpdate(ctx sdk.Context, contractAddr sdk.AccAddress, v contract.ValsetUpdate) error

SendValsetUpdate submit the valset update report to the virtual staking contract via sudo

func (Keeper) SetMaxCapLimit

func (k Keeper) SetMaxCapLimit(ctx sdk.Context, contract sdk.AccAddress, newAmount sdk.Coin) error

SetMaxCapLimit stores the max cap limit for the given contract address. Any existing limit for this contract will be overwritten

func (Keeper) SetParams

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

SetParams sets the module's parameters.

func (Keeper) Undelegate

func (k Keeper) Undelegate(pCtx sdk.Context, actor sdk.AccAddress, valAddr sdk.ValAddress, amt sdk.Coin) error

Undelegate executes an instant undelegate and burns the released virtual staking tokens. The amount burned is added to the (negative) SupplyOffset, when supported. Authorization of the actor should be handled before entering this method.

func (Keeper) ValsetUpdateReport

func (k Keeper) ValsetUpdateReport(ctx sdk.Context) (contract.ValsetUpdate, error)

ValsetUpdateReport aggregate all stored changes of the current block. Should be called by an end-blocker. The events reported are categorized by type and not time. Conflicting events as Bonded/ Unbonded are not supposed to happen within the same block

type MockWasmKeeper

type MockWasmKeeper struct {
	SudoFn            func(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error)
	HasContractInfoFn func(ctx sdk.Context, contractAddress sdk.AccAddress) bool
}

func (MockWasmKeeper) HasContractInfo

func (m MockWasmKeeper) HasContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress) bool

func (MockWasmKeeper) Sudo

func (m MockWasmKeeper) Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error)

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is an extension point to instantiate keeper with non default values

func WithWasmKeeperDecorated

func WithWasmKeeperDecorated(cb func(types.WasmKeeper) types.WasmKeeper) Option

WithWasmKeeperDecorated can set a decorator to the wasm keeper

type QueryHandlerFn

type QueryHandlerFn func(ctx sdk.Context, caller sdk.AccAddress, request wasmvmtypes.QueryRequest) ([]byte, error)

QueryHandlerFn helper type that implements wasmkeeper.WasmVMQueryHandler

func (QueryHandlerFn) HandleQuery

func (q QueryHandlerFn) HandleQuery(ctx sdk.Context, caller sdk.AccAddress, request wasmvmtypes.QueryRequest) ([]byte, error)

HandleQuery handles contract query

type SlashingKeeperDecorator

type SlashingKeeperDecorator struct {
	evidencetypes.SlashingKeeper
	// contains filtered or unexported fields
}

SlashingKeeperDecorator to capture tombstone events

func CaptureTombstoneDecorator

func CaptureTombstoneDecorator(k *Keeper, slashingKeeper evidencetypes.SlashingKeeper, stakingKeeper types.SDKStakingKeeper) *SlashingKeeperDecorator

CaptureTombstoneDecorator constructor

func (SlashingKeeperDecorator) Tombstone

func (e SlashingKeeperDecorator) Tombstone(ctx sdk.Context, address sdk.ConsAddress)

Tombstone is executed in the end-blocker by the evidence module

type StakingDecorator

type StakingDecorator struct {
	slashingtypes.StakingKeeper
	// contains filtered or unexported fields
}

StakingDecorator decorate vanilla staking keeper to capture the jail and unjail events

func NewStakingDecorator

func NewStakingDecorator(stakingKeeper slashingtypes.StakingKeeper, k *Keeper) *StakingDecorator

NewStakingDecorator constructor

func (StakingDecorator) Jail

func (s StakingDecorator) Jail(ctx sdk.Context, consAddr sdk.ConsAddress)

Jail captures the jail event and calls the decorated staking keeper jail method

func (StakingDecorator) Slash

func (s StakingDecorator) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, power int64, height int64, slashRatio sdk.Dec) math.Int

Slash captures the slash event and calls the decorated staking keeper slash method

func (StakingDecorator) SlashWithInfractionReason

func (s StakingDecorator) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec, _ stakingtypes.Infraction) math.Int

SlashWithInfractionReason implementation doesn't require the infraction (types.Infraction) to work but is required by Interchain Security.

func (StakingDecorator) Unjail

func (s StakingDecorator) Unjail(ctx sdk.Context, consAddr sdk.ConsAddress)

Unjail captures the unjail event and calls the decorated staking keeper unjail method

type StakingHooks

type StakingHooks struct{}

type StakingKeeperAdapter

type StakingKeeperAdapter struct {
	types.SDKStakingKeeper
	// contains filtered or unexported fields
}

StakingKeeperAdapter is an adapter to enhance the vanilla sdk staking keeper with additional functionality required for MS. The methods match Osmosis SDK fork.

func NewStakingKeeperAdapter

func NewStakingKeeperAdapter(k types.SDKStakingKeeper, b types.SDKBankKeeper) *StakingKeeperAdapter

NewStakingKeeperAdapter constructor

func (StakingKeeperAdapter) InstantUndelegate

func (s StakingKeeperAdapter) InstantUndelegate(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount sdk.Dec) (sdk.Coins, error)

InstantUndelegate allows another module account to undelegate while bypassing unbonding time. This function is a combination of Undelegate and CompleteUnbonding, but skips the creation and deletion of UnbondingDelegationEntry

The code is copied from the Osmosis SDK fork https://github.com/osmosis-labs/cosmos-sdk/blob/v0.45.0x-osmo-v9.3/x/staking/keeper/delegation.go#L757

type TestKeepers

type TestKeepers struct {
	StakingKeeper  *stakingkeeper.Keeper
	SlashingKeeper slashingkeeper.Keeper
	BankKeeper     bankkeeper.Keeper
	StoreKey       *storetypes.KVStoreKey
	EncodingConfig encodingConfig
	MeshKeeper     *Keeper
	AccountKeeper  authkeeper.AccountKeeper
	WasmKeeper     *wasmkeeper.Keeper
	Faucet         *wasmkeeper.TestFaucet
}

func CreateDefaultTestInput

func CreateDefaultTestInput(t testing.TB, opts ...Option) (sdk.Context, TestKeepers)

Jump to

Keyboard shortcuts

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