governance

package
v0.0.0-...-3c16dfa Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2019 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Governance contract: Users can apply for a candidate node to join consensus selection, deposit ONX to authorize for candidate nodes, quit selection and unAuthorize for candidate nodes through this contract. ONX deposited in the contract can get OXG bonus which come from transaction fee of the network.

Index

Constants

View Source
const (
	//function name
	INIT_CONFIG                      = "initConfig"
	REGISTER_CANDIDATE               = "registerCandidate"
	REGISTER_CANDIDATE_TRANSFER_FROM = "registerCandidateTransferFrom"
	UNREGISTER_CANDIDATE             = "unRegisterCandidate"
	AUTHORIZE_FOR_PEER               = "authorizeForPeer"
	AUTHORIZE_FOR_PEER_TRANSFER_FROM = "authorizeForPeerTransferFrom"
	UNAUTHORIZE_FOR_PEER             = "unAuthorizeForPeer"
	APPROVE_CANDIDATE                = "approveCandidate"
	REJECT_CANDIDATE                 = "rejectCandidate"
	BLACK_NODE                       = "blackNode"
	WHITE_NODE                       = "whiteNode"
	QUIT_NODE                        = "quitNode"
	WITHDRAW                         = "withdraw"
	WITHDRAW_OXG                     = "withdrawOxg"
	WITHDRAW_FEE                     = "withdrawFee"
	COMMIT_DPOS                      = "commitDpos"
	UPDATE_CONFIG                    = "updateConfig"
	UPDATE_GLOBAL_PARAM              = "updateGlobalParam"
	UPDATE_GLOBAL_PARAM2             = "updateGlobalParam2"
	UPDATE_SPLIT_CURVE               = "updateSplitCurve"
	TRANSFER_PENALTY                 = "transferPenalty"
	CHANGE_MAX_AUTHORIZATION         = "changeMaxAuthorization"
	SET_PEER_COST                    = "setPeerCost"
	ADD_INIT_POS                     = "addInitPos"
	REDUCE_INIT_POS                  = "reduceInitPos"
	SET_PROMISE_POS                  = "setPromisePos"

	//key prefix
	GLOBAL_PARAM      = "globalParam"
	GLOBAL_PARAM2     = "globalParam2"
	VBFT_CONFIG       = "vbftConfig"
	GOVERNANCE_VIEW   = "governanceView"
	CANDIDITE_INDEX   = "candidateIndex"
	PEER_POOL         = "peerPool"
	PEER_INDEX        = "peerIndex"
	BLACK_LIST        = "blackList"
	TOTAL_STAKE       = "totalStake"
	PENALTY_STAKE     = "penaltyStake"
	SPLIT_CURVE       = "splitCurve"
	PEER_ATTRIBUTES   = "peerAttributes"
	SPLIT_FEE         = "splitFee"
	SPLIT_FEE_ADDRESS = "splitFeeAddress"
	PROMISE_POS       = "promisePos"
	PRE_CONFIG        = "preConfig"

	//global
	PRECISE           = 1000000
	NEW_VERSION_VIEW  = 6
	NEW_VERSION_BLOCK = 414100
)

Variables

View Source
var AUTHORIZE_INFO_POOL = []byte{118, 111, 116, 101, 73, 110, 102, 111, 80, 111, 111, 108}
View Source
var MIN_CANDIDATE_FEE = uint64(math.Pow(10, constants.OXG_DECIMALS))

candidate fee must >= 1 OXG

View Source
var Xi = []uint32{}/* 101 elements not displayed */

Functions

func AddInitPos

func AddInitPos(native *native.NativeService) ([]byte, error)

add init pos of a node

func ApproveCandidate

func ApproveCandidate(native *native.NativeService) ([]byte, error)

Approve a registered candidate node Only approved candidate node can participate in consensus selection and get oxg bonus.

func AuthorizeForPeer

func AuthorizeForPeer(native *native.NativeService) ([]byte, error)

Authorize for a node by depositing ONX in this governance contract, used by users

func AuthorizeForPeerTransferFrom

func AuthorizeForPeerTransferFrom(native *native.NativeService) ([]byte, error)

Authorize for a node by depositing ONX in this governance contract, used by contracts

func BlackNode

func BlackNode(native *native.NativeService) ([]byte, error)

Put a node into black list, remove node from pool Whole of initPos of black node will be punished, and several percent of authorize deposit will be punished too. Node in black list can't be registered.

func ChangeMaxAuthorization

func ChangeMaxAuthorization(native *native.NativeService) ([]byte, error)

Change the status if node can receive authorization from onx holders

func CheckVBFTConfig

func CheckVBFTConfig(configuration *config.VBFTConfig) error

func CommitDpos

func CommitDpos(native *native.NativeService) ([]byte, error)

Go to next consensus epoch

func GetBytesUint32

func GetBytesUint32(b []byte) (uint32, error)

func GetBytesUint64

func GetBytesUint64(b []byte) (uint64, error)

func GetUint32Bytes

func GetUint32Bytes(num uint32) ([]byte, error)

func GetUint64Bytes

func GetUint64Bytes(num uint64) ([]byte, error)

func GetView

func GetView(native *native.NativeService, contract common.Address) (uint32, error)

func InitConfig

func InitConfig(native *native.NativeService) ([]byte, error)

Init governance contract, include vbft config, global param and onxid admin.

func InitGovernance

func InitGovernance()

Init governance contract address

func QuitNode

func QuitNode(native *native.NativeService) ([]byte, error)

Quit a registered node, used by node owner. Remove node from pool and unfreeze deposit next epoch(candidate node) / next next epoch(consensus node)

func ReduceInitPos

func ReduceInitPos(native *native.NativeService) ([]byte, error)

reduce init pos of a node

func RegisterCandidate

func RegisterCandidate(native *native.NativeService) ([]byte, error)

Register a candidate node, used by users. Users can register a candidate node with a authorized onxid. Candidate node can be authorized and become consensus node according to their pos. Candidate node can get oxg bonus according to their pos.

func RegisterCandidateTransferFrom

func RegisterCandidateTransferFrom(native *native.NativeService) ([]byte, error)

Register a candidate node, used by contracts. Contracts can register a candidate node with a authorized onxid after approving onx to governance contract before invoke this function. Candidate node can be authorized and become consensus node according to their pos. Candidate node can get oxg bonus according to their pos.

func RegisterGovernanceContract

func RegisterGovernanceContract(native *native.NativeService)

Register methods of governance contract

func RejectCandidate

func RejectCandidate(native *native.NativeService) ([]byte, error)

Reject a registered candidate node, remove node from pool and unfreeze deposit onx Only approved candidate node can participate in consensus selection and get oxg bonus.

func SetPeerCost

func SetPeerCost(native *native.NativeService) ([]byte, error)

Set node cost, node can take some percentage of fee before split

func SetPromisePos

func SetPromisePos(native *native.NativeService) ([]byte, error)

set promise pos of a node

func TransferPenalty

func TransferPenalty(native *native.NativeService) ([]byte, error)

Transfer all punished ONX of a black node to a certain address

func UnAuthorizeForPeer

func UnAuthorizeForPeer(native *native.NativeService) ([]byte, error)

UnAuthorize for a node by redeeming ONX from this governance contract

func UnRegisterCandidate

func UnRegisterCandidate(native *native.NativeService) ([]byte, error)

Unregister a registered candidate node, will remove node from pool, and unfreeze deposit onx.

func UpdateConfig

func UpdateConfig(native *native.NativeService) ([]byte, error)

Update VBFT config

func UpdateGlobalParam

func UpdateGlobalParam(native *native.NativeService) ([]byte, error)

Update global params of this governance contract

func UpdateGlobalParam2

func UpdateGlobalParam2(native *native.NativeService) ([]byte, error)

Update global params of this governance contract

func UpdateSplitCurve

func UpdateSplitCurve(native *native.NativeService) ([]byte, error)

Update split curve

func WhiteNode

func WhiteNode(native *native.NativeService) ([]byte, error)

Remove a node from black list, allow it to be registered

func Withdraw

func Withdraw(native *native.NativeService) ([]byte, error)

Withdraw unfreezed ONX deposited in this governance contract.

func WithdrawFee

func WithdrawFee(native *native.NativeService) ([]byte, error)

Withdraw split fee of address

func WithdrawOxg

func WithdrawOxg(native *native.NativeService) ([]byte, error)

Withdraw unbounded OXG according to deposit ONX in this governance contract

Types

type ApproveCandidateParam

type ApproveCandidateParam struct {
	PeerPubkey string
}

func (*ApproveCandidateParam) Deserialize

func (this *ApproveCandidateParam) Deserialize(r io.Reader) error

func (*ApproveCandidateParam) Serialize

func (this *ApproveCandidateParam) Serialize(w io.Writer) error

type AuthorizeForPeerParam

type AuthorizeForPeerParam struct {
	Address        common.Address
	PeerPubkeyList []string
	PosList        []uint32
}

func (*AuthorizeForPeerParam) Deserialize

func (this *AuthorizeForPeerParam) Deserialize(r io.Reader) error

func (*AuthorizeForPeerParam) Serialize

func (this *AuthorizeForPeerParam) Serialize(w io.Writer) error

type AuthorizeInfo

type AuthorizeInfo struct {
	PeerPubkey           string
	Address              common.Address
	ConsensusPos         uint64 //pos deposit in consensus node
	CandidatePos         uint64 //pos deposit in candidate node
	NewPos               uint64 //deposit new pos to consensus or candidate node, it will be calculated in next epoch, you can withdrawal it at any time
	WithdrawConsensusPos uint64 //unAuthorized pos from consensus pos, frozen until next next epoch
	WithdrawCandidatePos uint64 //unAuthorized pos from candidate pos, frozen until next epoch
	WithdrawUnfreezePos  uint64 //unfrozen pos, can withdraw at any time
}

func (*AuthorizeInfo) Deserialize

func (this *AuthorizeInfo) Deserialize(r io.Reader) error

func (*AuthorizeInfo) Serialize

func (this *AuthorizeInfo) Serialize(w io.Writer) error

type BlackListItem

type BlackListItem struct {
	PeerPubkey string         //peerPubkey in black list
	Address    common.Address //the owner of this peer
	InitPos    uint64         //initPos of this peer
}

func (*BlackListItem) Deserialize

func (this *BlackListItem) Deserialize(r io.Reader) error

func (*BlackListItem) Serialize

func (this *BlackListItem) Serialize(w io.Writer) error

type BlackNodeParam

type BlackNodeParam struct {
	PeerPubkeyList []string
}

func (*BlackNodeParam) Deserialize

func (this *BlackNodeParam) Deserialize(r io.Reader) error

func (*BlackNodeParam) Serialize

func (this *BlackNodeParam) Serialize(w io.Writer) error

type CandidateSplitInfo

type CandidateSplitInfo struct {
	PeerPubkey string
	Address    common.Address
	InitPos    uint64
	Stake      uint64 //total stake, init pos + total pos
	S          uint64 //fee split weight of this peer
}

type ChangeInitPosParam

type ChangeInitPosParam struct {
	PeerPubkey string
	Address    common.Address
	Pos        uint32
}

func (*ChangeInitPosParam) Deserialize

func (this *ChangeInitPosParam) Deserialize(r io.Reader) error

func (*ChangeInitPosParam) Serialize

func (this *ChangeInitPosParam) Serialize(w io.Writer) error

type ChangeMaxAuthorizationParam

type ChangeMaxAuthorizationParam struct {
	PeerPubkey   string
	Address      common.Address
	MaxAuthorize uint32
}

func (*ChangeMaxAuthorizationParam) Deserialize

func (this *ChangeMaxAuthorizationParam) Deserialize(r io.Reader) error

func (*ChangeMaxAuthorizationParam) Serialize

func (this *ChangeMaxAuthorizationParam) Serialize(w io.Writer) error

type Configuration

type Configuration struct {
	N                    uint32
	C                    uint32
	K                    uint32
	L                    uint32
	BlockMsgDelay        uint32
	HashMsgDelay         uint32
	PeerHandshakeTimeout uint32
	MaxBlockChangeView   uint32
}

func (*Configuration) Deserialize

func (this *Configuration) Deserialize(r io.Reader) error

func (*Configuration) Serialize

func (this *Configuration) Serialize(w io.Writer) error

type GlobalParam

type GlobalParam struct {
	CandidateFee uint64 //unit: 10^-9 oxg
	MinInitStake uint64 //min init pos
	CandidateNum uint32 //num of candidate and consensus node
	PosLimit     uint32 //authorize pos limit is initPos*posLimit
	A            uint32 //fee split to all consensus node
	B            uint32 //fee split to all candidate node
	Yita         uint32 //split curve coefficient
	Penalty      uint32 //authorize pos penalty percentage
}

func (*GlobalParam) Deserialize

func (this *GlobalParam) Deserialize(r io.Reader) error

func (*GlobalParam) Serialize

func (this *GlobalParam) Serialize(w io.Writer) error

type GlobalParam2

type GlobalParam2 struct {
	MinAuthorizePos      uint32 //min ONX of each authorization, 500 default
	CandidateFeeSplitNum uint32 //num of peer can receive motivation(include consensus and candidate)
	Field1               []byte //reserved field
	Field2               []byte //reserved field
	Field3               []byte //reserved field
	Field4               []byte //reserved field
	Field5               []byte //reserved field
	Field6               []byte //reserved field
}

func (*GlobalParam2) Deserialize

func (this *GlobalParam2) Deserialize(r io.Reader) error

func (*GlobalParam2) Serialize

func (this *GlobalParam2) Serialize(w io.Writer) error

type GovernanceView

type GovernanceView struct {
	View   uint32
	Height uint32
	TxHash common.Uint256
}

func GetGovernanceView

func GetGovernanceView(native *native.NativeService, contract common.Address) (*GovernanceView, error)

func (*GovernanceView) Deserialize

func (this *GovernanceView) Deserialize(r io.Reader) error

func (*GovernanceView) Serialize

func (this *GovernanceView) Serialize(w io.Writer) error

type PeerAttributes

type PeerAttributes struct {
	PeerPubkey   string
	MaxAuthorize uint64 //max authorzie pos this peer can receive(number of onx), set by peer owner
	T2PeerCost   uint64 //candidate or consensus node doesn't share income percent with authorize users, 100 means node will take all incomes, it will take effect in view T + 2
	T1PeerCost   uint64 //candidate or consensus node doesn't share income percent with authorize users, 100 means node will take all incomes, it will take effect in view T + 1
	TPeerCost    uint64 //candidate or consensus node doesn't share income percent with authorize users, 100 means node will take all incomes, it will take effect in view T
	Field1       []byte //reserved field
	Field2       []byte //reserved field
	Field3       []byte //reserved field
	Field4       []byte //reserved field
}

func (*PeerAttributes) Deserialize

func (this *PeerAttributes) Deserialize(r io.Reader) error

func (*PeerAttributes) Serialize

func (this *PeerAttributes) Serialize(w io.Writer) error

type PeerPoolItem

type PeerPoolItem struct {
	Index      uint32         //peer index
	PeerPubkey string         //peer pubkey
	Address    common.Address //peer owner
	Status     Status         //peer status
	InitPos    uint64         //peer initPos
	TotalPos   uint64         //total authorize pos this peer received
}

func (*PeerPoolItem) Deserialize

func (this *PeerPoolItem) Deserialize(r io.Reader) error

func (*PeerPoolItem) Serialize

func (this *PeerPoolItem) Serialize(w io.Writer) error

type PeerPoolList

type PeerPoolList struct {
	Peers []*PeerPoolItem
}

type PeerPoolMap

type PeerPoolMap struct {
	PeerPoolMap map[string]*PeerPoolItem
}

func GetPeerPoolMap

func GetPeerPoolMap(native *native.NativeService, contract common.Address, view uint32) (*PeerPoolMap, error)

func (*PeerPoolMap) Deserialize

func (this *PeerPoolMap) Deserialize(r io.Reader) error

func (*PeerPoolMap) Serialize

func (this *PeerPoolMap) Serialize(w io.Writer) error

type PeerStakeInfo

type PeerStakeInfo struct {
	Index      uint32
	PeerPubkey string
	Stake      uint64
}

type PenaltyStake

type PenaltyStake struct {
	PeerPubkey   string //peer pubKey of penalty stake
	InitPos      uint64 //initPos penalty
	AuthorizePos uint64 //authorize pos penalty
	TimeOffset   uint32 //time used for calculate unbound oxg
	Amount       uint64 //unbound oxg that this penalty unbounded
}

func (*PenaltyStake) Deserialize

func (this *PenaltyStake) Deserialize(r io.Reader) error

func (*PenaltyStake) Serialize

func (this *PenaltyStake) Serialize(w io.Writer) error

type PreConfig

type PreConfig struct {
	Configuration *Configuration
	SetView       uint32
}

func (*PreConfig) Deserialize

func (this *PreConfig) Deserialize(r io.Reader) error

func (*PreConfig) Serialize

func (this *PreConfig) Serialize(w io.Writer) error

type PromisePos

type PromisePos struct {
	PeerPubkey string
	PromisePos uint64
}

func (*PromisePos) Deserialize

func (this *PromisePos) Deserialize(r io.Reader) error

func (*PromisePos) Serialize

func (this *PromisePos) Serialize(w io.Writer) error

type QuitNodeParam

type QuitNodeParam struct {
	PeerPubkey string
	Address    common.Address
}

func (*QuitNodeParam) Deserialize

func (this *QuitNodeParam) Deserialize(r io.Reader) error

func (*QuitNodeParam) Serialize

func (this *QuitNodeParam) Serialize(w io.Writer) error

type RegisterCandidateParam

type RegisterCandidateParam struct {
	PeerPubkey string
	Address    common.Address
	InitPos    uint32
	Caller     []byte
	KeyNo      uint32
}

func (*RegisterCandidateParam) Deserialize

func (this *RegisterCandidateParam) Deserialize(r io.Reader) error

func (*RegisterCandidateParam) Serialize

func (this *RegisterCandidateParam) Serialize(w io.Writer) error

type RejectCandidateParam

type RejectCandidateParam struct {
	PeerPubkey string
}

func (*RejectCandidateParam) Deserialize

func (this *RejectCandidateParam) Deserialize(r io.Reader) error

func (*RejectCandidateParam) Serialize

func (this *RejectCandidateParam) Serialize(w io.Writer) error

type SetPeerCostParam

type SetPeerCostParam struct {
	PeerPubkey string
	Address    common.Address
	PeerCost   uint32
}

func (*SetPeerCostParam) Deserialize

func (this *SetPeerCostParam) Deserialize(r io.Reader) error

func (*SetPeerCostParam) Serialize

func (this *SetPeerCostParam) Serialize(w io.Writer) error

type SplitCurve

type SplitCurve struct {
	Yi []uint32
}

func (*SplitCurve) Deserialize

func (this *SplitCurve) Deserialize(r io.Reader) error

func (*SplitCurve) Serialize

func (this *SplitCurve) Serialize(w io.Writer) error

type SplitFeeAddress

type SplitFeeAddress struct {
	Address common.Address
	Amount  uint64
}

func (*SplitFeeAddress) Deserialize

func (this *SplitFeeAddress) Deserialize(r io.Reader) error

func (*SplitFeeAddress) Serialize

func (this *SplitFeeAddress) Serialize(w io.Writer) error

type Status

type Status uint8
const (
	//status
	RegisterCandidateStatus Status = iota
	CandidateStatus
	ConsensusStatus
	QuitConsensusStatus
	QuitingStatus
	BlackStatus
)

func (*Status) Deserialize

func (this *Status) Deserialize(r io.Reader) error

func (*Status) Serialize

func (this *Status) Serialize(w io.Writer) error

type TotalStake

type TotalStake struct {
	Address    common.Address
	Stake      uint64
	TimeOffset uint32
}

func (*TotalStake) Deserialize

func (this *TotalStake) Deserialize(r io.Reader) error

func (*TotalStake) Serialize

func (this *TotalStake) Serialize(w io.Writer) error

type TransferPenaltyParam

type TransferPenaltyParam struct {
	PeerPubkey string
	Address    common.Address
}

func (*TransferPenaltyParam) Deserialize

func (this *TransferPenaltyParam) Deserialize(r io.Reader) error

func (*TransferPenaltyParam) Serialize

func (this *TransferPenaltyParam) Serialize(w io.Writer) error

type UnRegisterCandidateParam

type UnRegisterCandidateParam struct {
	PeerPubkey string
	Address    common.Address
}

func (*UnRegisterCandidateParam) Deserialize

func (this *UnRegisterCandidateParam) Deserialize(r io.Reader) error

func (*UnRegisterCandidateParam) Serialize

func (this *UnRegisterCandidateParam) Serialize(w io.Writer) error

type WhiteNodeParam

type WhiteNodeParam struct {
	PeerPubkey string
}

func (*WhiteNodeParam) Deserialize

func (this *WhiteNodeParam) Deserialize(r io.Reader) error

func (*WhiteNodeParam) Serialize

func (this *WhiteNodeParam) Serialize(w io.Writer) error

type WithdrawFeeParam

type WithdrawFeeParam struct {
	Address common.Address
}

func (*WithdrawFeeParam) Deserialize

func (this *WithdrawFeeParam) Deserialize(r io.Reader) error

func (*WithdrawFeeParam) Serialize

func (this *WithdrawFeeParam) Serialize(w io.Writer) error

type WithdrawOxgParam

type WithdrawOxgParam struct {
	Address common.Address
}

func (*WithdrawOxgParam) Deserialize

func (this *WithdrawOxgParam) Deserialize(r io.Reader) error

func (*WithdrawOxgParam) Serialize

func (this *WithdrawOxgParam) Serialize(w io.Writer) error

type WithdrawParam

type WithdrawParam struct {
	Address        common.Address
	PeerPubkeyList []string
	WithdrawList   []uint32
}

func (*WithdrawParam) Deserialize

func (this *WithdrawParam) Deserialize(r io.Reader) error

func (*WithdrawParam) Serialize

func (this *WithdrawParam) Serialize(w io.Writer) error

Jump to

Keyboard shortcuts

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