governance

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package governance contains functions and variables used for voting and reflecting vote results in Klaytn.

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")
)
View Source
var (
	GovernanceKeyMap = map[string]int{
		"governance.governancemode":     params.GovernanceMode,
		"governance.governingnode":      params.GoverningNode,
		"istanbul.epoch":                params.Epoch,
		"istanbul.policy":               params.Policy,
		"istanbul.committeesize":        params.CommitteeSize,
		"governance.unitprice":          params.UnitPrice,
		"reward.mintingamount":          params.MintingAmount,
		"reward.ratio":                  params.Ratio,
		"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,
	}

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

		"governance.governancemode": params.GovernanceMode,
		"governance.governingnode":  params.GoverningNode,
		"istanbul.epoch":            params.Epoch,
		"istanbul.committeesize":    params.CommitteeSize,
		"governance.unitprice":      params.UnitPrice,
		"reward.mintingamount":      params.MintingAmount,
		"reward.ratio":              params.Ratio,
		"reward.useginicoeff":       params.UseGiniCoeff,
		"reward.deferredtxfee":      params.DeferredTxFee,
		"reward.minimumstake":       params.MinimumStake,
		"param.txgashumanreadable":  params.ConstTxGasHumanReadable,
	}

	GovernanceKeyMapReverse = map[int]string{
		params.GovernanceMode:          "governance.governancemode",
		params.GoverningNode:           "governance.governingnode",
		params.Epoch:                   "istanbul.epoch",
		params.CliqueEpoch:             "clique.epoch",
		params.Policy:                  "istanbul.policy",
		params.CommitteeSize:           "istanbul.committeesize",
		params.UnitPrice:               "governance.unitprice",
		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",
	}

	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, updateGovernanceConfig},
	params.GoverningNode:           {addressT, checkAddress, updateGovernanceConfig},
	params.UnitPrice:               {uint64T, checkUint64andBool, updateGovernanceConfig},
	params.AddValidator:            {addressT, checkAddress, updateGovernanceConfig},
	params.RemoveValidator:         {addressT, checkAddress, updateGovernanceConfig},
	params.MintingAmount:           {stringT, checkBigInt, updateGovernanceConfig},
	params.Ratio:                   {stringT, checkRatio, updateGovernanceConfig},
	params.UseGiniCoeff:            {boolT, checkUint64andBool, updateGovernanceConfig},
	params.DeferredTxFee:           {boolT, checkUint64andBool, updateGovernanceConfig},
	params.MinimumStake:            {stringT, checkBigInt, updateGovernanceConfig},
	params.StakeUpdateInterval:     {uint64T, checkUint64andBool, updateGovernanceConfig},
	params.ProposerRefreshInterval: {uint64T, checkUint64andBool, updateGovernanceConfig},
	params.Epoch:                   {uint64T, checkUint64andBool, updateGovernanceConfig},
	params.Policy:                  {uint64T, checkUint64andBool, updateGovernanceConfig},
	params.CommitteeSize:           {uint64T, checkUint64andBool, updateGovernanceConfig},
	params.ConstTxGasHumanReadable: {uint64T, checkUint64andBool, updateParams},
}

Functions

func AddGovernanceCacheForTest

func AddGovernanceCacheForTest(g *Governance, num uint64, config *params.ChainConfig)

func CalcGovernanceInfoBlock

func CalcGovernanceInfoBlock(num uint64, epoch uint64) uint64

func CheckGenesisValues

func CheckGenesisValues(c *params.ChainConfig) error

func GetDefaultCliqueConfig

func GetDefaultCliqueConfig() *params.CliqueConfig

func GetDefaultGovernanceConfig

func GetDefaultGovernanceConfig(engine params.EngineType) *params.GovernanceConfig

func GetDefaultIstanbulConfig

func GetDefaultIstanbulConfig() *params.IstanbulConfig

func GetDefaultRewardConfig

func GetDefaultRewardConfig() *params.RewardConfig

Types

type Governance

type Governance struct {
	ChainConfig *params.ChainConfig

	GovernanceVotes     []GovernanceVote
	GovernanceTally     []GovernanceTally
	GovernanceTallyLock sync.RWMutex

	TxPool *blockchain.TxPool
	// contains filtered or unexported fields
}

func NewGovernance

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

func (*Governance) AddVote

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

AddVote adds a vote to the voteMap

func (*Governance) CanWriteGovernanceState

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

func (*Governance) ClearVotes

func (g *Governance) ClearVotes(num uint64)

func (*Governance) GetEncodedVote

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

func (*Governance) GetGovernanceChange

func (g *Governance) GetGovernanceChange() GovernanceSet

func (*Governance) GetGovernanceItemAtNumber

func (gov *Governance) GetGovernanceItemAtNumber(num uint64, key string) (interface{}, error)

func (*Governance) GetGovernanceValue

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

func (*Governance) GetLatestGovernanceItem

func (gov *Governance) GetLatestGovernanceItem(key string) interface{}

func (*Governance) HandleGovernanceVote

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

func (*Governance) ParseVoteValue

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

parseVoteValue parse vote.Value from []uint8 to appropriate type

func (*Governance) ReadGovernance

func (g *Governance) ReadGovernance(num uint64) (uint64, GovernanceSet, error)

func (*Governance) ReadGovernanceState

func (gov *Governance) ReadGovernanceState()

func (*Governance) ReflectVotes

func (gov *Governance) ReflectVotes(vote GovernanceVote)

func (*Governance) RemoveVote

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

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

func (*Governance) SetBlockchain

func (gov *Governance) SetBlockchain(bc *blockchain.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 *blockchain.TxPool)

func (*Governance) UnmarshalJSON

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

func (*Governance) UpdateCurrentGovernance

func (gov *Governance) UpdateCurrentGovernance(num uint64)

func (*Governance) UpdateGovernance

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

func (*Governance) ValidateVote

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

func (*Governance) VerifyGovernance

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

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) 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 *Governance, chain *blockchain.BlockChain) *GovernanceKlayAPI

func (*GovernanceKlayAPI) GasPrice

func (api *GovernanceKlayAPI) GasPrice() *big.Int

func (*GovernanceKlayAPI) GasPriceAt

func (api *GovernanceKlayAPI) GasPriceAt(num *rpc.BlockNumber) (*big.Int, error)

func (*GovernanceKlayAPI) GasPriceAtNumber

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

func (*GovernanceKlayAPI) GetTxGasHumanReadable

func (api *GovernanceKlayAPI) GetTxGasHumanReadable(num *rpc.BlockNumber) (uint64, error)

type GovernanceSet

type GovernanceSet map[string]interface{}

Governance item set

func CopyGovernanceSet

func CopyGovernanceSet(dst GovernanceSet, src GovernanceSet) GovernanceSet

func (GovernanceSet) SetValue

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

type GovernanceTally

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

GovernanceTally represents a tally for each governance item

type GovernanceVote

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

Governance represents vote information given from istanbul.vote()

type PublicGovernanceAPI

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

func NewGovernanceAPI

func NewGovernanceAPI(gov *Governance) *PublicGovernanceAPI

func (*PublicGovernanceAPI) ChainConfig

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

func (*PublicGovernanceAPI) ItemsAt

func (api *PublicGovernanceAPI) ItemsAt(num *rpc.BlockNumber) (GovernanceSet, error)

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) 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.

type VoteList

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

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