types

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const PosTableMaxSize = 2000
View Source
const ThresholdUnit = 1000

it means the lowest balance must equal or larger than the 1/1000 of totalBalance

Variables

This section is empty.

Functions

func DeepCopy

func DeepCopy(dst, src interface{}) error

Types

type AccountMap

type AccountMap struct {
	Signer           common.Address `json:"signer"`
	SignerBalance    *big.Int       `json:"signerBalance"`
	BeneficiaryBonus *big.Int       `json:"beneficiaryBonus"`
	Beneficiary      common.Address `json:"beneficiary"`
	BlsKeyString     string         `json:"blsKeyString"`
}

AccountMap is an initial accountMap between tendermitn address and go-ethereum-address.

type AccountMapList

type AccountMapList struct {
	MapList map[string]*AccountMap `json:"accountmaplist"`

	FilePath string `json:"filePath"`
	// contains filtered or unexported fields
}

AccountMapList defines the initial list of AccountMap.

func AccountMapFromFile

func AccountMapFromFile(AccountMapFile string) (*AccountMapList, error)

AccountMapFromJSON reads JSON data from a file and unmarshalls it into a AccountMapList.

func AccountMapFromJSON

func AccountMapFromJSON(jsonBlob []byte) (*AccountMapList, error)

AccountMapFromJSON unmarshalls JSON data into a AccountMapList.

func (*AccountMapList) GenAccountMapList

func (am *AccountMapList) GenAccountMapList(filePath string) *AccountMapList

GenFilePV generates a new validator with randomly generated private key and sets the filePath, but does not call Save().

func (*AccountMapList) Save

func (am *AccountMapList) Save()

Save persists the FilePV to disk.

type CurrentRoundValData

type CurrentRoundValData struct {
	AccountMapList *AccountMapList `json:"accountMapList"`

	//This map was used when some validator was removed when initial at initChain(i.e dont have enough money)
	// and didnt existed in the accountMapList
	// we should remember it for balance bonus and then clear it
	AccMapInitial *AccountMapList `json:"accMapInitial"`

	// will be changed by addValidatorTx and removeValidatorTx.
	PosTable *PosTable `json:"posTable"`

	// current candidate Validators , will changed every 200 height,will be changed by addValidatorTx and removeValidatorTx
	CurrCandidateValidators []*abciTypes.Validator `json:"currCandidateValidators"`

	// Initial validators , only use for once
	InitialValidators []*abciTypes.Validator `json:"initialValidators"`

	// validators of currentBlock, will use to set votePower to 0 ,then remove from tendermint validatorSet
	// will be select by postable.
	// CurrentValidators is the true validators except commmittee validator when height != 1
	// if height =1 ,CurrentValidator = nil
	CurrentValidators []*abciTypes.Validator `json:"currentValidators"`

	// current validator weight represent the weight of random select.
	// will used to accumulateReward for next height
	CurrentValidatorWeight []int64 `json:"currentValidatorWeight"`

	TotalBalance *big.Int `json:"totalBalance"`

	ProposerAddress string `json:"proposerAddress"`
}

type EthAccounts

type EthAccounts struct {
	EthAccounts     []string   `json:"ethAccounts"`
	EthBalances     []*big.Int `json:"ethBalances"`
	EthBeneficiarys []string   `json:"ethBeneficiarys"`
}

func EthAccountsFromJSON

func EthAccountsFromJSON(jsonBlob []byte) (*EthAccounts, error)

EthAccountsFromJSON unmarshalls JSON data into a eth accounts.

func GetInitialEthAccountFromFile

func GetInitialEthAccountFromFile(EthAccountsPath string) (*EthAccounts, error)

GetInitialEthAccountFromFile reads JSON data from a file and unmarshalls it into a initial eth accounts.

type MinerRewardStrategy

type MinerRewardStrategy interface {
	Receiver() common.Address
}

MinerRewardStrategy is a mining strategy

type NextRoundValData

type NextRoundValData struct {
	//we should deepcopy evert 200 height
	//first deepcopy:copy at height 1 from CurrentRoundValData to NextRoundValData
	//height/200 ==0:c from NextRoundValData to CurrentRoundValData   `json:"-"`
	NextRoundPosTable *PosTable `json:"nextRoundPosTable"`

	NextRoundCandidateValidators []*abciTypes.Validator `json:"nextRoundCandidateValidators"`

	NextAccountMapList *AccountMapList `json:"nextAccountMapList"`
}

type PosItem

type PosItem struct {
	Signer      common.Address   `json:"signer"`
	Balance     *big.Int         `json:"balance"`
	PubKey      abciTypes.PubKey `json:"pubKey"`
	Indexes     map[int]bool     `json:"indexes"`
	Beneficiary common.Address   `json:"beneficiary"`
}

type PosTable

type PosTable struct {
	PosItemMap           map[common.Address]*PosItem `json:"posItemMap"`   //This isnt called by foreign struct except rpc
	PosArray             []common.Address            `json:"posArray"`     // All posItem,it will contained the same item
	PosArraySize         int                         `json:"posArraySize"` // real size of posArray
	Threshold            *big.Int                    `json:"threshold"`    // threshold value of PosTable
	ChangedFlagThisBlock bool                        `json:"changedFlagThisBlock"`
	PosNodeSortList      *ValSortlist                `json:"-"`
	// contains filtered or unexported fields
}

func NewPosTable

func NewPosTable(threshold *big.Int) *PosTable

func (*PosTable) RemovePosItem

func (posTable *PosTable) RemovePosItem(account common.Address) (bool, error)

func (*PosTable) SelectItemByHeightValue

func (posTable *PosTable) SelectItemByHeightValue(random int) PosItem

func (*PosTable) SelectItemBySeedValue

func (posTable *PosTable) SelectItemBySeedValue(vrf []byte, len int) PosItem

func (*PosTable) SetThreShold

func (posTable *PosTable) SetThreShold(threShold *big.Int)

func (*PosTable) UpsertPosItem

func (posTable *PosTable) UpsertPosItem(signer common.Address, balance *big.Int, beneficiary common.Address,
	pubkey abciTypes.PubKey) (bool, error)

type Strategy

type Strategy struct {
	MinerRewardStrategy
	ValidatorsStrategy

	//need to be persisted
	FirstInitial bool

	//needn't to be persisted
	BlsSelectStrategy bool

	// reused,need persistence
	CurrRoundValData CurrentRoundValData

	//reused,need persistence
	NextRoundValData NextRoundValData
	// contains filtered or unexported fields
}

Strategy encompasses all available strategies

func NewStrategy

func NewStrategy(totalBalance *big.Int) *Strategy

func (*Strategy) CollectTx

func (strategy *Strategy) CollectTx(tx *ethTypes.Transaction)

CollectTx collects the rewards for a transaction

func (*Strategy) GetUpdatedValidators

func (strategy *Strategy) GetUpdatedValidators() []*abciTypes.Validator

GetUpdatedValidators returns the current validators

func (*Strategy) Receiver

func (s *Strategy) Receiver() common.Address

Receiver returns which address should receive the mining reward

func (*Strategy) SetAccountMapList

func (strategy *Strategy) SetAccountMapList(accountMapList *AccountMapList)

GetUpdatedValidators returns the current validators

func (*Strategy) SetValidators

func (strategy *Strategy) SetValidators(validators []*abciTypes.Validator)

SetValidators updates the current validators

type ValListItem

type ValListItem struct {
	Signer    common.Address `json:"signer"`
	Balance   *big.Int       `json:"balance"`
	TmAddress string         `json:"tmAddress"`
}

type ValSortlist

type ValSortlist struct {
	ValList *list.List `json:"valList"`
	Len     int        `json:"len"`
}

func NewValSortlist

func NewValSortlist() *ValSortlist

func (*ValSortlist) GetTopValTmAddress

func (vallist *ValSortlist) GetTopValTmAddress() map[string]bool

func (*ValSortlist) RemoveVal

func (vallist *ValSortlist) RemoveVal(valListItem *ValListItem)

func (*ValSortlist) UpsertVal

func (valSortlist *ValSortlist) UpsertVal(valListItem *ValListItem, existFlag bool)

type ValidatorsStrategy

type ValidatorsStrategy interface {
	SetValidators(validators []*abciTypes.Validator)
	CollectTx(tx *ethTypes.Transaction)
	GetUpdatedValidators() []*abciTypes.Validator
}

ValidatorsStrategy is a validator strategy

Jump to

Keyboard shortcuts

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