state

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: LGPL-3.0 Imports: 22 Imported by: 10

Documentation

Index

Constants

View Source
const MaxStorageKeyLength = 40

Variables

View Source
var MaxTrieCacheGen = uint16(120)

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

Functions

func ConfirmReward

func ConfirmReward(state *StateDB, block *types.Block, confirmedBlock *types.Block)

func CopyStorageValue

func CopyStorageValue(value []byte) []byte

func MiningReward

func MiningReward(state *StateDB, block *types.Block)

func NewStateSync

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

NewStateSync create a new state trie download scheduler.

Types

type Account

type Account struct {
	TxNonceSet      nonces.NonceSet
	PackageNonceSet nonces.NonceSet

	Balance       *big.Int
	LockedBalance *big.Int
	LockToRound   uint64 // time uint(100ms): same to the "Round" in block

	Root     common.Hash
	CodeHash []byte

	ContractOwner common.Address
}

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

type AccountForStorage

type AccountForStorage struct {
	Code          string         `json:"code,omitempty"`
	Storage       Storage        `json:"storage,omitempty"`
	Balance       *big.Int       `json:"balance" gencodec:"required"`
	LockedBalance *big.Int       `json:"lockedBalance" gencodec:"required"`
	LockToRound   uint64         `json:"lockToRound" gencodec:"required"`
	PrivateKey    []byte         `json:"secretKey,omitempty"` // for tests
	Owner         common.Address `json:"owner,omitempty"`
}

type Code

type Code []byte

func (Code) String

func (self 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)

	// 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 dbwrapper.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 ManagedState

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

func ManageState

func ManageState(statedb *StateDB, elemType reflect.Type) *ManagedState

ManagedState returns a new managed state with the statedb as it's backing layer

func (*ManagedState) GetNonce

func (ms *ManagedState) GetNonce(addr common.Address) uint64

GetNonce returns the canonical nonce for the managed or unmanaged account.

Because GetNonce mutates the DB, we must take a write lock.

func (*ManagedState) SetNonce

func (ms *ManagedState) SetNonce(addr common.Address, nonce uint64)

SetNonce sets the new canonical nonce for the managed state

type StateDB

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

StateDBs within the fractal protocol are used to store anything within the merkle trie. StateDBs take care of caching and storing nested states.

func New

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

Create a new state from a given trie.

func (*StateDB) AddBalance

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

AddBalance adds amount to the account associated with addr.

func (*StateDB) AddLog

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

func (*StateDB) AddRefund

func (self *StateDB) AddRefund(gas uint64)

func (*StateDB) Commit

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

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

func (*StateDB) Copy

func (self *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 (self *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 WASM CREATE operation. The new contract address is generated by the crypto.CreateAddress function.

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

func (*StateDB) Database

func (self *StateDB) Database() Database

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

func (*StateDB) DumpAllState

func (s *StateDB) DumpAllState(path string)

func (*StateDB) DumpState

func (s *StateDB) DumpState(msg string)

func (*StateDB) Empty

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

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

func (*StateDB) Error

func (self *StateDB) Error() error

func (*StateDB) Exist

func (self *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 (s *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) FinaliseOne

func (s *StateDB) FinaliseOne()

FinaliseOne is called since a complete transaction/package ends

func (*StateDB) GetBalance

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

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

func (*StateDB) GetCode

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

func (*StateDB) GetCodeHash

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

func (*StateDB) GetCodeSize

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

func (*StateDB) GetContractOwner

func (self *StateDB) GetContractOwner(addr common.Address) common.Address

func (*StateDB) GetLogs

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

func (*StateDB) GetNonce

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

func (*StateDB) GetOrNewStateObject

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

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

func (*StateDB) GetPackageNonce

func (self *StateDB) GetPackageNonce(addr common.Address) uint64

func (*StateDB) GetPackerInfo

func (self *StateDB) GetPackerInfo(index uint32) *types.PackerInfo

func (*StateDB) GetPackerNumber

func (self *StateDB) GetPackerNumber() uint32

func (*StateDB) GetRefund

func (self *StateDB) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*StateDB) GetRoot

func (s *StateDB) GetRoot() common.Hash

func (*StateDB) GetState

func (self *StateDB) GetState(addr common.Address, key StorageKey) []byte

func (*StateDB) GetTradableBalance added in v0.2.2

func (self *StateDB) GetTradableBalance(addr common.Address, currentRound uint64) *big.Int

func (*StateDB) GetTransferBlackList

func (self *StateDB) GetTransferBlackList() []common.Address

func (*StateDB) GetTransferWhiteList

func (self *StateDB) GetTransferWhiteList() []common.Address

func (*StateDB) HasSuicided

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

func (*StateDB) InTransferBlackList

func (self *StateDB) InTransferBlackList(addr common.Address) bool

func (*StateDB) InTransferWhiteList

func (self *StateDB) InTransferWhiteList(addr common.Address) bool

func (*StateDB) IntermediateRoot

func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) 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) Logs

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

func (*StateDB) MarkNonceSetJournal

func (self *StateDB) MarkNonceSetJournal(address common.Address, prev *nonces.NonceSet)

func (*StateDB) MarkPackageNonceSetJournal

func (self *StateDB) MarkPackageNonceSetJournal(address common.Address)

func (*StateDB) PackageNonceSet

func (self *StateDB) PackageNonceSet(addr common.Address) *nonces.NonceSet

func (*StateDB) Prepare

func (self *StateDB) Prepare(thash common.Hash, pi uint32, ti uint32)

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

func (*StateDB) PrintNonceSet

func (s *StateDB) PrintNonceSet()

func (*StateDB) Reset

func (self *StateDB) Reset(root 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) ResetTo

func (self *StateDB) ResetTo(source *StateDB)

Snapshots of the copied state cannot be applied to the copy.

func (*StateDB) RevertToSnapshot

func (self *StateDB) RevertToSnapshot(revid int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*StateDB) SetBalance

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

func (*StateDB) SetBalanceLock added in v0.2.2

func (self *StateDB) SetBalanceLock(addr common.Address, amount *big.Int, lockToRound uint64)

Only set in genesis block when init. Must set total balance first.

func (*StateDB) SetCode

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

func (*StateDB) SetContractOwner

func (self *StateDB) SetContractOwner(addr common.Address, owner common.Address)

func (*StateDB) SetState

func (self *StateDB) SetState(addr common.Address, key StorageKey, value []byte)

func (*StateDB) Snapshot

func (self *StateDB) Snapshot() int

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

func (*StateDB) StorageTrie

func (self *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 (self *StateDB) SubBalance(addr common.Address, amount *big.Int)

SubBalance subtracts amount from the account associated with addr.

func (*StateDB) Suicide

func (self *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) TxNonceSet

func (self *StateDB) TxNonceSet(addr common.Address) *nonces.NonceSet

type Storage

type Storage map[StorageKey][]byte

func (Storage) Copy

func (self Storage) Copy() Storage

func (*Storage) DecodeRLP

func (self *Storage) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (Storage) EncodeRLP

func (self Storage) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (Storage) MarshalJSON

func (self Storage) MarshalJSON() ([]byte, error)

func (Storage) String

func (self Storage) String() (str string)

func (*Storage) UnmarshalJSON

func (self *Storage) UnmarshalJSON(input []byte) error

type StorageFormat

type StorageFormat struct {
	Key   string
	Value string
}

type StorageKey

type StorageKey struct {
	Length uint8
	Bytes  [MaxStorageKeyLength]byte
}

func GetStorageKey

func GetStorageKey(table uint64, key []byte) StorageKey

func LoadStorageKey

func LoadStorageKey(key []byte) StorageKey

func (*StorageKey) ToSlice

func (self *StorageKey) ToSlice() []byte

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 dbwrapper.Putter) error
}

Trie is a Merkle Trie.

Jump to

Keyboard shortcuts

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