Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewChainReader ¶
func NewChainReader( ctx context.Context, lgr logger.Logger, ptbClient *client.PTBClient, configs config.ChainReaderConfig, db sqlutil.DataSource, indexer indexer.IndexerApi, readerCache *Cache, ) (pkgtypes.ContractReader, error)
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache de-duplicates and caches the read-path RPCs that dominate Sui CCIP config polling:
- object reference metadata (GetObject) for shared/immutable objects, and
- optionally, decoded read-call (devInspect) results.
Concurrent identical loads are collapsed via singleflight — this is what relieves the cold-start storm where every node polls config simultaneously with empty caches — and successful loads are retained for a configurable TTL. The cache is process-local, which is sufficient because the redundancy it removes lives within a single relayer instance (each node re-reads the same shared objects on every poll); it does not need to be shared across nodes.
All methods are safe to call on a nil *Cache: they degrade to invoking the loader directly, so callers can hold an optional cache without nil checks.
func NewCache ¶
func NewCache(lggr logger.Logger, cfg CacheConfig) *Cache
NewCache builds a Cache from cfg (missing durations are defaulted).
func (*Cache) GetObjectMetadata ¶
func (rc *Cache) GetObjectMetadata( ctx context.Context, objectID string, loader func(context.Context) (*suirpcv2.Object, error), ) (*suirpcv2.Object, error)
GetObjectMetadata returns the object's reference metadata, serving it from cache when possible and otherwise invoking loader exactly once across concurrent callers for the same objectID. Only version-stable objects (SHARED/IMMUTABLE) are cached; address-owned objects, whose version changes on mutation, always go to loader so a stale ref is never served. This method satisfies the client.ObjectMetadataCache interface used by the gRPC client.
func (*Cache) GetReadResults ¶
func (rc *Cache) GetReadResults( ctx context.Context, key string, loader func(context.Context) ([]any, error), ) ([]any, error)
GetReadResults returns the decoded results of a read call, serving them from cache when enabled and otherwise invoking loader exactly once across concurrent callers for the same key. The cached value is the raw []any decoded result; callers decode it into their own return value on each call, so no shared mutable state escapes. Disabled by default — see CacheConfig.ReadCacheEnabled.
type CacheConfig ¶
type CacheConfig struct {
// ObjectCacheEnabled caches version-stable object reference metadata (owner/version/digest). The Sui
// read hot path resolves the same shared CCIP config objects (the CCIPObjectRef, OffRamp state, fee
// quoter, ...) on every read; caching their refs removes that redundant GetObject fan-out so it does
// not hit the node on every read across every config-poll cycle.
ObjectCacheEnabled bool
// ObjectTTL is how long object metadata is retained. Only SHARED/IMMUTABLE objects are cached (their
// refs are version-stable), so this can be minutes without serving a stale ref.
ObjectTTL time.Duration
// ReadCacheEnabled caches decoded read-call (devInspect) results keyed by read identifier + params.
// It is OFF by default: config reads change rarely, but caching them trades a little staleness for
// fewer node round-trips, so it is opt-in and should be enabled only with a short ReadTTL.
ReadCacheEnabled bool
// ReadTTL bounds how long a cached read result may be served before it is re-fetched.
ReadTTL time.Duration
// CleanupInterval is how often expired entries are purged from both underlying caches.
CleanupInterval time.Duration
}
CacheConfig tunes the Cache. Zero-value durations fall back to the values in DefaultCacheConfig via withDefaults(), so a partially-populated config is always valid.
func DefaultCacheConfig ¶
func DefaultCacheConfig() CacheConfig
DefaultCacheConfig returns safe defaults: object caching ON (high value, no staleness risk for version-stable objects) and read-call caching OFF (opt-in, since it can briefly mask config changes).
type ExtendedContractReader ¶
type ExtendedContractReader interface {
pkgtypes.ContractReader
QueryKeyWithMetadata(ctx context.Context, contract pkgtypes.BoundContract, filter query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]aptosCRConfig.SequenceWithMetadata, error)
}
type SequenceWithRecord ¶
type SequenceWithRecord struct {
Sequence pkgtypes.Sequence
Record *database.EventRecord
}