txsystem

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

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 or equal to the current round number")
	ErrInvalidPartitionID              = errors.New("error invalid partition identifier")
)

Functions

This section is empty.

Types

type ETBuffer

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

ETBuffer Executed Transactions Buffer. It is used to avoid processing the same transaction multiple times which would allow someone else to drain your fee credit by re-broadcasting the already processed transaction, since fees would still be charged for the duplicate transaction for verifying the fee predicate.

func NewETBuffer

func NewETBuffer(opts ...ETBufferOption) *ETBuffer

func (*ETBuffer) Add

func (b *ETBuffer) Add(txID string, timeout uint64)

func (*ETBuffer) ClearExpired

func (b *ETBuffer) ClearExpired(currentRound uint64)

ClearExpired deletes expired transactions from the buffer.

func (*ETBuffer) Commit

func (b *ETBuffer) Commit()

Commit commits pending changes.

func (*ETBuffer) Get

func (b *ETBuffer) Get(txID string) (uint64, bool)

func (*ETBuffer) Hash

func (b *ETBuffer) Hash() ([]byte, error)

Hash calculates hash of the executed transactions buffer.

func (*ETBuffer) Revert

func (b *ETBuffer) Revert()

Revert reverts pending changes.

type ETBufferOption

type ETBufferOption func(*ETBuffer)

func WithExecutedTxs

func WithExecutedTxs(txs map[string]uint64) ETBufferOption

type GenericTxSystem

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

func NewGenericTxSystem

func NewGenericTxSystem(shardConf types.PartitionDescriptionRecord, 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) 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)

func (*GenericTxSystem) TypeID

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) error

func WithBeginBlockFunctions

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

func WithEndBlockFunctions

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

func WithExecutedTransactions

func WithExecutedTransactions(executedTransactions map[string]uint64) 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(observe Observability) (*Options, error)

type StateReader

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, executedTransactions map[string]uint64) error

	GetUnits(unitTypeID *uint32, pdr *types.PartitionDescriptionRecord) ([]types.UnitID, error)
}

type StateSummary

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

StateSummary represents aggregate state hashes of the transaction system.

func NewStateSummary

func NewStateSummary(rootHash []byte, summary []byte, etHash []byte) *StateSummary

func (StateSummary) ETHash

func (s StateSummary) ETHash() []byte

func (StateSummary) Root

func (s StateSummary) Root() []byte

func (StateSummary) Summary

func (s StateSummary) Summary() []byte

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

	// TypeID returns the type identifier of the transaction system.
	TypeID() types.PartitionTypeID

	SerializeState(writer io.Writer) error
}

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
fc
testutils

Jump to

Keyboard shortcuts

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