state

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2018 License: MIT Imports: 19 Imported by: 22

Documentation

Overview

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

Index

Constants

View Source
const (
	CandidateStatusOffline = 0x01
	CandidateStatusOnline  = 0x02
)

Variables

View Source
var (
	BalanceChangeChan = make(chan BalanceChangeStruct, 10)
)
View Source
var MaxTrieCacheGen = uint16(120)

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

View Source
var (
	ValidatorMaxAbsentTimes = uint(12)
)

Functions

func EmitBalanceChange

func EmitBalanceChange(address types.Address, coin types.CoinSymbol, balance *big.Int)

Types

type Account

type Account struct {
	Nonce   uint64
	Balance Balances
	Root    types.Hash // merkle root of the storage trie
}

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

type Balance

type Balance struct {
	Coin   types.CoinSymbol
	Amount *big.Int
}

type BalanceChangeStruct

type BalanceChangeStruct struct {
	Address           types.Address
	Coin              types.CoinSymbol
	Balance           *big.Int
	BalanceInBasecoin *big.Int
}

func (BalanceChangeStruct) MarshalJSON

func (s BalanceChangeStruct) MarshalJSON() ([]byte, error)

type Balances

type Balances struct {
	Data map[types.CoinSymbol]*big.Int
}

func (*Balances) DecodeRLP

func (b *Balances) DecodeRLP(s *rlp.Stream) error

func (Balances) EncodeRLP

func (b Balances) EncodeRLP(w io.Writer) error

type Candidate

type Candidate struct {
	CandidateAddress types.Address
	TotalBipStake    *big.Int
	PubKey           types.Pubkey
	Commission       uint
	Stakes           []Stake
	CreatedAtBlock   uint
	Status           byte
	// contains filtered or unexported fields
}

func (Candidate) GetAddress added in v0.2.0

func (candidate Candidate) GetAddress() [20]byte

func (Candidate) GetStakeOfAddress

func (candidate Candidate) GetStakeOfAddress(addr types.Address, coin types.CoinSymbol) *Stake

func (Candidate) String

func (candidate Candidate) String() string

type Candidates

type Candidates []Candidate

type Code

type Code []byte

func (Code) String

func (self Code) String() string

type Coin

type Coin struct {
	Name           string
	Symbol         types.CoinSymbol
	Volume         *big.Int
	Crr            uint
	ReserveBalance *big.Int
	Creator        types.Address
}

func (Coin) String

func (coin Coin) String() string

type Database

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

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

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

	// 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 mintdb.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 FrozenFund

type FrozenFund struct {
	Address      types.Address
	CandidateKey []byte
	Coin         types.CoinSymbol
	Value        *big.Int
}

frozen funds are only for BaseCoin

type FrozenFunds

type FrozenFunds struct {
	BlockHeight uint64
	List        []FrozenFund
}

func (FrozenFunds) String

func (f FrozenFunds) String() string

type Stake

type Stake struct {
	Owner types.Address
	Coin  types.CoinSymbol
	Value *big.Int
}

func (*Stake) BipValue

func (s *Stake) BipValue(context *StateDB) *big.Int

func (*Stake) MarshalJSON

func (s *Stake) MarshalJSON() ([]byte, error)

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: * Coins * Accounts

func New

func New(root types.Hash, db Database) (*StateDB, error)

Create a new state from a given trie

func (*StateDB) AddAccumReward

func (s *StateDB) AddAccumReward(pubkey types.Pubkey, reward *big.Int)

func (*StateDB) AddBalance

func (s *StateDB) AddBalance(addr types.Address, coinSymbol types.CoinSymbol, amount *big.Int)

AddBalance adds amount to the account associated with addr

func (*StateDB) AddCoinReserve

func (s *StateDB) AddCoinReserve(symbol types.CoinSymbol, value *big.Int)

func (*StateDB) AddCoinVolume

func (s *StateDB) AddCoinVolume(symbol types.CoinSymbol, value *big.Int)

func (*StateDB) CandidateExists

func (s *StateDB) CandidateExists(key types.Pubkey) bool

func (*StateDB) CoinExists

func (s *StateDB) CoinExists(symbol types.CoinSymbol) bool

func (*StateDB) Commit

func (s *StateDB) Commit(deleteEmptyObjects bool) (root types.Hash, err error)

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

func (*StateDB) CreateCandidate

func (s *StateDB) CreateCandidate(
	address types.Address,
	pubkey types.Pubkey,
	commission uint,
	currentBlock uint,
	coin types.CoinSymbol,
	initialStake *big.Int) *stateCandidates

func (*StateDB) CreateCoin

func (s *StateDB) CreateCoin(
	symbol types.CoinSymbol,
	name string,
	volume *big.Int,
	crr uint,
	reserve *big.Int,
	creator types.Address) *stateCoin

func (*StateDB) CreateValidator added in v0.2.0

func (s *StateDB) CreateValidator(
	address types.Address,
	pubkey types.Pubkey,
	commission uint,
	currentBlock uint,
	coin types.CoinSymbol,
	initialStake *big.Int) *stateValidators

func (*StateDB) Database

func (s *StateDB) Database() Database

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

func (*StateDB) Delegate

func (s *StateDB) Delegate(sender types.Address, pubkey []byte, coin types.CoinSymbol, value *big.Int)

func (*StateDB) Empty

func (s *StateDB) Empty(addr types.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 (s *StateDB) Error() error

func (*StateDB) GetBalance

func (s *StateDB) GetBalance(addr types.Address, coinSymbol types.CoinSymbol) *big.Int

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

func (*StateDB) GetBalances

func (s *StateDB) GetBalances(addr types.Address) Balances

func (*StateDB) GetCandidates added in v0.2.0

func (s *StateDB) GetCandidates(count int, block int64) []Candidate

func (*StateDB) GetNonce

func (s *StateDB) GetNonce(addr types.Address) uint64

func (*StateDB) GetOrNewStateFrozenFunds

func (s *StateDB) GetOrNewStateFrozenFunds(blockHeight uint64) *stateFrozenFund

func (*StateDB) GetOrNewStateObject

func (s *StateDB) GetOrNewStateObject(addr types.Address) *stateObject

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

func (*StateDB) GetStateCandidate

func (s *StateDB) GetStateCandidate(key types.Pubkey) *Candidate

func (*StateDB) GetStateCandidates added in v0.2.0

func (s *StateDB) GetStateCandidates() (stateCandidates *stateCandidates)

func (*StateDB) GetStateCoin

func (s *StateDB) GetStateCoin(symbol types.CoinSymbol) *stateCoin

func (*StateDB) GetStateFrozenFunds

func (s *StateDB) GetStateFrozenFunds(blockHeight uint64) *stateFrozenFund

func (*StateDB) GetStateValidators added in v0.2.0

func (s *StateDB) GetStateValidators() (stateValidators *stateValidators)

func (*StateDB) IsCheckUsed

func (s *StateDB) IsCheckUsed(check *check.Check) bool

func (*StateDB) MarkStateCandidateDirty

func (s *StateDB) MarkStateCandidateDirty()

func (*StateDB) MarkStateCoinDirty

func (s *StateDB) MarkStateCoinDirty(symbol types.CoinSymbol)

func (*StateDB) MarkStateFrozenFundsDirty

func (s *StateDB) MarkStateFrozenFundsDirty(blockHeight uint64)

func (*StateDB) MarkStateObjectDirty

func (s *StateDB) MarkStateObjectDirty(addr types.Address)

MarkStateObjectDirty adds the specified object to the dirty map to avoid costly state object cache iteration to find a handful of modified ones.

func (*StateDB) MarkStateValidatorsDirty added in v0.2.0

func (s *StateDB) MarkStateValidatorsDirty()

func (*StateDB) PayRewards

func (s *StateDB) PayRewards()

func (*StateDB) PunishByzantineValidator added in v0.2.0

func (s *StateDB) PunishByzantineValidator(address [20]byte)

func (*StateDB) RecalculateTotalStakeValues

func (s *StateDB) RecalculateTotalStakeValues()

func (*StateDB) RemoveFrozenFundsWithAddress added in v0.2.0

func (s *StateDB) RemoveFrozenFundsWithAddress(fromBlock uint64, toBlock uint64, address [20]byte)

func (*StateDB) SetBalance

func (s *StateDB) SetBalance(addr types.Address, coinSymbol types.CoinSymbol, amount *big.Int)

func (*StateDB) SetCandidateOffline

func (s *StateDB) SetCandidateOffline(pubkey []byte)

func (*StateDB) SetCandidateOnline

func (s *StateDB) SetCandidateOnline(pubkey []byte)

func (*StateDB) SetNewValidators added in v0.2.0

func (s *StateDB) SetNewValidators(candidates []Candidate)

func (*StateDB) SetNonce

func (s *StateDB) SetNonce(addr types.Address, nonce uint64)

func (*StateDB) SetValidatorAbsent

func (s *StateDB) SetValidatorAbsent(address [20]byte)

func (*StateDB) SetValidatorPresent

func (s *StateDB) SetValidatorPresent(address [20]byte)

func (*StateDB) SubBalance

func (s *StateDB) SubBalance(addr types.Address, coinSymbol types.CoinSymbol, amount *big.Int)

SubBalance subtracts amount from the account associated with addr

func (*StateDB) SubCoinReserve

func (s *StateDB) SubCoinReserve(symbol types.CoinSymbol, value *big.Int)

func (*StateDB) SubCoinVolume

func (s *StateDB) SubCoinVolume(symbol types.CoinSymbol, value *big.Int)

func (*StateDB) SubStake

func (s *StateDB) SubStake(sender types.Address, pubkey []byte, coin types.CoinSymbol, value *big.Int)

func (*StateDB) UseCheck

func (s *StateDB) UseCheck(check *check.Check)

type Storage

type Storage map[types.Hash]types.Hash

func (Storage) Copy

func (self Storage) Copy() Storage

func (Storage) String

func (self 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) (types.Hash, error)
	Hash() types.Hash
	NodeIterator(startKey []byte) trie.NodeIterator
	GetKey([]byte) []byte // TODO(fjl): remove this when SecureTrie is removed
	Prove(key []byte, fromLevel uint, proofDb mintdb.Putter) error
}

Trie is a Ethereum Merkle Trie.

type Validator added in v0.2.0

type Validator struct {
	CandidateAddress types.Address
	TotalBipStake    *big.Int
	PubKey           types.Pubkey
	Commission       uint
	AccumReward      *big.Int
	AbsentTimes      uint
	// contains filtered or unexported fields
}

func (Validator) GetAddress added in v0.2.0

func (validator Validator) GetAddress() [20]byte

func (Validator) String added in v0.2.0

func (validator Validator) String() string

type Validators added in v0.2.0

type Validators []Validator

Jump to

Keyboard shortcuts

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