state

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2020 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const TreeBitWidth = 5

TreeBitWidth is the bit width of the HAMT used to store a state tree

Variables

This section is empty.

Functions

func MustCommit

func MustCommit(st State) cid.Cid

MustCommit flushes the StateTree or panics if it can't.

func MustGetActor

func MustGetActor(st State, a address.Address) (*actor.Actor, bool)

MustGetActor gets the actor or panics if it can't.

func MustSetActor

func MustSetActor(st State, address address.Address, actor *actor.Actor) cid.Cid

MustSetActor sets the actor or panics if it can't.

Types

type GetAllActorsResult

type GetAllActorsResult struct {
	Key   actorKey
	Actor *actor.Actor
	Error error
}

GetAllActorsResult is the struct returned via a channel by the GetAllActors method. This struct contains only an address string and the actor itself.

type Root

type Root = cid.Cid

Root is the root type of a state.

Any and all state can be identified by this.

Note: it might not be possible to locally reconstruct the entire state if the some parts are missing.

type State

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

State is the VM state manager.

func LoadState

func LoadState(ctx context.Context, store cbor.IpldStore, root Root) (*State, error)

LoadState creates a new VMStorage.

func NewFromString

func NewFromString(t *testing.T, s string, store cbor.IpldStore) *State

NewFromString sets a state tree based on an int.

TODO: we could avoid this if write a test cborStore that can map test cids to test states.

func NewState

func NewState(store cbor.IpldStore) *State

NewState creates a new VM state.

func (*State) Commit

func (st *State) Commit(ctx context.Context) (Root, error)

Commit will flush the state tree into the backing store. The new root is returned.

func (*State) DeleteActor

func (st *State) DeleteActor(ctx context.Context, key actorKey) error

DeleteActor remove the actor from the storage.

This method will NOT return an error if the actor was not found. This behaviour is based on a principle that some store implementations might not be able to determine whether something exists before deleting it.

func (*State) GetActor

func (st *State) GetActor(ctx context.Context, key actorKey) (*actor.Actor, bool, error)

GetActor retrieves an actor by their key. If the actor is not found it will return false and no error. If there are any IO or decoding errors, it will return false and the error.

func (*State) GetAllActors

func (st *State) GetAllActors(ctx context.Context) <-chan GetAllActorsResult

GetAllActors returns a channel which provides all actors in the StateTree.

func (*State) Rollback

func (st *State) Rollback(ctx context.Context, root Root) error

Rollback resets the root to a provided value.

func (*State) Root

func (st *State) Root() (Root, bool)

Root returns the last committed root of the tree and whether any writes have since occurred.

func (*State) SetActor

func (st *State) SetActor(ctx context.Context, key actorKey, a *actor.Actor) error

SetActor sets the the actor to the given value whether it previously existed or not.

This method will not check if the actor previuously existed, it will blindly overwrite it.

type Tree

type Tree interface {
	Root() (Root, bool)

	SetActor(ctx context.Context, key actorKey, a *actor.Actor) error
	GetActor(ctx context.Context, key actorKey) (*actor.Actor, bool, error)
	DeleteActor(ctx context.Context, key actorKey) error

	Rollback(ctx context.Context, root Root) error
	Commit(ctx context.Context) (Root, error)

	GetAllActors(ctx context.Context) <-chan GetAllActorsResult
}

Review: can we get rid of this?

Jump to

Keyboard shortcuts

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