governance

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CouncilProposalKey is key for CouncilProposal storage
	CouncilProposalKey = "councilProposalKey"

	// CouncilKey is key for council storage
	CouncilKey = "councilKey"

	// MinCouncilMembersCount is min council members count
	MinCouncilMembersCount = 4
)
View Source
const (
	// GasProposalKey is key for GasProposal storage
	GasProposalKey = "gasProposalKey"

	GasParamsKey = "gasParamsKey"
)
View Source
const (
	ProposeMethod  = "propose"
	VoteMethod     = "vote"
	ProposalMethod = "proposal"
	MaxTitleLength = 200
	MaxDescLength  = 10000
)
View Source
const (
	// NodeProposalKey is key for NodeProposal storage
	NodeProposalKey = "nodeProposalKey"

	// NodeMembersKey is key for node member storage
	NodeMembersKey = "nodeMembersKey"
)
View Source
const (
	ProposalIDKey           = "proposalIDKey"
	NotFinishedProposalsKey = "notFinishedProposalKey"

	Addr2NameSystemAddrKey = "addrKey"
	Addr2NameSystemNameKey = "nameKey"
)
View Source
const (
	WhiteListProviderProposalKey = "WhiteListProviderProposal"
)

Variables

View Source
var (
	ErrCouncilNumber            = errors.New("council members total count can't bigger than candidates count")
	ErrMinCouncilMembersCount   = errors.New("council members count can't less than 4")
	ErrRepeatedAddress          = errors.New("council member address repeated")
	ErrRepeatedName             = errors.New("council member name repeated")
	ErrNotFoundCouncilMember    = errors.New("council member is not found")
	ErrNotFoundCouncil          = errors.New("council is not found")
	ErrCouncilExtraArgs         = errors.New("unmarshal council extra arguments error")
	ErrNotFoundCouncilProposal  = errors.New("council proposal not found for the id")
	ErrExistNotFinishedProposal = errors.New("exist not finished proposal, must finished all proposal then propose council proposal")
	ErrDeadlineBlockNumber      = errors.New("can't vote, proposal is out of deadline block number")
)
View Source
var (
	ErrExistNotFinishedGasProposal     = errors.New("exist not gas finished proposal")
	ErrExistNotFinishedCouncilProposal = errors.New("exist not finished council proposal")
	ErrNotFoundGasProposal             = errors.New("gas proposal not found for the id")
	ErrUnKnownGasProposalArgs          = errors.New("unknown proposal args")
	ErrGasExtraArgs                    = errors.New("unmarshal gas extra arguments error")
	ErrGasArgsType                     = errors.New("gas arguments type error")
	ErrGasUpperOrLlower                = errors.New("gas upper or lower limit error")
	ErrRepeatedGasInfo                 = errors.New("repeated gas info")
)
View Source
var (
	ErrMethodName         = errors.New("no this method")
	ErrVoteResult         = errors.New("vote result is invalid")
	ErrProposalType       = errors.New("proposal type is invalid")
	ErrUser               = errors.New("user is invalid")
	ErrUseHasVoted        = errors.New("user has already voted")
	ErrTitle              = errors.New("title is invalid")
	ErrTooLongTitle       = errors.New("title is too long, max is 200 characters")
	ErrDesc               = errors.New("description is invalid")
	ErrTooLongDesc        = errors.New("description is too long, max is 10000 characters")
	ErrBlockNumber        = errors.New("block number is invalid")
	ErrProposalID         = errors.New("proposal id is invalid")
	ErrProposalFinished   = errors.New("proposal has already finished")
	ErrBlockNumberOutDate = errors.New("block number is out of date")
)
View Source
var (
	ErrNodeNumber              = errors.New("node members total count can't bigger than candidates count")
	ErrNotFoundNodeID          = errors.New("node id is not found")
	ErrNotFoundNodeName        = errors.New("node name is not found")
	ErrNotFoundNodeAddress     = errors.New("address is not found")
	ErrNodeExtraArgs           = errors.New("unmarshal node extra arguments error")
	ErrNodeProposalNumberLimit = errors.New("node proposal number limit, only allow one node proposal")
	ErrNotFoundNodeProposal    = errors.New("node proposal not found for the id")
	ErrUnKnownProposalArgs     = errors.New("unknown proposal args")
	ErrRepeatedNodeID          = errors.New("repeated node id")
	ErrRepeatedNodeName        = errors.New("repeated node name")
	ErrRepeatedNodeAddress     = errors.New("repeated address")
	ErrUpgradeExtraArgs        = errors.New("unmarshal node upgrade extra arguments error")
	ErrRepeatedDownloadUrl     = errors.New("repeated download url")
)
View Source
var (
	ErrExistVotingProposal = errors.New("check finished council proposal fail: exist voting proposal of council elect and whitelist provider")
)
View Source
var (
	ErrNilProposalAccount = errors.New("ProposalID must be reset then use")
)
View Source
var NowProposalStrategy = SimpleStrategy

Functions

func CheckAndUpdateState

func CheckAndUpdateState(lastHeight uint64, stateLedger ledger.StateLedger) error

func GetABI

func GetABI() (*abi.ABI, error)

GetABI get system contract abi

func GetNotFinishedProposals

func GetNotFinishedProposals(stateLedger ledger.StateLedger) ([]uint64, map[uint64]NotFinishedProposal, error)

func InitCouncilMembers

func InitCouncilMembers(lg ledger.StateLedger, admins []*repo.Admin, initBlance string) error

func InitGasMembers

func InitGasMembers(lg ledger.StateLedger, epochInfo *rbft.EpochInfo) error

func InitNodeMembers

func InitNodeMembers(lg ledger.StateLedger, members []*repo.NodeName, epochInfo *rbft.EpochInfo) error

Types

type Addr2NameSystem

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

func NewAddr2NameSystem

func NewAddr2NameSystem(stateLedger ledger.StateLedger) *Addr2NameSystem

func (*Addr2NameSystem) GetAddr

func (ans *Addr2NameSystem) GetAddr(name string) (bool, string)

func (*Addr2NameSystem) GetName

func (ans *Addr2NameSystem) GetName(addr string) (bool, string)

func (*Addr2NameSystem) SetName

func (ans *Addr2NameSystem) SetName(addr, name string)

SetName set address to new name

type BaseProposal

type BaseProposal struct {
	ID          uint64
	Type        ProposalType
	Strategy    ProposalStrategy
	Proposer    string
	Title       string
	Desc        string
	BlockNumber uint64

	// totalVotes is total votes for this proposal
	// attention: some users may not vote for this proposal
	TotalVotes uint64

	// passVotes record user address for passed vote
	PassVotes []string

	RejectVotes []string
	Status      ProposalStatus
}

func (*BaseProposal) GetBlockNumber

func (baseProposal *BaseProposal) GetBlockNumber() uint64

func (*BaseProposal) GetID

func (baseProposal *BaseProposal) GetID() uint64

func (*BaseProposal) GetStatus

func (baseProposal *BaseProposal) GetStatus() ProposalStatus

func (*BaseProposal) SetStatus

func (baseProposal *BaseProposal) SetStatus(status ProposalStatus)

type BaseProposalArgs

type BaseProposalArgs struct {
	ProposalType uint8
	Title        string
	Desc         string
	BlockNumber  uint64
}

type BaseVoteArgs

type BaseVoteArgs struct {
	ProposalId uint64
	VoteResult uint8
}

type Council

type Council struct {
	Members []*CouncilMember
}

Council is storage of council

func CheckInCouncil

func CheckInCouncil(account ledger.IAccount, addr string) (bool, *Council)

func GetCouncil

func GetCouncil(account ledger.IAccount) (*Council, bool)

type CouncilExtraArgs

type CouncilExtraArgs struct {
	Candidates []*CouncilMember
}

CouncilExtraArgs is council proposal extra arguments

type CouncilManager

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

func NewCouncilManager

func NewCouncilManager(cfg *common.SystemContractConfig) *CouncilManager

func (*CouncilManager) EstimateGas

func (cm *CouncilManager) EstimateGas(callArgs *types.CallArgs) (uint64, error)

func (*CouncilManager) Reset

func (cm *CouncilManager) Reset(lastHeight uint64, stateLedger ledger.StateLedger)

func (*CouncilManager) Run

func (cm *CouncilManager) Run(msg *vm.Message) (result *vm.ExecutionResult, err error)

type CouncilMember

type CouncilMember struct {
	Address string
	Weight  uint64
	Name    string
}

type CouncilProposal

type CouncilProposal struct {
	BaseProposal
	Candidates []*CouncilMember
}

CouncilProposal is storage of council proposal

type CouncilProposalArgs

type CouncilProposalArgs struct {
	BaseProposalArgs
	CouncilExtraArgs
}

CouncilProposalArgs is council proposal arguments

type CouncilVoteArgs

type CouncilVoteArgs struct {
	BaseVoteArgs
}

CouncilVoteArgs is council vote arguments

type GasExtraArgs

type GasExtraArgs struct {
	MaxGasPrice        uint64
	MinGasPrice        uint64
	InitGasPrice       uint64
	GasChangeRateValue uint64
}

type GasManager

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

func NewGasManager

func NewGasManager(cfg *common.SystemContractConfig) *GasManager

func (*GasManager) EstimateGas

func (gm *GasManager) EstimateGas(callArgs *types.CallArgs) (uint64, error)

func (*GasManager) Reset

func (gm *GasManager) Reset(lastHeight uint64, stateLedger ledger.StateLedger)

func (*GasManager) Run

func (gm *GasManager) Run(msg *vm.Message) (*vm.ExecutionResult, error)

type GasProposal

type GasProposal struct {
	BaseProposal
	GasExtraArgs
}

type GasProposalArgs

type GasProposalArgs struct {
	BaseProposalArgs
	GasExtraArgs
}

type GasVoteArgs

type GasVoteArgs struct {
	BaseVoteArgs
}

type GetProposalArgs

type GetProposalArgs struct {
	ProposalID uint64
}

type Governance

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

func NewGov

func NewGov(proposalTypes []ProposalType, logger logrus.FieldLogger) (*Governance, error)

func (*Governance) GetArgs

func (g *Governance) GetArgs(msg *vm.Message) (any, error)

GetArgs get system contract arguments from a message

func (*Governance) GetMethodName

func (g *Governance) GetMethodName(data []byte) (string, error)

GetMethodName quickly returns the name of a method. This is a quick way to get the name of a method. The method name is the first 4 bytes of the keccak256 hash of the method signature. If the method name is not found, the empty string is returned.

func (*Governance) PackOutputArgs

func (g *Governance) PackOutputArgs(methodName string, outputArgs ...any) ([]byte, error)

PackOutputArgs pack the output arguments by method name

func (*Governance) ParseArgs

func (g *Governance) ParseArgs(msg *vm.Message, methodName string, ret any) error

ParseArgs parse the arguments to specified interface by method name

func (*Governance) Propose

func (g *Governance) Propose(user *ethcommon.Address, proposalType ProposalType, title, desc string, blockNumber uint64, lastHeight uint64, nodeAddRole bool) (*BaseProposal, error)

func (*Governance) RecordLog

func (g *Governance) RecordLog(currentLog *common.Log, method string, proposal *BaseProposal, data []byte)

RecordLog record execution log for governance

func (*Governance) SaveLog

func (g *Governance) SaveLog(stateLedger ledger.StateLedger, currentLog *common.Log)

SaveLog save log

func (*Governance) UnpackOutputArgs

func (g *Governance) UnpackOutputArgs(methodName string, packed []byte) ([]any, error)

UnpackOutputArgs unpack the output arguments by method name

func (*Governance) Vote

func (g *Governance) Vote(user *ethcommon.Address, proposal *BaseProposal, voteResult VoteResult) (ProposalStatus, error)

Vote a proposal, return vote status

type Node

type Node struct {
	Members []*NodeMember
}

type NodeExtraArgs

type NodeExtraArgs struct {
	Nodes []*NodeMember
}

NodeExtraArgs is Node proposal extra arguments

type NodeManager

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

func NewNodeManager

func NewNodeManager(cfg *common.SystemContractConfig) *NodeManager

func (*NodeManager) EstimateGas

func (nm *NodeManager) EstimateGas(callArgs *types.CallArgs) (uint64, error)

func (*NodeManager) Reset

func (nm *NodeManager) Reset(lastHeight uint64, stateLedger ledger.StateLedger)

func (*NodeManager) Run

func (nm *NodeManager) Run(msg *vm.Message) (*vm.ExecutionResult, error)

type NodeMember

type NodeMember struct {
	Name    string `mapstructure:"name" toml:"name"`
	NodeId  string `mapstructure:"node_id" toml:"node_id"`
	Address string `mapstructure:"address" toml:"address"`
	ID      uint64 `mapstructure:"id" toml:"id"`
}

func GetNodeMembers

func GetNodeMembers(lg ledger.StateLedger) ([]*NodeMember, error)

type NodeProposal

type NodeProposal struct {
	BaseProposal
	NodeExtraArgs
	UpgradeExtraArgs
}

NodeProposal is storage of node proposal

type NodeProposalArgs

type NodeProposalArgs struct {
	BaseProposalArgs
	NodeExtraArgs
}

NodeProposalArgs is node proposal arguments For node add and remove

type NodeVoteArgs

type NodeVoteArgs struct {
	BaseVoteArgs
}

type NotFinishedProposal

type NotFinishedProposal struct {
	ID                  uint64
	DeadlineBlockNumber uint64
	ContractAddr        string
}

type NotFinishedProposalMgr

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

func NewNotFinishedProposalMgr

func NewNotFinishedProposalMgr(stateLedger ledger.StateLedger) *NotFinishedProposalMgr

func (*NotFinishedProposalMgr) GetProposals

func (nfpm *NotFinishedProposalMgr) GetProposals() ([]uint64, map[uint64]NotFinishedProposal, error)

func (*NotFinishedProposalMgr) RemoveProposal

func (nfpm *NotFinishedProposalMgr) RemoveProposal(id uint64) error

func (*NotFinishedProposalMgr) SetProposal

func (nfpm *NotFinishedProposalMgr) SetProposal(proposal *NotFinishedProposal) error

type ProposalArgs

type ProposalArgs struct {
	BaseProposalArgs
	Extra []byte
}

type ProposalID

type ProposalID struct {
	ID uint64
	// contains filtered or unexported fields
}

func NewProposalID

func NewProposalID(stateLedger ledger.StateLedger) *ProposalID

NewProposalID new proposal id from ledger

func (*ProposalID) GetAndAddID

func (pid *ProposalID) GetAndAddID() (uint64, error)

func (*ProposalID) GetID

func (pid *ProposalID) GetID() uint64

type ProposalObject

type ProposalObject interface {
	GetID() uint64
	GetStatus() ProposalStatus
	SetStatus(status ProposalStatus)
	GetBlockNumber() uint64
}

type ProposalStatus

type ProposalStatus uint8
const (
	Voting ProposalStatus = iota
	Approved
	Rejected
)

func CalcProposalStatus

func CalcProposalStatus(strategy ProposalStrategy, totalVotes, passVotes, rejectVotes uint64) ProposalStatus

type ProposalStrategy

type ProposalStrategy uint8
const (
	// SimpleStrategy means proposal is approved if pass votes is greater than half of total votes
	SimpleStrategy ProposalStrategy = iota
)

type ProposalType

type ProposalType uint8
const (
	// CouncilElect is a proposal for elect the council
	CouncilElect ProposalType = iota

	// NodeUpgrade is a proposal for update or upgrade the node
	NodeUpgrade

	// NodeAdd is a proposal for adding a new node
	NodeAdd

	// NodeRemove is a proposal for removing a node
	NodeRemove

	WhiteListProviderAdd

	WhiteListProviderRemove

	GasUpdate
)

type UpgradeExtraArgs

type UpgradeExtraArgs struct {
	DownloadUrls []string
	CheckHash    string
}

type UpgradeProposalArgs

type UpgradeProposalArgs struct {
	BaseProposalArgs
	UpgradeExtraArgs
}

UpgradeProposalArgs for node upgrade

type VoteArgs

type VoteArgs struct {
	BaseVoteArgs
	Extra []byte
}

type VoteResult

type VoteResult uint8
const (
	Pass VoteResult = iota
	Reject
)

type WhiteListProviderManager

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

func NewWhiteListProviderManager

func NewWhiteListProviderManager(cfg *common.SystemContractConfig) *WhiteListProviderManager

NewWhiteListProviderManager constructs a new NewWhiteListProviderManager

func (*WhiteListProviderManager) EstimateGas

func (wlpm *WhiteListProviderManager) EstimateGas(callArgs *types.CallArgs) (uint64, error)

func (*WhiteListProviderManager) Reset

func (wlpm *WhiteListProviderManager) Reset(lastHeight uint64, stateLedger ledger.StateLedger)

Reset resets the state of the WhiteListProviderManager.

stateLedger is the state ledger used to get or create an account.

func (*WhiteListProviderManager) Run

type WhiteListProviderProposal

type WhiteListProviderProposal struct {
	BaseProposal
	access.WhiteListProviderArgs
}

type WhiteListProviderProposalArgs

type WhiteListProviderProposalArgs struct {
	BaseProposalArgs
	access.WhiteListProviderArgs
}

type WhiteListProviderVoteArgs

type WhiteListProviderVoteArgs struct {
	BaseVoteArgs
}

Jump to

Keyboard shortcuts

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