cache

package
v0.0.0-...-fd63c1f Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TicketMaxCacheSize = 16384 // entries
)

Variables

View Source
var (
	BigmapHistoryMaxCacheSize = 2048    // full bigmaps (all keys + values)
	BigmapMaxCacheSize        = 1 << 20 // 1M entries
)
View Source
var (
	ContractMaxCacheSize     = 16384 // entries
	ContractTypeMaxCacheSize = 16384 // entries
)
View Source
var AccountCacheSizeMaxSize = 16384 // entries

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func UseLogger

func UseLogger(logger logpkg.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using logpkg.

Types

type AccountCache

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

func NewAccountCache

func NewAccountCache(sz int) *AccountCache

func (*AccountCache) AccountHashKey

func (c *AccountCache) AccountHashKey(a *model.Account) uint64

func (*AccountCache) Add

func (c *AccountCache) Add(a *model.Account)

func (*AccountCache) AddressHashKey

func (c *AccountCache) AddressHashKey(a tezos.Address) uint64

func (*AccountCache) Drop

func (c *AccountCache) Drop(a *model.Account)

func (*AccountCache) GetAddress

func (c *AccountCache) GetAddress(addr tezos.Address) (uint64, *model.Account, bool)

func (*AccountCache) GetId

func (c *AccountCache) GetId(id model.AccountID) (uint64, *model.Account, bool)

func (*AccountCache) Purge

func (c *AccountCache) Purge()

func (AccountCache) Stats

func (c AccountCache) Stats() Stats

func (*AccountCache) Walk

func (c *AccountCache) Walk(fn func(key uint64, acc *model.Account) error) error

type AddressCache

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

a cache of on-chain addresses id->hash

func NewAddressCache

func NewAddressCache(size int) *AddressCache

func (*AddressCache) Build

func (c *AddressCache) Build(ctx context.Context, table *pack.Table) error

func (AddressCache) Cap

func (c AddressCache) Cap() int

func (*AddressCache) GetAddress

func (c *AddressCache) GetAddress(id model.AccountID) tezos.Address

func (AddressCache) Len

func (c AddressCache) Len() int

func (AddressCache) Size

func (c AddressCache) Size() int

func (AddressCache) Stats

func (c AddressCache) Stats() Stats

func (*AddressCache) Update

func (c *AddressCache) Update(accounts map[model.AccountID]*model.Account) error

only called from single thread in crawler, no locking required

type BigmapCache

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

func NewBigmapCache

func NewBigmapCache(sz int) *BigmapCache

func (*BigmapCache) Add

func (c *BigmapCache) Add(b *model.BigmapAlloc)

func (*BigmapCache) Drop

func (c *BigmapCache) Drop(b *model.BigmapAlloc)

func (*BigmapCache) GetType

func (c *BigmapCache) GetType(id int64) (*model.BigmapAlloc, bool)

func (*BigmapCache) Purge

func (c *BigmapCache) Purge()

func (BigmapCache) Stats

func (c BigmapCache) Stats() Stats

type BigmapHistory

type BigmapHistory struct {
	BigmapId     int64
	Height       int64
	KeyOffsets   []uint32
	ValueOffsets []uint32
	Data         []byte
}

func (BigmapHistory) Get

func (BigmapHistory) Len

func (h BigmapHistory) Len() int

func (BigmapHistory) Range

func (h BigmapHistory) Range(from, to int) []*model.BigmapValue

func (BigmapHistory) Size

func (h BigmapHistory) Size() int64

type BigmapHistoryCache

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

func NewBigmapHistoryCache

func NewBigmapHistoryCache(sz int) *BigmapHistoryCache

func (*BigmapHistoryCache) Build

func (c *BigmapHistoryCache) Build(ctx context.Context, updates *pack.Table, id, height int64) (*BigmapHistory, error)

func (*BigmapHistoryCache) Get

func (c *BigmapHistoryCache) Get(id, height int64) (*BigmapHistory, bool)

func (*BigmapHistoryCache) GetBest

func (c *BigmapHistoryCache) GetBest(id, height int64) (*BigmapHistory, bool)

func (*BigmapHistoryCache) Purge

func (c *BigmapHistoryCache) Purge()

func (BigmapHistoryCache) Stats

func (c BigmapHistoryCache) Stats() Stats

func (*BigmapHistoryCache) Update

func (c *BigmapHistoryCache) Update(ctx context.Context, hist *BigmapHistory, updates *pack.Table, height int64) (*BigmapHistory, error)

type BlockCache

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

NOTE: simple read-mostly cache for timestamps and block hashes

Timestamps

  • 4-8 MB (2021)
  • block height ->> unix seconds (uint32)
  • first timestamp is actual time in unix secs, remainder are offsets in seconds
  • each entry uses 4 bytes per block, safe until June 2017 + 66 years; by then Tezos may have reached 34M blocks and the cache is 132MB in size

Block hashes - 32 byte per hash, growth rate is 16MB per year

func NewBlockCache

func NewBlockCache(size int) *BlockCache

func (*BlockCache) Build

func (c *BlockCache) Build(ctx context.Context, table *pack.Table) error

func (BlockCache) Cap

func (c BlockCache) Cap() int

func (*BlockCache) GetHash

func (c *BlockCache) GetHash(height int64) tezos.BlockHash

func (*BlockCache) GetHeight

func (c *BlockCache) GetHeight(tm time.Time) int64

func (*BlockCache) GetTime

func (c *BlockCache) GetTime(height int64) time.Time

func (BlockCache) Len

func (c BlockCache) Len() int

func (BlockCache) Size

func (c BlockCache) Size() int

func (BlockCache) Stats

func (c BlockCache) Stats() Stats

func (*BlockCache) Update

func (c *BlockCache) Update(block *model.Block) error

only called from single thread in crawler, no locking required

type ByRichRank

type ByRichRank []*model.AccountRank

func (ByRichRank) Len

func (h ByRichRank) Len() int

func (ByRichRank) Less

func (h ByRichRank) Less(i, j int) bool

func (ByRichRank) Swap

func (h ByRichRank) Swap(i, j int)

type ByTrafficRank

type ByTrafficRank []*model.AccountRank

func (ByTrafficRank) Len

func (h ByTrafficRank) Len() int

func (ByTrafficRank) Less

func (h ByTrafficRank) Less(i, j int) bool

func (ByTrafficRank) Swap

func (h ByTrafficRank) Swap(i, j int)

type ByVolumeRank

type ByVolumeRank []*model.AccountRank

func (ByVolumeRank) Len

func (h ByVolumeRank) Len() int

func (ByVolumeRank) Less

func (h ByVolumeRank) Less(i, j int) bool

func (ByVolumeRank) Swap

func (h ByVolumeRank) Swap(i, j int)

type ContractCache

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

func NewContractCache

func NewContractCache(sz int) *ContractCache

func (*ContractCache) Add

func (c *ContractCache) Add(cc *model.Contract)

func (*ContractCache) Drop

func (c *ContractCache) Drop(cc *model.Contract)

func (*ContractCache) Get

func (*ContractCache) Purge

func (c *ContractCache) Purge()

func (ContractCache) Size

func (c ContractCache) Size() int64

func (ContractCache) Stats

func (c ContractCache) Stats() Stats

type ContractTypeCache

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

func NewContractTypeCache

func NewContractTypeCache(sz int) *ContractTypeCache

func (*ContractTypeCache) Add

func (*ContractTypeCache) Drop

func (c *ContractTypeCache) Drop(cc *model.Contract)

func (*ContractTypeCache) Get

func (*ContractTypeCache) Purge

func (c *ContractTypeCache) Purge()

func (ContractTypeCache) Stats

func (c ContractTypeCache) Stats() Stats

type ContractTypeElem

type ContractTypeElem struct {
	ParamType   micheline.Type
	StorageType micheline.Type
	CodeHash    uint64
}

func (ContractTypeElem) Size

func (e ContractTypeElem) Size() int64

type ProposalCache

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

a cache of on-chain addresses id->hash

func NewProposalCache

func NewProposalCache() *ProposalCache

func (*ProposalCache) Build

func (c *ProposalCache) Build(ctx context.Context, table *pack.Table) error

func (*ProposalCache) GetHash

func (ProposalCache) Len

func (c ProposalCache) Len() int

func (ProposalCache) Size

func (c ProposalCache) Size() int

func (ProposalCache) Stats

func (c ProposalCache) Stats() Stats

type RankCache

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

func NewRankCache

func NewRankCache() *RankCache

func (*RankCache) Build

func (h *RankCache) Build(ctx context.Context, accounts, ops *pack.Table) error

func (RankCache) Cap

func (c RankCache) Cap() int

func (*RankCache) Expire

func (c *RankCache) Expire() *RankCache

func (RankCache) Expired

func (h RankCache) Expired() bool

func (*RankCache) GetAccount

func (h *RankCache) GetAccount(id model.AccountID) (*model.AccountRank, bool)

func (RankCache) Len

func (c RankCache) Len() int

func (RankCache) Size

func (c RankCache) Size() int

func (RankCache) Stats

func (c RankCache) Stats() Stats

func (RankCache) Time

func (h RankCache) Time() time.Time

func (*RankCache) TopRich

func (h *RankCache) TopRich(n, o int) []*model.AccountRank

func (*RankCache) TopTraffic

func (h *RankCache) TopTraffic(n, o int) []*model.AccountRank

func (*RankCache) TopVolume

func (h *RankCache) TopVolume(n, o int) []*model.AccountRank

type RightsCache

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

caches rights for up to 6 cycles (current + future preserved_cycles) for fast lookup of next right by account id + current height for about 500 active bakers that is - 2 * ((1024 byte per cycle * 6 cycles) + const slice+map overhead 48b) * 500 = 6MB

func NewRightsCache

func NewRightsCache(blocksPerCycle, numCycles int64, startHeight, startCycle int64) *RightsCache

func (*RightsCache) Add

func (c *RightsCache) Add(r *model.Right)

func (*RightsCache) BitmapSize

func (c *RightsCache) BitmapSize() int

func (*RightsCache) Build

func (c *RightsCache) Build(ctx context.Context, startCycle int64, table *pack.Table) error

func (RightsCache) Cap

func (c RightsCache) Cap() int

func (*RightsCache) End

func (c *RightsCache) End() int64

func (*RightsCache) Len

func (c *RightsCache) Len() int64

func (*RightsCache) Lookup

func (c *RightsCache) Lookup(id model.AccountID, height int64) (int64, int64)

func (RightsCache) Size

func (c RightsCache) Size() int

func (*RightsCache) Start

func (c *RightsCache) Start() int64

func (RightsCache) Stats

func (c RightsCache) Stats() Stats

type Stats

type Stats struct {
	Size      int   `json:"size"`
	Bytes     int64 `json:"bytes"`
	Inserts   int64 `json:"inserts"`
	Updates   int64 `json:"updates"`
	Hits      int64 `json:"hits"`
	Misses    int64 `json:"misses"`
	Evictions int64 `json:"evictions"`
}

func (*Stats) CountEvictions

func (s *Stats) CountEvictions(n int64)

func (*Stats) CountHits

func (s *Stats) CountHits(n int64)

func (*Stats) CountInserts

func (s *Stats) CountInserts(n int64)

func (*Stats) CountMisses

func (s *Stats) CountMisses(n int64)

func (*Stats) CountUpdates

func (s *Stats) CountUpdates(n int64)

func (Stats) Get

func (s Stats) Get() Stats

type TicketCache

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

func NewTicketCache

func NewTicketCache(sz int) *TicketCache

func (*TicketCache) Add

func (c *TicketCache) Add(t *model.Ticket)

func (*TicketCache) Drop

func (c *TicketCache) Drop(t *model.Ticket)

func (*TicketCache) Get

func (c *TicketCache) Get(id model.TicketID) (*model.Ticket, bool)

func (*TicketCache) Purge

func (c *TicketCache) Purge()

func (TicketCache) Stats

func (c TicketCache) Stats() Stats

Jump to

Keyboard shortcuts

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