keeper

package
v0.0.0-dev.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const EMISSIONS_PER_EPOCH = 1000
View Source
const EPOCH_LENGTH = 5

Emissions rate Constants TODO make these not constants and figure out how they should be changeable by governance or some algorithm or whatever

View Source
const REQUIRED_MINIMUM_STAKE = 1

Variables

View Source
var UintValue collcodec.ValueCodec[math.Uint] = uintValueCodec{}

Functions

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) state.MsgServer

NewMsgServerImpl returns an implementation of the module MsgServer interface.

func NewQueryServerImpl

func NewQueryServerImpl(k Keeper) state.QueryServer

NewQueryServerImpl returns an implementation of the module QueryServer.

Types

type ACC_ADDRESS

type ACC_ADDRESS = string

type AccountKeeper

type AccountKeeper interface {
	AddressCodec() address.Codec
	GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
	GetModuleAddress(name string) sdk.AccAddress
	GetModuleAccount(ctx context.Context, name string) sdk.ModuleAccountI
	// TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862
	SetModuleAccount(context.Context, sdk.ModuleAccountI)
}

AccountKeeper defines the expected account keeper used for simulations (noalias)

type BLOCK_NUMBER

type BLOCK_NUMBER = int64

type BankKeeper

type BankKeeper interface {
	MintCoins(ctx context.Context, moduleName string, amt sdk.Coins) error
	GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
	GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin

	SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins

	SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error
	SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
	SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error

	BlockedAddr(addr sdk.AccAddress) bool
}

BankKeeper defines the expected interface needed to retrieve account balances.

type DELEGATOR

type DELEGATOR = sdk.AccAddress

type DELEGATOR_STR

type DELEGATOR_STR = string

type Int

type Int = cosmosMath.Int

type Keeper

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

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	addressCodec address.Codec,
	storeService storetypes.KVStoreService,
	ak AccountKeeper,
	bk BankKeeper) Keeper

func (*Keeper) AddStake

func (k *Keeper) AddStake(ctx context.Context, topic TOPIC_ID, delegator string, target string, stake Uint) error

Add stake adds stake to the system for a given delegator and target it adds to existing holdings. it places the stake upon target, from delegator, in amount. it also updates the total stake for the subnet in question and the total global stake. see comments in keeper.go data structures for examples of how the data structure tracking works

func (*Keeper) AddStakePlacedUponTarget

func (k *Keeper) AddStakePlacedUponTarget(ctx context.Context, target sdk.AccAddress, amount Uint) error

Used by Modify functions to change stake placements. This function adds to the stakePlacedUponTarget mapping ONLY and does not modify any of the other stake mappings e.g. delegatorStake totalStake or topicStake in a system.

func (*Keeper) AddStakePlacement

func (k *Keeper) AddStakePlacement(ctx context.Context, delegator sdk.AccAddress, target sdk.AccAddress, amount Uint) error

Used by Modify functions to change stake placements. This function adds to the stakePlacement mapping ONLY and does not modify any of the other stake mappings e.g. delegatorStake totalStake or topicStake in a system.

func (*Keeper) CalculateAccumulatedEmissions

func (k *Keeper) CalculateAccumulatedEmissions(ctx context.Context) (cosmosMath.Int, error)

return how many new coins should be minted for the next emission

func (*Keeper) EpochLength

func (k *Keeper) EpochLength() int64

return epoch length

func (*Keeper) ExportGenesis

func (k *Keeper) ExportGenesis(ctx context.Context) (*state.GenesisState, error)

ExportGenesis exports the module state to a genesis state.

func (*Keeper) FindWorkerNodesByOwner

func (k *Keeper) FindWorkerNodesByOwner(ctx sdk.Context, nodeId string) ([]*state.OffchainNode, error)

func (*Keeper) GetActiveTopics

func (k *Keeper) GetActiveTopics(ctx context.Context) ([]*state.Topic, error)

GetActiveTopics returns a slice of all active topics.

func (*Keeper) GetAllBondsForDelegator

func (k *Keeper) GetAllBondsForDelegator(ctx context.Context, delegator sdk.AccAddress) ([]sdk.AccAddress, []Uint, error)

For a given delegator, return a map of every target they've placed stake upon, and how much stake they've placed upon them O(n) over the number of targets registered. since maps of byte array types aren't supported in golang, we instead return two equal length arrays where the first array is the targets, and the second array is the amount of stake placed upon them indexes in the two arrays correspond to each other invariant that len(targets) == len(stakes)

func (*Keeper) GetAllInferences

func (k *Keeper) GetAllInferences(ctx context.Context, topicId TOPIC_ID, timestamp uint64) (*state.Inferences, error)

func (*Keeper) GetBond

func (k *Keeper) GetBond(ctx context.Context, delegator sdk.AccAddress, target sdk.AccAddress) (Uint, error)

For a given delegator and target, find out how much stake the delegator has placed upon the target

func (*Keeper) GetDelegatorStake

func (k *Keeper) GetDelegatorStake(ctx context.Context, delegator sdk.AccAddress) (Uint, error)

for a given address, find out how much stake they've put into the system

func (*Keeper) GetLastRewardsUpdate

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

Returns the last block height at which rewards emissions were updated

func (*Keeper) GetLatestInferenceTimestamp

func (k *Keeper) GetLatestInferenceTimestamp(ctx context.Context, topicId TOPIC_ID) (uint64, error)

func (*Keeper) GetLatestInferencesFromTopic

func (k *Keeper) GetLatestInferencesFromTopic(ctx context.Context, topicId TOPIC_ID) ([]*state.InferenceSetForScoring, error)

A function that accepts a topicId and returns list of Inferences or error

func (*Keeper) GetNumTopics

func (k *Keeper) GetNumTopics(ctx context.Context) (TOPIC_ID, error)

Returns the number of topics that are active in the network

func (*Keeper) GetReputer

func (k *Keeper) GetReputer(ctx context.Context, reputer sdk.AccAddress) (state.OffchainNode, error)

func (*Keeper) GetReputerNormalizedStake

func (k *Keeper) GetReputerNormalizedStake(
	ctx sdk.Context,
	topicId TOPIC_ID,
	topicStake *big.Float) (reputerNormalizedStakeMap map[ACC_ADDRESS]*big.Float, retErr error)

for a given topic, returns every reputer node registered to it and their normalized stake

func (*Keeper) GetStakePlacedUponTarget

func (k *Keeper) GetStakePlacedUponTarget(ctx context.Context, target sdk.AccAddress) (Uint, error)

func (*Keeper) GetStakesForAccount

func (k *Keeper) GetStakesForAccount(ctx context.Context, delegator sdk.AccAddress) ([]*state.StakeInfo, error)

GetStakesForAccount returns the list of stakes for a given account address.

func (*Keeper) GetTopicStake

func (k *Keeper) GetTopicStake(ctx context.Context, topicId TOPIC_ID) (Uint, error)

Gets the stake in the network for a given topic

func (*Keeper) GetTopicsByCreator

func (k *Keeper) GetTopicsByCreator(ctx context.Context, creator string) ([]*state.Topic, error)

GetTopicsByCreator returns a slice of all topics created by a given creator.

func (*Keeper) GetTotalStake

func (k *Keeper) GetTotalStake(ctx context.Context) (Uint, error)

Gets the total sum of all stake in the network across all topics

func (*Keeper) GetWeightsFromTopic

func (k *Keeper) GetWeightsFromTopic(ctx context.Context, topicId TOPIC_ID) (map[REPUTERS]map[WORKERS]*Uint, error)

For a given topic return the matrix (double map) of all (reputers, workers) -> weight of reputer upon worker

func (*Keeper) GetWorker

func (k *Keeper) GetWorker(ctx context.Context, worker sdk.AccAddress) (state.OffchainNode, error)

func (*Keeper) GetWorkerAddressByP2PKey

func (k *Keeper) GetWorkerAddressByP2PKey(ctx context.Context, p2pKey string) (sdk.AccAddress, error)

func (*Keeper) IncrementTopicId

func (k *Keeper) IncrementTopicId(ctx context.Context) (TOPIC_ID, error)

Gets next topic id

func (*Keeper) InitGenesis

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

InitGenesis initializes the module state from a genesis state.

func (*Keeper) InsertInference

func (k *Keeper) InsertInference(ctx context.Context, topicId TOPIC_ID, timestamp uint64, inference state.Inference) error

func (*Keeper) InsertInferences

func (k *Keeper) InsertInferences(ctx context.Context, topicId TOPIC_ID, timestamp uint64, inferences state.Inferences) error

Insert a complete set of inferences for a topic/timestamp. Overwrites previous ones.

func (*Keeper) InsertReputer

func (k *Keeper) InsertReputer(ctx context.Context, topicId uint64, reputer sdk.AccAddress, reputerInfo state.OffchainNode) error

Adds a new reputer to the reputer tracking data structures, reputers and topicReputers

func (*Keeper) InsertWorker

func (k *Keeper) InsertWorker(ctx context.Context, topicId uint64, worker sdk.AccAddress, workerInfo state.OffchainNode) error

Adds a new worker to the worker tracking data structures, workers and topicWorkers

func (*Keeper) IsReputerRegistered

func (k *Keeper) IsReputerRegistered(ctx context.Context, reputer sdk.AccAddress) (bool, error)

check a reputer node is registered

func (*Keeper) IsWorkerRegistered

func (k *Keeper) IsWorkerRegistered(ctx context.Context, worker sdk.AccAddress) (bool, error)

check a worker node is registered

func (*Keeper) IterateAllTopicStake

func (k *Keeper) IterateAllTopicStake(ctx context.Context) (collections.Iterator[uint64, cosmosMath.Uint], error)

func (*Keeper) MintRewardsCoins

func (k *Keeper) MintRewardsCoins(ctx context.Context, amount cosmosMath.Int) error

mint new rewards coins to this module account

func (*Keeper) RemoveStakeFromBond

func (k *Keeper) RemoveStakeFromBond(
	ctx context.Context,
	topic TOPIC_ID,
	delegator sdk.AccAddress,
	target sdk.AccAddress,
	stake Uint) error

Remove stake from bond updates the various data structures associated with removing stake from the system for a given delegator and target it removes the stake upon target, from delegator, in amount. it also updates the total stake for the topic in question and the total global stake. see comments in keeper.go data structures for examples of how the data structure tracking works

func (*Keeper) RemoveStakeFromBondMissingTotalOrTopicStake

func (k *Keeper) RemoveStakeFromBondMissingTotalOrTopicStake(
	ctx context.Context,
	topic TOPIC_ID,
	delegator sdk.AccAddress,
	target sdk.AccAddress,
	stake Uint) error

Remove stake from bond updates the various data structures associated with removing stake from the system for a given delegator and target it removes the stake upon target, from delegator, in amount. it *DOES NOT* update the total stake for the subnet in question and the total global stake. this is used by RemoveAllStake to avoid double counting the topic/total stake removal

func (*Keeper) SetInference

func (k *Keeper) SetInference(
	ctx context.Context,
	topicID TOPIC_ID,
	worker sdk.AccAddress,
	inference state.Inference) error

func (*Keeper) SetLastRewardsUpdate

func (k *Keeper) SetLastRewardsUpdate(ctx context.Context, blockHeight int64) error

Set the last block height at which rewards emissions were updated

func (*Keeper) SetLatestInferenceTimestamp

func (k *Keeper) SetLatestInferenceTimestamp(ctx context.Context, topicId TOPIC_ID, timestamp uint64) error

func (*Keeper) SetParams

func (k *Keeper) SetParams(ctx context.Context, params state.Params) error

func (*Keeper) SetStakePlacedUponTarget

func (k *Keeper) SetStakePlacedUponTarget(ctx context.Context, target sdk.AccAddress, stake Uint) error

func (*Keeper) SetTopic

func (k *Keeper) SetTopic(ctx context.Context, topicId TOPIC_ID, topic state.Topic) error

Sets a topic config on a topicId

func (*Keeper) SetTopicStake

func (k *Keeper) SetTopicStake(ctx context.Context, topicId TOPIC_ID, stake Uint) error

Sets the stake in the network for a given topic

func (*Keeper) SetTotalStake

func (k *Keeper) SetTotalStake(ctx context.Context, totalStake Uint) error

Sets the total sum of all stake in the network across all topics

func (*Keeper) SetWeight

func (k *Keeper) SetWeight(
	ctx context.Context,
	topicId TOPIC_ID,
	reputer sdk.AccAddress,
	worker sdk.AccAddress,
	weight Uint) error

func (*Keeper) SubStakePlacedUponTarget

func (k *Keeper) SubStakePlacedUponTarget(ctx context.Context, target sdk.AccAddress, amount Uint) error

Used by Modify functions to change stake placements. This function subtracts from the stakePlacedUponTarget mapping ONLY and does not modify any of the other stake mappings e.g. delegatorStake totalStake or topicStake in a system.

func (*Keeper) SubStakePlacement

func (k *Keeper) SubStakePlacement(ctx context.Context, delegator sdk.AccAddress, target sdk.AccAddress, amount Uint) error

Used by Modify functions to change stake placements. This function subtracts from the stakePlacement mapping ONLY and does not modify any of the other stake mappings e.g. delegatorStake totalStake or topicStake in a system.

func (*Keeper) UpdateTopicInferenceLastRan

func (k *Keeper) UpdateTopicInferenceLastRan(ctx context.Context, topicId TOPIC_ID, lastRanTime uint64) error

UpdateTopicInferenceLastRan updates the InferenceLastRan timestamp for a given topic.

func (*Keeper) UpdateTopicWeightLastRan

func (k *Keeper) UpdateTopicWeightLastRan(ctx context.Context, topicId TOPIC_ID, lastRanTime uint64) error

UpdateTopicWeightLastRan updates the WeightLastRan timestamp for a given topic.

func (*Keeper) WalkAllTopicStake

func (k *Keeper) WalkAllTopicStake(ctx context.Context, walkFunc func(topicId TOPIC_ID, stake Uint) (stop bool, err error)) error

Runs an arbitrary function for every topic in the network

type NodeExists

type NodeExists int8

type REPUTERS

type REPUTERS = string

type RegistrationMessage

type RegistrationMessage interface {
	GetTopicId() uint64
	GetLibP2PKey() string
	GetInitialStake() cosmosMath.Uint
	GetCreator() string
}

Making common interfaces available to protobuf messages

type TARGET

type TARGET = sdk.AccAddress

type TARGET_STR

type TARGET_STR = string

type TOPIC_ID

type TOPIC_ID = uint64

type UNIX_TIMESTAMP

type UNIX_TIMESTAMP = uint64

type Uint

type Uint = cosmosMath.Uint

type WORKERS

type WORKERS = string

Jump to

Keyboard shortcuts

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