governance

package
v1.10.2-rc.4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: GPL-3.0 Imports: 26 Imported by: 26

Documentation

Overview

Package governance contains functions and variables used for voting and reflecting vote results in Klaytn. In Klaytn, various settings such as the amount of KLAY minted as a block reward can be changed by using governance vote. These votes can be casted by nodes of Governance Council and detailed introduction can be found at https://docs.klaytn.com/klaytn/design/governance

How to cast a vote

To cast a vote, a node have to be a member of the Governance Council. If the governance mode is "single", only one designated node (the governing node) can vote. In the console of the node, "governance.vote(key, value)" API can be used to cast a vote.

Keys for the voting API

Following keys can be handled as of 7/20/2019.

  • "governance.governancemode" : To change the governance mode
  • "governance.governingnode" : To change the governing node if the governance mode is "single"
  • "governance.unitprice" : To change the unitprice of Klaytn (Unit price is same as gasprice in Ethereum)
  • "governance.addvalidator" : To add new node as a council node
  • "governance.removevalidator" : To remove a node from the governance council
  • "istanbul.epoch" : To change Epoch, the period to gather votes
  • "istanbul.committeesize" : To change the size of the committee
  • "reward.mintingamount" : To change the amount of block generation reward
  • "reward.ratio" : To change the ratio used to distribute the reward between block proposer node, KFF and KCF
  • "reward.useginicoeff" : To change the application of gini coefficient to reduce gap between CCOs
  • "reward.deferredtxfee" : To change the way of distributing tx fee
  • "reward.minimumstake" : To change the minimum amount of stake to participate in the governance council

How governance works

Governance package contains a governance struct which stores current system configurations and voting status. If a vote passed, the governance struct is updated to provide new information to related packages and users. The API documentation can be found at https://docs.klaytn.com/bapp/json-rpc/api-references/governance

When a CN (consensus node which is managed by CCO) proposes a block, it writes its vote on the block header and other nodes parse the header and handle it. This process is handled by snapshot.go in the consensus engine and processed by functions in handler.go

If a vote satisfies the requirement (more than 50% of votes in favor of), it will update the governance struct and many other packages like "reward", "txpool" and so on will reference it.

Source Files

Governance related functions and variables are defined in the files listed below

  • default.go : the governance struct, cache and persistence
  • handler.go : functions to handle votes and its application
  • api.go : console APIs to get governance information and to cast a vote
  • interface.go : Abstract interfaces to various underlying implementations
  • mixed.go : Wrapper for multiple engine implementations

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValueTypeMismatch  = errors.New("Value's type mismatch")
	ErrDecodeGovChange    = errors.New("Failed to decode received governance changes")
	ErrUnmarshalGovChange = errors.New("Failed to unmarshal received governance changes")
	ErrVoteValueMismatch  = errors.New("Received change mismatches with the value this node has!!")
	ErrNotInitialized     = errors.New("Cache not initialized")
	ErrItemNotFound       = errors.New("Failed to find governance item")
	ErrItemNil            = errors.New("Governance Item is nil")
	ErrUnknownKey         = errors.New("Governnace value of the given key not found")
)
View Source
var (
	GovernanceKeyMap = map[string]int{
		"governance.governancemode":       params.GovernanceMode,
		"governance.governingnode":        params.GoverningNode,
		"governance.govparamcontract":     params.GovParamContract,
		"istanbul.epoch":                  params.Epoch,
		"istanbul.policy":                 params.Policy,
		"istanbul.committeesize":          params.CommitteeSize,
		"governance.unitprice":            params.UnitPrice,
		"governance.deriveshaimpl":        params.DeriveShaImpl,
		"kip71.lowerboundbasefee":         params.LowerBoundBaseFee,
		"kip71.gastarget":                 params.GasTarget,
		"kip71.maxblockgasusedforbasefee": params.MaxBlockGasUsedForBaseFee,
		"kip71.basefeedenominator":        params.BaseFeeDenominator,
		"kip71.upperboundbasefee":         params.UpperBoundBaseFee,
		"reward.mintingamount":            params.MintingAmount,
		"reward.ratio":                    params.Ratio,
		"reward.kip82ratio":               params.Kip82Ratio,
		"reward.useginicoeff":             params.UseGiniCoeff,
		"reward.deferredtxfee":            params.DeferredTxFee,
		"reward.minimumstake":             params.MinimumStake,
		"reward.stakingupdateinterval":    params.StakeUpdateInterval,
		"reward.proposerupdateinterval":   params.ProposerRefreshInterval,
		"governance.addvalidator":         params.AddValidator,
		"governance.removevalidator":      params.RemoveValidator,
		"param.txgashumanreadable":        params.ConstTxGasHumanReadable,
		"istanbul.timeout":                params.Timeout,
	}

	GovernanceForbiddenKeyMap = map[string]int{
		"istanbul.policy":               params.Policy,
		"reward.stakingupdateinterval":  params.StakeUpdateInterval,
		"reward.proposerupdateinterval": params.ProposerRefreshInterval,
	}

	GovernanceKeyMapReverse = map[int]string{
		params.GovernanceMode:            "governance.governancemode",
		params.GoverningNode:             "governance.governingnode",
		params.GovParamContract:          "governance.govparamcontract",
		params.Epoch:                     "istanbul.epoch",
		params.CliqueEpoch:               "clique.epoch",
		params.Policy:                    "istanbul.policy",
		params.CommitteeSize:             "istanbul.committeesize",
		params.UnitPrice:                 "governance.unitprice",
		params.DeriveShaImpl:             "governance.deriveshaimpl",
		params.LowerBoundBaseFee:         "kip71.lowerboundbasefee",
		params.UpperBoundBaseFee:         "kip71.upperboundbasefee",
		params.GasTarget:                 "kip71.gastarget",
		params.MaxBlockGasUsedForBaseFee: "kip71.maxblockgasusedforbasefee",
		params.BaseFeeDenominator:        "kip71.basefeedenominator",
		params.MintingAmount:             "reward.mintingamount",
		params.Ratio:                     "reward.ratio",
		params.UseGiniCoeff:              "reward.useginicoeff",
		params.DeferredTxFee:             "reward.deferredtxfee",
		params.MinimumStake:              "reward.minimumstake",
		params.StakeUpdateInterval:       "reward.stakingupdateinterval",
		params.ProposerRefreshInterval:   "reward.proposerupdateinterval",
		params.AddValidator:              "governance.addvalidator",
		params.RemoveValidator:           "governance.removevalidator",
		params.ConstTxGasHumanReadable:   "param.txgashumanreadable",
		params.Timeout:                   "istanbul.timeout",
		params.Kip82Ratio:                "reward.kip82ratio",
	}

	ProposerPolicyMap = map[string]int{
		"roundrobin":     params.RoundRobin,
		"sticky":         params.Sticky,
		"weightedrandom": params.WeightedRandom,
	}

	ProposerPolicyMapReverse = map[int]string{
		params.RoundRobin:     "roundrobin",
		params.Sticky:         "sticky",
		params.WeightedRandom: "weightedrandom",
	}

	GovernanceModeMap = map[string]int{
		"none":   params.GovernanceMode_None,
		"single": params.GovernanceMode_Single,
		"ballot": params.GovernanceMode_Ballot,
	}
)
View Source
var GovernanceItems = map[int]check{
	params.GovernanceMode:            {stringT, checkGovernanceMode, nil},
	params.GoverningNode:             {addressT, checkAddress, nil},
	params.GovParamContract:          {addressT, checkAddress, nil},
	params.UnitPrice:                 {uint64T, checkUint64andBool, nil},
	params.DeriveShaImpl:             {uint64T, checkUint64andBool, nil},
	params.LowerBoundBaseFee:         {uint64T, checkUint64andBool, nil},
	params.UpperBoundBaseFee:         {uint64T, checkUint64andBool, nil},
	params.GasTarget:                 {uint64T, checkUint64andBool, nil},
	params.MaxBlockGasUsedForBaseFee: {uint64T, checkUint64andBool, nil},
	params.BaseFeeDenominator:        {uint64T, checkUint64andBool, nil},
	params.AddValidator:              {addressT, checkAddressOrListOfUniqueAddresses, nil},
	params.RemoveValidator:           {addressT, checkAddressOrListOfUniqueAddresses, nil},
	params.MintingAmount:             {stringT, checkBigInt, nil},
	params.Ratio:                     {stringT, checkRatio, nil},
	params.UseGiniCoeff:              {boolT, checkUint64andBool, nil},
	params.Kip82Ratio:                {stringT, checkKip82Ratio, nil},
	params.DeferredTxFee:             {boolT, checkUint64andBool, nil},
	params.MinimumStake:              {stringT, checkRewardMinimumStake, nil},
	params.StakeUpdateInterval:       {uint64T, checkUint64andBool, nil},
	params.ProposerRefreshInterval:   {uint64T, checkUint64andBool, nil},
	params.Epoch:                     {uint64T, checkUint64andBool, nil},
	params.Policy:                    {uint64T, checkUint64andBool, nil},
	params.CommitteeSize:             {uint64T, checkCommitteeSize, nil},
	params.ConstTxGasHumanReadable:   {uint64T, checkUint64andBool, updateTxGasHumanReadable},
	params.Timeout:                   {uint64T, checkUint64andBool, nil},
}

Functions

func AddGovernanceCacheForTest

func AddGovernanceCacheForTest(e HeaderEngine, num uint64, config *params.ChainConfig)

func CalcGovernanceInfoBlock

func CalcGovernanceInfoBlock(num uint64, epoch uint64) uint64

func CheckGenesisValues

func CheckGenesisValues(c *params.ChainConfig) error

Types

type ContractEngine added in v1.10.0

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

func NewContractEngine added in v1.10.0

func NewContractEngine(headerGov *Governance) *ContractEngine

func (*ContractEngine) CurrentParams added in v1.10.2

func (e *ContractEngine) CurrentParams() *params.GovParamSet

CurrentParams effective at upcoming block (head+1)

func (*ContractEngine) EffectiveParams added in v1.10.2

func (e *ContractEngine) EffectiveParams(num uint64) (*params.GovParamSet, error)

Parameters effective at requested block (num)

func (*ContractEngine) UpdateParams added in v1.10.0

func (e *ContractEngine) UpdateParams(num uint64) error

if UpdateParam fails, leave currentParams as-is

type Engine added in v1.9.0

type Engine interface {
	HeaderEngine
	ReaderEngine
	HeaderGov() HeaderEngine
	ContractGov() ReaderEngine
}

type Governance

type Governance struct {
	ChainConfig *params.ChainConfig // Only exists to keep DB backward compatibility in WriteGovernanceState()

	GovernanceVotes   GovernanceVotes
	GovernanceTallies GovernanceTallyList

	TxPool txPool
	// contains filtered or unexported fields
}

func NewGovernance

func NewGovernance(chainConfig *params.ChainConfig, dbm database.DBManager) *Governance

NewGovernance creates Governance with the given configuration.

func NewGovernanceInitialize added in v1.6.0

func NewGovernanceInitialize(chainConfig *params.ChainConfig, dbm database.DBManager) *Governance

NewGovernanceInitialize creates Governance with the given configuration and read governance state from DB. If any items are not stored in DB, it stores governance items of the genesis block to DB.

func (*Governance) AddVote

func (g *Governance) AddVote(key string, val interface{}) bool

AddVote adds a vote to the voteMap

func (*Governance) BlockChain added in v1.9.0

func (gov *Governance) BlockChain() blockChain

func (*Governance) CanWriteGovernanceState

func (gov *Governance) CanWriteGovernanceState(num uint64) bool

func (*Governance) ClearVotes

func (g *Governance) ClearVotes(num uint64)

func (*Governance) CurrentParams added in v1.10.2

func (gov *Governance) CurrentParams() *params.GovParamSet

func (*Governance) CurrentSetCopy added in v1.9.0

func (gov *Governance) CurrentSetCopy() map[string]interface{}

func (*Governance) DB added in v1.9.0

func (gov *Governance) DB() database.DBManager

func (*Governance) EffectiveParams added in v1.10.2

func (gov *Governance) EffectiveParams(num uint64) (*params.GovParamSet, error)

EffectiveParams returns the parameter set used for generating the block `num`

func (*Governance) GetEncodedVote

func (g *Governance) GetEncodedVote(addr common.Address, number uint64) []byte

func (*Governance) GetGovernanceChange

func (g *Governance) GetGovernanceChange() map[string]interface{}

func (*Governance) GetGovernanceTalliesCopy added in v1.9.0

func (g *Governance) GetGovernanceTalliesCopy() []GovernanceTallyItem

func (*Governance) GetGovernanceValue

func (gov *Governance) GetGovernanceValue(key int) interface{}

func (*Governance) GetTxPool added in v1.9.0

func (gov *Governance) GetTxPool() txPool

func (*Governance) GetVoteMapCopy added in v1.9.0

func (g *Governance) GetVoteMapCopy() map[string]VoteStatus

func (*Governance) HandleGovernanceVote

func (gov *Governance) HandleGovernanceVote(valset istanbul.ValidatorSet, votes []GovernanceVote, tally []GovernanceTallyItem, header *types.Header, proposer common.Address, self common.Address, writable bool) (istanbul.ValidatorSet, []GovernanceVote, []GovernanceTallyItem)

func (*Governance) IdxCache added in v1.1.0

func (gov *Governance) IdxCache() []uint64

func (*Governance) IdxCacheFromDb added in v1.1.0

func (gov *Governance) IdxCacheFromDb() []uint64

func (*Governance) MyVotingPower added in v1.9.0

func (g *Governance) MyVotingPower() uint64

func (*Governance) NodeAddress added in v1.9.0

func (g *Governance) NodeAddress() common.Address

func (*Governance) ParseVoteValue

func (g *Governance) ParseVoteValue(gVote *GovernanceVote) (*GovernanceVote, error)

ParseVoteValue parses vote.Value from []uint8, [][]uint8 to appropriate type

func (*Governance) PendingChanges added in v1.1.0

func (gov *Governance) PendingChanges() map[string]interface{}

func (*Governance) ReadGovernance

func (g *Governance) ReadGovernance(num uint64) (uint64, map[string]interface{}, error)

func (*Governance) ReadGovernanceState

func (gov *Governance) ReadGovernanceState()

ReadGovernanceState reads field values of the Governance struct from database. It also updates params.stakingUpdateInterval and params.proposerUpdateInterval with the retrieved value.

func (*Governance) ReflectVotes

func (gov *Governance) ReflectVotes(vote GovernanceVote)

func (*Governance) RemoveVote

func (g *Governance) RemoveVote(key string, value interface{}, number uint64)

RemoveVote removes a vote from the voteMap to prevent repetitive addition of same vote

func (*Governance) SetBlockchain

func (gov *Governance) SetBlockchain(bc blockChain)

func (*Governance) SetMyVotingPower

func (g *Governance) SetMyVotingPower(t uint64)

func (*Governance) SetNodeAddress

func (g *Governance) SetNodeAddress(addr common.Address)

func (*Governance) SetTotalVotingPower

func (g *Governance) SetTotalVotingPower(t uint64)

func (*Governance) SetTxPool

func (gov *Governance) SetTxPool(txpool txPool)

func (*Governance) TotalVotingPower added in v1.9.0

func (g *Governance) TotalVotingPower() uint64

func (*Governance) UnmarshalJSON

func (gov *Governance) UnmarshalJSON(b []byte) error

func (*Governance) UpdateCurrentSet added in v1.7.0

func (gov *Governance) UpdateCurrentSet(num uint64)

func (*Governance) UpdateParams added in v1.10.0

func (gov *Governance) UpdateParams(num uint64) error

func (*Governance) ValidateVote

func (gov *Governance) ValidateVote(vote *GovernanceVote) (*GovernanceVote, bool)

func (*Governance) VerifyGovernance

func (gov *Governance) VerifyGovernance(received []byte) error

func (*Governance) Votes added in v1.1.0

func (gov *Governance) Votes() []GovernanceVote

func (*Governance) WriteGovernance

func (g *Governance) WriteGovernance(num uint64, data GovernanceSet, delta GovernanceSet) error

Store new governance data on DB. This updates Governance cache too.

func (*Governance) WriteGovernanceForNextEpoch added in v1.7.0

func (gov *Governance) WriteGovernanceForNextEpoch(number uint64, governance []byte)

WriteGovernanceForNextEpoch creates governance items for next epoch and writes them to the database. The governance items on next epoch will be the given `governance` items applied on the top of past epoch items.

func (*Governance) WriteGovernanceState

func (gov *Governance) WriteGovernanceState(num uint64, isCheckpoint bool) error

type GovernanceKlayAPI

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

func NewGovernanceKlayAPI

func NewGovernanceKlayAPI(gov Engine, chain blockChain) *GovernanceKlayAPI

func (*GovernanceKlayAPI) ChainConfig added in v1.10.0

func (api *GovernanceKlayAPI) ChainConfig() *params.ChainConfig

func (*GovernanceKlayAPI) ChainConfigAt added in v1.10.0

func (api *GovernanceKlayAPI) ChainConfigAt(num *rpc.BlockNumber) *params.ChainConfig

TODO-Klaytn-Mantle: deprecate this

func (*GovernanceKlayAPI) GasPriceAt

func (api *GovernanceKlayAPI) GasPriceAt(num *rpc.BlockNumber) (*hexutil.Big, error)

GasPriceAt returns the base fee of the given block in peb, or returns unit price by using governance if there is no base fee set in header, or returns gas price of txpool if the block is pending block.

func (*GovernanceKlayAPI) GasPriceAtNumber

func (api *GovernanceKlayAPI) GasPriceAtNumber(num uint64) (uint64, error)

func (*GovernanceKlayAPI) GetChainConfig added in v1.10.2

func (api *GovernanceKlayAPI) GetChainConfig(num *rpc.BlockNumber) *params.ChainConfig

func (*GovernanceKlayAPI) GetParams added in v1.10.2

func (api *GovernanceKlayAPI) GetParams(num *rpc.BlockNumber) (map[string]interface{}, error)

func (*GovernanceKlayAPI) GetRewards added in v1.10.0

func (api *GovernanceKlayAPI) GetRewards(num *rpc.BlockNumber) (*reward.RewardSpec, error)

GetRewards returns detailed information of the block reward at a given block number.

func (*GovernanceKlayAPI) GetStakingInfo added in v1.10.0

func (api *GovernanceKlayAPI) GetStakingInfo(num *rpc.BlockNumber) (*reward.StakingInfo, error)

func (*GovernanceKlayAPI) GovParamsAt added in v1.10.0

func (api *GovernanceKlayAPI) GovParamsAt(num *rpc.BlockNumber) (map[string]interface{}, error)

TODO-Klaytn-Mantle: deprecate this

func (*GovernanceKlayAPI) NodeAddress added in v1.10.0

func (api *GovernanceKlayAPI) NodeAddress() common.Address

type GovernanceSet

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

GovernanceSet contains an item set for governance

func GetGovernanceItemsFromChainConfig added in v1.6.0

func GetGovernanceItemsFromChainConfig(config *params.ChainConfig) GovernanceSet

GetGovernanceItemsFromChainConfig returns governance set that is effective at the genesis block

func NewGovernanceSet added in v1.1.0

func NewGovernanceSet() GovernanceSet

func (*GovernanceSet) Clear added in v1.1.0

func (gs *GovernanceSet) Clear()

func (*GovernanceSet) GetValue added in v1.1.0

func (gs *GovernanceSet) GetValue(key int) (interface{}, bool)

func (*GovernanceSet) Import added in v1.1.0

func (gs *GovernanceSet) Import(src map[string]interface{})

func (*GovernanceSet) Items added in v1.1.0

func (gs *GovernanceSet) Items() map[string]interface{}

func (*GovernanceSet) Merge added in v1.1.0

func (gs *GovernanceSet) Merge(change map[string]interface{})

func (*GovernanceSet) RemoveItem added in v1.1.0

func (gs *GovernanceSet) RemoveItem(key string)

func (*GovernanceSet) SetValue

func (gs *GovernanceSet) SetValue(itemType int, value interface{}) error

func (*GovernanceSet) Size added in v1.1.0

func (gs *GovernanceSet) Size() int

type GovernanceTallyItem added in v1.1.0

type GovernanceTallyItem struct {
	Key   string      `json:"key"`
	Value interface{} `json:"value"`
	Votes uint64      `json:"votes"`
}

GovernanceTallyItem represents a tally for each governance item

type GovernanceTallyList added in v1.1.0

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

func NewGovernanceTallies added in v1.1.0

func NewGovernanceTallies() GovernanceTallyList

func (*GovernanceTallyList) Clear added in v1.1.0

func (gt *GovernanceTallyList) Clear()

func (*GovernanceTallyList) Copy added in v1.1.0

func (*GovernanceTallyList) Import added in v1.1.0

func (gt *GovernanceTallyList) Import(src []GovernanceTallyItem)

type GovernanceVote

type GovernanceVote struct {
	Validator common.Address `json:"validator"`
	Key       string         `json:"key"`
	Value     interface{}    `json:"value"`
}

GovernanceVote represents vote information given from istanbul.vote()

type GovernanceVotes added in v1.1.0

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

func NewGovernanceVotes added in v1.1.0

func NewGovernanceVotes() GovernanceVotes

func (*GovernanceVotes) Clear added in v1.1.0

func (gv *GovernanceVotes) Clear()

func (*GovernanceVotes) Copy added in v1.1.0

func (gv *GovernanceVotes) Copy() []GovernanceVote

func (*GovernanceVotes) Import added in v1.1.0

func (gv *GovernanceVotes) Import(src []GovernanceVote)

type HeaderEngine added in v1.9.0

type HeaderEngine interface {
	// AddVote casts votes from API
	AddVote(key string, val interface{}) bool
	ValidateVote(vote *GovernanceVote) (*GovernanceVote, bool)

	// Access database for voting states
	CanWriteGovernanceState(num uint64) bool
	WriteGovernanceState(num uint64, isCheckpoint bool) error

	// Access database for network params
	ReadGovernance(num uint64) (uint64, map[string]interface{}, error)
	WriteGovernance(num uint64, data GovernanceSet, delta GovernanceSet) error

	// Compose header.Vote and header.Governance
	GetEncodedVote(addr common.Address, number uint64) []byte
	GetGovernanceChange() map[string]interface{}

	// Intake header.Vote and header.Governance
	VerifyGovernance(received []byte) error
	ClearVotes(num uint64)
	WriteGovernanceForNextEpoch(number uint64, governance []byte)
	UpdateCurrentSet(num uint64)
	HandleGovernanceVote(
		valset istanbul.ValidatorSet, votes []GovernanceVote, tally []GovernanceTallyItem,
		header *types.Header, proposer common.Address, self common.Address, writable bool) (
		istanbul.ValidatorSet, []GovernanceVote, []GovernanceTallyItem)

	// Get internal fields
	GetVoteMapCopy() map[string]VoteStatus
	GetGovernanceTalliesCopy() []GovernanceTallyItem
	CurrentSetCopy() map[string]interface{}
	PendingChanges() map[string]interface{}
	Votes() []GovernanceVote
	IdxCache() []uint64
	IdxCacheFromDb() []uint64

	NodeAddress() common.Address
	TotalVotingPower() uint64
	MyVotingPower() uint64
	BlockChain() blockChain
	DB() database.DBManager

	// Set internal fields
	SetNodeAddress(addr common.Address)
	SetTotalVotingPower(t uint64)
	SetMyVotingPower(t uint64)
	SetBlockchain(chain blockChain)
	SetTxPool(txpool txPool)
	GetTxPool() txPool
}

type MixedEngine added in v1.9.0

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

MixedEngine consists of multiple governance engines

Each parameter is added to a parameter set from one of the following sources: The highest priority is 1, and falls back to lower ones if non-existent

  1. contractParams: ContractEngine items (when enabled)
  2. headerParams: Header Governance items
  3. initialParams: initial ChainConfig from genesis.json
  4. defaultParams: Default params such as params.Default* Note that some items are not backed by defaultParams.

func NewMixedEngine added in v1.9.0

func NewMixedEngine(config *params.ChainConfig, db database.DBManager) *MixedEngine

NewMixedEngine creates a governance engine using both contract-based and haeder-based gov. Developers are encouraged to call this constructor in most cases.

func NewMixedEngineNoInit added in v1.9.0

func NewMixedEngineNoInit(config *params.ChainConfig, db database.DBManager) *MixedEngine

NewMixedEngineNoInit creates a MixedEngine without initializing governance.

func (*MixedEngine) AddVote added in v1.9.0

func (e *MixedEngine) AddVote(key string, val interface{}) bool

Pass-through to HeaderEngine

func (*MixedEngine) BlockChain added in v1.9.0

func (e *MixedEngine) BlockChain() blockChain

func (*MixedEngine) CanWriteGovernanceState added in v1.9.0

func (e *MixedEngine) CanWriteGovernanceState(num uint64) bool

func (*MixedEngine) ClearVotes added in v1.9.0

func (e *MixedEngine) ClearVotes(num uint64)

func (*MixedEngine) ContractGov added in v1.10.0

func (e *MixedEngine) ContractGov() ReaderEngine

func (*MixedEngine) CurrentParams added in v1.10.2

func (e *MixedEngine) CurrentParams() *params.GovParamSet

func (*MixedEngine) CurrentSetCopy added in v1.9.0

func (e *MixedEngine) CurrentSetCopy() map[string]interface{}

func (*MixedEngine) DB added in v1.9.0

func (e *MixedEngine) DB() database.DBManager

func (*MixedEngine) EffectiveParams added in v1.10.2

func (e *MixedEngine) EffectiveParams(num uint64) (*params.GovParamSet, error)

EffectiveParams returns the parameter set used for generating the block `num`

func (*MixedEngine) GetEncodedVote added in v1.9.0

func (e *MixedEngine) GetEncodedVote(addr common.Address, number uint64) []byte

func (*MixedEngine) GetGovernanceChange added in v1.9.0

func (e *MixedEngine) GetGovernanceChange() map[string]interface{}

func (*MixedEngine) GetGovernanceTalliesCopy added in v1.9.0

func (e *MixedEngine) GetGovernanceTalliesCopy() []GovernanceTallyItem

func (*MixedEngine) GetTxPool added in v1.9.0

func (e *MixedEngine) GetTxPool() txPool

func (*MixedEngine) GetVoteMapCopy added in v1.9.0

func (e *MixedEngine) GetVoteMapCopy() map[string]VoteStatus

func (*MixedEngine) HandleGovernanceVote added in v1.9.0

func (e *MixedEngine) HandleGovernanceVote(
	valset istanbul.ValidatorSet, votes []GovernanceVote, tally []GovernanceTallyItem,
	header *types.Header, proposer common.Address, self common.Address, writable bool,
) (
	istanbul.ValidatorSet, []GovernanceVote, []GovernanceTallyItem,
)

func (*MixedEngine) HeaderGov added in v1.10.0

func (e *MixedEngine) HeaderGov() HeaderEngine

func (*MixedEngine) IdxCache added in v1.9.0

func (e *MixedEngine) IdxCache() []uint64

func (*MixedEngine) IdxCacheFromDb added in v1.9.0

func (e *MixedEngine) IdxCacheFromDb() []uint64

func (*MixedEngine) MyVotingPower added in v1.9.0

func (e *MixedEngine) MyVotingPower() uint64

func (*MixedEngine) NodeAddress added in v1.9.0

func (e *MixedEngine) NodeAddress() common.Address

func (*MixedEngine) PendingChanges added in v1.9.0

func (e *MixedEngine) PendingChanges() map[string]interface{}

func (*MixedEngine) ReadGovernance added in v1.9.0

func (e *MixedEngine) ReadGovernance(num uint64) (uint64, map[string]interface{}, error)

func (*MixedEngine) SetBlockchain added in v1.9.0

func (e *MixedEngine) SetBlockchain(chain blockChain)

func (*MixedEngine) SetMyVotingPower added in v1.9.0

func (e *MixedEngine) SetMyVotingPower(t uint64)

func (*MixedEngine) SetNodeAddress added in v1.9.0

func (e *MixedEngine) SetNodeAddress(addr common.Address)

func (*MixedEngine) SetTotalVotingPower added in v1.9.0

func (e *MixedEngine) SetTotalVotingPower(t uint64)

func (*MixedEngine) SetTxPool added in v1.9.0

func (e *MixedEngine) SetTxPool(txpool txPool)

func (*MixedEngine) TotalVotingPower added in v1.9.0

func (e *MixedEngine) TotalVotingPower() uint64

func (*MixedEngine) UpdateCurrentSet added in v1.9.0

func (e *MixedEngine) UpdateCurrentSet(num uint64)

func (*MixedEngine) UpdateParams added in v1.9.0

func (e *MixedEngine) UpdateParams(num uint64) error

func (*MixedEngine) ValidateVote added in v1.9.0

func (e *MixedEngine) ValidateVote(vote *GovernanceVote) (*GovernanceVote, bool)

func (*MixedEngine) VerifyGovernance added in v1.9.0

func (e *MixedEngine) VerifyGovernance(received []byte) error

func (*MixedEngine) Votes added in v1.9.0

func (e *MixedEngine) Votes() []GovernanceVote

func (*MixedEngine) WriteGovernance added in v1.9.0

func (e *MixedEngine) WriteGovernance(num uint64, data GovernanceSet, delta GovernanceSet) error

func (*MixedEngine) WriteGovernanceForNextEpoch added in v1.9.0

func (e *MixedEngine) WriteGovernanceForNextEpoch(number uint64, governance []byte)

func (*MixedEngine) WriteGovernanceState added in v1.9.0

func (e *MixedEngine) WriteGovernanceState(num uint64, isCheckpoint bool) error

type PublicGovernanceAPI

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

func NewGovernanceAPI

func NewGovernanceAPI(gov Engine) *PublicGovernanceAPI

func (*PublicGovernanceAPI) ChainConfig

func (api *PublicGovernanceAPI) ChainConfig() *params.ChainConfig

func (*PublicGovernanceAPI) ChainConfigAt added in v1.10.0

func (api *PublicGovernanceAPI) ChainConfigAt(num *rpc.BlockNumber) *params.ChainConfig

TODO-Klaytn-Mantle: deprecate this

func (*PublicGovernanceAPI) GetChainConfig added in v1.10.2

func (api *PublicGovernanceAPI) GetChainConfig(num *rpc.BlockNumber) *params.ChainConfig

func (*PublicGovernanceAPI) GetParams added in v1.10.2

func (api *PublicGovernanceAPI) GetParams(num *rpc.BlockNumber) (map[string]interface{}, error)

func (*PublicGovernanceAPI) GetStakingInfo added in v1.6.1

func (api *PublicGovernanceAPI) GetStakingInfo(num *rpc.BlockNumber) (*reward.StakingInfo, error)

func (*PublicGovernanceAPI) IdxCache added in v1.1.0

func (api *PublicGovernanceAPI) IdxCache() []uint64

func (*PublicGovernanceAPI) IdxCacheFromDb added in v1.1.0

func (api *PublicGovernanceAPI) IdxCacheFromDb() []uint64

func (*PublicGovernanceAPI) ItemCacheFromDb added in v1.1.0

func (api *PublicGovernanceAPI) ItemCacheFromDb(num *rpc.BlockNumber) map[string]interface{}

TODO-Klaytn: Return error if invalid input is given such as pending or a too big number

func (*PublicGovernanceAPI) ItemsAt

func (api *PublicGovernanceAPI) ItemsAt(num *rpc.BlockNumber) (map[string]interface{}, error)

TODO-Klaytn-Mantle: deprecate this

func (*PublicGovernanceAPI) MyVotes

func (api *PublicGovernanceAPI) MyVotes() []*VoteList

func (*PublicGovernanceAPI) MyVotingPower

func (api *PublicGovernanceAPI) MyVotingPower() (float64, error)

func (*PublicGovernanceAPI) NodeAddress

func (api *PublicGovernanceAPI) NodeAddress() common.Address

func (*PublicGovernanceAPI) PendingChanges added in v1.1.0

func (api *PublicGovernanceAPI) PendingChanges() map[string]interface{}

func (*PublicGovernanceAPI) ShowTally

func (api *PublicGovernanceAPI) ShowTally() []*returnTally

func (*PublicGovernanceAPI) TotalVotingPower

func (api *PublicGovernanceAPI) TotalVotingPower() (float64, error)

func (*PublicGovernanceAPI) Vote

func (api *PublicGovernanceAPI) Vote(key string, val interface{}) (string, error)

Vote injects a new vote for governance targets such as unitprice and governingnode.

func (*PublicGovernanceAPI) Votes added in v1.1.0

func (api *PublicGovernanceAPI) Votes() []GovernanceVote

type ReaderEngine added in v1.9.0

type ReaderEngine interface {
	// CurrentParams returns the params at the current block. The returned params shall be
	// used to build the upcoming (head+1) block. Block processing codes
	// should use this method.
	CurrentParams() *params.GovParamSet

	// EffectiveParams returns the params at given block number. The returned params
	// were used to build the block at given number.
	// The number must be equal or less than current block height (head).
	EffectiveParams(num uint64) (*params.GovParamSet, error)

	// UpdateParams updates the current params (the ones returned by CurrentParams()).
	// by reading the latest blockchain states.
	// This function must be called after every block is mined to
	// guarantee that CurrentParams() works correctly.
	UpdateParams(num uint64) error
}

type VoteList

type VoteList struct {
	Key      string
	Value    interface{}
	Casted   bool
	BlockNum uint64
}

type VoteMap added in v1.1.0

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

func NewVoteMap added in v1.1.0

func NewVoteMap() VoteMap

func (*VoteMap) Clear added in v1.1.0

func (vl *VoteMap) Clear()

func (*VoteMap) Copy added in v1.1.0

func (vl *VoteMap) Copy() map[string]VoteStatus

func (*VoteMap) GetValue added in v1.1.0

func (vl *VoteMap) GetValue(key string) VoteStatus

func (*VoteMap) Import added in v1.1.0

func (vl *VoteMap) Import(src map[string]VoteStatus)

func (*VoteMap) SetValue added in v1.1.0

func (vl *VoteMap) SetValue(key string, val VoteStatus)

func (*VoteMap) Size added in v1.1.0

func (vl *VoteMap) Size() int

type VoteStatus

type VoteStatus struct {
	Value  interface{} `json:"value"`
	Casted bool        `json:"casted"`
	Num    uint64      `json:"num"`
}

Jump to

Keyboard shortcuts

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