state

package
v0.2012.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AppName is the ABCI application name.
	AppName = "100_staking"
	// KeyAddEscrow is an ABCI event attribute key for AddEscrow calls
	// (value is an api.AddEscrowEvent).
	KeyAddEscrow = []byte("add_escrow")
	// KeyTakeEscrow is an ABCI event attribute key for TakeEscrow calls
	// (value is an app.TakeEscrowEvent).
	KeyTakeEscrow = []byte("take_escrow")
	// KeyTransfer is an ABCI event attribute key for Transfers (value is
	// an app.TransferEvent).
	KeyTransfer = []byte("transfer")
)

Functions

func AddStakeClaim

func AddStakeClaim(
	ctx *abciAPI.Context,
	addr staking.Address,
	claim staking.StakeClaim,
	thresholds []staking.StakeThreshold,
) error

AddStakeClaim is a convenience function for adding a single stake claim to an entity.

In case there is no errors, the added claim is automatically committed. The caller must ensure that this does not overwrite any outstanding account updates.

func AuthenticateAndPayFees

func AuthenticateAndPayFees(
	ctx *abciAPI.Context,
	signer signature.PublicKey,
	nonce uint64,
	fee *transaction.Fee,
) error

AuthenticateAndPayFees authenticates the message signer and makes sure that any gas fees are paid.

This method transfers the fees to the per-block fee accumulator which is persisted at the end of the block.

func BlockFees

func BlockFees(ctx *abciAPI.Context) quantity.Quantity

BlockFees returns the accumulated fee balance for the current block.

func BlockProposer

func BlockProposer(ctx *abciAPI.Context) *signature.PublicKey

func CheckStakeClaims

func CheckStakeClaims(ctx *abciAPI.Context, addr staking.Address) error

CheckStakeClaims is a convenience function for checking a single entity's stake claims.

func RemoveStakeClaim

func RemoveStakeClaim(ctx *abciAPI.Context, addr staking.Address, claim staking.StakeClaim) error

RemoveStakeClaim is a convenience function for removing a single stake claim from an entity.

In case there is no errors, the removed claim is automatically committed. The caller must ensure that this does not overwrite any outstanding account updates.

func SetBlockProposer

func SetBlockProposer(ctx *abciAPI.Context, p *signature.PublicKey)

Types

type DebondingQueueEntry

type DebondingQueueEntry struct {
	Epoch         epochtime.EpochTime
	DelegatorAddr staking.Address
	EscrowAddr    staking.Address
	Seq           uint64
	Delegation    *staking.DebondingDelegation
}

type EpochSigning

type EpochSigning struct {
	Total    uint64
	ByEntity map[signature.PublicKey]uint64
}

func (*EpochSigning) EligibleEntities

func (es *EpochSigning) EligibleEntities(thresholdNumerator, thresholdDenominator uint64) ([]signature.PublicKey, error)

func (*EpochSigning) Update

func (es *EpochSigning) Update(signingEntities []signature.PublicKey) error

type ImmutableState

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

ImmutableState is the immutable staking state wrapper.

func NewImmutableState

func NewImmutableState(ctx context.Context, state abciAPI.ApplicationQueryState, version int64) (*ImmutableState, error)

func (*ImmutableState) Account

func (s *ImmutableState) Account(ctx context.Context, address staking.Address) (*staking.Account, error)

Account returns the staking account for the given account address.

func (*ImmutableState) Addresses

func (s *ImmutableState) Addresses(ctx context.Context) ([]staking.Address, error)

func (*ImmutableState) CommissionScheduleRules

func (s *ImmutableState) CommissionScheduleRules(ctx context.Context) (*staking.CommissionScheduleRules, error)

func (*ImmutableState) CommonPool

func (s *ImmutableState) CommonPool(ctx context.Context) (*quantity.Quantity, error)

CommonPool returns the balance of the global common pool.

func (*ImmutableState) ConsensusParameters

func (s *ImmutableState) ConsensusParameters(ctx context.Context) (*staking.ConsensusParameters, error)

func (*ImmutableState) DebondingDelegation

func (s *ImmutableState) DebondingDelegation(
	ctx context.Context,
	delegatorAddr, escrowAddr staking.Address,
	seq uint64,
) (*staking.DebondingDelegation, error)

func (*ImmutableState) DebondingDelegations

func (s *ImmutableState) DebondingDelegations(
	ctx context.Context,
) (map[staking.Address]map[staking.Address][]*staking.DebondingDelegation, error)

func (*ImmutableState) DebondingDelegationsFor

func (s *ImmutableState) DebondingDelegationsFor(
	ctx context.Context,
	delegatorAddr staking.Address,
) (map[staking.Address][]*staking.DebondingDelegation, error)

func (*ImmutableState) DebondingInterval

func (s *ImmutableState) DebondingInterval(ctx context.Context) (epochtime.EpochTime, error)

func (*ImmutableState) Delegation

func (s *ImmutableState) Delegation(
	ctx context.Context,
	delegatorAddr, escrowAddr staking.Address,
) (*staking.Delegation, error)

func (*ImmutableState) Delegations

func (s *ImmutableState) Delegations(
	ctx context.Context,
) (map[staking.Address]map[staking.Address]*staking.Delegation, error)

func (*ImmutableState) DelegationsFor

func (s *ImmutableState) DelegationsFor(
	ctx context.Context,
	delegatorAddr staking.Address,
) (map[staking.Address]*staking.Delegation, error)

func (*ImmutableState) EpochSigning

func (s *ImmutableState) EpochSigning(ctx context.Context) (*EpochSigning, error)

func (*ImmutableState) EscrowBalance

func (s *ImmutableState) EscrowBalance(ctx context.Context, address staking.Address) (*quantity.Quantity, error)

EscrowBalance returns the escrow balance for the given account address.

func (*ImmutableState) ExpiredDebondingQueue

func (s *ImmutableState) ExpiredDebondingQueue(ctx context.Context, epoch epochtime.EpochTime) ([]*DebondingQueueEntry, error)

func (*ImmutableState) LastBlockFees

func (s *ImmutableState) LastBlockFees(ctx context.Context) (*quantity.Quantity, error)

func (*ImmutableState) RewardSchedule

func (s *ImmutableState) RewardSchedule(ctx context.Context) ([]staking.RewardStep, error)

func (*ImmutableState) Slashing

func (*ImmutableState) Thresholds

Thresholds returns the currently configured thresholds if any.

func (*ImmutableState) TotalSupply

func (s *ImmutableState) TotalSupply(ctx context.Context) (*quantity.Quantity, error)

type MutableState

type MutableState struct {
	*ImmutableState
	// contains filtered or unexported fields
}

MutableState is a mutable staking state wrapper.

func NewMutableState

func NewMutableState(tree mkvs.KeyValueTree) *MutableState

NewMutableState creates a new mutable staking state wrapper.

func (*MutableState) AddRewardSingleAttenuated

func (s *MutableState) AddRewardSingleAttenuated(
	ctx *abciAPI.Context,
	time epochtime.EpochTime,
	factor *quantity.Quantity,
	attenuationNumerator, attenuationDenominator int,
	address staking.Address,
) error

AddRewardSingleAttenuated computes, scales, and transfers a staking reward to an active escrow account.

func (*MutableState) AddRewards

func (s *MutableState) AddRewards(
	ctx *abciAPI.Context,
	time epochtime.EpochTime,
	factor *quantity.Quantity,
	addresses []staking.Address,
) error

AddRewards computes and transfers a staking reward to active escrow accounts. If an error occurs, the pool and affected accounts are left in an invalid state. This may fail due to the common pool running out of stake. In this case, the returned error's cause will be `staking.ErrInsufficientBalance`, and it should be safe for the caller to roll back to an earlier state tree and continue from there.

func (*MutableState) ClearEpochSigning

func (s *MutableState) ClearEpochSigning(ctx context.Context) error

func (*MutableState) RemoveFromDebondingQueue

func (s *MutableState) RemoveFromDebondingQueue(
	ctx context.Context,
	epoch epochtime.EpochTime,
	delegatorAddr, escrowAddr staking.Address,
	seq uint64,
) error

func (*MutableState) SetAccount

func (s *MutableState) SetAccount(ctx context.Context, addr staking.Address, account *staking.Account) error

func (*MutableState) SetCommonPool

func (s *MutableState) SetCommonPool(ctx context.Context, q *quantity.Quantity) error

func (*MutableState) SetConsensusParameters

func (s *MutableState) SetConsensusParameters(ctx context.Context, params *staking.ConsensusParameters) error

func (*MutableState) SetDebondingDelegation

func (s *MutableState) SetDebondingDelegation(
	ctx context.Context,
	delegatorAddr, escrowAddr staking.Address,
	seq uint64,
	d *staking.DebondingDelegation,
) error

func (*MutableState) SetDelegation

func (s *MutableState) SetDelegation(
	ctx context.Context,
	delegatorAddr, escrowAddr staking.Address,
	d *staking.Delegation,
) error

func (*MutableState) SetEpochSigning

func (s *MutableState) SetEpochSigning(ctx context.Context, es *EpochSigning) error

func (*MutableState) SetLastBlockFees

func (s *MutableState) SetLastBlockFees(ctx context.Context, q *quantity.Quantity) error

func (*MutableState) SetTotalSupply

func (s *MutableState) SetTotalSupply(ctx context.Context, q *quantity.Quantity) error

func (*MutableState) SlashEscrow

func (s *MutableState) SlashEscrow(
	ctx *abciAPI.Context,
	fromAddr staking.Address,
	amount *quantity.Quantity,
) (bool, error)

SlashEscrow slashes the escrow balance and the escrow-but-undergoing-debonding balance of the account, transferring it to the global common pool, returning true iff the amount actually slashed is > 0.

WARNING: This is an internal routine to be used to implement staking policy, and MUST NOT be exposed outside of backend implementations.

func (*MutableState) TransferFromCommon

func (s *MutableState) TransferFromCommon(
	ctx *abciAPI.Context,
	toAddr staking.Address,
	amount *quantity.Quantity,
) (bool, error)

TransferFromCommon transfers up to the amount from the global common pool to the general balance of the account, returning true iff the amount transferred is > 0.

WARNING: This is an internal routine to be used to implement incentivization policy, and MUST NOT be exposed outside of backend implementations.

type StakeAccumulatorCache

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

StakeAccumulatorCache is a thin wrapper around an underlying escrow accounts which caches some values (like the threshold map) between operations.

func NewStakeAccumulatorCache

func NewStakeAccumulatorCache(ctx *abciAPI.Context) (*StakeAccumulatorCache, error)

NewStakeAccumulatorCache creates a new stake accumulator cache.

func (*StakeAccumulatorCache) AddStakeClaim

func (c *StakeAccumulatorCache) AddStakeClaim(
	addr staking.Address,
	claim staking.StakeClaim,
	thresholds []staking.StakeThreshold,
) error

AddStakeClaim attempts to add a stake claim to the given escrow account.

In case there is insufficient stake to cover the claim or an error occurs, no modifications are made to the stake accumulator.

func (*StakeAccumulatorCache) CheckStakeClaims

func (c *StakeAccumulatorCache) CheckStakeClaims(addr staking.Address) error

CheckStakeClaims checks whether the escrow account balance satisfies all the stake claims.

func (*StakeAccumulatorCache) Commit

func (c *StakeAccumulatorCache) Commit() error

Commit commits the stake accumulator changes. The caller must ensure that this does not overwrite any outstanding account updates.

func (*StakeAccumulatorCache) Discard

func (c *StakeAccumulatorCache) Discard()

Discard discards any stake accumulator changes.

func (*StakeAccumulatorCache) GetEscrowBalance

func (c *StakeAccumulatorCache) GetEscrowBalance(addr staking.Address) (*quantity.Quantity, error)

GetEscrowBalance returns a given account's escrow balance.

func (*StakeAccumulatorCache) RemoveStakeClaim

func (c *StakeAccumulatorCache) RemoveStakeClaim(
	addr staking.Address,
	claim staking.StakeClaim,
) error

RemoveStakeClaim removes a given stake claim.

It is an error if the stake claim does not exist.

Jump to

Keyboard shortcuts

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