Documentation ¶
Overview ¶
Package state provides a caching layer atop the Ethereum state trie.
Index ¶
- Constants
- Variables
- func EmitBalanceChange(address types.Address, coin types.CoinSymbol, balance *big.Int)
- type Account
- type Balance
- type BalanceChangeStruct
- type Balances
- type Candidate
- type Candidates
- type Code
- type Coin
- type Database
- type FrozenFund
- type FrozenFunds
- type Stake
- type StateDB
- func (s *StateDB) AddAccumReward(pubkey types.Pubkey, reward *big.Int)
- func (s *StateDB) AddBalance(addr types.Address, coinSymbol types.CoinSymbol, amount *big.Int)
- func (s *StateDB) AddCoinReserve(symbol types.CoinSymbol, value *big.Int)
- func (s *StateDB) AddCoinVolume(symbol types.CoinSymbol, value *big.Int)
- func (s *StateDB) CandidateExists(key types.Pubkey) bool
- func (s *StateDB) CoinExists(symbol types.CoinSymbol) bool
- func (s *StateDB) Commit(deleteEmptyObjects bool) (root types.Hash, err error)
- func (s *StateDB) CreateCandidate(address types.Address, pubkey types.Pubkey, commission uint, currentBlock uint, ...) *stateCandidates
- func (s *StateDB) CreateCoin(symbol types.CoinSymbol, name string, volume *big.Int, crr uint, ...) *stateCoin
- func (s *StateDB) Database() Database
- func (s *StateDB) Delegate(sender types.Address, pubkey []byte, coin types.CoinSymbol, value *big.Int)
- func (s *StateDB) Empty(addr types.Address) bool
- func (s *StateDB) Error() error
- func (s *StateDB) GetBalance(addr types.Address, coinSymbol types.CoinSymbol) *big.Int
- func (s *StateDB) GetBalances(addr types.Address) Balances
- func (s *StateDB) GetNonce(addr types.Address) uint64
- func (s *StateDB) GetOrNewStateFrozenFunds(blockHeight uint64) *stateFrozenFund
- func (s *StateDB) GetOrNewStateObject(addr types.Address) *stateObject
- func (s *StateDB) GetStateCandidate(key types.Pubkey) *Candidate
- func (s *StateDB) GetStateCoin(symbol types.CoinSymbol) *stateCoin
- func (s *StateDB) GetStateFrozenFunds(blockHeight uint64) *stateFrozenFund
- func (s *StateDB) GetValidators(count int) ([]abci.Validator, []Candidate)
- func (s *StateDB) IsCheckUsed(check *check.Check) bool
- func (s *StateDB) MarkStateCandidateDirty()
- func (s *StateDB) MarkStateCoinDirty(symbol types.CoinSymbol)
- func (s *StateDB) MarkStateFrozenFundsDirty(blockHeight uint64)
- func (s *StateDB) MarkStateObjectDirty(addr types.Address)
- func (s *StateDB) PayRewards()
- func (s *StateDB) PunishByzantineCandidate(PubKey []byte)
- func (s *StateDB) RecalculateTotalStakeValues()
- func (s *StateDB) RemoveFrozenFundsWithPubKey(fromBlock uint64, toBlock uint64, PubKey []byte)
- func (s *StateDB) SetBalance(addr types.Address, coinSymbol types.CoinSymbol, amount *big.Int)
- func (s *StateDB) SetCandidateOffline(pubkey []byte)
- func (s *StateDB) SetCandidateOnline(pubkey []byte)
- func (s *StateDB) SetNonce(addr types.Address, nonce uint64)
- func (s *StateDB) SetValidatorAbsent(pubkey types.Pubkey)
- func (s *StateDB) SetValidatorPresent(pubkey types.Pubkey)
- func (s *StateDB) SubBalance(addr types.Address, coinSymbol types.CoinSymbol, amount *big.Int)
- func (s *StateDB) SubCoinReserve(symbol types.CoinSymbol, value *big.Int)
- func (s *StateDB) SubCoinVolume(symbol types.CoinSymbol, value *big.Int)
- func (s *StateDB) SubStake(sender types.Address, pubkey []byte, coin types.CoinSymbol, value *big.Int)
- func (s *StateDB) UseCheck(check *check.Check)
- type Storage
- type Trie
Constants ¶
const ( CandidateStatusOffline = 0x01 CandidateStatusOnline = 0x02 )
Variables ¶
var (
BalanceChangeChan = make(chan BalanceChangeStruct, 10)
)
var (
CandidateMaxAbsentTimes = uint(12)
)
var MaxTrieCacheGen = uint16(120)
Trie cache generation limit after which to evic trie nodes from memory.
Functions ¶
func EmitBalanceChange ¶
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 BalanceChangeStruct ¶
func (BalanceChangeStruct) MarshalJSON ¶
func (s BalanceChangeStruct) MarshalJSON() ([]byte, error)
type Candidate ¶
type Candidate struct { CandidateAddress types.Address TotalBipStake *big.Int PubKey types.Pubkey Commission uint AccumReward *big.Int Stakes []Stake CreatedAtBlock uint Status byte AbsentTimes uint }
func (Candidate) GetStakeOfAddress ¶
type Candidates ¶
type Candidates []Candidate
type Coin ¶
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 ¶
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 int64 List []FrozenFund }
func (FrozenFunds) String ¶
func (f FrozenFunds) String() string
type Stake ¶
func (*Stake) MarshalJSON ¶
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 (*StateDB) AddAccumReward ¶
func (*StateDB) AddBalance ¶
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) CoinExists ¶
func (s *StateDB) CoinExists(symbol types.CoinSymbol) bool
func (*StateDB) CreateCandidate ¶
func (*StateDB) CreateCoin ¶
func (*StateDB) Database ¶
Database retrieves the low level database supporting the lower level trie ops.
func (*StateDB) Empty ¶
Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0)
func (*StateDB) GetBalance ¶
Retrieve the balance from the given address or 0 if object not found
func (*StateDB) GetOrNewStateFrozenFunds ¶
func (*StateDB) GetOrNewStateObject ¶
Retrieve a state object or create a new state object if nil
func (*StateDB) GetStateCandidate ¶
func (*StateDB) GetStateCoin ¶
func (s *StateDB) GetStateCoin(symbol types.CoinSymbol) *stateCoin
func (*StateDB) GetStateFrozenFunds ¶
func (*StateDB) GetValidators ¶
func (*StateDB) MarkStateCandidateDirty ¶
func (s *StateDB) MarkStateCandidateDirty()
func (*StateDB) MarkStateCoinDirty ¶
func (s *StateDB) MarkStateCoinDirty(symbol types.CoinSymbol)
func (*StateDB) MarkStateFrozenFundsDirty ¶
func (*StateDB) MarkStateObjectDirty ¶
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) PayRewards ¶
func (s *StateDB) PayRewards()
func (*StateDB) PunishByzantineCandidate ¶
func (*StateDB) RecalculateTotalStakeValues ¶
func (s *StateDB) RecalculateTotalStakeValues()
func (*StateDB) RemoveFrozenFundsWithPubKey ¶
func (*StateDB) SetBalance ¶
func (*StateDB) SetCandidateOffline ¶
func (*StateDB) SetCandidateOnline ¶
func (*StateDB) SetValidatorAbsent ¶
func (*StateDB) SetValidatorPresent ¶
func (*StateDB) SubBalance ¶
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)
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.