staking

package
v1.0.4-beta Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: GPL-3.0 Imports: 32 Imported by: 0

README

Staking Module

Table of Contents

Preliminary terminology

  • An epoch represents the period until a checkpoint is submitted on Ethereum (i.e. one epoch ends when a checkpoint is committed on Ethereum and the next one begins).

Overview

The staking module in Heimdall is responsible for a validator's stake related operations. It primarily aids in

  • A node joining the protocol as a validator.
  • An node leaving the protocol as a validator.
  • Updating an existing validator's stake in the network.
  • Updating the signer address of an existing validator.

How does one join the network as a validator

The node that wants to be a validator stakes its tokens by invoking the stakeFor method on the StakeManager contract on L1 (Ethereum), which emits a Staked event:

/// @param signer validator address.
/// @param validatorId unique integer to identify a validator.
/// @param nonce to synchronize the events in heimdall.
/// @param activationEpoch validator's first epoch as proposer.
/// @param amount staking amount.
/// @param total total staking amount.
/// @param signerPubkey public key of the validator
event Staked(
    address indexed signer,
    uint256 indexed validatorId,
    uint256 nonce,
    uint256 indexed activationEpoch,
    uint256 amount,
    uint256 total,
    bytes signerPubkey
);

An existing validator on Heimdall catches this event and sends a MsgValidatorJoin transaction, which is represented by the data structure:

type MsgValidatorJoin struct {
	From            hmTypes.HeimdallAddress `json:"from"`
	ID              hmTypes.ValidatorID     `json:"id"`
	ActivationEpoch uint64                  `json:"activationEpoch"`
	Amount          sdk.Int                 `json:"amount"`
	SignerPubKey    hmTypes.PubKey          `json:"pub_key"`
	TxHash          hmTypes.HeimdallHash    `json:"tx_hash"`
	LogIndex        uint64                  `json:"log_index"`
	BlockNumber     uint64                  `json:"block_number"`
	Nonce           uint64                  `json:"nonce"`
}

where

  • From represents the address of the validator that initiated the MsgValidatorJoin transaction on heimdall.
  • ID represents the id of the new validator.
  • ActivationEpoch is the epoch at which the new validator will be activated.
  • Amount is the total staked amount.
  • SignerPubKey is the signer public key of the new validator.
  • TxHash is the hash of the staking transaction on L1.
  • LogIndex is the index of the Staked log in the staking transaction receipt.
  • BlockNumber is the L1 block number in which the staking transaction was included.
  • Nonce is the the count representing all the staking related transactions performed from the new validator's account. This is meant to keep Heimdall and L1 in sync.

Upon broadcasting the message, it goes through HandleMsgValidatorJoin handler which checks the basic sanity of the transaction (verifying the validator isn't already existing, voting power, etc.).

The SideHandleMsgValidatorJoin side-handler in all the existing (honest) validators then ensures the authenticity of staking transaction on L1. It fetches the transaction receipt from L1 contract and validates it with the data provided in the MsgValidatorJoin transaction. Upon successful validation, YES is voted.

The PostHandleMsgValidatorJoin post-handler then initializes the new validator and persists in the state via the keeper:

// create new validator
newValidator := hmTypes.Validator{
	ID:          msg.ID,
	StartEpoch:  msg.ActivationEpoch,
	EndEpoch:    0,
	Nonce:       msg.Nonce,
	VotingPower: votingPower.Int64(),
	PubKey:      pubkey,
	Signer:      hmTypes.BytesToHeimdallAddress(signer.Bytes()),
	LastUpdated: "",
}

// update last updated
newValidator.LastUpdated = sequence.String()

// add validator to store
k.Logger(ctx).Debug("Adding new validator to state", "validator", newValidator.String())

if err = k.AddValidator(ctx, newValidator); err != nil {
	k.Logger(ctx).Error("Unable to add validator to state", "validator", newValidator.String(), "error", err)
	return hmCommon.ErrValidatorSave(k.Codespace()).Result()
}

The EndBlocker hook, which is executed at the end of a heimdall block, then adds the new validator and updates the validator set once activation epoch is completed:

// --- Start update to new validators
currentValidatorSet := app.StakingKeeper.GetValidatorSet(ctx)
allValidators := app.StakingKeeper.GetAllValidators(ctx)
ackCount := app.CheckpointKeeper.GetACKCount(ctx)

// get validator updates
setUpdates := helper.GetUpdatedValidators(
	&currentValidatorSet, // pointer to current validator set -- UpdateValidators will modify it
	allValidators,        // All validators
	ackCount,             // ack count
)

if len(setUpdates) > 0 {
	// create new validator set
	if err := currentValidatorSet.UpdateWithChangeSet(setUpdates); err != nil {
		// return with nothing
		logger.Error("Unable to update current validator set", "Error", err)
		return abci.ResponseEndBlock{}
	}

	// validator set change
	logger.Debug("[ENDBLOCK] Updated current validator set", "proposer", currentValidatorSet.GetProposer())

	// save set in store
	if err := app.StakingKeeper.UpdateValidatorSetInStore(ctx, currentValidatorSet); err != nil {
		// return with nothing
		logger.Error("Unable to update current validator set in state", "Error", err)
		return abci.ResponseEndBlock{}
	}

// more code
	}
How to propose a MsgValidatorJoin transaction

The bridge service in an existing validator's heimdall process polls for Staked event periodically and generates and broadcasts the transaction once it detects and parses the event. An existing validator on the network can also leverage the CLI to send the transaction:

heimdallcli tx staking validator-join --proposer <PROPOSER_ADDRESS> --tx-hash <ETH_TX_HASH> --signer-pubkey <PUB_KEY> --staked-amount <STAKED_AMOUNT> --activation-epoch <ACTIVATION_EPOCH>

Or the REST server :

curl -X POST "localhost:1317/staking/validator-join?from=<PROPOSER_ADDRESS>&tx-hash=<ETH_TX_HASH>&signer-pubkey=<PUB_KEY>&staked-amount=<STAKED_AMOUNT>&activation-epoch=<ACTIVATION_EPOCH>"

How does an existing validator exit the network

If a validator wishes to exit the network and unbond its stake, it invokes the unstake function on the StakeManager contract on L1, which emits an UnstakeInit event:

/// @param user address of the validator.
/// @param validatorId unique integer to identify a validator.
/// @param nonce to synchronize the events in heimdall.
/// @param deactivationEpoch last epoch for validator.
/// @param amount staking amount.
event UnstakeInit(
    address indexed user,
    uint256 indexed validatorId,
    uint256 nonce,
    uint256 deactivationEpoch,
    uint256 indexed amount
);

An existing validator on Heimdall catches and parses this event and sends a MsgValidatorExit transaction, which is represented by the data structure:

type MsgValidatorExit struct {
	From              hmTypes.HeimdallAddress `json:"from"`
	ID                hmTypes.ValidatorID     `json:"id"`
	DeactivationEpoch uint64                  `json:"deactivationEpoch"`
	TxHash            hmTypes.HeimdallHash    `json:"tx_hash"`
	LogIndex          uint64                  `json:"log_index"`
	BlockNumber       uint64                  `json:"block_number"`
	Nonce             uint64                  `json:"nonce"`
}

where

  • From represents the address of the validator that initiated the MsgValidatorExit transaction on heimdall.
  • ID represents the id of the validator to be unstaked.
  • DeactivationEpoch is the last epoch as a validator.
  • TxHash is the hash of the unstake transaction on L1.
  • LogIndex is the index of the UnstakeInit log in the unstake transaction receipt.
  • BlockNumber is the L1 block number in which the unstake transaction was included.
  • Nonce is the the count representing all the staking related transactions performed from the validator's account.

Upon broadcasting the message, it goes through HandleMsgValidatorExit handler which checks the basic sanity of the data in the transaction.

The SideHandleMsgValidatorExit side-handler in all the existing (honest) validators then ensures the authenticity of unstake init transaction on L1. It fetches the transaction receipt from L1 contract and validates it with the data provided in the MsgValidatorExit transaction. Upon successful validation, YES is voted.

The PostHandleMsgValidatorExit post-handler then sets the deactivation epoch for the validator and persists in the state via the keeper:

validator, ok := k.GetValidatorFromValID(ctx, msg.ID)
if !ok {
	k.Logger(ctx).Error("Fetching of validator from store failed", "validatorID", msg.ID)
	return hmCommon.ErrNoValidator(k.Codespace()).Result()
}

// set end epoch
validator.EndEpoch = msg.DeactivationEpoch

// update last updated
validator.LastUpdated = sequence.String()

// update nonce
validator.Nonce = msg.Nonce

// Add deactivation time for validator
if err := k.AddValidator(ctx, validator); err != nil {
	k.Logger(ctx).Error("Error while setting deactivation epoch to validator", "error", err, "validatorID", validator.ID.String())
	return hmCommon.ErrValidatorNotDeactivated(k.Codespace()).Result()
}

The EndBlocker hook then updates the validator set once deactivation epoch is completed.

How to propose a MsgValidatorExit transaction

The bridge service in an existing validator's heimdall process polls for UnstakeInit event periodically and generates and broadcasts the transaction once it detects and parses the event. An existing validator on the network can also leverage the CLI to send the transaction:

heimdallcli tx staking validator-exit --proposer <PROPOSER_ADDRESS> --id <VALIDATOR_ID> --tx-hash <ETH_TX_HASH> --nonce <VALIDATOR_NONCE> --log-index <LOG_INDEX> --block-number <BLOCK_NUMBER> --deactivation-epoch <DEACTIVATION_EPOCH>

Or the REST server :

curl -X POST "localhost:1317/staking/validator-exit?from=<PROPOSER_ADDRESS>&id=<VALIDATOR_ID>&tx-hash=<ETH_TX_HASH>&nonce=<VALIDATOR_NONCE>&log-index=<LOG_INDEX>&block-number=<BLOCK_NUMBER>&deactivation-epoch=<DEACTIVATION_EPOCH>"

How does a validator update its stake

A validator can update its stake in the network by invoking the restake function on the StakeManager contract on L1, which emits an StakeUpdate event:

/// @param validatorId unique integer to identify a validator.
/// @param nonce to synchronize the events in heimdall.
/// @param newAmount the updated stake amount.
event StakeUpdate(
    uint256 indexed validatorId,
    uint256 indexed nonce,
    uint256 indexed newAmount
);

On Heimdall, this event is parsed and a MsgStakeUpdate transaction is broadcasted, which is represented by the data structure:

type MsgStakeUpdate struct {
	From        hmTypes.HeimdallAddress `json:"from"`
	ID          hmTypes.ValidatorID     `json:"id"`
	NewAmount   sdk.Int                 `json:"amount"`
	TxHash      hmTypes.HeimdallHash    `json:"tx_hash"`
	LogIndex    uint64                  `json:"log_index"`
	BlockNumber uint64                  `json:"block_number"`
	Nonce       uint64                  `json:"nonce"`
}

where

  • From represents the address of the validator that initiated the MsgStakeUpdate transaction on heimdall.
  • ID represents the id of the validator whose stake is to be updated.
  • NewAmount is the new staked amount.
  • TxHash is the hash of the stake update transaction on L1.
  • LogIndex is the index of the StakeUpdate log in the stake update transaction receipt.
  • BlockNumber is the L1 block number in which the stake update transaction was included.
  • Nonce is the the count representing all the staking related transactions performed from the validator's account.

Upon broadcasting the message, it goes through HandleMsgStakeUpdate handler which checks the basic sanity of the data in the transaction.

The SideHandleMsgStakeUpdate side-handler in all the existing (honest) validators then ensures the authenticity of the stake update transaction on L1. It fetches the transaction receipt from L1 contract and validates it with the data provided in the MsgStakeUpdate transaction. Upon successful validation, YES is voted.

The PostHandleMsgStakeUpdate post-handler then derives the new voting power for the validator and persists in the state via the keeper:

// set validator amount
p, err := helper.GetPowerFromAmount(msg.NewAmount.BigInt())
if err != nil {
	return hmCommon.ErrInvalidMsg(k.Codespace(), fmt.Sprintf("Invalid amount %v for validator %v", msg.NewAmount, msg.ID)).Result()
}

validator.VotingPower = p.Int64()

// save validator
err = k.AddValidator(ctx, validator)
if err != nil {
	k.Logger(ctx).Error("Unable to update signer", "ValidatorID", validator.ID, "error", err)
	return hmCommon.ErrSignerUpdateError(k.Codespace()).Result()
}

The EndBlocker hook then updates the changes in the validator set.

How to propose a MsgStakeUpdate transaction

The bridge service in an existing validator's heimdall process polls for StakeUpdate event periodically and generates and broadcasts the transaction once it detects and parses the event. An existing validator on the network can also leverage the CLI to send the transaction:

heimdallcli tx staking stake-update --proposer <PROPOSER_ADDRESS> --id <VALIDATOR_ID> --tx-hash <ETH_TX_HASH> --staked-amount <STAKED_AMOUNT> --nonce <VALIDATOR_NONCE> --log-index <LOG_INDEX> --block-number <BLOCK_NUMBER>

Or the REST server :

curl -X POST "localhost:1317/staking/stake-update?proposer=<PROPOSER_ADDRESS>&id=<VALIDATOR_ID>&tx-hash=<ETH_TX_HASH>&staked-amount=<STAKED_AMOUNT>&nonce=<VALIDATOR_NONCE>&log-index=<LOG_INDEX>&block-number=<BLOCK_NUMBER>"

How does a validator update its signer address

A validator can update its signer address in the network by invoking the the updateSigner function on the StakeManager contract on L1, which emits an SignerChange event:

/// @param validatorId unique integer to identify a validator.
/// @param nonce to synchronize the events in heimdall.
/// @param oldSigner old address of the validator.
/// @param newSigner new address of the validator.
/// @param signerPubkey public key of the validator.
event SignerChange(
    uint256 indexed validatorId,
    uint256 nonce,
    address indexed oldSigner,
    address indexed newSigner,
    bytes signerPubkey
);

On Heimdall, this event is parsed and a MsgSignerUpdate transaction is broadcasted, which is represented by the data structure:

type MsgSignerUpdate struct {
	From            hmTypes.HeimdallAddress `json:"from"`
	ID              hmTypes.ValidatorID     `json:"id"`
	NewSignerPubKey hmTypes.PubKey          `json:"pubKey"`
	TxHash          hmTypes.HeimdallHash    `json:"tx_hash"`
	LogIndex        uint64                  `json:"log_index"`
	BlockNumber     uint64                  `json:"block_number"`
	Nonce           uint64                  `json:"nonce"`
}

where

  • From represents the address of the validator that initiated the MsgSignerUpdate transaction on heimdall.
  • ID represents the id of the validator whose signer address is to be updated.
  • NewSignerPubKey is new public key of the validator.
  • TxHash is the hash of the signer update transaction on L1.
  • LogIndex is the index of the SignerChange log in the signer update transaction receipt.
  • BlockNumber is the L1 block number in which the signer update transaction was included.
  • Nonce is the the count representing all the staking related transactions performed from the validator's account.

Upon broadcasting the message, it goes through HandleMsgSignerUpdate handler which checks the basic sanity of the data in the transaction.

The SideHandleMsgSignerUpdate side-handler in all the existing (honest) validators then ensures the authenticity of the signer update transaction on L1. It fetches the transaction receipt from L1 contract and validates it with the data provided in the MsgSignerUpdate transaction. Upon successful validation, YES is voted.

The PostHandleMsgSignerUpdate post-handler then updates the signer address for the validator, "unstakes" the validator instance with the old signer address and persists the changes in the state via the keeper:

oldValidator := validator.Copy()

// more code
...

// check if we are actually updating signer
if !bytes.Equal(newSigner.Bytes(), validator.Signer.Bytes()) {
	// Update signer in prev Validator
	validator.Signer = hmTypes.HeimdallAddress(newSigner)
	validator.PubKey = newPubKey

	k.Logger(ctx).Debug("Updating new signer", "newSigner", newSigner.String(), "oldSigner", oldValidator.Signer.String(), "validatorID", msg.ID)
} else {
	k.Logger(ctx).Error("No signer change", "newSigner", newSigner.String(), "oldSigner", oldValidator.Signer.String(), "validatorID", msg.ID)
	return hmCommon.ErrSignerUpdateError(k.Codespace()).Result()
}

k.Logger(ctx).Debug("Removing old validator", "validator", oldValidator.String())

// remove old validator from HM
oldValidator.EndEpoch = k.moduleCommunicator.GetACKCount(ctx)

// more code
...

// save old validator
if err := k.AddValidator(ctx, *oldValidator); err != nil {
	k.Logger(ctx).Error("Unable to update signer", "validatorId", validator.ID, "error", err)
	return hmCommon.ErrSignerUpdateError(k.Codespace()).Result()
}

// adding new validator
k.Logger(ctx).Debug("Adding new validator", "validator", validator.String())

// save validator
err := k.AddValidator(ctx, validator)
if err != nil {
	k.Logger(ctx).Error("Unable to update signer", "ValidatorID", validator.ID, "error", err)
	return hmCommon.ErrSignerUpdateError(k.Codespace()).Result()
}

The EndBlocker hook then updates the validator set upon completion of the epoch.

How to propose a MsgSignerUpdate transaction

The bridge service in an existing validator's heimdall process polls for SignerChange event periodically and generates and broadcasts the transaction once it detects and parses the event. An existing validator on the network can also leverage the CLI to send the transaction:

heimdallcli tx staking signer-update --proposer <PROPOSER_ADDRESS> --id <VALIDATOR_ID> --new-pubkey <NEW_PUBKEY> --tx-hash <ETH_TX_HASH> --nonce <VALIDATOR_NONCE> --log-index <LOG_INDEX> --block-number <BLOCK_NUMBER>

Or the REST server :

curl -X POST "localhost:1317/staking/signer-update?proposer=<PROPOSER_ADDRESS>&id=<VALIDATOR_ID>&new-pubkey=<NEW_PUBKEY>&tx-hash=<ETH_TX_HASH>&nonce=<VALIDATOR_NONCE>&log-index=<LOG_INDEX>&block-number=<BLOCK_NUMBER>"

Query commands

One can run the following query commands from the staking module :

  • validator-info - Query validator information via validator id or validator address.
  • current-validator-set - Query the current validator set.
  • staking-power - Query the current staking power.
  • validator-status - Query the validator status by validator address.
  • proposer - Fetch the first <TIMES> validators from the validator set, sorted by priority as a checkpoint proposer.
  • current-proposer - Fetch the validator info selected as proposer of the current checkpoint.
  • is-old-tx - Check whether the staking transaction is old.
CLI commands
heimdallcli query staking validator-info --id=<VALIDATOR_ID>

OR

heimdallcli query staking validator-info --validator=<VALIDATOR_ADDRESS>
heimdallcli query staking current-validator-set
heimdallcli query staking staking-power
heimdallcli query staking validator-status --validator=<VALIDATOR_ADDRESS>
heimdallcli query staking proposer --times=<TIMES>
heimdallcli query staking current-proposer 
heimdallcli query staking is-old-tx --tx-hash=<ETH_TX_HASH> --log-index=<LOG_INDEX>
REST endpoints
curl localhost:1317/staking/validator/<VALIDATOR_ID>

OR

curl localhost:1317/staking/validator/<VALIDATOR_ADDRESS>
curl localhost:1317/staking/validator-set
curl localhost:1317/staking/totalpower
curl localhost:1317/staking/validator-status/<VALIDATOR_ADDRESS>
curl localhost:1317/staking/proposer/<TIMES>
curl "localhost:1317/staking/current-proposer
curl localhost:1317/staking/isoldtx?tx-hash=<ETH_TX_HASH>&log-index=<LOG_INDEX>

Some other utility REST URLs:

  • To query validator by signer address:
curl "localhost:1317/staking/signer/<SIGNER_ADDRESS>
  • To fetch the first <TIMES> validators from the validator set, sorted by priority as a milestone proposer:
curl "localhost:1317/staking/milestoneProposer/<TIMES>

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultValue = []byte{0x01} // Value to store in CacheCheckpoint and CacheCheckpointACK & ValidatorSetChange Flag

	ValidatorsKey                   = []byte{0x21} // prefix for each key to a validator
	ValidatorMapKey                 = []byte{0x22} // prefix for each key for validator map
	CurrentValidatorSetKey          = []byte{0x23} // Key to store current validator set
	StakingSequenceKey              = []byte{0x24} // prefix for each key for staking sequence map
	CurrentMilestoneValidatorSetKey = []byte{0x25} // Key to store current validator set for milestone
)

Functions

func ExportGenesis

func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState

ExportGenesis returns a GenesisState for a given context and keeper.

func GetStakingSequenceKey

func GetStakingSequenceKey(sequence string) []byte

GetStakingSequenceKey returns staking sequence key

func GetValidatorKey

func GetValidatorKey(address []byte) []byte

GetValidatorKey drafts the validator key for addresses

func GetValidatorMapKey

func GetValidatorMapKey(address []byte) []byte

GetValidatorMapKey returns validator map

func HandleMsgSignerUpdate

func HandleMsgSignerUpdate(ctx sdk.Context, msg types.MsgSignerUpdate, k Keeper, contractCaller helper.IContractCaller) sdk.Result

HandleMsgSignerUpdate handles signer update message

func HandleMsgStakeUpdate

func HandleMsgStakeUpdate(ctx sdk.Context, msg types.MsgStakeUpdate, k Keeper, contractCaller helper.IContractCaller) sdk.Result

HandleMsgStakeUpdate handles stake update message

func HandleMsgValidatorExit

func HandleMsgValidatorExit(ctx sdk.Context, msg types.MsgValidatorExit, k Keeper, contractCaller helper.IContractCaller) sdk.Result

HandleMsgValidatorExit handle msg validator exit

func HandleMsgValidatorJoin

func HandleMsgValidatorJoin(ctx sdk.Context, msg types.MsgValidatorJoin, k Keeper, contractCaller helper.IContractCaller) sdk.Result

HandleMsgValidatorJoin msg validator join

func InitGenesis

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

InitGenesis sets distribution information for genesis.

func NewHandler

func NewHandler(k Keeper, contractCaller helper.IContractCaller) sdk.Handler

NewHandler new handler

func NewPostTxHandler added in v0.1.7

func NewPostTxHandler(k Keeper, contractCaller helper.IContractCaller) hmTypes.PostTxHandler

NewPostTxHandler returns a side handler for "bank" type messages.

func NewQuerier

func NewQuerier(keeper Keeper, contractCaller helper.IContractCaller) sdk.Querier

NewQuerier returns querier for staking Rest endpoints

func NewSideTxHandler added in v0.1.7

func NewSideTxHandler(k Keeper, contractCaller helper.IContractCaller) hmTypes.SideTxHandler

NewSideTxHandler returns a side handler for "staking" type messages.

func PostHandleMsgSignerUpdate added in v0.1.7

func PostHandleMsgSignerUpdate(ctx sdk.Context, k Keeper, msg types.MsgSignerUpdate, sideTxResult abci.SideTxResultType) sdk.Result

PostHandleMsgSignerUpdate handles signer update message

func PostHandleMsgStakeUpdate added in v0.1.7

func PostHandleMsgStakeUpdate(ctx sdk.Context, k Keeper, msg types.MsgStakeUpdate, sideTxResult abci.SideTxResultType) sdk.Result

PostHandleMsgStakeUpdate handles stake update message

func PostHandleMsgValidatorExit added in v0.1.7

func PostHandleMsgValidatorExit(ctx sdk.Context, k Keeper, msg types.MsgValidatorExit, sideTxResult abci.SideTxResultType) sdk.Result

PostHandleMsgValidatorExit handle msg validator exit

func PostHandleMsgValidatorJoin added in v0.1.7

func PostHandleMsgValidatorJoin(ctx sdk.Context, k Keeper, msg types.MsgValidatorJoin, sideTxResult abci.SideTxResultType) sdk.Result

PostHandleMsgValidatorJoin msg validator join

func SideHandleMsgSignerUpdate added in v0.1.7

func SideHandleMsgSignerUpdate(ctx sdk.Context, msg types.MsgSignerUpdate, k Keeper, contractCaller helper.IContractCaller) (result abci.ResponseDeliverSideTx)

SideHandleMsgSignerUpdate handles signer update message

func SideHandleMsgStakeUpdate added in v0.1.7

func SideHandleMsgStakeUpdate(ctx sdk.Context, msg types.MsgStakeUpdate, k Keeper, contractCaller helper.IContractCaller) (result abci.ResponseDeliverSideTx)

SideHandleMsgStakeUpdate handles stake update message

func SideHandleMsgValidatorExit added in v0.1.7

func SideHandleMsgValidatorExit(ctx sdk.Context, msg types.MsgValidatorExit, k Keeper, contractCaller helper.IContractCaller) (result abci.ResponseDeliverSideTx)

SideHandleMsgValidatorExit handle side msg validator exit

func SideHandleMsgValidatorJoin added in v0.1.7

func SideHandleMsgValidatorJoin(ctx sdk.Context, msg types.MsgValidatorJoin, k Keeper, contractCaller helper.IContractCaller) (result abci.ResponseDeliverSideTx)

SideHandleMsgValidatorJoin side msg validator join

Types

type AppModule

type AppModule struct {
	AppModuleBasic
	// contains filtered or unexported fields
}

AppModule implements an application module for the supply module.

func NewAppModule

func NewAppModule(keeper Keeper, contractCaller helper.IContractCaller) AppModule

NewAppModule creates a new AppModule object

func (AppModule) BeginBlock

func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock)

BeginBlock returns the begin blocker for the auth module.

func (AppModule) EndBlock

EndBlock returns the end blocker for the auth module. It returns no validator updates.

func (AppModule) ExportGenesis

func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage

ExportGenesis returns the exported genesis state as raw bytes for the auth module.

func (AppModule) GenerateGenesisState added in v0.1.7

func (AppModule) GenerateGenesisState(simState *hmModule.SimulationState)

GenerateGenesisState creates a randomized GenState of the Staking module

func (AppModule) InitGenesis

func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate

InitGenesis performs genesis initialization for the auth module. It returns no validator updates.

func (AppModule) Name

func (AppModule) Name() string

Name returns the module's name.

func (AppModule) NewHandler

func (am AppModule) NewHandler() sdk.Handler

NewHandler returns an sdk.Handler for the module.

func (AppModule) NewPostTxHandler added in v0.1.7

func (am AppModule) NewPostTxHandler() hmTypes.PostTxHandler

NewPostTxHandler side tx handler

func (AppModule) NewQuerierHandler

func (am AppModule) NewQuerierHandler() sdk.Querier

NewQuerierHandler returns the auth module sdk.Querier.

func (AppModule) NewSideTxHandler added in v0.1.7

func (am AppModule) NewSideTxHandler() hmTypes.SideTxHandler

func (AppModule) ProposalContents added in v0.1.7

func (AppModule) ProposalContents(simState hmModule.SimulationState) []simTypes.WeightedProposalContent

ProposalContents doesn't return any content functions.

func (AppModule) QuerierRoute

func (AppModule) QuerierRoute() string

QuerierRoute returns the staking module's querier route name.

func (AppModule) RandomizedParams added in v0.1.7

func (AppModule) RandomizedParams(r *rand.Rand) []simTypes.ParamChange

RandomizedParams creates randomized param changes for the simulator.

func (AppModule) RegisterInvariants

func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry)

RegisterInvariants performs a no-op.

func (AppModule) RegisterStoreDecoder added in v0.1.7

func (AppModule) RegisterStoreDecoder(sdr hmModule.StoreDecoderRegistry)

RegisterStoreDecoder registers a decoder for chainmanager module's types

func (AppModule) Route

func (AppModule) Route() string

Route returns the message routing key for the module.

func (AppModule) WeightedOperations added in v0.1.7

WeightedOperations doesn't return any chainmanager module operation.

type AppModuleBasic

type AppModuleBasic struct{}

AppModuleBasic defines the basic application module used by the auth module.

func (AppModuleBasic) DefaultGenesis

func (AppModuleBasic) DefaultGenesis() json.RawMessage

DefaultGenesis returns default genesis state as raw bytes for the auth module.

func (AppModuleBasic) GetQueryCmd

func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command

GetQueryCmd returns the root query command for the auth module.

func (AppModuleBasic) GetTxCmd

func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command

GetTxCmd returns the root tx command for the auth module.

func (AppModuleBasic) Name

func (AppModuleBasic) Name() string

Name returns the auth module's name.

func (AppModuleBasic) RegisterCodec

func (AppModuleBasic) RegisterCodec(cdc *codec.Codec)

RegisterCodec registers the auth module's types for the given codec.

func (AppModuleBasic) RegisterRESTRoutes

func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router)

RegisterRESTRoutes registers the REST routes for the auth module.

func (AppModuleBasic) ValidateGenesis

func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error

ValidateGenesis performs genesis state validation for the auth module.

func (AppModuleBasic) VerifyGenesis

func (AppModuleBasic) VerifyGenesis(bz map[string]json.RawMessage) error

VerifyGenesis performs verification on auth module state.

type Keeper

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

Keeper stores all related data

func NewKeeper

func NewKeeper(
	cdc *codec.Codec,
	storeKey sdk.StoreKey,
	paramSpace subspace.Subspace,
	codespace sdk.CodespaceType,
	chainKeeper chainmanager.Keeper,
	moduleCommunicator ModuleCommunicator,
) Keeper

NewKeeper create new keeper

func (*Keeper) AddValidator

func (k *Keeper) AddValidator(ctx sdk.Context, validator hmTypes.Validator) error

AddValidator adds validator indexed with address

func (*Keeper) AddValidatorSigningInfo added in v0.1.7

func (k *Keeper) AddValidatorSigningInfo(ctx sdk.Context, valID hmTypes.ValidatorID, valSigningInfo hmTypes.ValidatorSigningInfo) error

Slashing api's AddValidatorSigningInfo creates a signing info for validator

func (Keeper) Codespace

func (k Keeper) Codespace() sdk.CodespaceType

Codespace returns the codespace

func (*Keeper) GetActiveValidatorInfo

func (k *Keeper) GetActiveValidatorInfo(ctx sdk.Context, address []byte) (validator hmTypes.Validator, err error)

GetActiveValidatorInfo returns active validator

func (*Keeper) GetAllValidators

func (k *Keeper) GetAllValidators(ctx sdk.Context) (validators []*hmTypes.Validator)

GetAllValidators returns all validators

func (*Keeper) GetCurrentProposer

func (k *Keeper) GetCurrentProposer(ctx sdk.Context) *hmTypes.Validator

GetCurrentProposer returns current proposer

func (*Keeper) GetCurrentValidators

func (k *Keeper) GetCurrentValidators(ctx sdk.Context) (validators []hmTypes.Validator)

GetCurrentValidators returns all validators who are in validator set

func (*Keeper) GetLastUpdated

func (k *Keeper) GetLastUpdated(ctx sdk.Context, valID hmTypes.ValidatorID) (updatedAt string, found bool)

GetLastUpdated get last updated at for validator

func (*Keeper) GetMilestoneCurrentProposer added in v1.0.1

func (k *Keeper) GetMilestoneCurrentProposer(ctx sdk.Context) *hmTypes.Validator

GetMilestoneCurrentProposer returns current proposer

func (*Keeper) GetMilestoneValidatorSet added in v1.0.1

func (k *Keeper) GetMilestoneValidatorSet(ctx sdk.Context) (validatorSet hmTypes.ValidatorSet)

GetMilestoneValidatorSet returns current milestone Validator Set from store

func (*Keeper) GetNextProposer

func (k *Keeper) GetNextProposer(ctx sdk.Context) *hmTypes.Validator

GetNextProposer returns next proposer

func (*Keeper) GetSignerFromValidatorID

func (k *Keeper) GetSignerFromValidatorID(ctx sdk.Context, valID hmTypes.ValidatorID) (common.Address, bool)

GetSignerFromValidatorID get signer address from validator ID

func (*Keeper) GetSpanEligibleValidators

func (k *Keeper) GetSpanEligibleValidators(ctx sdk.Context) (validators []hmTypes.Validator)

GetSpanEligibleValidators returns current validators who are not getting deactivated in between next span

func (*Keeper) GetStakingSequences

func (k *Keeper) GetStakingSequences(ctx sdk.Context) (sequences []string)

GetStakingSequences checks if Staking already exists

func (*Keeper) GetTotalPower added in v0.1.7

func (k *Keeper) GetTotalPower(ctx sdk.Context) (totalPower int64)

func (*Keeper) GetValidatorFromValID

func (k *Keeper) GetValidatorFromValID(ctx sdk.Context, valID hmTypes.ValidatorID) (validator hmTypes.Validator, ok bool)

GetValidatorFromValID returns signer from validator ID

func (*Keeper) GetValidatorInfo

func (k *Keeper) GetValidatorInfo(ctx sdk.Context, address []byte) (validator hmTypes.Validator, err error)

GetValidatorInfo returns validator

func (*Keeper) GetValidatorSet

func (k *Keeper) GetValidatorSet(ctx sdk.Context) (validatorSet hmTypes.ValidatorSet)

GetValidatorSet returns current Validator Set from store

func (*Keeper) HasStakingSequence

func (k *Keeper) HasStakingSequence(ctx sdk.Context, sequence string) bool

HasStakingSequence checks if staking sequence already exists

func (*Keeper) IncrementAccum

func (k *Keeper) IncrementAccum(ctx sdk.Context, times int)

IncrementAccum increments accum for validator set by n times and replace validator set in store

func (*Keeper) IsCurrentValidatorByAddress

func (k *Keeper) IsCurrentValidatorByAddress(ctx sdk.Context, address []byte) bool

IsCurrentValidatorByAddress check if validator is in current validator set by signer address

func (*Keeper) IterateCurrentValidatorsAndApplyFn

func (k *Keeper) IterateCurrentValidatorsAndApplyFn(ctx sdk.Context, f func(validator *hmTypes.Validator) bool)

IterateCurrentValidatorsAndApplyFn iterate through current validators

func (*Keeper) IterateStakingSequencesAndApplyFn

func (k *Keeper) IterateStakingSequencesAndApplyFn(ctx sdk.Context, f func(sequence string) error)

IterateStakingSequencesAndApplyFn iterate validators and apply the given function.

func (*Keeper) IterateValidatorsAndApplyFn

func (k *Keeper) IterateValidatorsAndApplyFn(ctx sdk.Context, f func(validator hmTypes.Validator) error)

IterateValidatorsAndApplyFn iterate validators and apply the given function.

func (Keeper) Logger

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

Logger returns a module-specific logger

func (*Keeper) MilestoneIncrementAccum added in v1.0.1

func (k *Keeper) MilestoneIncrementAccum(ctx sdk.Context, times int)

MilestoneIncrementAccum increments accum for milestone validator set by n times and replace validator set in store

func (*Keeper) SetStakingSequence

func (k *Keeper) SetStakingSequence(ctx sdk.Context, sequence string)

SetStakingSequence sets staking sequence

func (*Keeper) SetValidatorIDToSignerAddr

func (k *Keeper) SetValidatorIDToSignerAddr(ctx sdk.Context, valID hmTypes.ValidatorID, signerAddr hmTypes.HeimdallAddress)

SetValidatorIDToSignerAddr sets mapping for validator ID to signer address

func (*Keeper) Slash added in v0.1.7

func (k *Keeper) Slash(ctx sdk.Context, valSlashingInfo hmTypes.ValidatorSlashingInfo) error

UpdatePower updates validator with signer and pubkey + validator => signer map

func (*Keeper) Unjail added in v0.1.7

func (k *Keeper) Unjail(ctx sdk.Context, valID hmTypes.ValidatorID)

Unjail a validator

func (*Keeper) UpdateMilestoneValidatorSetInStore added in v1.0.1

func (k *Keeper) UpdateMilestoneValidatorSetInStore(ctx sdk.Context, newValidatorSet hmTypes.ValidatorSet) error

UpdateMilestoneValidatorSetInStore adds milestone validator set to store

func (*Keeper) UpdateSigner

func (k *Keeper) UpdateSigner(ctx sdk.Context, newSigner hmTypes.HeimdallAddress, newPubkey hmTypes.PubKey, prevSigner hmTypes.HeimdallAddress) error

UpdateSigner updates validator with signer and pubkey + validator => signer map

func (*Keeper) UpdateValidatorSetInStore

func (k *Keeper) UpdateValidatorSetInStore(ctx sdk.Context, newValidatorSet hmTypes.ValidatorSet) error

UpdateValidatorSetInStore adds validator set to store

type ModuleCommunicator

type ModuleCommunicator interface {
	GetACKCount(ctx sdk.Context) uint64
	SetCoins(ctx sdk.Context, addr hmTypes.HeimdallAddress, amt sdk.Coins) sdk.Error
	GetCoins(ctx sdk.Context, addr hmTypes.HeimdallAddress) sdk.Coins
	SendCoins(ctx sdk.Context, from hmTypes.HeimdallAddress, to hmTypes.HeimdallAddress, amt sdk.Coins) sdk.Error
	CreateValidatorSigningInfo(ctx sdk.Context, valID hmTypes.ValidatorID, valSigningInfo hmTypes.ValidatorSigningInfo)
}

ModuleCommunicator manages different module interaction

Directories

Path Synopsis
client
cli
rest
nolint
nolint

Jump to

Keyboard shortcuts

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