datastore

package
v0.2.24-beta.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 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 comparable, 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 comparable, 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 NewVRFNonceCache

func NewVRFNonceCache(size int) *Cache[string, types.VRFPostIndex]

NewVRFCache creates a new cache for VRF nonces.

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) GetEpochAtx

func (db *CachedDB) GetEpochAtx(epoch types.EpochID, nodeID types.NodeID) (*types.ActivationTxHeader, error)

GetEpochAtx gets the atx header of specified node ID in the specified epoch.

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) GetLastAtx

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

GetLastAtx gets the last atx header of specified node ID.

func (*CachedDB) GetMalfeasanceProof

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

GetMalfeasanceProof gets the malfeasance proof associated with the NodeID.

func (*CachedDB) IdentityExists

func (db *CachedDB) IdentityExists(nodeID types.NodeID) (bool, error)

IdentityExists returns true if this NodeID has published any ATX.

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

func (*CachedDB) VRFNonce

func (db *CachedDB) VRFNonce(id types.NodeID, epoch types.EpochID) (types.VRFPostIndex, error)

VRFNonce returns the VRF nonce of for the given node in the given epoch. This function is thread safe and will return an error if the nonce is not found in the ATX DB.

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"
	Malfeasance Hint = "malfeasance"
)

DB hints per DB.

Jump to

Keyboard shortcuts

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