state

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: LGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package state provides a caching layer atop the Ethereum state trie.

Index

Constants

This section is empty.

Variables

View Source
var MaxTrieCacheGen = uint16(120)

Trie cache generation limit after which to evict trie nodes from memory.

Functions

func NewStateSync

func NewStateSync(root common.Hash, database trie.DatabaseReader) *trie.Sync

NewStateSync create a new state trie download scheduler.

func NewSync

func NewSync(root common.Hash, database trie.DatabaseReader) *trie.Sync

NewSync create a syncer for trie

func PubToAddress

func PubToAddress(pubkey []byte) common.Address

Types

type Account

type Account struct {
	Nonce    uint64
	Balance  *big.Int
	Root     common.Hash // merkle root of the storage trie
	CodeHash []byte

	DelegationBalance *big.Int
	DelegationsHash   []byte
}

Account is the Ethereum consensus representation of accounts. These objects are stored in the main account trie.

type AliasValidator

type AliasValidator Validator // alias to Validator, for the purpose of marshalling or encoding.

type Code

type Code []byte

func (Code) String

func (c Code) String() string

type Database

type Database interface {
	// OpenTrie opens the main account trie.
	OpenTrie(root common.Hash) (Trie, error)

	// OpenStorageTrie opens the storage trie of an account.
	OpenStorageTrie(addrHash, root common.Hash) (Trie, error)

	// CopyTrie returns an independent copy of the given trie.
	CopyTrie(Trie) Trie

	// ContractCode retrieves a particular contract's code.
	ContractCode(addrHash, codeHash common.Hash) ([]byte, error)

	// ContractCodeSize retrieves a particular contracts code's size.
	ContractCodeSize(addrHash, codeHash common.Hash) (int, error)

	// DelegationBytes retrieves a particular
	DelegationBytes(dlgHash common.Hash) ([]byte, error)

	// TrieDB retrieves the low level trie database used for data storage.
	TrieDB() *trie.Database
}

Database wraps access to tries and contract code.

func NewDatabase

func NewDatabase(db youdb.Database) Database

NewDatabase creates a backing store for state. The returned database is safe for concurrent use and retains cached trie nodes in memory. The pool is an optional intermediate trie-node memory pool between the low level storage layer and the high level trie abstraction.

type DelegationFrom

type DelegationFrom struct {
	Delegator common.Address `json:"delegator"`
	Stake     *big.Int       `json:"stake"`
	Token     *big.Int       `json:"token"`
}

func (*DelegationFrom) DeepCopy

func (d *DelegationFrom) DeepCopy() *DelegationFrom

func (*DelegationFrom) Empty

func (d *DelegationFrom) Empty() bool

type DelegationFroms

type DelegationFroms []*DelegationFrom

func (DelegationFroms) Exist

func (d DelegationFroms) Exist(a common.Address) bool

func (DelegationFroms) Len

func (d DelegationFroms) Len() int

func (DelegationFroms) Less

func (d DelegationFroms) Less(i, j int) bool

func (DelegationFroms) Search

func (d DelegationFroms) Search(a common.Address) int

func (DelegationFroms) Swap

func (d DelegationFroms) Swap(i, j int)

type DelegationTo

type DelegationTo struct {
	Validator common.Address `json:"validator"`
	Stake     *big.Int       `json:"stake"`
	Token     *big.Int       `json:"token"`
}

type DelegationTos

type DelegationTos []*DelegationTo

type Dump

type Dump struct {
	Root               string                   `json:"root"`
	ValRoot            string                   `json:"valRoot"`
	StakingRoot        string                   `json:"stakingRoot"`
	Accounts           map[string]DumpAccount   `json:"accounts"`
	Validators         map[string]DumpValidator `json:"validators"`
	ValidatorsStat     *DumpValidatorsStat      `json:"validatorsStat"`
	ValidatorsWithdraw []*DumpWithdrawRecord    `json:"validatorsWithdraw"`
}

type DumpAccount

type DumpAccount struct {
	Balance           string            `json:"balance"`
	Nonce             uint64            `json:"nonce"`
	Root              string            `json:"root"`
	Storage           map[string]string `json:"storage"`
	DelegationBalance string            `json:"delegationBalance"`
	Delegations       []string          `json:"delegations,omitempty"`
}

type DumpAllLogs

type DumpAllLogs struct {
	Logs map[string][]DumpLog `json:"txhash"`
}

type DumpDelegationFrom

type DumpDelegationFrom struct {
	Delegator common.Address `json:"delegator"`
	Stake     string         `json:"stake"`
	Token     string         `json:"token"`
}

type DumpLog

type DumpLog struct {
	Address     common.Address `json:"address"`
	Topics      []common.Hash  `json:"topics"`
	Data        hexutil.Bytes  `json:"data"`
	BlockNumber hexutil.Uint64 `json:"blockNumber"`
	TxHash      common.Hash    `json:"transactionHash"`
	TxIndex     hexutil.Uint   `json:"transactionIndex"`
	BlockHash   common.Hash    `json:"blockHash"`
	Index       hexutil.Uint   `json:"logIndex"`
	Removed     bool           `json:"removed"`
}

type DumpValidator

type DumpValidator struct {
	MainAddress     common.Address `json:"mainAddress"`
	Name            string         `json:"name"`
	OperatorAddress common.Address `json:"operatorAddress"`
	Coinbase        common.Address `json:"coinbase"`
	MainPubKey      hexutil.Bytes  `json:"mainPubKey"`
	BlsPubKey       hexutil.Bytes  `json:"blsPubKey"`
	Token           string         `json:"token"`
	Stake           string         `json:"stake"`
	Status          uint8          `json:"status"`
	Role            uint8          `json:"role"`
	Expelled        bool           `json:"expelled"`
	ExpelExpired    uint64         `json:"expelExpired"`
	LastInactive    uint64         `json:"lastInactive"`
	SelfToken       string         `json:"selfToken"` // self staking tokens, LU
	SelfStake       string         `json:"selfStake"`

	RewardsDistributable string `json:"rewardsDistributable"`
	RewardsTotal         string `json:"rewardsTotal"`
	RewardsLastSettled   uint64 `json:"rewardsLastSettled"` // 最后一次分配的区块的高度

	AcceptDelegation uint16                `json:"acceptDelegation"`
	CommissionRate   uint16                `json:"commissionRate"` // 抽佣率,万分数
	RiskObligation   uint16                `json:"riskObligation"` // 风险承担率,万分数
	Delegations      []*DumpDelegationFrom `json:"delegations"`    // 名下委托集合,必须是排好序的

	// for later extend
	Ext Extension `json:"ext"`
}

type DumpValidatorsStat

type DumpValidatorsStat struct {
	Kinds map[params.ValidatorKind]DumpValidatorsStatItem `json:"kinds"`
	Roles map[params.ValidatorRole]DumpValidatorsStatItem `json:"roles"`
}

type DumpValidatorsStatItem

type DumpValidatorsStatItem struct {
	OnlineStake          string `json:"onlineStake"`
	OnlineToken          string `json:"onlineToken"`
	OnlineCount          uint64 `json:"onlineCount"`
	OfflineStake         string `json:"offlineStake"`
	OfflineToken         string `json:"offlineToken"`
	OfflineCount         uint64 `json:"offlineCount"`
	RewardsResidue       string `json:"rewardsResidue"`
	RewardsDistributable string `json:"rewardsDistributable"`
}

type DumpWithdrawRecord

type DumpWithdrawRecord struct {
	Operator         common.Address `json:"operator"`
	Delegator        common.Address `json:"delegator"`
	Validator        common.Address `json:"validator"`
	Recipient        common.Address `json:"recipient"`
	Nonce            uint64         `json:"nonce"`
	CreationHeight   uint64         `json:"creationHeight"`   // height which the withdrawing took place
	CompletionHeight uint64         `json:"completionHeight"` // height which the withdrawing will complete
	InitialBalance   string         `json:"initialBalance"`   // tokens initially scheduled to receive at completion
	FinalBalance     string         `json:"finalBalance"`     // tokens to receive at completion 最后实际收到的token数量
	Finished         uint8          `json:"finished"`
	TxHash           common.Hash    `json:"txHash"`
}

type ExtV1 added in v1.0.0

type ExtV1 struct {
	LastActive uint64 // last active block. Used for inactivity check.
}

type Extension

type Extension struct {
	Version uint8         `json:"version"`
	Data    hexutil.Bytes `json:"data"`
	// contains filtered or unexported fields
}

type NodeIterator

type NodeIterator struct {
	Hash   common.Hash // Hash of the current entry being iterated (nil if not standalone)
	Parent common.Hash // Hash of the first full ancestor node (nil if current is the root)

	Error error // Failure set in case of an internal error in the iterator
	// contains filtered or unexported fields
}

NodeIterator is an iterator to traverse the entire state trie post-order, including all of the contract code and contract state tries.

func NewNodeIterator

func NewNodeIterator(state *StateDB) *NodeIterator

NewNodeIterator creates an post-order state node iterator.

func (*NodeIterator) Next

func (it *NodeIterator) Next() bool

Next moves the iterator to the next node, returning whether there are any further nodes. In case of an internal error this method returns false and sets the Error field to the encountered failure.

type Record

type Record struct {
	FinalValue *big.Int
	TxHashes   []common.Hash
}

type StateDB

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

StateDBs within the ethereum protocol are used to store anything within the merkle trie. StateDBs take care of caching and storing nested states. It's the general query interface to retrieve: * Contracts * Accounts the valTrie is used to store validators and global stat. the global stat data will be stored with a special key.

func New

func New(root, valRoot, stakingRoot common.Hash, db Database) (*StateDB, error)

Create a new state from the given tries.

func (*StateDB) AddBalance

func (st *StateDB) AddBalance(addr common.Address, amount *big.Int)

AddBalance adds amount to the account associated with addr.

func (*StateDB) AddLog

func (st *StateDB) AddLog(log *types.Log)

func (*StateDB) AddPendingRelationship

func (st *StateDB) AddPendingRelationship(d, v common.Address)

AddPendingRelationship adds a relationship to current staking trie Note: It's the caller's responsibility to make sure that the relationship is unique globally.

func (*StateDB) AddPreimage

func (st *StateDB) AddPreimage(hash common.Hash, preimage []byte)

AddPreimage records a SHA3 preimage seen by the VM.

func (*StateDB) AddRefund

func (st *StateDB) AddRefund(gas uint64)

func (*StateDB) AddStakingRecord

func (st *StateDB) AddStakingRecord(d, v common.Address, txHash common.Hash, newFinalValue *big.Int)

func (*StateDB) AddWithdrawRecord

func (st *StateDB) AddWithdrawRecord(record *WithdrawRecord) bool

func (*StateDB) BlockHash

func (st *StateDB) BlockHash() common.Hash

BlockHash returns the current block hash set by Prepare.

func (*StateDB) Commit

func (st *StateDB) Commit(deleteEmptyObjects bool) (root, valRoot, stakingRoot common.Hash, err error)

Commit writes the state to the underlying in-memory trie database.

func (*StateDB) Copy

func (st *StateDB) Copy() *StateDB

Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.

func (*StateDB) CreateAccount

func (st *StateDB) CreateAccount(addr common.Address)

CreateAccount explicitly creates a state object. If a state object with the address already exists the balance is carried over to the new account.

CreateAccount is called during the EVM CREATE operation. The situation might arise that a contract does the following:

  1. sends funds to sha(account ++ (nonce + 1))
  2. tx_create(sha(account ++ nonce)) (note that this gets the address of 1)

Carrying over the balance ensures that Ether doesn't disappear.

func (*StateDB) CreateValidator

func (st *StateDB) CreateValidator(name string, operator, coinbase common.Address, role params.ValidatorRole, mainPubKey, blsPubKey hexutil.Bytes, token, stake *big.Int, acceptDelegation, commissionRate, riskObligation uint16, status uint8) (newVal *Validator)

func (*StateDB) Database

func (st *StateDB) Database() Database

Database retrieves the low level database supporting the lower level trie ops.

func (*StateDB) DelegatorPendingCount

func (st *StateDB) DelegatorPendingCount(d common.Address) int

func (*StateDB) Dump

func (st *StateDB) Dump() []byte

func (*StateDB) Empty

func (st *StateDB) Empty(addr common.Address) bool

Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0)

func (*StateDB) Error

func (st *StateDB) Error() error

func (*StateDB) Exist

func (st *StateDB) Exist(addr common.Address) bool

Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.

func (*StateDB) Finalise

func (st *StateDB) Finalise(deleteEmptyObjects bool)

Finalise finalises the state by removing the self destructed objects and clears the journal as well as the refunds.

func (*StateDB) ForEachStakingRecord

func (st *StateDB) ForEachStakingRecord(cb func(d, v common.Address, record *Record) error) error

func (*StateDB) ForEachStorage

func (st *StateDB) ForEachStorage(addr common.Address, cb func(key, value common.Hash) bool)

func (*StateDB) GetBalance

func (st *StateDB) GetBalance(addr common.Address) *big.Int

Retrieve the balance from the given address or 0 if object not found

func (*StateDB) GetCode

func (st *StateDB) GetCode(addr common.Address) []byte

func (*StateDB) GetCodeHash

func (st *StateDB) GetCodeHash(addr common.Address) common.Hash

func (*StateDB) GetCodeSize

func (st *StateDB) GetCodeSize(addr common.Address) int

func (*StateDB) GetCommittedState

func (st *StateDB) GetCommittedState(addr common.Address, hash common.Hash) common.Hash

GetCommittedState retrieves a value from the given account's committed storage trie.

func (*StateDB) GetCountOfDelegateTo

func (st *StateDB) GetCountOfDelegateTo(d common.Address) int

GetCountOfDelegateTo gets a delegator address, returns how many validators it has delegation to.

func (*StateDB) GetDelegationsFrom

func (st *StateDB) GetDelegationsFrom(d common.Address) ([]*DelegationTo, error)

func (*StateDB) GetLogs

func (st *StateDB) GetLogs(hash common.Hash) []*types.Log

func (*StateDB) GetNonce

func (st *StateDB) GetNonce(addr common.Address) uint64

func (*StateDB) GetOrNewStateObject

func (st *StateDB) GetOrNewStateObject(addr common.Address) *stateObject

Retrieve a state object or create a new state object if nil.

func (*StateDB) GetProof

func (st *StateDB) GetProof(a common.Address) ([][]byte, error)

GetProof returns the MerkleProof for a given Account

func (*StateDB) GetRefund

func (st *StateDB) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*StateDB) GetStakingRecord added in v0.9.9

func (st *StateDB) GetStakingRecord(d, v common.Address) *Record

func (*StateDB) GetStakingRecordValue

func (st *StateDB) GetStakingRecordValue(d, v common.Address) *big.Int

func (*StateDB) GetState

func (st *StateDB) GetState(addr common.Address, bhash common.Hash) common.Hash

func (*StateDB) GetStorageProof

func (st *StateDB) GetStorageProof(a common.Address, key common.Hash) ([][]byte, error)

GetProof returns the StorageProof for given key

func (*StateDB) GetValidatorByMainAddr

func (st *StateDB) GetValidatorByMainAddr(mainAddress common.Address) *Validator

func (*StateDB) GetValidators

func (st *StateDB) GetValidators() *Validators

GetValidators 获取全部 validator 集合 There's an in-memory cache for the results, so the results must be used as read-only.

func (*StateDB) GetValidatorsForUpdate added in v1.0.0

func (st *StateDB) GetValidatorsForUpdate() []*Validator

func (*StateDB) GetValidatorsStat

func (st *StateDB) GetValidatorsStat() (*ValidatorsStat, error)

func (*StateDB) GetWithdrawQueue

func (st *StateDB) GetWithdrawQueue() *WithdrawQueue

func (*StateDB) HasSuicided

func (st *StateDB) HasSuicided(addr common.Address) bool

func (*StateDB) IntermediateRoot

func (st *StateDB) IntermediateRoot(deleteEmptyObjects bool) (common.Hash, common.Hash, common.Hash)

IntermediateRoot computes the current root hash of the state trie. It is called in between transactions to get the root hash that goes into transaction receipts.

func (*StateDB) LogDump

func (st *StateDB) LogDump() (DumpAllLogs, error)

func (*StateDB) Logs

func (st *StateDB) Logs() []*types.Log

func (*StateDB) PendingRelationshipExist

func (st *StateDB) PendingRelationshipExist(d, v common.Address) bool

func (*StateDB) PendingValidatorExist

func (st *StateDB) PendingValidatorExist(v common.Address) bool

func (*StateDB) Preimages

func (st *StateDB) Preimages() map[common.Hash][]byte

Preimages returns a list of SHA3 preimages that have been submitted.

func (*StateDB) Prepare

func (st *StateDB) Prepare(thash, bhash common.Hash, ti int)

Prepare sets the current transaction hash and index and block hash which is used when the EVM emits new state logs.

func (*StateDB) RawDump

func (st *StateDB) RawDump() Dump

func (*StateDB) RemoveValidator

func (st *StateDB) RemoveValidator(mainAddress common.Address) bool

func (*StateDB) RemoveWithdrawRecords

func (st *StateDB) RemoveWithdrawRecords(index []int) bool

func (*StateDB) Reset

func (st *StateDB) Reset(root, valRoot common.Hash) error

Reset clears out all ephemeral state objects from the state db, but keeps the underlying state trie to avoid reloading data for the next operations.

func (*StateDB) ResetStakingTrie

func (st *StateDB) ResetStakingTrie()

ResetStakingTrie will force the staking trie to start a new trie

func (*StateDB) RevertToSnapshot

func (st *StateDB) RevertToSnapshot(revid int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*StateDB) SetBalance

func (st *StateDB) SetBalance(addr common.Address, amount *big.Int)

func (*StateDB) SetCode

func (st *StateDB) SetCode(addr common.Address, code []byte)

func (*StateDB) SetNonce

func (st *StateDB) SetNonce(addr common.Address, nonce uint64)

func (*StateDB) SetState

func (st *StateDB) SetState(addr common.Address, key, value common.Hash)

func (*StateDB) Snapshot

func (st *StateDB) Snapshot() int

Snapshot returns an identifier for the current revision of the state.

func (*StateDB) StorageTrie

func (st *StateDB) StorageTrie(addr common.Address) Trie

StorageTrie returns the storage trie of an account. The return value is a copy and is nil for non-existent accounts.

func (*StateDB) SubBalance

func (st *StateDB) SubBalance(addr common.Address, amount *big.Int)

SubBalance subtracts amount from the account associated with addr.

func (*StateDB) SubRefund

func (st *StateDB) SubRefund(gas uint64)

SubRefund removes gas from the refund counter. This method will panic if the refund counter goes below zero

func (*StateDB) Suicide

func (st *StateDB) Suicide(addr common.Address) bool

Suicide marks the given account as suicided. This clears the account balance.

The account's state object is still available until the state is committed, getStateObject will return a non-nil account after Suicide.

func (*StateDB) TxIndex

func (st *StateDB) TxIndex() int

TxIndex returns the current transaction index set by Prepare.

func (*StateDB) UpdateDelegation

func (st *StateDB) UpdateDelegation(d common.Address, val *Validator, tokenChanged *big.Int) (*Validator, *DelegationFrom, *big.Int, params.CurdFlag)

UpdateDelegation will update both delegator and validator without any business check. returns newValidator,newDelegationFrom, stakeChanged, delegatorUpdateStatus

func (*StateDB) UpdateDelegator

func (st *StateDB) UpdateDelegator(addr, toValidator common.Address, delta *big.Int, delete bool)

UpdateDelegator updates delegations index for an account, `delta` is the delegation amount current added (when delta is positive) or subtracted (when delta is negative).

func (*StateDB) UpdateValidator

func (st *StateDB) UpdateValidator(newVal, oldVal *Validator) bool

func (*StateDB) ValidatorPendingCount

func (st *StateDB) ValidatorPendingCount(v common.Address) int

func (*StateDB) ValidatorsModified

func (st *StateDB) ValidatorsModified() bool

type Storage

type Storage map[common.Hash]common.Hash

func (Storage) Copy

func (s Storage) Copy() Storage

func (Storage) String

func (s Storage) String() (str string)

type Trie

type Trie interface {
	TryGet(key []byte) ([]byte, error)
	TryUpdate(key, value []byte) error
	TryDelete(key []byte) error
	Commit(onleaf trie.LeafCallback) (common.Hash, error)
	Hash() common.Hash
	NodeIterator(startKey []byte) trie.NodeIterator
	GetKey([]byte) []byte // TODO(fjl): remove this when SecureTrie is removed
	Prove(key []byte, fromLevel uint, proofDb youdb.Putter) error
}

Trie is a Ethereum Merkle Trie.

type ValKindStat

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

func NewValKindStat

func NewValKindStat() *ValKindStat

func (*ValKindStat) AddRewards

func (v *ValKindStat) AddRewards(amount *big.Int) *ValKindStat

func (*ValKindStat) AddVal

func (v *ValKindStat) AddVal(val *Validator)

func (*ValKindStat) DecodeRLP

func (v *ValKindStat) DecodeRLP(s *rlp.Stream) error

func (ValKindStat) DeepCopy

func (v ValKindStat) DeepCopy() *ValKindStat

func (ValKindStat) Dump

func (ValKindStat) EncodeRLP

func (v ValKindStat) EncodeRLP(w io.Writer) error

func (ValKindStat) GetCount

func (v ValKindStat) GetCount() uint64

func (ValKindStat) GetOfflineCount

func (v ValKindStat) GetOfflineCount() uint64

func (ValKindStat) GetOfflineStake

func (v ValKindStat) GetOfflineStake() *big.Int

func (ValKindStat) GetOfflineToken

func (v ValKindStat) GetOfflineToken() *big.Int

func (ValKindStat) GetOnlineStake

func (v ValKindStat) GetOnlineStake() *big.Int

func (ValKindStat) GetOnlineToken

func (v ValKindStat) GetOnlineToken() *big.Int

func (ValKindStat) GetRewardsDistributable

func (v ValKindStat) GetRewardsDistributable() *big.Int

func (ValKindStat) GetRewardsResidue

func (v ValKindStat) GetRewardsResidue() *big.Int

func (*ValKindStat) ResetRewards

func (v *ValKindStat) ResetRewards(total *big.Int) *ValKindStat

func (*ValKindStat) SetRewardsResidue

func (v *ValKindStat) SetRewardsResidue(amount *big.Int) *ValKindStat

func (*ValKindStat) SubVal

func (v *ValKindStat) SubVal(val *Validator)

type Validator

type Validator struct {
	Name            string               `json:"name"`            // alias name for validator
	OperatorAddress common.Address       `json:"operatorAddress"` // manager address
	Coinbase        common.Address       `json:"coinbase"`        // send rewards
	Role            params.ValidatorRole `json:"role"`            // role of validator
	Status          uint8                `json:"status"`
	Expelled        bool                 `json:"expelled" rlp:"-"` // rlp did not support bool type
	ExpelExpired    uint64               `json:"expelExpired"`
	LastInactive    uint64               `json:"lastInactive"`

	MainPubKey hexutil.Bytes `json:"mainPubKey"` // consensus pubkey
	BlsPubKey  hexutil.Bytes `json:"blsPubKey"`  // bls pubkey

	Token     *big.Int `json:"token"`     // Lu
	Stake     *big.Int `json:"stake"`     // token / StakeUnit
	SelfToken *big.Int `json:"selfToken"` // self staking tokens, LU
	SelfStake *big.Int `json:"selfStake"`

	RewardsDistributable *big.Int `json:"rewardsDistributable"`
	RewardsTotal         *big.Int `json:"rewardsTotal"`
	RewardsLastSettled   uint64   `json:"rewardsLastSettled"`

	AcceptDelegation uint16          `json:"acceptDelegation"`
	CommissionRate   uint16          `json:"commissionRate"` // 抽佣率,万分数
	RiskObligation   uint16          `json:"riskObligation"` // 风险承担率,万分数
	Delegations      DelegationFroms `json:"delegations"`    // 名下委托集合,必须是排好序的

	// for later extend
	Ext Extension `json:"ext"`
	// contains filtered or unexported fields
}

func NewValidator

func NewValidator(name string, operatorAddress, coinbase common.Address, role params.ValidatorRole, mainPubKey, blsPubKey hexutil.Bytes, token, stake *big.Int, acceptDelegation, commissionRate, riskObligation uint16, status uint8) *Validator

NewValidator creates a validator object.

func (*Validator) AddTotalRewards

func (v *Validator) AddTotalRewards(reward *big.Int)

func (*Validator) DecodeRLP

func (v *Validator) DecodeRLP(s *rlp.Stream) error

func (*Validator) DeepCopy

func (v *Validator) DeepCopy() *Validator

func (Validator) Dump

func (v Validator) Dump() DumpValidator

func (Validator) EncodeRLP

func (v Validator) EncodeRLP(w io.Writer) error

func (Validator) Equal

func (v Validator) Equal(val *Validator) bool

func (*Validator) GetDelegationFrom

func (v *Validator) GetDelegationFrom(d common.Address) *DelegationFrom

func (*Validator) IsInvalid

func (v *Validator) IsInvalid() bool

func (*Validator) IsOffline

func (v *Validator) IsOffline() bool

func (*Validator) IsOnline

func (v *Validator) IsOnline() bool

func (*Validator) IsOperator

func (v *Validator) IsOperator(addr common.Address) bool

func (Validator) Kind

func (v Validator) Kind() params.ValidatorKind

func (*Validator) LastActive added in v1.0.0

func (v *Validator) LastActive() uint64

func (*Validator) Less

func (v *Validator) Less(val *Validator) bool

func (*Validator) MainAddress

func (v *Validator) MainAddress() common.Address

func (Validator) MarshalJSON

func (v Validator) MarshalJSON() ([]byte, error)

func (*Validator) PartialCopy

func (v *Validator) PartialCopy() *Validator

PartialCopy is a deep copy except that PartialCopy do not copy the Delegations slice

func (Validator) StakeEqual

func (v Validator) StakeEqual(val *Validator) bool

func (*Validator) UpdateDelegationFrom

func (v *Validator) UpdateDelegationFrom(d *DelegationFrom) (flag params.CurdFlag)

func (*Validator) UpdateLastActive added in v1.0.0

func (v *Validator) UpdateLastActive(num uint64)

type ValidatorIndex

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

func NewValidatorIndex

func NewValidatorIndex() *ValidatorIndex

func (*ValidatorIndex) Add

func (index *ValidatorIndex) Add(mainAddress common.Address)

func (*ValidatorIndex) DecodeRLP

func (index *ValidatorIndex) DecodeRLP(s *rlp.Stream) error

func (*ValidatorIndex) DeepCopy

func (index *ValidatorIndex) DeepCopy() *ValidatorIndex

func (*ValidatorIndex) Delete

func (index *ValidatorIndex) Delete(mainAddress common.Address)

func (*ValidatorIndex) Empty

func (index *ValidatorIndex) Empty() bool

func (*ValidatorIndex) EncodeRLP

func (index *ValidatorIndex) EncodeRLP(w io.Writer) error

func (*ValidatorIndex) List

func (index *ValidatorIndex) List() []common.Address

type ValidatorReader

type ValidatorReader interface {
	GetValidatorsStat() (*ValidatorsStat, error)
	GetValidatorByMainAddr(mainAddress common.Address) *Validator
	GetValidators() *Validators
}

func NewVldReader

func NewVldReader(valRoot common.Hash, db Database, checkIntegrity bool) (ValidatorReader, error)

NewVldReader create a new state that only with the given validator trie.

type Validators

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

func NewValidators

func NewValidators(list []*Validator) *Validators

func (*Validators) DecodeRLP

func (s *Validators) DecodeRLP(stream *rlp.Stream) error

func (Validators) EncodeRLP

func (s Validators) EncodeRLP(w io.Writer) error

func (Validators) GetByIndex

func (s Validators) GetByIndex(index int) (*Validator, bool)

func (Validators) GetIndex

func (s Validators) GetIndex(mainAddress common.Address) (int, bool)

func (Validators) GetRlp

func (s Validators) GetRlp(i int) []byte

func (Validators) Len

func (s Validators) Len() int

func (*Validators) Less

func (s *Validators) Less(i, j int) bool

func (Validators) List

func (s Validators) List() []*Validator

func (*Validators) Remove

func (s *Validators) Remove(mainAddress common.Address) bool

func (*Validators) Swap

func (s *Validators) Swap(i, j int)

type ValidatorsStat

type ValidatorsStat struct {
	Kinds map[params.ValidatorKind]*ValKindStat `json:"kinds"`
	Roles map[params.ValidatorRole]*ValKindStat `json:"roles"`
}

func NewValidatorsStat

func NewValidatorsStat() *ValidatorsStat

func (*ValidatorsStat) DecodeRLP

func (m *ValidatorsStat) DecodeRLP(s *rlp.Stream) error

func (*ValidatorsStat) DeepCopy

func (m *ValidatorsStat) DeepCopy() *ValidatorsStat

func (ValidatorsStat) Dump

func (*ValidatorsStat) EncodeRLP

func (m *ValidatorsStat) EncodeRLP(w io.Writer) error

func (*ValidatorsStat) GetByKind

func (m *ValidatorsStat) GetByKind(kind params.ValidatorKind) *ValKindStat

func (*ValidatorsStat) GetByRole

func (m *ValidatorsStat) GetByRole(role params.ValidatorRole) *ValKindStat

func (*ValidatorsStat) GetCountOfKind

func (m *ValidatorsStat) GetCountOfKind(kind params.ValidatorKind) uint64

func (*ValidatorsStat) GetRewardResidue

func (m *ValidatorsStat) GetRewardResidue() *big.Int

func (*ValidatorsStat) GetStakeByKind

func (m *ValidatorsStat) GetStakeByKind(kind params.ValidatorKind) *big.Int

func (*ValidatorsStat) String

func (m *ValidatorsStat) String() string

type WithdrawQueue

type WithdrawQueue struct {
	Records []*WithdrawRecord
}

func NewWithdrawQueue

func NewWithdrawQueue() *WithdrawQueue

func (*WithdrawQueue) Add

func (q *WithdrawQueue) Add(record *WithdrawRecord)

func (WithdrawQueue) DeepCopy

func (q WithdrawQueue) DeepCopy() *WithdrawQueue

func (*WithdrawQueue) Delete

func (q *WithdrawQueue) Delete(record *WithdrawRecord)

func (WithdrawQueue) Len

func (q WithdrawQueue) Len() int

func (WithdrawQueue) Less

func (q WithdrawQueue) Less(i, j int) bool

func (*WithdrawQueue) RemoveRecords

func (q *WithdrawQueue) RemoveRecords(idx []int) []*WithdrawRecord

RemoveEntry - remove entry at index i to the withdrawing delegation

func (*WithdrawQueue) Swap

func (q *WithdrawQueue) Swap(i, j int)

type WithdrawRecord

type WithdrawRecord struct {
	Operator         common.Address `json:"operator"`
	Delegator        common.Address `json:"delegator"`
	Validator        common.Address `json:"validator"`
	Recipient        common.Address `json:"recipient"`
	Nonce            uint64         `json:"nonce"`
	CreationHeight   uint64         `json:"creationHeight"`   // height which the withdraw took place
	CompletionHeight uint64         `json:"completionHeight"` // height which the withdraw will complete
	InitialBalance   *big.Int       `json:"initialBalance"`   // tokens initially scheduled to receive at completion
	FinalBalance     *big.Int       `json:"finalBalance"`     // tokens to receive at completion 最后实际收到的token数量
	Finished         uint8          `json:"finished"`
	TxHash           common.Hash    `json:"txHash"`
}

func NewWithdrawRecord

func NewWithdrawRecord() *WithdrawRecord

func (*WithdrawRecord) DeepCopy

func (u *WithdrawRecord) DeepCopy() *WithdrawRecord

func (*WithdrawRecord) Dump

func (WithdrawRecord) IsMature

func (u WithdrawRecord) IsMature(height uint64) bool

func (*WithdrawRecord) String

func (u *WithdrawRecord) String() string

Jump to

Keyboard shortcuts

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