pposm

package
v1.8.17-0...-7deff2d Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GET_WITNESS   = 1
	GET_IM_RE     = 2
	GET_WIT_IM_RE = 3
)
View Source
const (

	/** about candidate pool */
	// immediate elected candidate
	ImmediatePrefix     = "id"
	ImmediateListPrefix = "iL"
	// reserve elected candidate
	ReservePrefix     = "rd"
	ReserveListPrefix = "rL"
	// previous witness
	PreWitnessPrefix     = "Pwn"
	PreWitnessListPrefix = "PwL"
	// witness
	WitnessPrefix     = "wn"
	WitnessListPrefix = "wL"
	// next witness
	NextWitnessPrefix     = "Nwn"
	NextWitnessListPrefix = "NwL"
	// need refund
	DefeatPrefix     = "df"
	DefeatListPrefix = "dL"

	/** about ticket pool */
	// Remaining number key
	SurplusQuantity = "sq"
	// Expire ticket prefix
	ExpireTicket = "et"
	// candidate attach
	CandidateAttach = "ca"
	// Ticket pool hash
	TicketPoolHash = "tph"
)
View Source
const (
	PREVIOUS_C = iota - 1
	CURRENT_C
	NEXT_C
)
View Source
const (
	IS_LOST = iota
	IS_IMMEDIATE
	IS_RESERVE
)

Variables

View Source
var (
	//CandidateEncodeErr          = errors.New("Candidate encoding err")
	//CandidateDecodeErr          = errors.New("Candidate decoding err")
	CandidateEmptyErr           = errors.New("Candidate is empty")
	ContractBalanceNotEnoughErr = errors.New("Contract's balance is not enough")
	CandidateOwnerErr           = errors.New("CandidateOwner Addr is illegal")
	DepositLowErr               = errors.New("Candidate deposit too low")
	WithdrawPriceErr            = errors.New("Withdraw Price err")
	WithdrawLowErr              = errors.New("Withdraw Price too low")
	RefundEmptyErr              = errors.New("Refund is empty")
)
View Source
var (

	/** about candidate pool */
	// immediate elected candidate
	ImmediateBytePrefix     = []byte(ImmediatePrefix)
	ImmediateListBytePrefix = []byte(ImmediateListPrefix)
	// reserve elected candidate
	ReserveBytePrefix     = []byte(ReservePrefix)
	ReserveListBytePrefix = []byte(ReserveListPrefix)
	// previous witness
	PreWitnessBytePrefix     = []byte(PreWitnessPrefix)
	PreWitnessListBytePrefix = []byte(PreWitnessListPrefix)
	// witness
	WitnessBytePrefix     = []byte(WitnessPrefix)
	WitnessListBytePrefix = []byte(WitnessListPrefix)
	// next witness
	NextWitnessBytePrefix     = []byte(NextWitnessPrefix)
	NextWitnessListBytePrefix = []byte(NextWitnessListPrefix)
	// need refund
	DefeatBytePrefix     = []byte(DefeatPrefix)
	DefeatListBytePrefix = []byte(DefeatListPrefix)

	/** about ticket pool */
	// Remaining number key
	SurplusQuantityKey = []byte(SurplusQuantity)
	// Expire ticket prefix
	ExpireTicketPrefix    = []byte(ExpireTicket)
	CandidateAttachPrefix = []byte(CandidateAttach)

	TicketPoolHashKey = []byte(TicketPoolHash)
)
View Source
var (
	TicketPoolNilErr      = errors.New("Ticket Insufficient quantity")
	TicketPoolOverflowErr = errors.New("Number of ticket pool overflow")
	EncodeTicketErr       = errors.New("Encode Ticket error")
	EncodePoolNumberErr   = errors.New("Encode SurplusQuantity error")
	DecodeTicketErr       = errors.New("Decode Ticket error")
	DecodePoolNumberErr   = errors.New("Decode SurplusQuantity error")
	RecordExpireTicketErr = errors.New("Record Expire Ticket error")
	CandidateNotFindErr   = errors.New("The Candidate not find")
	CandidateNilTicketErr = errors.New("This candidate has no ticket")
	TicketPoolBalanceErr  = errors.New("TicketPool not sufficient funds")
	TicketNotFindErr      = errors.New("The Ticket not find")
	HandleExpireTicketErr = errors.New("Failure to deal with expired tickets")
	GetCandidateAttachErr = errors.New("Get CandidateAttach error")
	SetCandidateAttachErr = errors.New("Update CandidateAttach error")
	VoteTicketErr         = errors.New("Voting failed")
)

Functions

func PrintObject

func PrintObject(s string, obj interface{})

Types

type CandidatePool

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

func NewCandidatePool

func NewCandidatePool(configs *params.PposConfig) *CandidatePool

Initialize the global candidate pool object

func (*CandidatePool) Election

func (c *CandidatePool) Election(state *state.StateDB, parentHash common.Hash, currBlockNumber *big.Int) ([]*discover.Node, error)

Announce witness

func (*CandidatePool) GetAllWitness

func (c *CandidatePool) GetAllWitness(state *state.StateDB, blockNumber *big.Int) ([]*discover.Node, []*discover.Node, []*discover.Node, error)

Getting previous and current and next witnesses

func (*CandidatePool) GetCandidate

func (c *CandidatePool) GetCandidate(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) *types.Candidate

Getting immediate or reserve candidate info by nodeId

func (*CandidatePool) GetCandidateArr

func (c *CandidatePool) GetCandidateArr(state vm.StateDB, blockNumber *big.Int, nodeIds ...discover.NodeID) types.CandidateQueue

Getting immediate or reserve candidate info arr by nodeIds

func (*CandidatePool) GetCandidatePendArr

func (c *CandidatePool) GetCandidatePendArr(state vm.StateDB, flag int, blockNumber *big.Int) types.CandidateQueue

Getting elected candidates array flag: 0: Getting all elected candidates array 1: Getting all immediate elected candidates array 2: Getting all reserve elected candidates array

func (*CandidatePool) GetChairpersons

func (c *CandidatePool) GetChairpersons(state vm.StateDB, blockNumber *big.Int) types.CandidateQueue

Getting current witness array

func (*CandidatePool) GetChosens

func (c *CandidatePool) GetChosens(state vm.StateDB, flag int, blockNumber *big.Int) types.KindCanQueue

Getting elected candidates array flag: 0: Getting all elected candidates array 1: Getting all immediate elected candidates array 2: Getting all reserve elected candidates array

func (*CandidatePool) GetDefeat

func (c *CandidatePool) GetDefeat(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) types.RefundQueue

Getting all refund array by nodeId

func (*CandidatePool) GetOwner

func (c *CandidatePool) GetOwner(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) common.Address

Getting owner's address of candidate info by nodeId

func (*CandidatePool) GetRefundInterval

func (c *CandidatePool) GetRefundInterval(blockNumber *big.Int) uint32

func (*CandidatePool) GetWitness

func (c *CandidatePool) GetWitness(state *state.StateDB, flag int, blockNumber *big.Int) ([]*discover.Node, error)

Getting nodes of witnesses flag: -1: the previous round of witnesses 0: the current round of witnesses 1: the next round of witnesses

func (*CandidatePool) GetWitnessCandidate

func (c *CandidatePool) GetWitnessCandidate(state vm.StateDB, nodeId discover.NodeID, flag int, blockNumber *big.Int) *types.Candidate

Getting can by witnesses flag: -1: previous round 0: current round 1: next round

func (*CandidatePool) IsChosens

func (c *CandidatePool) IsChosens(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) bool

func (*CandidatePool) IsDefeat

func (c *CandidatePool) IsDefeat(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) bool

Checked current candidate was defeat by nodeId

func (*CandidatePool) MaxChair

func (c *CandidatePool) MaxChair() uint32

func (*CandidatePool) MaxCount

func (c *CandidatePool) MaxCount() uint32

func (*CandidatePool) RefundBalance

func (c *CandidatePool) RefundBalance(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) error

refund once

func (*CandidatePool) SetCandidate

func (c *CandidatePool) SetCandidate(state vm.StateDB, nodeId discover.NodeID, can *types.Candidate) error

pledge Candidate

func (*CandidatePool) SetCandidateExtra

func (c *CandidatePool) SetCandidateExtra(state vm.StateDB, nodeId discover.NodeID, extra string) error

set elected candidate extra value

func (*CandidatePool) Switch

func (c *CandidatePool) Switch(state *state.StateDB, blockNumber *big.Int) bool

switch next witnesses to current witnesses

func (*CandidatePool) UpdateElectedQueue

func (c *CandidatePool) UpdateElectedQueue(state vm.StateDB, currBlockNumber *big.Int, nodeIds ...discover.NodeID) error

According to the nodeId to ensure the current candidate's stay

func (*CandidatePool) WithdrawCandidate

func (c *CandidatePool) WithdrawCandidate(state vm.StateDB, nodeId discover.NodeID, price, blockNumber *big.Int) error

candidate withdraw from immediates or reserve elected candidates

type CandidatePoolContext

type CandidatePoolContext struct {
	Configs *params.PposConfig
}

func GetCandidateContextPtr

func GetCandidateContextPtr() *CandidatePoolContext

func NewCandidatePoolContext

func NewCandidatePoolContext(configs *params.PposConfig) *CandidatePoolContext

Initialize the global candidate pool context object

func (*CandidatePoolContext) Election

func (c *CandidatePoolContext) Election(state *state.StateDB, parentHash common.Hash, blocknumber *big.Int) ([]*discover.Node, error)

func (*CandidatePoolContext) GetAllWitness

func (c *CandidatePoolContext) GetAllWitness(state *state.StateDB, blockNumber *big.Int) ([]*discover.Node, []*discover.Node, []*discover.Node, error)

func (*CandidatePoolContext) GetCandidate

func (c *CandidatePoolContext) GetCandidate(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) *types.Candidate

func (*CandidatePoolContext) GetCandidateArr

func (c *CandidatePoolContext) GetCandidateArr(state vm.StateDB, blockNumber *big.Int, nodeIds ...discover.NodeID) types.CandidateQueue

func (*CandidatePoolContext) GetCandidatePendArr

func (c *CandidatePoolContext) GetCandidatePendArr(state vm.StateDB, flag int, blockNumber *big.Int) types.CandidateQueue

func (*CandidatePoolContext) GetChairpersons

func (c *CandidatePoolContext) GetChairpersons(state vm.StateDB, blockNumber *big.Int) types.CandidateQueue

func (*CandidatePoolContext) GetChosens

func (c *CandidatePoolContext) GetChosens(state vm.StateDB, flag int, blockNumber *big.Int) types.KindCanQueue

func (*CandidatePoolContext) GetDefeat

func (c *CandidatePoolContext) GetDefeat(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) types.RefundQueue

func (*CandidatePoolContext) GetOwner

func (c *CandidatePoolContext) GetOwner(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) common.Address

func (*CandidatePoolContext) GetRefundInterval

func (c *CandidatePoolContext) GetRefundInterval(blockNumber *big.Int) uint32

func (*CandidatePoolContext) GetWitness

func (c *CandidatePoolContext) GetWitness(state *state.StateDB, flag int, blockNumber *big.Int) ([]*discover.Node, error)

func (*CandidatePoolContext) GetWitnessCandidate

func (c *CandidatePoolContext) GetWitnessCandidate(state vm.StateDB, nodeId discover.NodeID, flag int, blockNumber *big.Int) *types.Candidate

func (*CandidatePoolContext) IsChosens

func (c *CandidatePoolContext) IsChosens(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) bool

func (*CandidatePoolContext) IsDefeat

func (c *CandidatePoolContext) IsDefeat(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) bool

func (*CandidatePoolContext) MaxChair

func (c *CandidatePoolContext) MaxChair() uint32

func (*CandidatePoolContext) MaxCount

func (c *CandidatePoolContext) MaxCount() uint32

func (*CandidatePoolContext) RefundBalance

func (c *CandidatePoolContext) RefundBalance(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) error

func (*CandidatePoolContext) SetCandidate

func (c *CandidatePoolContext) SetCandidate(state vm.StateDB, nodeId discover.NodeID, can *types.Candidate) error

func (*CandidatePoolContext) SetCandidateExtra

func (c *CandidatePoolContext) SetCandidateExtra(state vm.StateDB, nodeId discover.NodeID, extra string) error

func (*CandidatePoolContext) Switch

func (c *CandidatePoolContext) Switch(state *state.StateDB, blockNumber *big.Int) bool

func (*CandidatePoolContext) UpdateElectedQueue

func (c *CandidatePoolContext) UpdateElectedQueue(state vm.StateDB, currBlockNumber *big.Int, nodeIds ...discover.NodeID) error

func (*CandidatePoolContext) WithdrawCandidate

func (c *CandidatePoolContext) WithdrawCandidate(state vm.StateDB, nodeId discover.NodeID, price, blockNumber *big.Int) error

type ChainInfo

type ChainInfo interface {
	FindTransaction(txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64)
	GetHeader(blockHash common.Hash, blockNumber uint64) *types.Header
	GetBody(blockNumber uint64) *types.Body
	GetNewStateDB(root common.Hash, blockNumber *big.Int, blockHash common.Hash) (*state.StateDB, error)
}

type TicketPool

type TicketPool struct {
	// Ticket price
	TicketPrice *big.Int
	// Maximum number of ticket pool
	MaxCount uint32
	// Reach expired quantity
	ExpireBlockNumber uint32
	// contains filtered or unexported fields
}

func NewTicketPool

func NewTicketPool(configs *params.PposConfig) *TicketPool

initialize the global ticket pool object

func (*TicketPool) CommitHash

func (t *TicketPool) CommitHash(stateDB vm.StateDB, blockNumber *big.Int, blockHash common.Hash) error

Save the hash value of the current state of the ticket pool

func (*TicketPool) DropReturnTicket

func (t *TicketPool) DropReturnTicket(stateDB vm.StateDB, blockNumber *big.Int, nodeIds ...discover.NodeID) error

func (*TicketPool) GetBatchTicketRemaining

func (t *TicketPool) GetBatchTicketRemaining(stateDB vm.StateDB, ticketIds []common.Hash) map[common.Hash]uint32

Get the batch remaining number of ticket

func (*TicketPool) GetCandidateEpoch

func (t *TicketPool) GetCandidateEpoch(stateDB vm.StateDB, nodeId discover.NodeID) uint64

func (*TicketPool) GetCandidateTicketCount

func (t *TicketPool) GetCandidateTicketCount(stateDB vm.StateDB, nodeId discover.NodeID) uint32

func (*TicketPool) GetCandidateTicketIds

func (t *TicketPool) GetCandidateTicketIds(stateDB vm.StateDB, nodeId discover.NodeID) []common.Hash

func (*TicketPool) GetCandidatesTicketCount

func (t *TicketPool) GetCandidatesTicketCount(stateDB vm.StateDB, nodeIds []discover.NodeID) map[discover.NodeID]uint32

func (*TicketPool) GetCandidatesTicketIds

func (t *TicketPool) GetCandidatesTicketIds(stateDB vm.StateDB, nodeIds []discover.NodeID) map[discover.NodeID][]common.Hash

func (*TicketPool) GetExpireTicketIds

func (t *TicketPool) GetExpireTicketIds(stateDB vm.StateDB, blockNumber *big.Int) []common.Hash

func (*TicketPool) GetPoolNumber

func (t *TicketPool) GetPoolNumber(stateDB vm.StateDB) uint32

func (*TicketPool) GetTicket

func (t *TicketPool) GetTicket(stateDB vm.StateDB, txHash common.Hash) *types.Ticket

Get ticket details based on TicketId

func (*TicketPool) GetTicketList

func (t *TicketPool) GetTicketList(stateDB vm.StateDB, ticketIds []common.Hash) []*types.Ticket

Get ticket list

func (*TicketPool) GetTicketPrice

func (t *TicketPool) GetTicketPrice(stateDB vm.StateDB) *big.Int

func (*TicketPool) GetTicketRemainByTxHash

func (t *TicketPool) GetTicketRemainByTxHash(stateDB vm.StateDB, txHash common.Hash) uint32

func (*TicketPool) GetTicketRemaining

func (t *TicketPool) GetTicketRemaining(stateDB vm.StateDB, ticketId common.Hash) uint32

Get the remaining number of ticket

func (*TicketPool) Notify

func (t *TicketPool) Notify(stateDB vm.StateDB, blockNumber *big.Int) error

func (*TicketPool) ReturnTicket

func (t *TicketPool) ReturnTicket(stateDB vm.StateDB, nodeId discover.NodeID, ticketId common.Hash, blockNumber *big.Int) error

func (*TicketPool) SelectionLuckyTicket

func (t *TicketPool) SelectionLuckyTicket(stateDB vm.StateDB, nodeId discover.NodeID, blockHash common.Hash) (common.Hash, error)

Simple version of the lucky ticket algorithm According to the previous block Hash, find the first ticket Id which is larger than the Hash. If not found, the last ticket Id is taken.

func (*TicketPool) VoteTicket

func (t *TicketPool) VoteTicket(stateDB vm.StateDB, owner common.Address, voteNumber uint32, deposit *big.Int, nodeId discover.NodeID, blockNumber *big.Int) (uint32, error)

type TicketPoolContext

type TicketPoolContext struct {
	Configs *params.PposConfig

	ChainInfo
	// contains filtered or unexported fields
}

func GetTicketPoolContextPtr

func GetTicketPoolContextPtr() *TicketPoolContext

func NewTicketPoolContext

func NewTicketPoolContext(configs *params.PposConfig) *TicketPoolContext

Initialize the global ticket pool context object

func (*TicketPoolContext) DropReturnTicket

func (c *TicketPoolContext) DropReturnTicket(stateDB vm.StateDB, blockNumber *big.Int, nodeIds ...discover.NodeID) error

func (*TicketPoolContext) GetBatchTicketRemaining

func (c *TicketPoolContext) GetBatchTicketRemaining(stateDB vm.StateDB, ticketIds []common.Hash) map[common.Hash]uint32

func (*TicketPoolContext) GetCandidateEpoch

func (c *TicketPoolContext) GetCandidateEpoch(state vm.StateDB, nodeId discover.NodeID) uint64

func (*TicketPoolContext) GetCandidateTicketCount

func (c *TicketPoolContext) GetCandidateTicketCount(state vm.StateDB, nodeId discover.NodeID) uint32

func (*TicketPoolContext) GetCandidateTicketIds

func (c *TicketPoolContext) GetCandidateTicketIds(state vm.StateDB, nodeId discover.NodeID) []common.Hash

func (*TicketPoolContext) GetCandidatesTicketCount

func (c *TicketPoolContext) GetCandidatesTicketCount(state vm.StateDB, nodeIds []discover.NodeID) map[discover.NodeID]uint32

func (*TicketPoolContext) GetCandidatesTicketIds

func (c *TicketPoolContext) GetCandidatesTicketIds(state vm.StateDB, nodeIds []discover.NodeID) map[discover.NodeID][]common.Hash

func (*TicketPoolContext) GetExpireTicketIds

func (c *TicketPoolContext) GetExpireTicketIds(state vm.StateDB, blockNumber *big.Int) []common.Hash

func (*TicketPoolContext) GetPoolNumber

func (c *TicketPoolContext) GetPoolNumber(state vm.StateDB) uint32

func (*TicketPoolContext) GetTicket

func (c *TicketPoolContext) GetTicket(state vm.StateDB, ticketId common.Hash) *types.Ticket

func (*TicketPoolContext) GetTicketList

func (c *TicketPoolContext) GetTicketList(state vm.StateDB, ticketIds []common.Hash) []*types.Ticket

func (*TicketPoolContext) GetTicketPrice

func (c *TicketPoolContext) GetTicketPrice(state vm.StateDB) *big.Int

func (*TicketPoolContext) Notify

func (c *TicketPoolContext) Notify(state vm.StateDB, blockNumber *big.Int) error

func (*TicketPoolContext) ReturnTicket

func (c *TicketPoolContext) ReturnTicket(stateDB vm.StateDB, nodeId discover.NodeID, ticketId common.Hash, blockNumber *big.Int) error

func (*TicketPoolContext) SelectionLuckyTicket

func (c *TicketPoolContext) SelectionLuckyTicket(stateDB vm.StateDB, nodeId discover.NodeID, blockHash common.Hash) (common.Hash, error)

func (*TicketPoolContext) SetChainConfig

func (c *TicketPoolContext) SetChainConfig(chainConfig *params.ChainConfig)

func (*TicketPoolContext) SetChainInfo

func (c *TicketPoolContext) SetChainInfo(ci ChainInfo)

func (*TicketPoolContext) StoreHash

func (c *TicketPoolContext) StoreHash(state vm.StateDB, blockNumber *big.Int, blockHash common.Hash) error

func (*TicketPoolContext) VoteTicket

func (c *TicketPoolContext) VoteTicket(state vm.StateDB, owner common.Address, voteNumber uint32, deposit *big.Int, nodeId discover.NodeID, blockNumber *big.Int) (uint32, error)

Jump to

Keyboard shortcuts

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