mesh

package
v0.2.13-beta.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package mesh defines the main store point for all the block-mesh objects such as ballots, blocks, transactions and global state

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LayerIDs

func LayerIDs(db database.Database, namespace string, lid types.LayerID, f func(id []byte) error) error

LayerIDs is a utility function that finds namespaced IDs saved in a database as a key.

Types

type AtxDB

type AtxDB interface {
	GetAtxHeader(id types.ATXID) (*types.ActivationTxHeader, error)
	GetFullAtx(id types.ATXID) (*types.ActivationTx, error)
	SyntacticallyValidateAtx(ctx context.Context, atx *types.ActivationTx) error
}

AtxDB holds logic for working with atxs.

type BallotFetcherDB

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

BallotFetcherDB implements API that allows fetcher to get a ballot from a remote database.

func (*BallotFetcherDB) Get

func (db *BallotFetcherDB) Get(hash []byte) ([]byte, error)

Get types.Block encoded in byte using hash.

type BlockFetcherDB

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

BlockFetcherDB implements API that allows fetcher to get a block from a remote database.

func (*BlockFetcherDB) Get

func (db *BlockFetcherDB) Get(hash []byte) ([]byte, error)

Get types.Block encoded in byte using hash.

type DB added in v0.1.11

type DB struct {
	log.Log
	// contains filtered or unexported fields
}

DB represents a mesh database instance.

func NewMemMeshDB

func NewMemMeshDB(logger log.Log) *DB

NewMemMeshDB is a mock used for testing.

func NewPersistentMeshDB

func NewPersistentMeshDB(db *sql.Database, blockCacheSize int, logger log.Log) (*DB, error)

NewPersistentMeshDB creates an instance of a mesh database.

func (*DB) AddBallot

func (m *DB) AddBallot(b *types.Ballot) error

AddBallot adds a ballot to the database.

func (*DB) AddBlock added in v0.1.11

func (m *DB) AddBlock(b *types.Block) error

AddBlock adds a block to the database.

func (*DB) AddZeroBlockLayer added in v0.1.15

func (m *DB) AddZeroBlockLayer(lid types.LayerID) error

AddZeroBlockLayer tags lyr as a layer without blocks.

func (*DB) Ballots

func (m *DB) Ballots() database.Getter

Ballots exports the ballot database.

func (*DB) Blocks

func (m *DB) Blocks() database.Getter

Blocks exports the block database.

func (*DB) BlocksByValidity added in v0.1.11

func (m *DB) BlocksByValidity(blocks []*types.Block) ([]*types.Block, []*types.Block)

BlocksByValidity classifies a slice of blocks by validity.

func (*DB) Close added in v0.1.11

func (m *DB) Close()

Close closes all resources.

func (*DB) ContextualValidity added in v0.1.11

func (m *DB) ContextualValidity(id types.BlockID) (bool, error)

ContextualValidity retrieves opinion on block from the database.

func (*DB) GetBallot

func (m *DB) GetBallot(id types.BallotID) (*types.Ballot, error)

GetBallot returns true if the database has Ballot specified by the BallotID and false otherwise.

func (*DB) GetBlock added in v0.1.11

func (m *DB) GetBlock(bid types.BlockID) (*types.Block, error)

GetBlock returns the block specified by the block ID.

func (*DB) GetCoinflip

func (m *DB) GetCoinflip(_ context.Context, layerID types.LayerID) (bool, bool)

GetCoinflip returns the weak coinflip result for the given layer.

func (*DB) GetHareConsensusOutput

func (m *DB) GetHareConsensusOutput(layerID types.LayerID) (types.BlockID, error)

GetHareConsensusOutput gets the input vote vector for a layer (hare results).

func (*DB) GetLatestLayer

func (m *DB) GetLatestLayer() (types.LayerID, error)

GetLatestLayer loads latest layer from database.

func (*DB) GetMeshTransaction

func (m *DB) GetMeshTransaction(id types.TransactionID) (*types.MeshTransaction, error)

GetMeshTransaction retrieves a tx by its id.

func (*DB) GetMeshTransactions

func (m *DB) GetMeshTransactions(transactions []types.TransactionID) ([]*types.MeshTransaction, map[types.TransactionID]struct{})

GetMeshTransactions retrieves list of txs with information in what blocks and layers they are included.

func (*DB) GetProcessedLayer

func (m *DB) GetProcessedLayer() (types.LayerID, error)

GetProcessedLayer loads processed layer from database.

func (*DB) GetProjection added in v0.1.11

func (m *DB) GetProjection(addr types.Address, prevNonce, prevBalance uint64) (uint64, uint64, error)

GetProjection returns projection of address.

func (*DB) GetRewards added in v0.1.11

func (m *DB) GetRewards(coinbase types.Address) ([]types.Reward, error)

GetRewards retrieves account's rewards by the coinbase address.

func (*DB) GetRewardsBySmesherID added in v0.1.28

func (m *DB) GetRewardsBySmesherID(smesherID types.NodeID) ([]types.Reward, error)

GetRewardsBySmesherID retrieves rewards by smesherID.

func (*DB) GetTransactions added in v0.1.11

func (m *DB) GetTransactions(transactions []types.TransactionID) ([]*types.Transaction, map[types.TransactionID]struct{})

GetTransactions retrieves a list of txs by their id's.

func (*DB) GetTransactionsByAddress

func (m *DB) GetTransactionsByAddress(from, to types.LayerID, address types.Address) ([]*types.MeshTransaction, error)

GetTransactionsByAddress retrieves txs for a single address in beetween layers [from, to]. Guarantees that transaction will appear exactly once, even if origin and recipient is the same, and in insertion order.

func (*DB) GetTransactionsByDestination added in v0.1.11

func (m *DB) GetTransactionsByDestination(from, to types.LayerID, address types.Address) ([]*types.MeshTransaction, error)

GetTransactionsByDestination retrieves txs by destination in between layers [from, to].

func (*DB) GetTransactionsByOrigin added in v0.1.11

func (m *DB) GetTransactionsByOrigin(from, to types.LayerID, address types.Address) ([]*types.MeshTransaction, error)

GetTransactionsByOrigin retrieves txs by origin in beetween layers [from, to].

func (*DB) GetVerifiedLayer

func (m *DB) GetVerifiedLayer() (types.LayerID, error)

GetVerifiedLayer loads verified layer from database.

func (*DB) HasBallot

func (m *DB) HasBallot(ballot types.BallotID) bool

HasBallot returns true if the ballot is stored in a database.

func (*DB) HasBlock

func (m *DB) HasBlock(bid types.BlockID) bool

HasBlock returns true if block exists in the database.

func (*DB) LayerBallotIDs

func (m *DB) LayerBallotIDs(lid types.LayerID) ([]types.BallotID, error)

LayerBallotIDs returns list of the ballot ids in the layer.

func (*DB) LayerBallots

func (m *DB) LayerBallots(lid types.LayerID) ([]*types.Ballot, error)

LayerBallots retrieves all ballots from a layer by layer ID.

func (*DB) LayerBlockIds added in v0.1.11

func (m *DB) LayerBlockIds(lid types.LayerID) ([]types.BlockID, error)

LayerBlockIds retrieves all block IDs from the layer specified by layer ID.

func (*DB) LayerBlocks added in v0.1.11

func (m *DB) LayerBlocks(lid types.LayerID) ([]*types.Block, error)

LayerBlocks retrieves all blocks from the layer specified by layer ID.

func (*DB) LayerContextuallyValidBlocks

func (m *DB) LayerContextuallyValidBlocks(ctx context.Context, layer types.LayerID) (map[types.BlockID]struct{}, error)

LayerContextuallyValidBlocks returns the set of contextually valid block IDs for the provided layer.

func (*DB) PersistentData added in v0.1.11

func (m *DB) PersistentData() bool

PersistentData checks to see if db is empty.

func (*DB) RecordCoinflip

func (m *DB) RecordCoinflip(ctx context.Context, layerID types.LayerID, coinflip bool)

RecordCoinflip saves the weak coinflip result to memory for the given layer.

func (*DB) SaveContextualValidity added in v0.1.11

func (m *DB) SaveContextualValidity(id types.BlockID, lid types.LayerID, valid bool) error

SaveContextualValidity persists opinion on block to the database.

func (*DB) SaveHareConsensusOutput

func (m *DB) SaveHareConsensusOutput(ctx context.Context, id types.LayerID, blockID types.BlockID) error

SaveHareConsensusOutput gets the input vote vector for a layer (hare results).

func (*DB) SetMalicious

func (m *DB) SetMalicious(smesher *signing.PublicKey) error

SetMalicious updates smesher as malicious.

type Mesh

type Mesh struct {
	log.Log
	*DB
	AtxDB
	// contains filtered or unexported fields
}

Mesh is the logic layer above our mesh.DB database.

func NewMesh

func NewMesh(db *DB, atxDb AtxDB, trtl tortoise, txPool txMemPool, state state, logger log.Log) *Mesh

NewMesh creates a new instant of a mesh.

func NewRecoveredMesh

func NewRecoveredMesh(db *DB, atxDb AtxDB, trtl tortoise, txPool txMemPool, state state, logger log.Log) *Mesh

NewRecoveredMesh creates new instance of mesh with recovered mesh data fom database.

func (*Mesh) AddBallot added in v1.0.0

func (msh *Mesh) AddBallot(ballot *types.Ballot) error

AddBallot to the mesh.

func (*Mesh) AddBlockWithTXs added in v1.0.0

func (msh *Mesh) AddBlockWithTXs(ctx context.Context, block *types.Block) error

AddBlockWithTXs adds the block and its TXs in into the database.

func (*Mesh) AddTXsFromProposal added in v1.0.0

func (msh *Mesh) AddTXsFromProposal(ctx context.Context, layerID types.LayerID, proposalID types.ProposalID, txIDs []types.TransactionID) error

AddTXsFromProposal adds the TXs in a Proposal into the database.

func (*Mesh) CacheWarmUp added in v0.1.4

func (msh *Mesh) CacheWarmUp(layerSize int)

CacheWarmUp warms up cache with latest blocks.

func (*Mesh) GetATXs

func (msh *Mesh) GetATXs(ctx context.Context, atxIds []types.ATXID) (map[types.ATXID]*types.ActivationTx, []types.ATXID)

GetATXs uses GetFullAtx to return a list of atxs corresponding to atxIds requested.

func (*Mesh) GetAggregatedLayerHash

func (msh *Mesh) GetAggregatedLayerHash(layerID types.LayerID) types.Hash32

GetAggregatedLayerHash returns the aggregated layer hash up to the specified layer.

func (*Mesh) GetLayer

func (msh *Mesh) GetLayer(i types.LayerID) (*types.Layer, error)

GetLayer returns Layer i from the database.

func (*Mesh) GetLayerHash

func (msh *Mesh) GetLayerHash(layerID types.LayerID) types.Hash32

GetLayerHash returns layer hash.

func (*Mesh) LatestLayer

func (msh *Mesh) LatestLayer() types.LayerID

LatestLayer - returns the latest layer we saw from the network.

func (*Mesh) LatestLayerInState

func (msh *Mesh) LatestLayerInState() types.LayerID

LatestLayerInState returns the latest layer we applied to state.

func (*Mesh) MissingLayer

func (msh *Mesh) MissingLayer() types.LayerID

MissingLayer is a layer in (latestLayerInState, processLayer]. this layer is missing critical data (valid blocks or transactions) and can't be applied to the state.

First valid layer starts with 1. 0 is empty layer and can be ignored.

func (*Mesh) ProcessLayer added in v1.0.0

func (msh *Mesh) ProcessLayer(ctx context.Context, layerID types.LayerID) error

ProcessLayer performs fairly heavy lifting: it triggers tortoise to process the full contents of the layer (i.e., all of its blocks), then to attempt to validate all unvalidated layers up to this layer. It also applies state for newly-validated layers.

func (*Mesh) ProcessLayerPerHareOutput added in v1.0.0

func (msh *Mesh) ProcessLayerPerHareOutput(ctx context.Context, layerID types.LayerID, blockID types.BlockID) error

ProcessLayerPerHareOutput receives hare output once it finishes running for a given layer.

func (*Mesh) ProcessedLayer

func (msh *Mesh) ProcessedLayer() types.LayerID

ProcessedLayer returns the last processed layer ID.

func (*Mesh) SetZeroBlockLayer added in v0.1.6

func (msh *Mesh) SetZeroBlockLayer(lyr types.LayerID) error

SetZeroBlockLayer tags lyr as a layer without blocks.

func (*Mesh) Transactions

func (msh *Mesh) Transactions() database.Getter

Transactions exports the transactions DB.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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