derived

package
v0.31.13-amlandeep-scr... Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: AGPL-3.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultDerivedDataCacheSize = 1000

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(
	initialSnapshotTime logical.Time,
) *DerivedBlockData

func (*DerivedBlockData) CachedPrograms

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,
) (
	*DerivedTransactionData,
	error,
)

func (*DerivedBlockData) NewSnapshotReadDerivedTransactionData

func (block *DerivedBlockData) NewSnapshotReadDerivedTransactionData() *DerivedTransactionData

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,
](
	initialSnapshotTime logical.Time,
) *DerivedDataTable[TKey, TVal]

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() *TableTransaction[TKey, TVal]

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 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.NestedTransactionPreparer,
	getMeterParamOverrides ValueComputer[struct{}, MeterParamOverrides],
) (
	MeterParamOverrides,
	error,
)

func (*DerivedTransactionData) GetOrComputeProgram

func (transaction *DerivedTransactionData) GetOrComputeProgram(
	txState state.NestedTransactionPreparer,
	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 DerivedTransactionPreparer

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

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

	AddInvalidator(invalidator TransactionInvalidator)
}

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

type Program struct {
	*interpreter.Program

	Dependencies ProgramDependencies
}

type ProgramDependencies

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

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

func NewProgramDependencies

func NewProgramDependencies() ProgramDependencies

func (ProgramDependencies) Add

Add adds the location as a dependency.

func (ProgramDependencies) ContainsAddress

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

ContainsAddress returns true if the address is a dependency.

func (ProgramDependencies) ContainsLocation

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

ContainsLocation returns true if the location is a dependency.

func (ProgramDependencies) Count

func (d ProgramDependencies) Count() int

Count returns the number of locations dependencies of this program.

func (ProgramDependencies) Merge

Merge merges current dependencies with other dependencies.

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, *snapshot.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() error

func (*TableTransaction[TKey, TVal]) GetForTestingOnly

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

func (*TableTransaction[TKey, TVal]) GetOrCompute

func (txn *TableTransaction[TKey, TVal]) GetOrCompute(
	txnState state.NestedTransactionPreparer,
	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

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

func (*TableTransaction[TKey, TVal]) ToValidateTimeForTestingOnly

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

func (*TableTransaction[TKey, TVal]) Validate

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

type TransactionInvalidator

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

type ValueComputer

type ValueComputer[TKey any, TVal any] interface {
	Compute(txnState state.NestedTransactionPreparer, 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