tracecache

package
v0.16.7-rc.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBlockCapacity = 256

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockTrace

type BlockTrace struct {
	Source       Source
	Traces       []TransactionTrace
	InitialReads *vm.InitialReads
}

BlockTrace holds version-neutral traces in block order; published data is read-only. InitialReads is nil when uncollected or unavailable (Feeder).

func FromFeeder

func FromFeeder(
	kinds []vm.TransactionType,
	receipts []*core.TransactionReceipt,
	source *starknet.BlockTrace,
) (*BlockTrace, error)

FromFeeder pairs source traces with supplied types and receipt gas.

func FromVM

func FromVM(
	transactions []core.Transaction,
	result *vm.ExecutionResults,
	initialReads bool,
) (*BlockTrace, error)

FromVM retains traces and gas. Requested initial reads must be non-nil, even for empty blocks.

func (*BlockTrace) Covers

func (b *BlockTrace) Covers(initialReads bool) bool

Covers checks requested read coverage, allowing unavailable feeder reads.

type Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Cache shares immutable results across requests, using a Lease to coordinate one producer per key while keeping existing results available to readers. See the usage example in Cache.Acquire.

func New

func New[K comparable, V any](limit int) *Cache[K, V]

func (*Cache[K, V]) Acquire

func (c *Cache[K, V]) Acquire(
	ctx context.Context,
	key *K,
	accepts func(V) bool,
) (V, *Lease[K, V], error)

Acquire returns a cached value, grants a lease, or waits.

Parameters:

  • ctx: controls cancellation while waiting for another lease to be released.
  • key: identifies the cached value; must be non-nil.
  • accepts: a brief, read-only function that reports whether the cached value satisfies this request. Returning true accepts the value without a lease; returning false requests a replacement lease or waits for the current owner. If accepts is nil, any cached value is accepted. It must not call back into this cache.

Outcomes:

  • A cached value exists and accepts is nil or returns true: return it without a lease.
  • No cached value and no lease exists: return a lease with the zero value.
  • accepts returns false and no lease exists: return a lease with the cached value.
  • A lease exists and no cached value meets the request: wait for its release and retry.

Caller responsibilities:

  • Cached values aren't deep-copied (as traces can be very large); callers must not mutate shared data they reference.
  • Call Lease.Release to relinquish ownership without changing the cached value, or Lease.Publish to store a value and release ownership.

Example usage:

cached, lease, err := cache.Acquire(ctx, &key, accepts)
if err != nil {
    return nil, err
}
if lease == nil {
    return cached, nil
}

defer lease.Release()

// buildValue must leave shared cached data unchanged.
result, err := buildValue(cached)
if err != nil {
    return nil, err
}
lease.Publish(result)
return result, nil

type Lease

type Lease[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Lease represents a caller's exclusive right to produce and publish a result for one Cache key. It coordinates replacement of the cached value without blocking requests that the existing value already satisfies. See the usage example in Cache.Acquire.

func (*Lease[K, V]) Publish

func (l *Lease[K, V]) Publish(value V)

Publish stores read-only data and releases ownership. Released leases are ignored.

func (*Lease[K, V]) Release

func (l *Lease[K, V]) Release()

Release releases ownership without changing the value. Repeated calls are safe.

type Source

type Source uint8
const (
	LocalVM Source = iota
	Feeder
)

type TransactionTrace

type TransactionTrace struct {
	Hash felt.Felt
	Type vm.TransactionType // Set by [FromFeeder]; VM traces carry their own type.
	Gas  core.GasConsumed
	// contains filtered or unexported fields
}

TransactionTrace holds one source trace and its RPC adaptation metadata.

func (*TransactionTrace) FeederTrace

func (t *TransactionTrace) FeederTrace() *starknet.TransactionTrace

func (*TransactionTrace) VMTrace

func (t *TransactionTrace) VMTrace() *vm.TransactionTrace

Jump to

Keyboard shortcuts

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