Documentation ¶
Index ¶
- Constants
- type DerivedBlockData
- func (block *DerivedBlockData) CachedPrograms() int
- func (block *DerivedBlockData) GetProgramForTestingOnly(addressLocation common.AddressLocation) *invalidatableEntry[*Program]
- func (block *DerivedBlockData) NewCachingSnapshotReadDerivedTransactionData() *DerivedTransactionData
- func (block *DerivedBlockData) NewChildDerivedBlockData() *DerivedBlockData
- func (block *DerivedBlockData) NewDerivedTransactionData(snapshotTime logical.Time, executionTime logical.Time) (*DerivedTransactionData, error)
- func (block *DerivedBlockData) NewSnapshotReadDerivedTransactionData() *DerivedTransactionData
- func (block *DerivedBlockData) NextTxIndexForTestingOnly() uint32
- type DerivedChainData
- func (chain *DerivedChainData) Get(currentBlockId flow.Identifier) *DerivedBlockData
- func (chain *DerivedChainData) GetOrCreateDerivedBlockData(currentBlockId flow.Identifier, parentBlockId flow.Identifier) *DerivedBlockData
- func (chain *DerivedChainData) NewDerivedBlockDataForScript(currentBlockId flow.Identifier) *DerivedBlockData
- type DerivedDataTable
- func (table *DerivedDataTable[TKey, TVal]) EntriesForTestingOnly() map[TKey]*invalidatableEntry[TVal]
- func (table *DerivedDataTable[TKey, TVal]) GetForTestingOnly(key TKey) *invalidatableEntry[TVal]
- func (table *DerivedDataTable[TKey, TVal]) InvalidatorsForTestingOnly() chainedTableInvalidators[TKey, TVal]
- func (table *DerivedDataTable[TKey, TVal]) LatestCommitExecutionTimeForTestingOnly() logical.Time
- func (table *DerivedDataTable[TKey, TVal]) NewCachingSnapshotReadTableTransaction() *TableTransaction[TKey, TVal]
- func (table *DerivedDataTable[TKey, TVal]) NewChildTable() *DerivedDataTable[TKey, TVal]
- func (table *DerivedDataTable[TKey, TVal]) NewSnapshotReadTableTransaction() *TableTransaction[TKey, TVal]
- func (table *DerivedDataTable[TKey, TVal]) NewTableTransaction(snapshotTime logical.Time, executionTime logical.Time) (*TableTransaction[TKey, TVal], error)
- func (table *DerivedDataTable[TKey, TVal]) NextTxIndexForTestingOnly() uint32
- type DerivedTransactionData
- func (transaction *DerivedTransactionData) AddInvalidator(invalidator TransactionInvalidator)
- func (transaction *DerivedTransactionData) Commit() error
- func (transaction *DerivedTransactionData) GetOrComputeProgram(txState state.NestedTransactionPreparer, ...) (*Program, error)
- func (transaction *DerivedTransactionData) GetProgram(location common.AddressLocation) (*Program, bool)
- func (transaction *DerivedTransactionData) GetStateExecutionParameters(txnState state.NestedTransactionPreparer, ...) (StateExecutionParameters, *snapshot.ExecutionSnapshot, error)
- func (transaction *DerivedTransactionData) Validate() error
- type DerivedTransactionPreparer
- type ExecutionParametersInvalidator
- type MeterParamOverrides
- type Program
- type ProgramDependencies
- func (d ProgramDependencies) Add(location common.Location) ProgramDependencies
- func (d ProgramDependencies) ContainsAddress(address common.Address) bool
- func (d ProgramDependencies) ContainsLocation(location common.Location) bool
- func (d ProgramDependencies) Count() int
- func (d ProgramDependencies) Merge(other ProgramDependencies)
- type ProgramInvalidator
- type StateExecutionParameters
- type TableInvalidator
- type TableTransaction
- func (txn *TableTransaction[TKey, TVal]) AddInvalidator(invalidator TableInvalidator[TKey, TVal])
- func (txn *TableTransaction[TKey, TVal]) Commit() error
- func (txn *TableTransaction[TKey, TVal]) GetForTestingOnly(key TKey) (TVal, *snapshot.ExecutionSnapshot, bool)
- func (txn *TableTransaction[TKey, TVal]) GetOrCompute(txnState state.NestedTransactionPreparer, key TKey, ...) (TVal, error)
- func (txn *TableTransaction[TKey, TVal]) GetWithStateOrCompute(txnState state.NestedTransactionPreparer, key TKey, ...) (TVal, *snapshot.ExecutionSnapshot, error)
- func (txn *TableTransaction[TKey, TVal]) SetForTestingOnly(key TKey, value TVal, snapshot *snapshot.ExecutionSnapshot)
- func (txn *TableTransaction[TKey, TVal]) ToValidateTimeForTestingOnly() logical.Time
- func (txn *TableTransaction[TKey, TVal]) Validate() error
- type TransactionInvalidator
- type ValueComputer
Constants ¶
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) NewCachingSnapshotReadDerivedTransactionData ¶ added in v0.33.19
func (block *DerivedBlockData) NewCachingSnapshotReadDerivedTransactionData() *DerivedTransactionData
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]) NewCachingSnapshotReadTableTransaction ¶ added in v0.33.19
func (table *DerivedDataTable[TKey, TVal]) NewCachingSnapshotReadTableTransaction() *TableTransaction[TKey, TVal]
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) 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) GetStateExecutionParameters ¶ added in v0.37.20
func (transaction *DerivedTransactionData) GetStateExecutionParameters( txnState state.NestedTransactionPreparer, getMeterParamOverrides ValueComputer[struct{}, StateExecutionParameters], ) ( StateExecutionParameters, *snapshot.ExecutionSnapshot, error, )
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) // GetStateExecutionParameters returns parameters needed for execution from the state. GetStateExecutionParameters( txnState state.NestedTransactionPreparer, getMeterParamOverrides ValueComputer[struct{}, StateExecutionParameters], ) ( StateExecutionParameters, *snapshot.ExecutionSnapshot, error, ) AddInvalidator(invalidator TransactionInvalidator) }
type ExecutionParametersInvalidator ¶ added in v0.37.20
type ExecutionParametersInvalidator TableInvalidator[ struct{}, StateExecutionParameters, ]
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 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 ¶
func (d ProgramDependencies) Add(location common.Location) ProgramDependencies
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 ¶
func (d ProgramDependencies) Merge(other ProgramDependencies)
Merge merges current dependencies with other dependencies.
type ProgramInvalidator ¶
type ProgramInvalidator TableInvalidator[ common.AddressLocation, *Program, ]
type StateExecutionParameters ¶ added in v0.37.20
type StateExecutionParameters struct { MeterParamOverrides ExecutionVersion semver.Version }
StateExecutionParameters are parameters needed for execution defined in the execution state.
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]) GetWithStateOrCompute ¶ added in v0.37.12
func (txn *TableTransaction[TKey, TVal]) GetWithStateOrCompute( txnState state.NestedTransactionPreparer, key TKey, computer ValueComputer[TKey, TVal], ) ( TVal, *snapshot.ExecutionSnapshot, error, )
GetWithStateOrCompute returns the key's value and the execution snapshot used to compute it. 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 ExecutionParametersInvalidator() ExecutionParametersInvalidator }
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").