cache

package
v1.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultItemsCacheSize is the default size for items cache.
	DefaultItemsCacheSize = 200_000

	// DefaultHashesCacheSize is the default size for hash tracking.
	DefaultHashesCacheSize = 200_000

	// DefaultDAIncludedCacheSize is the default size for DA inclusion tracking.
	DefaultDAIncludedCacheSize = 200_000
)
View Source
const DefaultPendingCacheSize = 200_000

DefaultPendingCacheSize is the default size for the pending items cache.

View Source
const (

	// DefaultTxCacheRetention is the default time to keep transaction hashes in cache
	DefaultTxCacheRetention = 24 * time.Hour
)
View Source
const LastSubmittedDataHeightKey = "last-submitted-data-height"

LastSubmittedDataHeightKey is the key used for persisting the last submitted data height in store.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache is a generic cache that maintains items that are seen and hard confirmed. Uses bounded thread-safe LRU caches to prevent unbounded memory growth.

func NewCache

func NewCache[T any](s store.Store, keyPrefix string) *Cache[T]

NewCache returns a new Cache struct with default sizes. If store and keyPrefix are provided, DA inclusion data will be persisted to the store for populating the cache on restarts.

func (*Cache[T]) ClearFromStore

func (c *Cache[T]) ClearFromStore(ctx context.Context, hashes []string) error

ClearFromStore removes all DA inclusion entries from the store for this cache.

func (*Cache[T]) RestoreFromStore

func (c *Cache[T]) RestoreFromStore(ctx context.Context) error

RestoreFromStore loads DA inclusion data from the store into the in-memory cache. This should be called during initialization to restore persisted state. It directly queries store metadata keys with the cache's prefix, avoiding iteration through all blocks.

func (*Cache[T]) SaveToStore

func (c *Cache[T]) SaveToStore(ctx context.Context) error

SaveToStore persists all current DA inclusion entries to the store. This can be called before shutdown to ensure all data is persisted.

type CacheManager

type CacheManager interface {
	DaHeight() uint64

	// Header operations
	IsHeaderSeen(hash string) bool
	SetHeaderSeen(hash string, blockHeight uint64)
	GetHeaderDAIncluded(hash string) (uint64, bool)
	SetHeaderDAIncluded(hash string, daHeight uint64, blockHeight uint64)
	RemoveHeaderDAIncluded(hash string)

	// Data operations
	IsDataSeen(hash string) bool
	SetDataSeen(hash string, blockHeight uint64)
	GetDataDAIncluded(hash string) (uint64, bool)
	SetDataDAIncluded(hash string, daHeight uint64, blockHeight uint64)
	RemoveDataDAIncluded(hash string)

	// Transaction operations
	IsTxSeen(hash string) bool
	SetTxSeen(hash string)
	CleanupOldTxs(olderThan time.Duration) int

	// Pending events syncing coordination
	GetNextPendingEvent(blockHeight uint64) *common.DAHeightEvent
	SetPendingEvent(blockHeight uint64, event *common.DAHeightEvent)

	// Store operations
	SaveToStore() error
	RestoreFromStore() error

	// Cleanup operations
	DeleteHeight(blockHeight uint64)
}

CacheManager provides thread-safe cache operations for tracking seen blocks and DA inclusion status during block execution and syncing.

type Manager

type Manager interface {
	CacheManager
	PendingManager
}

Manager provides centralized cache management for both executing and syncing components

func NewManager

func NewManager(cfg config.Config, st store.Store, logger zerolog.Logger) (Manager, error)

NewManager creates a new cache manager instance

type PendingData

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

PendingData maintains Data that need to be published to DA layer

Important assertions: - data is safely stored in database before submission to DA - data is always pushed to DA in order (by height) - DA submission of multiple data is atomic - it's impossible to submit only part of a batch

lastSubmittedDataHeight is updated only after receiving confirmation from DA. Worst case scenario is when data was successfully submitted to DA, but confirmation was not received (e.g. node was restarted, networking issue occurred). In this case data is re-submitted to DA (it's extra cost). evolve is able to skip duplicate data so this shouldn't affect full nodes. Note: Submission of pending data to DA should account for the DA max blob size.

func NewPendingData

func NewPendingData(store store.Store, logger zerolog.Logger) (*PendingData, error)

NewPendingData returns a new PendingData struct

func (*PendingData) GetLastSubmittedDataHeight

func (pd *PendingData) GetLastSubmittedDataHeight() uint64

func (*PendingData) GetPendingData

func (pd *PendingData) GetPendingData(ctx context.Context) ([]*types.Data, [][]byte, error)

GetPendingData returns a sorted slice of pending Data along with their marshalled bytes.

func (*PendingData) NumPendingData

func (pd *PendingData) NumPendingData() uint64

func (*PendingData) SetLastSubmittedDataHeight

func (pd *PendingData) SetLastSubmittedDataHeight(ctx context.Context, newLastSubmittedDataHeight uint64)

type PendingHeaders

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

PendingHeaders maintains headers that need to be published to DA layer

Important assertions: - headers are safely stored in database before submission to DA - headers are always pushed to DA in order (by height) - DA submission of multiple headers is atomic - it's impossible to submit only part of a batch

lastSubmittedHeaderHeight is updated only after receiving confirmation from DA. Worst case scenario is when headers were successfully submitted to DA, but confirmation was not received (e.g. node was restarted, networking issue occurred). In this case headers are re-submitted to DA (it's extra cost). evolve is able to skip duplicate headers so this shouldn't affect full nodes.

func NewPendingHeaders

func NewPendingHeaders(store storepkg.Store, logger zerolog.Logger) (*PendingHeaders, error)

NewPendingHeaders returns a new PendingHeaders struct

func (*PendingHeaders) GetLastSubmittedHeaderHeight

func (ph *PendingHeaders) GetLastSubmittedHeaderHeight() uint64

func (*PendingHeaders) GetPendingHeaders

func (ph *PendingHeaders) GetPendingHeaders(ctx context.Context) ([]*types.SignedHeader, [][]byte, error)

GetPendingHeaders returns a sorted slice of pending headers along with their marshalled bytes.

func (*PendingHeaders) NumPendingHeaders

func (ph *PendingHeaders) NumPendingHeaders() uint64

func (*PendingHeaders) SetLastSubmittedHeaderHeight

func (ph *PendingHeaders) SetLastSubmittedHeaderHeight(ctx context.Context, newLastSubmittedHeaderHeight uint64)

type PendingManager

type PendingManager interface {
	GetPendingHeaders(ctx context.Context) ([]*types.SignedHeader, [][]byte, error)
	GetPendingData(ctx context.Context) ([]*types.SignedData, [][]byte, error)
	SetLastSubmittedHeaderHeight(ctx context.Context, height uint64)
	GetLastSubmittedHeaderHeight() uint64
	SetLastSubmittedDataHeight(ctx context.Context, height uint64)
	GetLastSubmittedDataHeight() uint64
	NumPendingHeaders() uint64
	NumPendingData() uint64
}

PendingManager provides operations for managing pending headers and data

Jump to

Keyboard shortcuts

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