datastore

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 16 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 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, opts ...Opt) *CachedDB

NewCachedDB create an instance of a CachedDB.

func (*CachedDB) CacheMalfeasanceProof

func (db *CachedDB) CacheMalfeasanceProof(id types.NodeID, proof *types.MalfeasanceProof)

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 published 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) error,
) error

IterateEpochATXHeaders iterates over ActivationTxs that target an epoch.

func (*CachedDB) IterateMalfeasanceProofs added in v1.1.0

func (db *CachedDB) IterateMalfeasanceProofs(
	iter func(types.NodeID, *types.MalfeasanceProof) error,
) error

func (*CachedDB) MalfeasanceCacheSize

func (db *CachedDB) MalfeasanceCacheSize() int

func (*CachedDB) MaxHeightAtx

func (db *CachedDB) MaxHeightAtx() (types.ATXID, error)

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 Config added in v1.1.2

type Config struct {
	// ATXSize must be larger than the sum of all ATXs in last 2 epochs to be effective
	// (Epoch 12: ~ 300k, Epoch 11: ~ 200k)
	ATXSize         int `mapstructure:"atx-size"`
	MalfeasenceSize int `mapstructure:"malfeasence-size"`
}

func DefaultConfig added in v1.1.2

func DefaultConfig() Config

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"
	ActiveSet   Hint = "activeset"
)

DB hints per DB.

type Opt added in v1.1.2

type Opt func(*cacheOpts)

func WithConfig added in v1.1.2

func WithConfig(cfg Config) Opt

type VrfNonceKey

type VrfNonceKey struct {
	ID    types.NodeID
	Epoch types.EpochID
}

Jump to

Keyboard shortcuts

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