programs

package
v0.28.15-fix-metric-label Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// All events associated with the parent block is assigned the same value.
	//
	// Note that we can assign the time to any value in the range
	// [math.MinInt64, -1].
	ParentBlockTime = LogicalTime(-1)

	// All events associated with a child block is assigned the same value.
	//
	// Note that we can assign the time to any value in the range
	// (math.MaxUint32 + 1, math.MaxInt64].  (The +1 is needed for assigning
	// EndOfBlockExecutionTime a unique value)
	ChildBlockTime = LogicalTime(math.MaxInt64)

	// EndOfBlockExecutionTime is used when the real tx index is unavailable,
	// such as during script execution.
	EndOfBlockExecutionTime = ChildBlockTime - 1

	// A snapshot read transaction may occur at any time within the range
	// [0, EndOfBlockExecutionTime]
	LargestSnapshotReadTransactionExecutionTime = EndOfBlockExecutionTime

	// A normal transaction cannot commit to EndOfBlockExecutionTime.
	//
	// Note that we can assign the time to any value in the range
	// [max.MathUInt32, EndOfBlockExecutionTime)
	LargestNormalTransactionExecutionTime = EndOfBlockExecutionTime - 1
)
View Source
const DefaultProgramsCacheSize = 1000

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockPrograms added in v0.28.0

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

BlockPrograms is a simple fork-aware OCC database for "caching" programs for a particular block.

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

Furthermore, because programs are derived data, 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.

func NewEmptyBlockPrograms added in v0.28.0

func NewEmptyBlockPrograms() *BlockPrograms

func NewEmptyBlockProgramsWithTransactionOffset added in v0.28.0

func NewEmptyBlockProgramsWithTransactionOffset(offset uint32) *BlockPrograms

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

func (*BlockPrograms) EntriesForTestingOnly added in v0.28.0

func (block *BlockPrograms) EntriesForTestingOnly() map[common.Location]*invalidatableProgramEntry

func (*BlockPrograms) GetForTestingOnly added in v0.28.0

func (block *BlockPrograms) GetForTestingOnly(
	location common.Location,
) (
	*interpreter.Program,
	*state.State,
	bool,
)

func (*BlockPrograms) InvalidatorsForTestingOnly added in v0.28.0

func (block *BlockPrograms) InvalidatorsForTestingOnly() chainedInvalidators

func (*BlockPrograms) LatestCommitExecutionTimeForTestingOnly added in v0.28.0

func (block *BlockPrograms) LatestCommitExecutionTimeForTestingOnly() LogicalTime

func (*BlockPrograms) NewChildBlockPrograms added in v0.28.0

func (block *BlockPrograms) NewChildBlockPrograms() *BlockPrograms

func (*BlockPrograms) NewSnapshotReadTransactionPrograms added in v0.28.0

func (block *BlockPrograms) NewSnapshotReadTransactionPrograms(
	snapshotTime LogicalTime,
	executionTime LogicalTime,
) (
	*TransactionPrograms,
	error,
)

func (*BlockPrograms) NewTransactionPrograms added in v0.28.0

func (block *BlockPrograms) NewTransactionPrograms(
	snapshotTime LogicalTime,
	executionTime LogicalTime,
) (
	*TransactionPrograms,
	error,
)

func (*BlockPrograms) NextTxIndexForTestingOnly added in v0.28.0

func (block *BlockPrograms) NextTxIndexForTestingOnly() uint32

type ChainPrograms added in v0.28.0

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

ChainPrograms is a cache of BlockPrograms databases used for speeding up cadence execution.

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

func NewChainPrograms added in v0.28.0

func NewChainPrograms(chainCacheSize uint) (*ChainPrograms, error)

func (*ChainPrograms) Get added in v0.28.0

func (chain *ChainPrograms) Get(
	currentBlockId flow.Identifier,
) *BlockPrograms

func (*ChainPrograms) GetOrCreateBlockPrograms added in v0.28.0

func (chain *ChainPrograms) GetOrCreateBlockPrograms(
	currentBlockId flow.Identifier,
	parentBlockId flow.Identifier,
) *BlockPrograms

func (*ChainPrograms) NewBlockProgramsForScript added in v0.28.0

func (chain *ChainPrograms) NewBlockProgramsForScript(
	currentBlockId flow.Identifier,
) *BlockPrograms

type ContractUpdate

type ContractUpdate struct {
	ContractUpdateKey
	Code []byte
}

type ContractUpdateKey

type ContractUpdateKey struct {
	Address flow.Address
	Name    string
}

type Invalidator added in v0.28.0

type Invalidator interface {
	// This returns true if the this invalidates at least one program
	ShouldInvalidatePrograms() bool

	// This returns true if the program entry should be invalidated.
	ShouldInvalidateEntry(ProgramEntry) bool
}

type LogicalTime added in v0.28.0

type LogicalTime int64

We will use txIndex as logical time for the purpose of "caching" programs.

Execution time refers to the transaction's start time. Snapshot time refers to the time when the snapshot first becomes readable (i.e., the "snapshot time - 1" transaction committed the snapshot view). The snapshot is where the program source code is read from if no cached program entry is available. Each transaction's snapshot time must be smaller than or equal to its execution time.

Normal transaction advances the time clock and must be committed to BlockPrograms in monotonically increasing execution time order.

Snapshot read transaction (aka script) does not advance the time clock. Its execution and snapshot time must be set to the latest snapshot time (or EndOfBlockExecutionTime in case the real logical time is unavailable).

Note that the "real" txIndex range is [0, math.MaxUint32], but we have expanded the range to support events that are not part of the block execution.

type ModifiedSetsInvalidator added in v0.28.0

type ModifiedSetsInvalidator struct {
	ContractUpdateKeys []ContractUpdateKey
	FrozenAccounts     []common.Address
}

func (ModifiedSetsInvalidator) ShouldInvalidateEntry added in v0.28.0

func (sets ModifiedSetsInvalidator) ShouldInvalidateEntry(
	entry ProgramEntry,
) bool

func (ModifiedSetsInvalidator) ShouldInvalidatePrograms added in v0.28.0

func (sets ModifiedSetsInvalidator) ShouldInvalidatePrograms() bool

type ProgramEntry

type ProgramEntry struct {
	Location common.AddressLocation
	Program  *interpreter.Program
	State    *state.State
}

type Programs

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

TODO(patrick): Remove after emulator is updated.

func NewEmptyPrograms

func NewEmptyPrograms() *Programs

func (*Programs) ChildPrograms

func (p *Programs) ChildPrograms() *Programs

func (*Programs) Cleanup

func (p *Programs) Cleanup(modifiedSets ModifiedSetsInvalidator)

func (*Programs) Get

func (p *Programs) Get(location common.Location) (*interpreter.Program, *state.State, bool)

Get returns stored program, state which contains changes which correspond to loading this program, and boolean indicating if the value was found

func (*Programs) GetForTestingOnly added in v0.28.0

func (p *Programs) GetForTestingOnly(location common.Location) (*interpreter.Program, *state.State, bool)

func (*Programs) NextTxIndexForTestingOnly added in v0.28.0

func (p *Programs) NextTxIndexForTestingOnly() uint32

func (*Programs) Set

func (p *Programs) Set(location common.Location, program *interpreter.Program, state *state.State)

type RetryableError added in v0.28.0

type RetryableError interface {
	error
	IsRetryable() bool
}

type TransactionPrograms added in v0.28.0

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

TransactionPrograms is the scratch space for a single transaction.

func (*TransactionPrograms) AddInvalidator added in v0.28.0

func (transaction *TransactionPrograms) AddInvalidator(
	invalidator Invalidator,
)

func (*TransactionPrograms) Commit added in v0.28.0

func (transaction *TransactionPrograms) Commit() RetryableError

func (*TransactionPrograms) Get added in v0.28.0

func (transaction *TransactionPrograms) Get(
	location common.Location,
) (
	*interpreter.Program,
	*state.State,
	bool,
)

func (*TransactionPrograms) Set added in v0.28.0

func (transaction *TransactionPrograms) Set(
	location common.Location,
	program *interpreter.Program,
	state *state.State,
)

func (*TransactionPrograms) Validate added in v0.28.0

func (transaction *TransactionPrograms) Validate() RetryableError

Jump to

Keyboard shortcuts

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