derived

package
v0.30.3 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDerivedDataCacheSize = 1000
View Source
const EndOfBlockExecutionTime = logical.EndOfBlockExecutionTime

TODO(patrick): rm once emulator is updated

Variables

This section is empty.

Functions

This section is empty.

Types

type DerivedBlockData

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

DerivedBlockData is a simple fork-aware OCC database for "caching" derived data for a particular block.

func NewEmptyDerivedBlockData

func NewEmptyDerivedBlockData() *DerivedBlockData

func NewEmptyDerivedBlockDataWithTransactionOffset

func NewEmptyDerivedBlockDataWithTransactionOffset(offset uint32) *DerivedBlockData

This variant is needed by the chunk verifier, which does not start at the beginning of the block.

func (*DerivedBlockData) CachedPrograms added in v0.29.17

func (block *DerivedBlockData) CachedPrograms() int

CachedPrograms returns the number of programs cached. Note: this should only be called after calling commit, otherwise the count will contain invalidated entries.

func (*DerivedBlockData) GetProgramForTestingOnly

func (block *DerivedBlockData) GetProgramForTestingOnly(
	addressLocation common.AddressLocation,
) *invalidatableEntry[*Program]

func (*DerivedBlockData) NewChildDerivedBlockData

func (block *DerivedBlockData) NewChildDerivedBlockData() *DerivedBlockData

func (*DerivedBlockData) NewDerivedTransactionData

func (block *DerivedBlockData) NewDerivedTransactionData(
	snapshotTime logical.Time,
	executionTime logical.Time,
) (
	DerivedTransactionCommitter,
	error,
)

func (*DerivedBlockData) NewSnapshotReadDerivedTransactionData

func (block *DerivedBlockData) NewSnapshotReadDerivedTransactionData(
	snapshotTime logical.Time,
	executionTime logical.Time,
) (
	DerivedTransactionCommitter,
	error,
)

func (*DerivedBlockData) NextTxIndexForTestingOnly

func (block *DerivedBlockData) NextTxIndexForTestingOnly() uint32

type DerivedChainData

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

DerivedChainData is a cache of DerivedBlockData databases used for speeding up cadence execution.

Since programs are derived from external source, the DerivedBlockData databases need not be durable and can be recreated on the fly.

func NewDerivedChainData

func NewDerivedChainData(chainCacheSize uint) (*DerivedChainData, error)

func (*DerivedChainData) Get

func (chain *DerivedChainData) Get(
	currentBlockId flow.Identifier,
) *DerivedBlockData

func (*DerivedChainData) GetOrCreateDerivedBlockData

func (chain *DerivedChainData) GetOrCreateDerivedBlockData(
	currentBlockId flow.Identifier,
	parentBlockId flow.Identifier,
) *DerivedBlockData

func (*DerivedChainData) NewDerivedBlockDataForScript

func (chain *DerivedChainData) NewDerivedBlockDataForScript(
	currentBlockId flow.Identifier,
) *DerivedBlockData

type DerivedDataTable

type DerivedDataTable[TKey comparable, TVal any] struct {
	// contains filtered or unexported fields
}

DerivedDataTable is a rudimentary fork-aware OCC database table for "caching" homogeneous (TKey, TVal) pairs for a particular block.

The database table enforces atomicity and isolation, but not consistency and durability. Consistency depends on the user correctly implementing the table's invalidator. Durability is not needed since the values are derived from ledger and can be computed on the fly (This assumes that recomputation is idempotent).

Furthermore, because data are derived, transaction validation looks a bit unusual when compared with a textbook OCC implementation. In particular, the transaction's invalidator represents "real" writes to the canonical source, whereas the transaction's readSet/writeSet entries represent "real" reads from the canonical source.

Multiple tables are grouped together via Validate/Commit 2 phase commit to form the complete derived data database.

func NewEmptyTable

func NewEmptyTable[TKey comparable, TVal any]() *DerivedDataTable[TKey, TVal]

func NewEmptyTableWithOffset

func NewEmptyTableWithOffset[
	TKey comparable,
	TVal any,
](
	offset uint32,
) *DerivedDataTable[TKey, TVal]

This variant is needed by the chunk verifier, which does not start at the beginning of the block.

func (*DerivedDataTable[TKey, TVal]) EntriesForTestingOnly

func (table *DerivedDataTable[TKey, TVal]) EntriesForTestingOnly() map[TKey]*invalidatableEntry[TVal]

func (*DerivedDataTable[TKey, TVal]) GetForTestingOnly

func (table *DerivedDataTable[TKey, TVal]) GetForTestingOnly(
	key TKey,
) *invalidatableEntry[TVal]

func (*DerivedDataTable[TKey, TVal]) InvalidatorsForTestingOnly

func (table *DerivedDataTable[TKey, TVal]) InvalidatorsForTestingOnly() chainedTableInvalidators[TKey, TVal]

func (*DerivedDataTable[TKey, TVal]) LatestCommitExecutionTimeForTestingOnly

func (table *DerivedDataTable[TKey, TVal]) LatestCommitExecutionTimeForTestingOnly() logical.Time

func (*DerivedDataTable[TKey, TVal]) NewChildTable

func (table *DerivedDataTable[TKey, TVal]) NewChildTable() *DerivedDataTable[TKey, TVal]

func (*DerivedDataTable[TKey, TVal]) NewSnapshotReadTableTransaction

func (table *DerivedDataTable[TKey, TVal]) NewSnapshotReadTableTransaction(
	snapshotTime logical.Time,
	executionTime logical.Time,
) (
	*TableTransaction[TKey, TVal],
	error,
)

func (*DerivedDataTable[TKey, TVal]) NewTableTransaction

func (table *DerivedDataTable[TKey, TVal]) NewTableTransaction(
	snapshotTime logical.Time,
	executionTime logical.Time,
) (
	*TableTransaction[TKey, TVal],
	error,
)

func (*DerivedDataTable[TKey, TVal]) NextTxIndexForTestingOnly

func (table *DerivedDataTable[TKey, TVal]) NextTxIndexForTestingOnly() uint32

type DerivedTransaction added in v0.30.0

type DerivedTransaction interface {
	GetOrComputeProgram(
		txState state.NestedTransaction,
		addressLocation common.AddressLocation,
		programComputer ValueComputer[common.AddressLocation, *Program],
	) (
		*Program,
		error,
	)
	GetProgram(location common.AddressLocation) (*Program, bool)

	GetMeterParamOverrides(
		txnState state.NestedTransaction,
		getMeterParamOverrides ValueComputer[struct{}, MeterParamOverrides],
	) (
		MeterParamOverrides,
		error,
	)

	AddInvalidator(invalidator TransactionInvalidator)
}

type DerivedTransactionCommitter added in v0.30.0

type DerivedTransactionCommitter interface {
	DerivedTransaction

	Validate() error
	Commit() error
}

type DerivedTransactionData

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

DerivedTransactionData is the derived data scratch space for a single transaction.

func (*DerivedTransactionData) AddInvalidator

func (transaction *DerivedTransactionData) AddInvalidator(
	invalidator TransactionInvalidator,
)

func (*DerivedTransactionData) Commit

func (transaction *DerivedTransactionData) Commit() error

func (*DerivedTransactionData) GetMeterParamOverrides

func (transaction *DerivedTransactionData) GetMeterParamOverrides(
	txnState state.NestedTransaction,
	getMeterParamOverrides ValueComputer[struct{}, MeterParamOverrides],
) (
	MeterParamOverrides,
	error,
)

func (*DerivedTransactionData) GetOrComputeProgram added in v0.30.0

func (transaction *DerivedTransactionData) GetOrComputeProgram(
	txState state.NestedTransaction,
	addressLocation common.AddressLocation,
	programComputer ValueComputer[common.AddressLocation, *Program],
) (
	*Program,
	error,
)

func (*DerivedTransactionData) GetProgram

func (transaction *DerivedTransactionData) GetProgram(
	location common.AddressLocation,
) (
	*Program,
	bool,
)

GetProgram returns the program for the given address location. This does NOT apply reads/metering to any nested transaction. Use with caution!

func (*DerivedTransactionData) Validate

func (transaction *DerivedTransactionData) Validate() error

type MeterParamOverrides

type MeterParamOverrides struct {
	ComputationWeights meter.ExecutionEffortWeights // nil indicates no override
	MemoryWeights      meter.ExecutionMemoryWeights // nil indicates no override
	MemoryLimit        *uint64                      // nil indicates no override
}

type MeterParamOverridesInvalidator

type MeterParamOverridesInvalidator TableInvalidator[
	struct{},
	MeterParamOverrides,
]

type Program added in v0.29.17

type Program struct {
	*interpreter.Program

	Dependencies ProgramDependencies
}

type ProgramDependencies added in v0.29.17

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

ProgramDependencies are the locations of programs that a program depends on.

func NewProgramDependencies added in v0.30.0

func NewProgramDependencies() ProgramDependencies

func (ProgramDependencies) Add added in v0.30.0

Add adds the location as a dependency.

func (ProgramDependencies) ContainsAddress added in v0.30.0

func (d ProgramDependencies) ContainsAddress(address common.Address) bool

ContainsAddress returns true if the address is a dependency.

func (ProgramDependencies) ContainsLocation added in v0.30.0

func (d ProgramDependencies) ContainsLocation(location common.Location) bool

ContainsLocation returns true if the location is a dependency.

func (ProgramDependencies) Count added in v0.30.0

func (d ProgramDependencies) Count() int

Count returns the number of locations dependencies of this program.

func (ProgramDependencies) Merge added in v0.29.17

Merge merges current dependencies with other dependencies.

type RetryableError

type RetryableError interface {
	error
	IsRetryable() bool
}

type TableInvalidator

type TableInvalidator[TKey comparable, TVal any] interface {
	// This returns true if the this invalidates any data
	ShouldInvalidateEntries() bool

	// This returns true if the table entry should be invalidated.
	ShouldInvalidateEntry(TKey, TVal, *state.ExecutionSnapshot) bool
}

type TableTransaction

type TableTransaction[TKey comparable, TVal any] struct {
	// contains filtered or unexported fields
}

func (*TableTransaction[TKey, TVal]) AddInvalidator

func (txn *TableTransaction[TKey, TVal]) AddInvalidator(
	invalidator TableInvalidator[TKey, TVal],
)

func (*TableTransaction[TKey, TVal]) Commit

func (txn *TableTransaction[TKey, TVal]) Commit() RetryableError

func (*TableTransaction[TKey, TVal]) GetForTestingOnly added in v0.30.0

func (txn *TableTransaction[TKey, TVal]) GetForTestingOnly(key TKey) (
	TVal,
	*state.ExecutionSnapshot,
	bool,
)

func (*TableTransaction[TKey, TVal]) GetOrCompute

func (txn *TableTransaction[TKey, TVal]) GetOrCompute(
	txnState state.NestedTransaction,
	key TKey,
	computer ValueComputer[TKey, TVal],
) (
	TVal,
	error,
)

GetOrCompute returns the key's value. If a pre-computed value is available, then the pre-computed value is returned and the cached state is replayed on txnState. Otherwise, the value is computed using valFunc; both the value and the states used to compute the value are captured.

Note: valFunc must be an idempotent function and it must not modify txnState's values.

func (*TableTransaction[TKey, TVal]) SetForTestingOnly added in v0.30.0

func (txn *TableTransaction[TKey, TVal]) SetForTestingOnly(
	key TKey,
	value TVal,
	snapshot *state.ExecutionSnapshot,
)

func (*TableTransaction[TKey, TVal]) ToValidateTimeForTestingOnly added in v0.30.0

func (txn *TableTransaction[TKey, TVal]) ToValidateTimeForTestingOnly() logical.Time

func (*TableTransaction[TKey, TVal]) Validate

func (txn *TableTransaction[TKey, TVal]) Validate() RetryableError

type TransactionInvalidator

type TransactionInvalidator interface {
	ProgramInvalidator() ProgramInvalidator
	MeterParamOverridesInvalidator() MeterParamOverridesInvalidator
}

type ValueComputer

type ValueComputer[TKey any, TVal any] interface {
	Compute(txnState state.NestedTransaction, key TKey) (TVal, error)
}

ValueComputer is used by DerivedDataTable's GetOrCompute to compute the derived value when the value is not in DerivedDataTable (i.e., "cache miss").

Jump to

Keyboard shortcuts

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