cache

package
v0.17.6 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheEmpty       = errors.New("cache empty")
	ErrAddOutOfOrder    = errors.New("added tipset height lower than current head")
	ErrRevertOutOfOrder = errors.New("reverted tipset does not match current head")
	ErrEmptyRevert      = errors.New("reverted received on empty cache")
)

Functions

This section is empty.

Types

type TipSetCache

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

TipSetCache is a cache of recent tipsets that can keep track of reversions. Inspired by tipSetCache in Lotus chain/events package.

func NewTipSetCache

func NewTipSetCache(size int) *TipSetCache

func (*TipSetCache) Add

func (c *TipSetCache) Add(ts *types.TipSet) (*types.TipSet, error)

Add adds a new tipset which becomes the new head of the cache. If the buffer is full, the tail being evicted is also returned.

func (*TipSetCache) Confidence

func (c *TipSetCache) Confidence() int

Confidence returns the number of tipset that the cache must hold before tipsets are evicted on Add.

func (*TipSetCache) Head

func (c *TipSetCache) Head() (*types.TipSet, error)

Head returns the tipset at the head of the cache.

func (*TipSetCache) Height

func (c *TipSetCache) Height() abi.ChainEpoch

Height returns the height of the current head or zero if the cache is empty.

func (*TipSetCache) Len

func (c *TipSetCache) Len() int

Len returns the number of tipsets in the cache. This will never exceed the size of the cache.

func (*TipSetCache) Reset

func (c *TipSetCache) Reset()

Reset removes all tipsets from the cache

func (*TipSetCache) Revert

func (c *TipSetCache) Revert(ts *types.TipSet) error

Revert removes the head tipset

func (*TipSetCache) SetCurrent

func (c *TipSetCache) SetCurrent(ts *types.TipSet) error

SetCurrent replaces the current head

func (*TipSetCache) Size

func (c *TipSetCache) Size() int

Size returns the maximum number of tipsets that may be present in the cache.

func (*TipSetCache) Tail

func (c *TipSetCache) Tail() (*types.TipSet, error)

Tail returns the tipset at the tail of the cache.

func (*TipSetCache) TailHeight

func (c *TipSetCache) TailHeight() abi.ChainEpoch

TailHeight returns the height of the current tail or zero if the cache is empty.

func (*TipSetCache) Warm

func (c *TipSetCache) Warm(ctx context.Context, head *types.TipSet, getTipSetFn func(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error)) error

Warm fills the TipSetCache with confidence tipsets so that subsequent calls to Add return a tipset.

Jump to

Keyboard shortcuts

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