gov

package
v0.11.1-0...-daaff9c Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModuleStaking  = "staking"
	ModuleSlashing = "slashing"
	ModuleBlock    = "block"
	ModuleTxPool   = "txPool"
	ModuleReward   = "reward"
)
View Source
const (
	KeyStakeThreshold             = "stakeThreshold"
	KeyOperatingThreshold         = "operatingThreshold"
	KeyMaxValidators              = "maxValidators"
	KeyUnStakeFreezeDuration      = "unStakeFreezeDuration"
	KeySlashFractionDuplicateSign = "slashFractionDuplicateSign"
	KeyDuplicateSignReportReward  = "duplicateSignReportReward"
	KeyMaxEvidenceAge             = "maxEvidenceAge"
	KeySlashBlocksReward          = "slashBlocksReward"
	KeyMaxBlockGasLimit           = "maxBlockGasLimit"
	KeyMaxTxDataLimit             = "maxTxDataLimit"
	KeyZeroProduceNumberThreshold = "zeroProduceNumberThreshold"
	KeyZeroProduceCumulativeTime  = "zeroProduceCumulativeTime"
	KeyRewardPerMaxChangeRange    = "rewardPerMaxChangeRange"
	KeyRewardPerChangeInterval    = "rewardPerChangeInterval"
	KeyIncreaseIssuanceRatio      = "increaseIssuanceRatio"
)
View Source
const RateCoefficient = uint64(10000)

in genesis.json, the config value of the supportRate( and voteRate...) is the real value * 10000. the RateCoefficient is used to calculate the supportRate (and voteRate) of a proposal correctly.

Variables

View Source
var (
	ActiveVersionError                = common.NewBizError(302001, "current active version not found")
	VoteOptionError                   = common.NewBizError(302002, "vote option error")
	ProposalTypeError                 = common.NewBizError(302003, "proposal type error")
	ProposalIDEmpty                   = common.NewBizError(302004, "proposal ID is empty")
	ProposalIDExist                   = common.NewBizError(302005, "proposal ID already exists")
	ProposalNotFound                  = common.NewBizError(302006, "proposal not found")
	PIPIDEmpty                        = common.NewBizError(302007, "PIPID is empty")
	PIPIDExist                        = common.NewBizError(302008, "PIPID already exists")
	EndVotingRoundsTooSmall           = common.NewBizError(302009, "endVotingRounds too small")
	EndVotingRoundsTooLarge           = common.NewBizError(302010, "endVotingRounds too large")
	NewVersionError                   = common.NewBizError(302011, "newVersion should larger than current active version")
	VotingVersionProposalExist        = common.NewBizError(302012, "another version proposal at voting stage")
	PreActiveVersionProposalExist     = common.NewBizError(302013, "another version proposal at pre-active stage")
	VotingCancelProposalExist         = common.NewBizError(302014, "another cancel proposal at voting stage")
	TobeCanceledProposalNotFound      = common.NewBizError(302015, "to be canceled proposal not found")
	TobeCanceledProposalTypeError     = common.NewBizError(302016, "to be canceled proposal not version type")
	TobeCanceledProposalNotAtVoting   = common.NewBizError(302017, "to be canceled proposal not at voting stage")
	ProposerEmpty                     = common.NewBizError(302018, "proposer is empty")
	VerifierInfoNotFound              = common.NewBizError(302019, "verifier detail info not found")
	VerifierStatusInvalid             = common.NewBizError(302020, "verifier status is invalid")
	TxSenderDifferFromStaking         = common.NewBizError(302021, "Tx caller differ from staking")
	TxSenderIsNotVerifier             = common.NewBizError(302022, "Tx caller is not verifier")
	TxSenderIsNotCandidate            = common.NewBizError(302023, "Tx caller is not candidate")
	VersionSignError                  = common.NewBizError(302024, "version sign error")
	VerifierNotUpgraded               = common.NewBizError(302025, "verifier not upgraded")
	ProposalNotAtVoting               = common.NewBizError(302026, "proposal not at voting stage")
	VoteDuplicated                    = common.NewBizError(302027, "vote duplicated")
	DeclareVersionError               = common.NewBizError(302028, "declared version error")
	NotifyStakingDeclaredVersionError = common.NewBizError(302029, "notify staking declared version error")
	TallyResultNotFound               = common.NewBizError(302030, "tally result not found")
	UnsupportedGovernParam            = common.NewBizError(302031, "unsupported govern parameter")
	VotingParamProposalExist          = common.NewBizError(302032, "another param proposal at voting stage")
	GovernParamValueError             = common.NewBizError(302033, "govern parameter value error")
	ParamProposalIsSameValue          = common.NewBizError(302034, "the new value of the parameter proposal is the same as the old value")
)
View Source
var (
	KeyDelimiter = []byte(":")
)
View Source
var ParamVerifierMap = make(map[string]ParamVerifier)
View Source
var (
	ValueDelimiter = []byte(":")
)

Functions

func AccuVerifiers

func AccuVerifiers(blockHash common.Hash, proposalID common.Hash, verifierList []discover.NodeID) error

AccuVerifiers accumulates all distinct verifiers those can vote this proposal ID

func AddActiveNode

func AddActiveNode(blockHash common.Hash, proposalID common.Hash, nodeID discover.NodeID) error

Add the node that has made a new version declare or vote during voting period

func AddActiveVersion

func AddActiveVersion(activeVersion uint32, activeBlock uint64, state xcom.StateDB) error

Set active version record

func AddPIPID

func AddPIPID(pipID string, state xcom.StateDB) error

func AddVoteValue

func AddVoteValue(proposalID common.Hash, voter discover.NodeID, option VoteOption, blockHash common.Hash) error

Add the Vote detail

func AddVotingProposalID

func AddVotingProposalID(blockHash common.Hash, proposalID common.Hash) error

func ClearAccuVerifiers

func ClearAccuVerifiers(blockHash common.Hash, proposalID common.Hash) error

func ClearActiveNodes

func ClearActiveNodes(blockHash common.Hash, proposalID common.Hash) error

Clear the version declaration records after upgrade

func ClearProcessingProposals

func ClearProcessingProposals(blockHash common.Hash, state xcom.StateDB) error

func ClearVoteValue

func ClearVoteValue(proposalID common.Hash, blockHash common.Hash) error

func DeclareVersion

func DeclareVersion(from common.Address, declaredNodeID discover.NodeID, declaredVersion uint32, programVersionSign common.VersionSign, blockHash common.Hash, blockNumber uint64, stk Staking, state xcom.StateDB) error

node declares it's version

func GetActiveNodeList

func GetActiveNodeList(blockHash common.Hash, proposalID common.Hash) ([]discover.NodeID, error)

Get the node list that have made a new version declare or vote during voting period

func GetCurrentActiveVersion

func GetCurrentActiveVersion(state xcom.StateDB) uint32

Get current active version record

func GetGovernParamValue

func GetGovernParamValue(module, name string, blockNumber uint64, blockHash common.Hash) (string, error)

func GetMaxEndVotingBlock

func GetMaxEndVotingBlock(nodeID discover.NodeID, blockHash common.Hash, state xcom.StateDB) (uint64, error)

GetMaxEndVotingBlock returns the max endVotingBlock of proposals those are at voting stage, and the nodeID has voted for those proposals. or returns 0 if there's no proposal at voting stage, or nodeID didn't voted for any proposal. if any error happened, return 0 and the error

func GetPreActiveProposalID

func GetPreActiveProposalID(blockHash common.Hash) (common.Hash, error)

func GetPreActiveVersion

func GetPreActiveVersion(blockHash common.Hash) uint32

Get pre-active version

func GetVersionForStaking

func GetVersionForStaking(blockHash common.Hash, state xcom.StateDB) uint32

func GetVotedVerifierMap

func GetVotedVerifierMap(proposalID common.Hash, blockHash common.Hash) (map[discover.NodeID]struct{}, error)

func GovernDuplicateSignReportReward

func GovernDuplicateSignReportReward(blockNumber uint64, blockHash common.Hash) (uint32, error)

func GovernIncreaseIssuanceRatio

func GovernIncreaseIssuanceRatio(blockNumber uint64, blockHash common.Hash) (uint16, error)

func GovernMaxBlockGasLimit

func GovernMaxBlockGasLimit(blockNumber uint64, blockHash common.Hash) (int, error)

func GovernMaxEvidenceAge

func GovernMaxEvidenceAge(blockNumber uint64, blockHash common.Hash) (uint32, error)

func GovernMaxValidators

func GovernMaxValidators(blockNumber uint64, blockHash common.Hash) (uint64, error)

func GovernOperatingThreshold

func GovernOperatingThreshold(blockNumber uint64, blockHash common.Hash) (*big.Int, error)

func GovernRewardPerChangeInterval

func GovernRewardPerChangeInterval(blockNumber uint64, blockHash common.Hash) (uint16, error)

func GovernRewardPerMaxChangeRange

func GovernRewardPerMaxChangeRange(blockNumber uint64, blockHash common.Hash) (uint16, error)

func GovernSlashBlocksReward

func GovernSlashBlocksReward(blockNumber uint64, blockHash common.Hash) (uint32, error)

func GovernSlashFractionDuplicateSign

func GovernSlashFractionDuplicateSign(blockNumber uint64, blockHash common.Hash) (uint32, error)

func GovernStakeThreshold

func GovernStakeThreshold(blockNumber uint64, blockHash common.Hash) (*big.Int, error)

func GovernUnStakeFreezeDuration

func GovernUnStakeFreezeDuration(blockNumber uint64, blockHash common.Hash) (uint64, error)

func GovernZeroProduceCumulativeTime

func GovernZeroProduceCumulativeTime(blockNumber uint64, blockHash common.Hash) (uint16, error)

func GovernZeroProduceNumberThreshold

func GovernZeroProduceNumberThreshold(blockNumber uint64, blockHash common.Hash) (uint16, error)

func InitGenesisGovernParam

func InitGenesisGovernParam(prevHash common.Hash, snapDB snapshotdb.BaseDB, genesisVersion uint32) (common.Hash, error)

func KeyAccuVerifier

func KeyAccuVerifier(proposalID common.Hash) []byte

func KeyActiveNodes

func KeyActiveNodes(proposalID common.Hash) []byte

func KeyActiveVersions

func KeyActiveVersions() []byte

func KeyEndProposals

func KeyEndProposals() []byte

func KeyGovernHASHKey

func KeyGovernHASHKey() []byte

func KeyPIPIDs

func KeyPIPIDs() []byte

func KeyParamItems

func KeyParamItems() []byte

func KeyParamValue

func KeyParamValue(module, name string) []byte

func KeyPreActiveProposal

func KeyPreActiveProposal() []byte

func KeyPreActiveVersion

func KeyPreActiveVersion() []byte

func KeyProposal

func KeyProposal(proposalID common.Hash) []byte

func KeyTallyResult

func KeyTallyResult(proposalID common.Hash) []byte

func KeyVote

func KeyVote(proposalID common.Hash) []byte

func KeyVotingProposals

func KeyVotingProposals() []byte

func ListAccuVerifier

func ListAccuVerifier(blockHash common.Hash, proposalID common.Hash) ([]discover.NodeID, error)

Get the total number of all voting verifiers

func ListEndProposalID

func ListEndProposalID(blockHash common.Hash) ([]common.Hash, error)

func ListPIPID

func ListPIPID(state xcom.StateDB) ([]string, error)

func ListVotingProposal

func ListVotingProposal(blockHash common.Hash) ([]common.Hash, error)

Get voting proposal

func ListVotingProposalID

func ListVotingProposalID(blockHash common.Hash) ([]common.Hash, error)

list all proposal IDs at voting stage

func MovePreActiveProposalIDToEnd

func MovePreActiveProposalIDToEnd(blockHash common.Hash, proposalID common.Hash) error

func MoveVotingProposalIDToEnd

func MoveVotingProposalIDToEnd(proposalID common.Hash, blockHash common.Hash) error

func MoveVotingProposalIDToPreActive

func MoveVotingProposalIDToPreActive(blockHash common.Hash, proposalID common.Hash, preactiveVersion uint32) error

func NotifyPunishedVerifiers

func NotifyPunishedVerifiers(blockHash common.Hash, punishedVerifierMap map[discover.NodeID]struct{}, state xcom.StateDB) error

NotifyPunishedVerifiers receives punished verifies notification from Staking

func RegGovernParamVerifier

func RegGovernParamVerifier(module, name string, callback ParamVerifier)

func RegisterGovernParamVerifiers

func RegisterGovernParamVerifiers()

func SetGovernParam

func SetGovernParam(module, name, desc, initValue string, activeBlockNumber uint64, currentBlockHash common.Hash) error

func SetPreActiveVersion

func SetPreActiveVersion(blockHash common.Hash, preActiveVersion uint32) error

Set pre-active version

func SetProposal

func SetProposal(proposal Proposal, state xcom.StateDB) error

func SetTallyResult

func SetTallyResult(tallyResult TallyResult, state xcom.StateDB) error

func Submit

func Submit(from common.Address, proposal Proposal, blockHash common.Hash, blockNumber uint64, stk Staking, state xcom.StateDB, chainID *big.Int) error

submit a proposal

func TallyVoteValue

func TallyVoteValue(proposalID common.Hash, blockHash common.Hash) (yeas, nays, abstentions uint64, e error)

TallyVoteValue statistics vote option for a proposal

func UpdateGovernParamValue

func UpdateGovernParamValue(module, name string, newValue string, activeBlock uint64, blockHash common.Hash) error

func UpdateVoteValue

func UpdateVoteValue(proposalID common.Hash, voteValueList []VoteValue, blockHash common.Hash) error

func Vote

func Vote(from common.Address, vote VoteInfo, blockHash common.Hash, blockNumber uint64, programVersion uint32, programVersionSign common.VersionSign, stk Staking, state xcom.StateDB) error

vote for a proposal

Types

type ActiveVersionValue

type ActiveVersionValue struct {
	ActiveVersion uint32 `json:"ActiveVersion"`
	ActiveBlock   uint64 `json:"ActiveBlock"`
}

func ListActiveVersion

func ListActiveVersion(state xcom.StateDB) ([]ActiveVersionValue, error)

type CancelProposal

type CancelProposal struct {
	ProposalID      common.Hash
	ProposalType    ProposalType
	PIPID           string
	SubmitBlock     uint64
	EndVotingRounds uint64
	EndVotingBlock  uint64
	Proposer        discover.NodeID
	TobeCanceled    common.Hash
	Result          TallyResult `json:"-"`
}

func (*CancelProposal) GetEndVotingBlock

func (cp *CancelProposal) GetEndVotingBlock() uint64

func (*CancelProposal) GetPIPID

func (cp *CancelProposal) GetPIPID() string

func (*CancelProposal) GetProposalID

func (cp *CancelProposal) GetProposalID() common.Hash

func (*CancelProposal) GetProposalType

func (cp *CancelProposal) GetProposalType() ProposalType

func (*CancelProposal) GetProposer

func (cp *CancelProposal) GetProposer() discover.NodeID

func (*CancelProposal) GetSubmitBlock

func (cp *CancelProposal) GetSubmitBlock() uint64

func (*CancelProposal) GetTallyResult

func (cp *CancelProposal) GetTallyResult() TallyResult

func (*CancelProposal) String

func (cp *CancelProposal) String() string

func (*CancelProposal) Verify

func (cp *CancelProposal) Verify(submitBlock uint64, blockHash common.Hash, state xcom.StateDB, chainID *big.Int) error

type GovernParam

type GovernParam struct {
	ParamItem     *ParamItem
	ParamValue    *ParamValue
	ParamVerifier ParamVerifier `json:"-"`
}

func FindGovernParam

func FindGovernParam(module, name string, blockHash common.Hash) (*GovernParam, error)

func ListGovernParam

func ListGovernParam(module string, blockHash common.Hash) ([]*GovernParam, error)

type ParamItem

type ParamItem struct {
	Module string `json:"Module"`
	Name   string `json:"Name"`
	Desc   string `json:"Desc"`
}

type ParamProposal

type ParamProposal struct {
	ProposalID     common.Hash
	ProposalType   ProposalType
	PIPID          string
	SubmitBlock    uint64
	EndVotingBlock uint64
	Proposer       discover.NodeID
	Result         TallyResult `json:"-"`
	Module         string
	Name           string
	NewValue       string
}

func (*ParamProposal) GetEndVotingBlock

func (pp *ParamProposal) GetEndVotingBlock() uint64

func (*ParamProposal) GetPIPID

func (pp *ParamProposal) GetPIPID() string

func (*ParamProposal) GetProposalID

func (pp *ParamProposal) GetProposalID() common.Hash

func (*ParamProposal) GetProposalType

func (pp *ParamProposal) GetProposalType() ProposalType

func (*ParamProposal) GetProposer

func (pp *ParamProposal) GetProposer() discover.NodeID

func (*ParamProposal) GetSubmitBlock

func (pp *ParamProposal) GetSubmitBlock() uint64

func (*ParamProposal) GetTallyResult

func (pp *ParamProposal) GetTallyResult() TallyResult

func (*ParamProposal) String

func (pp *ParamProposal) String() string

func (*ParamProposal) Verify

func (pp *ParamProposal) Verify(submitBlock uint64, blockHash common.Hash, state xcom.StateDB, chainID *big.Int) error

type ParamValue

type ParamValue struct {
	StaleValue  string `json:"StaleValue"`
	Value       string `json:"Value"`
	ActiveBlock uint64 `json:"ActiveBlock"`
}

type ParamVerifier

type ParamVerifier func(blockNumber uint64, blockHash common.Hash, value string) error

type Proposal

type Proposal interface {
	GetProposalID() common.Hash
	GetProposalType() ProposalType
	GetPIPID() string
	GetSubmitBlock() uint64
	GetEndVotingBlock() uint64
	GetProposer() discover.NodeID
	GetTallyResult() TallyResult
	Verify(blockNumber uint64, blockHash common.Hash, state xcom.StateDB, chainID *big.Int) error
	String() string
}

func FindVotingProposal

func FindVotingProposal(blockHash common.Hash, state xcom.StateDB, proposalTypes ...ProposalType) (Proposal, error)

find a proposal at voting stage

func GetExistProposal

func GetExistProposal(proposalID common.Hash, state xcom.StateDB) (Proposal, error)

func GetProposal

func GetProposal(proposalID common.Hash, state xcom.StateDB) (Proposal, error)

func GetProposalList

func GetProposalList(blockHash common.Hash, state xcom.StateDB) ([]Proposal, error)

Select proposal id list from snapshot database ,then get proposal detail from statedb one by one

func ListProposal

func ListProposal(blockHash common.Hash, state xcom.StateDB) ([]Proposal, error)

query proposal list

type ProposalStatus

type ProposalStatus uint8
const (
	Voting    ProposalStatus = 0x01
	Pass      ProposalStatus = 0x02
	Failed    ProposalStatus = 0x03
	PreActive ProposalStatus = 0x04
	Active    ProposalStatus = 0x05
	Canceled  ProposalStatus = 0x06
)

func (ProposalStatus) ToString

func (status ProposalStatus) ToString() string

type ProposalType

type ProposalType uint8
const (
	Text    ProposalType = 0x01
	Version ProposalType = 0x02
	Param   ProposalType = 0x03
	Cancel  ProposalType = 0x04
)

type Staking

type Staking interface {
	GetVerifierList(blockHash common.Hash, blockNumber uint64, isCommit bool) (staking.ValidatorExQueue, error)
	ListVerifierNodeID(blockHash common.Hash, blockNumber uint64) ([]discover.NodeID, error)
	GetCanBaseList(blockHash common.Hash, blockNumber uint64) (staking.CandidateBaseQueue, error)
	GetCandidateInfo(blockHash common.Hash, addr common.NodeAddress) (*staking.Candidate, error)
	GetCanBase(blockHash common.Hash, addr common.NodeAddress) (*staking.CandidateBase, error)
	GetCanMutable(blockHash common.Hash, addr common.NodeAddress) (*staking.CandidateMutable, error)
	DeclarePromoteNotify(blockHash common.Hash, blockNumber uint64, nodeId discover.NodeID, programVersion uint32) error
}

type TallyResult

type TallyResult struct {
	ProposalID    common.Hash    `json:"proposalID"`
	Yeas          uint64         `json:"yeas"`
	Nays          uint64         `json:"nays"`
	Abstentions   uint64         `json:"abstentions"`
	AccuVerifiers uint64         `json:"accuVerifiers"`
	Status        ProposalStatus `json:"status"`
	CanceledBy    common.Hash    `json:"canceledBy"`
}

func GetTallyResult

func GetTallyResult(proposalID common.Hash, state xcom.StateDB) (*TallyResult, error)

type TextProposal

type TextProposal struct {
	ProposalID     common.Hash
	ProposalType   ProposalType
	PIPID          string
	SubmitBlock    uint64
	EndVotingBlock uint64
	Proposer       discover.NodeID
	Result         TallyResult `json:"-"`
}

func (*TextProposal) GetEndVotingBlock

func (tp *TextProposal) GetEndVotingBlock() uint64

func (*TextProposal) GetPIPID

func (tp *TextProposal) GetPIPID() string

func (*TextProposal) GetProposalID

func (tp *TextProposal) GetProposalID() common.Hash

func (*TextProposal) GetProposalType

func (tp *TextProposal) GetProposalType() ProposalType

func (*TextProposal) GetProposer

func (tp *TextProposal) GetProposer() discover.NodeID

func (*TextProposal) GetSubmitBlock

func (tp *TextProposal) GetSubmitBlock() uint64

func (*TextProposal) GetTallyResult

func (tp *TextProposal) GetTallyResult() TallyResult

func (*TextProposal) String

func (tp *TextProposal) String() string

func (*TextProposal) Verify

func (tp *TextProposal) Verify(submitBlock uint64, blockHash common.Hash, state xcom.StateDB, chainID *big.Int) error

type VersionProposal

type VersionProposal struct {
	ProposalID      common.Hash
	ProposalType    ProposalType
	PIPID           string
	SubmitBlock     uint64
	EndVotingRounds uint64
	EndVotingBlock  uint64
	Proposer        discover.NodeID
	Result          TallyResult `json:"-"`
	NewVersion      uint32
	ActiveBlock     uint64
}

func (*VersionProposal) GetActiveBlock

func (vp *VersionProposal) GetActiveBlock() uint64

func (*VersionProposal) GetEndVotingBlock

func (vp *VersionProposal) GetEndVotingBlock() uint64

func (*VersionProposal) GetNewVersion

func (vp *VersionProposal) GetNewVersion() uint32

func (*VersionProposal) GetPIPID

func (vp *VersionProposal) GetPIPID() string

func (*VersionProposal) GetProposalID

func (vp *VersionProposal) GetProposalID() common.Hash

func (*VersionProposal) GetProposalType

func (vp *VersionProposal) GetProposalType() ProposalType

func (*VersionProposal) GetProposer

func (vp *VersionProposal) GetProposer() discover.NodeID

func (*VersionProposal) GetSubmitBlock

func (vp *VersionProposal) GetSubmitBlock() uint64

func (*VersionProposal) GetTallyResult

func (vp *VersionProposal) GetTallyResult() TallyResult

func (*VersionProposal) String

func (vp *VersionProposal) String() string

func (*VersionProposal) Verify

func (vp *VersionProposal) Verify(submitBlock uint64, blockHash common.Hash, state xcom.StateDB, chainID *big.Int) error

type VoteInfo

type VoteInfo struct {
	ProposalID common.Hash     `json:"proposalID"`
	VoteNodeID discover.NodeID `json:"voteNodeID"`
	VoteOption VoteOption      `json:"voteOption"`
}

type VoteOption

type VoteOption uint8
const (
	Yes        VoteOption = 0x01
	No         VoteOption = 0x02
	Abstention VoteOption = 0x03
)

func ParseVoteOption

func ParseVoteOption(option uint8) VoteOption

type VoteValue

type VoteValue struct {
	VoteNodeID discover.NodeID `json:"voteNodeID"`
	VoteOption VoteOption      `json:"voteOption"`
}

func ListVoteValue

func ListVoteValue(proposalID common.Hash, blockHash common.Hash) ([]VoteValue, error)

list vote detail

Jump to

Keyboard shortcuts

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