state

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: LGPL-3.0 Imports: 11 Imported by: 1

Documentation

Overview

Package state manages the main accounts trie. It follows the flow as bellow:

         o
         |
[ revertable state ]
         |
  [ stacked map ] -> [ journal ] -> [ playback(staging) ] -> [ updated trie ]
         |
   [ trie cache ]
         |
  [ read-only trie ]

It's much simpler than Ethereum's statedb. An important difference with statedb is the logic of account suicide. TODO: explain more

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Balance      *big.Int
	Energy       *big.Int
	BoundBalance *big.Int
	BoundEnergy  *big.Int
	Master       []byte // master address
	CodeHash     []byte // hash of code
	StorageRoot  []byte // merkle root of the storage trie
}

Account is the Thor consensus representation of an account. RLP encoded objects are stored in main account trie.

func (*Account) CalcEnergy

func (a *Account) CalcEnergy() *big.Int

CalcEnergy calculates energy based on current block time.

func (*Account) IsEmpty

func (a *Account) IsEmpty() bool

IsEmpty returns if an account is empty. An empty account has zero balance and zero length code hash.

type Creator

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

Creator state creator to cut-off kv dependency.

func NewCreator

func NewCreator(kv kv.GetPutter) *Creator

NewCreator create a new state creator.

func (*Creator) NewState

func (c *Creator) NewState(root meter.Bytes32) (*State, error)

NewState create a new state object.

type Stage

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

Stage abstracts changes on the main accounts trie.

func (*Stage) Commit

func (s *Stage) Commit() (meter.Bytes32, error)

Commit commits all changes into main accounts trie and storage tries.

func (*Stage) Hash

func (s *Stage) Hash() (meter.Bytes32, error)

Hash computes hash of the main accounts trie.

type State

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

State manages the main accounts trie.

func New

func New(root meter.Bytes32, kv kv.GetPutter) (*State, error)

New create an state object.

func (*State) AddBalance

func (s *State) AddBalance(addr meter.Address, amount *big.Int)

AddBalance stub.

func (*State) AddBoundedBalance added in v1.2.0

func (s *State) AddBoundedBalance(addr meter.Address, amount *big.Int)

AddBoundedBalance stub.

func (*State) AddBoundedEnergy added in v1.2.0

func (s *State) AddBoundedEnergy(addr meter.Address, amount *big.Int)

func (*State) AddEnergy

func (s *State) AddEnergy(addr meter.Address, amount *big.Int)

AddEnergy stub.

func (*State) BuildStorageTrie

func (s *State) BuildStorageTrie(addr meter.Address) (*trie.SecureTrie, error)

BuildStorageTrie build up storage trie for given address with cumulative changes.

func (*State) DecodeStorage

func (s *State) DecodeStorage(addr meter.Address, key meter.Bytes32, dec func([]byte) error)

DecodeStorage get and decode storage value. Error returned by dec will be absorbed by State instance.

func (*State) Delete

func (s *State) Delete(addr meter.Address)

Delete delete an account at the given address. That's set balance, energy and code to zero value.

func (*State) EncodeStorage

func (s *State) EncodeStorage(addr meter.Address, key meter.Bytes32, enc func() ([]byte, error))

EncodeStorage set storage value encoded by given enc method. Error returned by end will be absorbed by State instance.

func (*State) Err

func (s *State) Err() error

Err returns first occurred error.

func (*State) Exists

func (s *State) Exists(addr meter.Address) bool

Exists returns whether an account exists at the given address. See Account.IsEmpty()

func (*State) GetBalance

func (s *State) GetBalance(addr meter.Address) *big.Int

GetBalance returns balance for the given address.

func (*State) GetBoundedBalance

func (s *State) GetBoundedBalance(addr meter.Address) *big.Int

GetBalance returns balance for the given address.

func (*State) GetBoundedEnergy

func (s *State) GetBoundedEnergy(addr meter.Address) *big.Int

GetEnergy get energy for the given address at block number specified.

func (*State) GetCode

func (s *State) GetCode(addr meter.Address) []byte

GetCode returns code for the given address.

func (*State) GetCodeHash

func (s *State) GetCodeHash(addr meter.Address) meter.Bytes32

GetCodeHash returns code hash for the given address.

func (*State) GetEnergy

func (s *State) GetEnergy(addr meter.Address) *big.Int

GetEnergy get energy for the given address at block number specified.

func (*State) GetMaster

func (s *State) GetMaster(addr meter.Address) meter.Address

GetMaster get master for the given address. Master can move energy, manage users...

func (*State) GetRawStorage

func (s *State) GetRawStorage(addr meter.Address, key meter.Bytes32) rlp.RawValue

GetRawStorage returns storage value in rlp raw for given address and key.

func (*State) GetStorage

func (s *State) GetStorage(addr meter.Address, key meter.Bytes32) meter.Bytes32

GetStorage returns storage value for the given address and key.

func (*State) IsExclusiveAccount added in v1.2.0

func (s *State) IsExclusiveAccount(addr meter.Address) bool

func (*State) NewCheckpoint

func (s *State) NewCheckpoint() int

NewCheckpoint makes a checkpoint of current state. It returns revision of the checkpoint.

func (*State) RevertTo

func (s *State) RevertTo(revision int)

RevertTo revert to checkpoint specified by revision.

func (*State) SetBalance

func (s *State) SetBalance(addr meter.Address, balance *big.Int)

SetBalance set balance for the given address.

func (*State) SetBoundedBalance

func (s *State) SetBoundedBalance(addr meter.Address, balance *big.Int)

SetBalance set balance for the given address.

func (*State) SetBoundedEnergy

func (s *State) SetBoundedEnergy(addr meter.Address, energy *big.Int)

SetEnergy set energy at block number for the given address.

func (*State) SetCode

func (s *State) SetCode(addr meter.Address, code []byte)

SetCode set code for the given address.

func (*State) SetEnergy

func (s *State) SetEnergy(addr meter.Address, energy *big.Int)

SetEnergy set energy at block number for the given address.

func (*State) SetMaster

func (s *State) SetMaster(addr meter.Address, master meter.Address)

SetMaster set master for the given address.

func (*State) SetRawStorage

func (s *State) SetRawStorage(addr meter.Address, key meter.Bytes32, raw rlp.RawValue)

SetRawStorage set storage value in rlp raw.

func (*State) SetStorage

func (s *State) SetStorage(addr meter.Address, key, value meter.Bytes32)

SetStorage set storage value for the given address and key.

func (*State) Spawn

func (s *State) Spawn(root meter.Bytes32) *State

Spawn create a new state object shares current state's underlying db. Also errors will be reported to current state.

func (*State) Stage

func (s *State) Stage() *Stage

Stage makes a stage object to compute hash of trie or commit all changes.

func (*State) SubBalance

func (s *State) SubBalance(addr meter.Address, amount *big.Int) bool

SubBalance stub.

func (*State) SubBoundedBalance added in v1.2.0

func (s *State) SubBoundedBalance(addr meter.Address, amount *big.Int) bool

SubBoundedBalance stub.

func (*State) SubBoundedEnergy added in v1.2.0

func (s *State) SubBoundedEnergy(addr meter.Address, amount *big.Int) bool

SubEnergy stub.

func (*State) SubEnergy

func (s *State) SubEnergy(addr meter.Address, amount *big.Int) bool

SubEnergy stub.

Jump to

Keyboard shortcuts

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