state

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyUnitStateProof

func VerifyUnitStateProof(u *UnitStateProof, algorithm crypto.Hash, ucv UnicityCertificateValidator) error

Types

type Action

type Action func(s ShardState, hashAlgorithm crypto.Hash) error

func AddUnit

func AddUnit(id types.UnitID, bearer Predicate, data UnitData) Action

AddUnit adds a new unit with given identifier, owner condition, unit data.

func DeleteUnit

func DeleteUnit(id types.UnitID) Action

DeleteUnit removes the unit from the state with given identifier.

func SetOwner

func SetOwner(id types.UnitID, bearer Predicate) Action

SetOwner changes the owner of the item, leaves data as is

func UpdateUnitData

func UpdateUnitData(id types.UnitID, f UpdateFunction) Action

UpdateUnitData changes the data of the item, leaves owner as is.

type LogPruner

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

func NewLogPruner

func NewLogPruner(s *State) *LogPruner

func (*LogPruner) Add

func (s *LogPruner) Add(blockNr uint64, id types.UnitID)

func (*LogPruner) Count

func (s *LogPruner) Count(blockNr uint64) int

func (*LogPruner) Prune

func (s *LogPruner) Prune(blockNr uint64) error

func (*LogPruner) Remove

func (s *LogPruner) Remove(blockNr uint64)

type Option

type Option func(o *Options)

func WithHashAlgorithm

func WithHashAlgorithm(hashAlgorithm crypto.Hash) Option

func WithInitActions

func WithInitActions(actions ...Action) Option

type Options

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

type Predicate

type Predicate []byte

type ShardState

type ShardState interface {
	Add(id types.UnitID, u *Unit) error
	Get(id types.UnitID) (*Unit, error)
	Update(id types.UnitID, unit *Unit) error
	Delete(id types.UnitID) error
}

type State

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

State is a data structure that keeps track of units, unit ledgers, and calculates global state tree root hash.

State can be changed by calling Apply function with one or more Action function. Savepoint method can be used to add a special marker to the state that allows all actions that are executed after savepoint was established to be rolled back. In the other words, savepoint lets you roll back part of the state changes instead of the entire state. Releasing a savepoint does NOT trigger a state root hash calculation. To calculate the root hash of the state use method CalculateRoot. Calling a Commit method commits and releases all savepoints.

func New

func New(opts ...Option) (*State, error)

New creates a new state with given options.

func NewEmptyState

func NewEmptyState() *State

func (*State) AddUnitLog

func (s *State) AddUnitLog(id types.UnitID, transactionRecordHash []byte) (int, error)

func (*State) Apply

func (s *State) Apply(actions ...Action) error

Apply applies given actions to the state. All Action functions are executed together as a single atomic operation. If any of the Action functions returns an error all previous state changes made by any of the action function will be reverted.

func (*State) CalculateRoot

func (s *State) CalculateRoot() (uint64, []byte, error)

func (*State) Clone

func (s *State) Clone() *State

Clone returns a clone of the state. The original state and the cloned state can be used by different goroutines but can never be merged. The cloned state is usually used by read only operations (e.g. unit proof generation).

func (*State) Commit

func (s *State) Commit() error

Commit commits the state.

func (*State) CommittedTreeBlockNumber

func (s *State) CommittedTreeBlockNumber() uint64

CommittedTreeBlockNumber returns the block number of the committed state tree.

func (*State) CreateUnitStateProof

func (s *State) CreateUnitStateProof(id types.UnitID, logIndex int, uc *types.UnicityCertificate) (*UnitStateProof, error)

func (*State) GetUnit

func (s *State) GetUnit(id types.UnitID, committed bool) (*Unit, error)

func (*State) IsCommitted

func (s *State) IsCommitted() bool

func (*State) PruneLog

func (s *State) PruneLog(id types.UnitID) error

func (*State) ReleaseToSavepoint

func (s *State) ReleaseToSavepoint(id int)

ReleaseToSavepoint destroys all savepoints, keeping all state changes after it was created. If a savepoint with given id does not exist then this method does nothing.

Releasing savepoints does NOT trigger a state root hash calculation. To calculate the root hash of the state a Commit method must be called.

func (*State) Revert

func (s *State) Revert()

Revert rolls back all changes made to the state.

func (*State) RollbackToSavepoint

func (s *State) RollbackToSavepoint(id int)

RollbackToSavepoint destroys savepoints without keeping the changes in the state tree. All actions that were executed after the savepoint was established are rolled back, restoring the state to what it was at the time of the savepoint.

func (*State) Savepoint

func (s *State) Savepoint() int

Savepoint creates a new savepoint and returns an id of the savepoint. Use RollbackSavepoint to roll back all changes made after calling Savepoint method. Use ReleaseSavepoint to save all changes made to the state.

type StateTreeCert

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

type StateTreePathItem

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

type UnicityCertificateValidator

type UnicityCertificateValidator interface {
	Validate(uc *types.UnicityCertificate) error
}

type Unit

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

Unit is a node in the state tree. It is used to build state tree and unit ledgers.

func NewUnit

func NewUnit(bearer Predicate, data UnitData) *Unit

func (*Unit) Bearer

func (u *Unit) Bearer() Predicate

func (*Unit) Clone

func (u *Unit) Clone() *Unit

func (*Unit) Data

func (u *Unit) Data() UnitData

func (*Unit) String

func (u *Unit) String() string

type UnitData

type UnitData interface {
	Write(hasher hash.Hash)
	SummaryValueInput() uint64
	Copy() UnitData
}

UnitData is a generic data type for the unit state.

type UnitStateProof

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

func (*UnitStateProof) CalculateSateTreeOutput

func (u *UnitStateProof) CalculateSateTreeOutput(algorithm crypto.Hash) ([]byte, uint64)

type UnitTreeCert

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

type UpdateFunction

type UpdateFunction func(data UnitData) (newData UnitData, err error)

UpdateFunction is a function for updating the data of an item. Taken in previous UnitData and returns new UnitData.

Jump to

Keyboard shortcuts

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