datastore

package
v0.2.21-beta.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlobStore

type BlobStore struct {
	DB *sql.Database
}

BlobStore gets data as a blob to serve direct fetch requests.

func NewBlobStore

func NewBlobStore(db *sql.Database) *BlobStore

NewBlobStore returns a BlobStore.

func (*BlobStore) Get

func (bs *BlobStore) Get(hint Hint, key []byte) ([]byte, error)

Get gets an ATX as bytes by an ATX ID as bytes.

type Cache

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

Cache holds a lru cache of recent T instances.

func NewAtxCache

func NewAtxCache(size int) *Cache[types.ATXID, types.ActivationTxHeader]

NewAtxCache creates a new cache for activation transaction headers.

func NewCache

func NewCache[K, V any](size int) *Cache[K, V]

func NewMalfeasanceCache

func NewMalfeasanceCache(size int) *Cache[types.NodeID, types.MalfeasanceProof]

NewMalfeasanceCache creates a cache of MalfeasanceProof of recent malicious identities.

func (*Cache[K, V]) Add

func (c *Cache[K, V]) Add(key K, val *V)

Add adds a key-value pair to cache.

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(key K) (*V, bool)

Get gets the corresponding value for the given key. it also returns a boolean to indicate whether the item was found in cache.

type CachedDB

type CachedDB struct {
	*sql.Database
	// contains filtered or unexported fields
}

CachedDB is simply a database injected with cache.

func NewCachedDB

func NewCachedDB(db *sql.Database, lg log.Log) *CachedDB

NewCachedDB create an instance of a CachedDB.

func (*CachedDB) AddMalfeasanceProof

func (db *CachedDB) AddMalfeasanceProof(id types.NodeID, proof *types.MalfeasanceProof, dbtx *sql.Tx) error

func (*CachedDB) GetAtxHeader

func (db *CachedDB) GetAtxHeader(id types.ATXID) (*types.ActivationTxHeader, error)

GetAtxHeader returns the ATX header by the given ID. This function is thread safe and will return an error if the ID is not found in the ATX DB.

func (*CachedDB) GetEpochWeight

func (db *CachedDB) GetEpochWeight(epoch types.EpochID) (uint64, []types.ATXID, error)

GetEpochWeight returns the total weight of ATXs targeting the given epochID.

func (*CachedDB) GetFullAtx

func (db *CachedDB) GetFullAtx(id types.ATXID) (*types.VerifiedActivationTx, error)

GetFullAtx returns the full atx struct of the given atxId id, it returns an error if the full atx cannot be found in all databases.

func (*CachedDB) GetMalfeasanceProof

func (db *CachedDB) GetMalfeasanceProof(id types.NodeID) (*types.MalfeasanceProof, error)

GetMalfeasanceProof gets the malfeasance proof associated with the NodeID.

func (*CachedDB) GetPrevAtx

func (db *CachedDB) GetPrevAtx(nodeID types.NodeID) (*types.ActivationTxHeader, error)

GetPrevAtx gets the last atx header of specified node Id, it returns error if no previous atx found or if no AtxHeader struct in db.

func (*CachedDB) IsMalicious

func (db *CachedDB) IsMalicious(id types.NodeID) (bool, error)

IsMalicious returns true if the NodeID is malicious.

func (*CachedDB) IterateEpochATXHeaders

func (db *CachedDB) IterateEpochATXHeaders(epoch types.EpochID, iter func(*types.ActivationTxHeader) bool) error

IterateEpochATXHeaders iterates over ActivationTxs that target an epoch.

func (*CachedDB) MalfeasanceCacheSize

func (db *CachedDB) MalfeasanceCacheSize() int

type Getter

type Getter interface {
	Get(Hint, []byte) ([]byte, error)
}

Getter wraps the database read operation.

type Hint

type Hint string

Hint marks which DB should be queried for a certain provided hash.

const (
	BallotDB   Hint = "ballotDB"
	BlockDB    Hint = "blocksDB"
	ProposalDB Hint = "proposalDB"
	ATXDB      Hint = "ATXDB"
	TXDB       Hint = "TXDB"
	POETDB     Hint = "POETDB"
)

DB hints per DB.

Jump to

Keyboard shortcuts

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