txsystem

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: AGPL-3.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStateContainsUncommittedChanges = errors.New("state contains uncommitted changes")
	ErrTransactionExpired              = errors.New("transaction timeout must be greater than current block number")
	ErrInvalidPartitionIdentifier      = errors.New("error invalid partition identifier")
)

Functions

func NewStateSummary

func NewStateSummary(rootHash []byte, summary []byte) stateSummary

Types

type GenericTxSystem

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

func NewGenericTxSystem

func NewGenericTxSystem(pdr types.PartitionDescriptionRecord, shardID types.ShardID, trustBase types.RootTrustBase, modules []txtypes.Module, observe Observability, opts ...Option) (*GenericTxSystem, error)

func (*GenericTxSystem) BeginBlock

func (m *GenericTxSystem) BeginBlock(roundNo uint64) error

func (*GenericTxSystem) Commit

func (*GenericTxSystem) CommittedUC

func (m *GenericTxSystem) CommittedUC() *types.UnicityCertificate

func (*GenericTxSystem) CurrentRound

func (m *GenericTxSystem) CurrentRound() uint64

func (*GenericTxSystem) EndBlock

func (m *GenericTxSystem) EndBlock() (StateSummary, error)

func (*GenericTxSystem) Execute

func (*GenericTxSystem) GetUnit

func (m *GenericTxSystem) GetUnit(id types.UnitID, committed bool) (*state.Unit, error)

func (*GenericTxSystem) IsFeelessMode

func (m *GenericTxSystem) IsFeelessMode() bool

func (*GenericTxSystem) IsPermissionedMode

func (m *GenericTxSystem) IsPermissionedMode() bool

func (*GenericTxSystem) Revert

func (m *GenericTxSystem) Revert()

func (*GenericTxSystem) SerializeState

func (m *GenericTxSystem) SerializeState(writer io.Writer, committed bool) error

func (*GenericTxSystem) State

func (m *GenericTxSystem) State() StateReader

func (*GenericTxSystem) StateSize

func (m *GenericTxSystem) StateSize() (uint64, error)

func (*GenericTxSystem) StateSummary

func (m *GenericTxSystem) StateSummary() (StateSummary, error)

type Observability

type Observability interface {
	Meter(name string, opts ...metric.MeterOption) metric.Meter
	Logger() *slog.Logger
	RoundLogger(curRound func() uint64) *slog.Logger
}

type Option

type Option func(*Options)

func WithBeginBlockFunctions

func WithBeginBlockFunctions(funcs ...func(blockNumber uint64) error) Option

func WithEndBlockFunctions

func WithEndBlockFunctions(funcs ...func(blockNumber uint64) error) Option

func WithFeeCredits

func WithFeeCredits(f txtypes.FeeCreditModule) Option

func WithHashAlgorithm

func WithHashAlgorithm(hashAlgorithm crypto.Hash) Option

func WithState

func WithState(s *state.State) Option

type Options

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

func DefaultOptions

func DefaultOptions() *Options

type StateReader added in v0.4.0

type StateReader interface {
	GetUnit(id types.UnitID, committed bool) (*state.Unit, error)

	CreateUnitStateProof(id types.UnitID, logIndex int) (*types.UnitStateProof, error)

	CreateIndex(state.KeyExtractor[string]) (state.Index[string], error)

	// Serialize writes the serialized state to the given writer.
	Serialize(writer io.Writer, committed bool) error
}

type StateSummary

type StateSummary interface {
	// Root returns the root hash of the TransactionSystem.
	Root() []byte
	// Summary returns the summary value of the state.
	Summary() []byte
}

StateSummary represents the root hash and summary value of the transaction system.

type StateUnlockProof

type StateUnlockProof struct {
	Kind  StateUnlockProofKind
	Proof []byte
}

type StateUnlockProofKind

type StateUnlockProofKind byte
const (
	StateUnlockRollback StateUnlockProofKind = iota
	StateUnlockExecute
)

type TransactionExecutor

type TransactionExecutor interface {
	// Execute method executes the transaction order. An error must be returned if the transaction order execution
	// was not successful.
	Execute(order *types.TransactionOrder) (*types.TransactionRecord, error)
}

type TransactionSystem

type TransactionSystem interface {
	TransactionExecutor

	// StateSummary returns the summary of the current state of the transaction system or an ErrStateContainsUncommittedChanges if
	// current state contains uncommitted changes.
	StateSummary() (StateSummary, error)

	StateSize() (uint64, error)

	// BeginBlock signals the start of a new block and is invoked before any Execute method calls.
	BeginBlock(uint64) error

	// EndBlock signals the end of the block and is called after all transactions have been delivered to the
	// transaction system.
	EndBlock() (StateSummary, error)

	// Revert signals the unsuccessful consensus round. When called the transaction system must revert all the changes
	// made during the BeginBlock, EndBlock, and Execute method calls.
	Revert()

	// Commit signals the successful consensus round. Called after the block was approved by the root chain. When called
	// the transaction system must commit all the changes made during the BeginBlock,
	// EndBlock, and Execute method calls.
	Commit(uc *types.UnicityCertificate) error

	// CommittedUC returns the unicity certificate of the latest commit.
	CommittedUC() *types.UnicityCertificate

	// State returns clone of transaction system state
	State() StateReader

	// IsPermissionedMode returns true if permissioned mode is enabled and only transactions from approved parties
	// are executed.
	IsPermissionedMode() bool

	// IsFeelessMode returns true if feeless mode is enabled and the cost of executing transactions is 0.
	IsFeelessMode() bool
}

TransactionSystem is a set of rules and logic for defining units and performing transactions with them. The following sequence of methods is executed for each block: BeginBlock, Execute (called once for each transaction in the block), EndBlock, and Commit (consensus round was successful) or Revert (consensus round was unsuccessful).

Directories

Path Synopsis
evm
api
fc
testutils

Jump to

Keyboard shortcuts

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