governance

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: GPL-3.0 Imports: 26 Imported by: 1

Documentation

Overview

Package governance contains functions and variables used for voting and reflecting vote results in Kaia. In Kaia, various settings such as the amount of KAIA 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.kaia.io/docs/learn/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 Kaia (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, KIF and KEF
  • "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.kaia.io/docs/references/json-rpc/governance/chain-config/

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, checkBigInt, 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 AccumulatedRewards

type AccumulatedRewards struct {
	FirstBlockTime string   `json:"firstBlockTime"`
	LastBlockTime  string   `json:"lastBlockTime"`
	FirstBlock     *big.Int `json:"firstBlock"`
	LastBlock      *big.Int `json:"lastBlock"`

	// TotalMinted + TotalTxFee - TotalBurntTxFee = TotalProposerRewards + TotalStakingRewards + TotalKIFRewards + TotalKEFRewards
	TotalMinted          *big.Int                    `json:"totalMinted"`
	TotalTxFee           *big.Int                    `json:"totalTxFee"`
	TotalBurntTxFee      *big.Int                    `json:"totalBurntTxFee"`
	TotalProposerRewards *big.Int                    `json:"totalProposerRewards"`
	TotalStakingRewards  *big.Int                    `json:"totalStakingRewards"`
	TotalKIFRewards      *big.Int                    `json:"totalKIFRewards"`
	TotalKEFRewards      *big.Int                    `json:"totalKEFRewards"`
	Rewards              map[common.Address]*big.Int `json:"rewards"`
}

type ContractEngine

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

func NewContractEngine

func NewContractEngine(headerGov *Governance) *ContractEngine

func (*ContractEngine) CurrentParams

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

CurrentParams effective at upcoming block (head+1)

func (*ContractEngine) EffectiveParams

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

Parameters effective at requested block (num)

func (*ContractEngine) UpdateParams

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

if UpdateParam fails, leave currentParams as-is

type Engine

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

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

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

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

func (*Governance) CurrentSetCopy

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

func (*Governance) DB

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

func (*Governance) EffectiveParams

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

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

func (*Governance) GetGovernanceValue

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

func (*Governance) GetTxPool

func (gov *Governance) GetTxPool() txPool

func (*Governance) GetVoteMapCopy

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

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

func (*Governance) IdxCacheFromDb

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

func (*Governance) InitGovCache

func (gov *Governance) InitGovCache()

func (*Governance) InitLastGovStateBlkNum

func (gov *Governance) InitLastGovStateBlkNum()

func (*Governance) MyVotingPower

func (g *Governance) MyVotingPower() uint64

func (*Governance) NodeAddress

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

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

func (g *Governance) TotalVotingPower() uint64

func (*Governance) UnmarshalJSON

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

func (*Governance) UpdateCurrentSet

func (gov *Governance) UpdateCurrentSet(num uint64)

func (*Governance) UpdateParams

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

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

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 GovernanceAPI

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

func NewGovernanceAPI

func NewGovernanceAPI(gov Engine) *GovernanceAPI

func (*GovernanceAPI) GetChainConfig

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

func (*GovernanceAPI) GetParams

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

func (*GovernanceAPI) GetRewardsAccumulated

func (api *GovernanceAPI) GetRewardsAccumulated(first rpc.BlockNumber, last rpc.BlockNumber) (*AccumulatedRewards, error)

GetRewardsAccumulated returns accumulated rewards data in the block range of [first, last].

func (*GovernanceAPI) GetStakingInfo

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

func (*GovernanceAPI) IdxCache

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

func (*GovernanceAPI) IdxCacheFromDb

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

func (*GovernanceAPI) ItemCacheFromDb

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

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

func (*GovernanceAPI) MyVotes

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

func (*GovernanceAPI) MyVotingPower

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

func (*GovernanceAPI) NodeAddress

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

func (*GovernanceAPI) PendingChanges

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

func (*GovernanceAPI) ShowTally

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

func (*GovernanceAPI) TotalVotingPower

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

func (*GovernanceAPI) Vote

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

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

func (*GovernanceAPI) Votes

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

type GovernanceKaiaAPI

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

func NewGovernanceKaiaAPI

func NewGovernanceKaiaAPI(gov Engine, chain blockChain) *GovernanceKaiaAPI

func (*GovernanceKaiaAPI) GetChainConfig

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

func (*GovernanceKaiaAPI) GetParams

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

func (*GovernanceKaiaAPI) GetRewards

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

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

func (*GovernanceKaiaAPI) GetStakingInfo

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

func (*GovernanceKaiaAPI) NodeAddress

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

type GovernanceSet

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

GovernanceSet contains an item set for governance

func GetGovernanceItemsFromChainConfig

func GetGovernanceItemsFromChainConfig(config *params.ChainConfig) GovernanceSet

GetGovernanceItemsFromChainConfig returns governance set that is effective at the genesis block

func NewGovernanceSet

func NewGovernanceSet() GovernanceSet

func (*GovernanceSet) Clear

func (gs *GovernanceSet) Clear()

func (*GovernanceSet) GetValue

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

func (*GovernanceSet) Import

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

func (*GovernanceSet) Items

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

func (*GovernanceSet) Merge

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

func (*GovernanceSet) RemoveItem

func (gs *GovernanceSet) RemoveItem(key string)

func (*GovernanceSet) SetValue

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

func (*GovernanceSet) Size

func (gs *GovernanceSet) Size() int

type GovernanceTallyItem

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

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

func NewGovernanceTallies

func NewGovernanceTallies() GovernanceTallyList

func (*GovernanceTallyList) Clear

func (gt *GovernanceTallyList) Clear()

func (*GovernanceTallyList) Copy

func (*GovernanceTallyList) Import

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

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

func NewGovernanceVotes

func NewGovernanceVotes() GovernanceVotes

func (*GovernanceVotes) Clear

func (gv *GovernanceVotes) Clear()

func (*GovernanceVotes) Copy

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

func (*GovernanceVotes) Import

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

type HeaderEngine

type HeaderEngine interface {
	// Governance cache initialization
	InitGovCache()

	// Reset the latest block number that contains governance data
	InitLastGovStateBlkNum()

	// 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

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

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

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

NewMixedEngineNoInit creates a MixedEngine without initializing governance.

func (*MixedEngine) AddVote

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

Pass-through to HeaderEngine

func (*MixedEngine) BlockChain

func (e *MixedEngine) BlockChain() blockChain

func (*MixedEngine) CanWriteGovernanceState

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

func (*MixedEngine) ClearVotes

func (e *MixedEngine) ClearVotes(num uint64)

func (*MixedEngine) ContractGov

func (e *MixedEngine) ContractGov() ReaderEngine

func (*MixedEngine) CurrentParams

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

func (*MixedEngine) CurrentSetCopy

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

func (*MixedEngine) DB

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

func (*MixedEngine) EffectiveParams

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

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

func (*MixedEngine) GetEncodedVote

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

func (*MixedEngine) GetGovernanceChange

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

func (*MixedEngine) GetGovernanceTalliesCopy

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

func (*MixedEngine) GetTxPool

func (e *MixedEngine) GetTxPool() txPool

func (*MixedEngine) GetVoteMapCopy

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

func (*MixedEngine) HandleGovernanceVote

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

func (e *MixedEngine) HeaderGov() HeaderEngine

func (*MixedEngine) IdxCache

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

func (*MixedEngine) IdxCacheFromDb

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

func (*MixedEngine) InitGovCache

func (e *MixedEngine) InitGovCache()

func (*MixedEngine) InitLastGovStateBlkNum

func (e *MixedEngine) InitLastGovStateBlkNum()

func (*MixedEngine) MyVotingPower

func (e *MixedEngine) MyVotingPower() uint64

func (*MixedEngine) NodeAddress

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

func (*MixedEngine) PendingChanges

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

func (*MixedEngine) ReadGovernance

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

func (*MixedEngine) SetBlockchain

func (e *MixedEngine) SetBlockchain(chain blockChain)

func (*MixedEngine) SetMyVotingPower

func (e *MixedEngine) SetMyVotingPower(t uint64)

func (*MixedEngine) SetNodeAddress

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

func (*MixedEngine) SetTotalVotingPower

func (e *MixedEngine) SetTotalVotingPower(t uint64)

func (*MixedEngine) SetTxPool

func (e *MixedEngine) SetTxPool(txpool txPool)

func (*MixedEngine) TotalVotingPower

func (e *MixedEngine) TotalVotingPower() uint64

func (*MixedEngine) UpdateCurrentSet

func (e *MixedEngine) UpdateCurrentSet(num uint64)

func (*MixedEngine) UpdateParams

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

func (*MixedEngine) ValidateVote

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

func (*MixedEngine) VerifyGovernance

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

func (*MixedEngine) Votes

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

func (*MixedEngine) WriteGovernance

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

func (*MixedEngine) WriteGovernanceForNextEpoch

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

func (*MixedEngine) WriteGovernanceState

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

type ReaderEngine

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

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

func NewVoteMap

func NewVoteMap() VoteMap

func (*VoteMap) Clear

func (vl *VoteMap) Clear()

func (*VoteMap) Copy

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

func (*VoteMap) GetValue

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

func (*VoteMap) Import

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

func (*VoteMap) SetValue

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

func (*VoteMap) Size

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