Documentation ¶
Overview ¶
Package mesh defines the main store point for all the block-mesh objects such as blocks, transactions and global state
Index ¶
- Variables
- func GenesisBlock() *types.Block
- func GenesisLayer() *types.Layer
- type AtxDB
- type AtxDbMock
- func (t *AtxDbMock) AddAtx(id types.ATXID, atx *types.ActivationTx)
- func (t *AtxDbMock) GetAtxHeader(id types.ATXID) (*types.ActivationTxHeader, error)
- func (t *AtxDbMock) GetFullAtx(id types.ATXID) (*types.ActivationTx, error)
- func (t *AtxDbMock) ProcessAtxs(_ context.Context, atxs []*types.ActivationTx) error
- func (AtxDbMock) SyntacticallyValidateAtx(context.Context, *types.ActivationTx) error
- type BlockFetcherDB
- type Config
- type DB
- func (m *DB) AddBlock(bl *types.Block) error
- func (m *DB) AddZeroBlockLayer(index types.LayerID) error
- func (m *DB) Blocks() database.Getter
- func (m *DB) BlocksByValidity(blocks []*types.Block) (validBlocks, invalidBlocks []*types.Block)
- func (m *DB) Close()
- func (m *DB) ContextualValidity(id types.BlockID) (bool, error)
- func (m *DB) ForBlockInView(view map[types.BlockID]struct{}, layer types.LayerID, ...) error
- func (m *DB) GetBlock(id types.BlockID) (*types.Block, error)
- func (m *DB) GetCoinflip(_ context.Context, layerID types.LayerID) (bool, bool)
- func (m *DB) GetInputVectorBackupFunc() InputVectorBackupFunc
- func (m *DB) GetLayerInputVectorByID(layerID types.LayerID) ([]types.BlockID, error)
- func (m *DB) GetMeshTransaction(id types.TransactionID) (*types.MeshTransaction, error)
- func (m *DB) GetMeshTransactions(transactions []types.TransactionID) ([]*types.MeshTransaction, map[types.TransactionID]struct{})
- func (m *DB) GetProjection(addr types.Address, prevNonce, prevBalance uint64) (nonce, balance uint64, err error)
- func (m *DB) GetRewards(account types.Address) (rewards []types.Reward, err error)
- func (m *DB) GetRewardsBySmesherID(smesherID types.NodeID) (rewards []types.Reward, err error)
- func (m *DB) GetTransactions(transactions []types.TransactionID) (txs []*types.Transaction, missing map[types.TransactionID]struct{})
- func (m *DB) GetTransactionsByDestination(l types.LayerID, account types.Address) (txs []types.TransactionID, err error)
- func (m *DB) GetTransactionsByOrigin(l types.LayerID, account types.Address) (txs []types.TransactionID, err error)
- func (m *DB) InvalidateLayer(ctx context.Context, layerID types.LayerID)
- func (m *DB) LayerBlockIds(index types.LayerID) ([]types.BlockID, error)
- func (m *DB) LayerBlocks(index types.LayerID) ([]*types.Block, error)
- func (m *DB) LayerContextuallyValidBlocks(ctx context.Context, layer types.LayerID) (map[types.BlockID]struct{}, error)
- func (m *DB) PersistentData() bool
- func (m *DB) RecordCoinflip(ctx context.Context, layerID types.LayerID, coinflip bool)
- func (m *DB) SaveContextualValidity(id types.BlockID, _ types.LayerID, valid bool) error
- func (m *DB) SaveLayerInputVector(hash types.Hash32, vector []types.BlockID) error
- func (m *DB) SaveLayerInputVectorByID(ctx context.Context, id types.LayerID, blks []types.BlockID) error
- func (m *DB) SetInputVectorBackupFunc(fn InputVectorBackupFunc)
- func (m *DB) Transactions() database.Getter
- type DbTransaction
- type InputVectorBackupFunc
- type Mesh
- func (msh *Mesh) AddBlockWithTxs(ctx context.Context, blk *types.Block) error
- func (msh *Mesh) CacheWarmUp(layerSize int)
- func (msh *Mesh) GetATXs(ctx context.Context, atxIds []types.ATXID) (map[types.ATXID]*types.ActivationTx, []types.ATXID)
- func (msh *Mesh) GetAggregatedLayerHash(layerID types.LayerID) types.Hash32
- func (msh *Mesh) GetLayer(i types.LayerID) (*types.Layer, error)
- func (msh *Mesh) GetLayerHash(layerID types.LayerID) types.Hash32
- func (msh *Mesh) GetOrphanBlocksBefore(l types.LayerID) ([]types.BlockID, error)
- func (msh *Mesh) HandleLateBlock(ctx context.Context, b *types.Block)
- func (msh *Mesh) HandleValidatedLayer(ctx context.Context, validatedLayer types.LayerID, layer []types.BlockID)
- func (msh *Mesh) LatestLayer() types.LayerID
- func (msh *Mesh) LatestLayerInState() types.LayerID
- func (msh *Mesh) ProcessedLayer() types.LayerID
- func (msh *Mesh) SetZeroBlockLayer(lyr types.LayerID) error
- func (msh *Mesh) StoreTransactionsFromPool(blk *types.Block) error
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyExist = errors.New("block already exists in database")
ErrAlreadyExist error returned when adding an existing value to the database
var ErrInvalidLayer = errors.New("layer invalid")
ErrInvalidLayer signifies that hare has failed for a given layer, thus marking it invalid
var VERIFIED = []byte("verified")
VERIFIED refers to layers we pushed into the state
Functions ¶
func GenesisBlock ¶
GenesisBlock is a is the first static block that xists at the beginning of each network. it exist one layer before actual blocks could be created
func GenesisLayer ¶
GenesisLayer generates layer 0 should be removed after the genesis flow is implemented
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 AtxDbMock ¶
type AtxDbMock struct { ProcCnt int // contains filtered or unexported fields }
AtxDbMock is a mock of an activation DB
func (*AtxDbMock) AddAtx ¶
func (t *AtxDbMock) AddAtx(id types.ATXID, atx *types.ActivationTx)
AddAtx stores an ATX for later retrieval
func (*AtxDbMock) GetAtxHeader ¶
GetAtxHeader returns a new ActivationTxHeader
func (*AtxDbMock) GetFullAtx ¶
GetFullAtx returns a full ATX
func (*AtxDbMock) ProcessAtxs ¶
ProcessAtxs counts how many ATXs were processed
func (AtxDbMock) SyntacticallyValidateAtx ¶
SyntacticallyValidateAtx always returns no error
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 NewBlockFetcherDB ¶
func NewBlockFetcherDB(mdb *DB) *BlockFetcherDB
NewBlockFetcherDB returns reference to a BlockFetcherDB instance.
type Config ¶
Config defines the configuration options for Spacemesh rewards.
func DefaultMeshConfig ¶
func DefaultMeshConfig() Config
DefaultMeshConfig returns the default Config.
type DB ¶ added in v0.1.11
type DB struct { log.Log InputVectorBackupFunc func(id types.LayerID) ([]types.BlockID, error) // contains filtered or unexported fields }
DB represents a mesh database instance
func NewPersistentMeshDB ¶
NewPersistentMeshDB creates an instance of a mesh database
func (*DB) AddZeroBlockLayer ¶ added in v0.1.15
AddZeroBlockLayer tags lyr as a layer without blocks
func (*DB) BlocksByValidity ¶ added in v0.1.11
BlocksByValidity classifies a slice of blocks by validity
func (*DB) ContextualValidity ¶ added in v0.1.11
ContextualValidity retrieves opinion on block from the database
func (*DB) ForBlockInView ¶ added in v0.1.11
func (m *DB) ForBlockInView(view map[types.BlockID]struct{}, layer types.LayerID, blockHandler func(block *types.Block) (bool, error)) error
ForBlockInView traverses all blocks in a view and uses blockHandler func on each block The block handler func should return two values - a bool indicating whether or not we should stop traversing after the current block (happy flow) and an error indicating that an error occurred while handling the block, the traversing will stop in that case as well (error flow)
func (*DB) GetCoinflip ¶
GetCoinflip returns the weak coinflip result for the given layer
func (*DB) GetInputVectorBackupFunc ¶
func (m *DB) GetInputVectorBackupFunc() InputVectorBackupFunc
GetInputVectorBackupFunc gets the backup function for testing
func (*DB) GetLayerInputVectorByID ¶
GetLayerInputVectorByID gets the input vote vector for a layer (hare results)
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) GetProjection ¶ added in v0.1.11
func (m *DB) GetProjection(addr types.Address, prevNonce, prevBalance uint64) (nonce, balance uint64, err error)
GetProjection returns projection of address
func (*DB) GetRewards ¶ added in v0.1.11
GetRewards retrieves account's rewards by address
func (*DB) GetRewardsBySmesherID ¶ added in v0.1.28
GetRewardsBySmesherID retrieves rewards by smesherID
func (*DB) GetTransactions ¶ added in v0.1.11
func (m *DB) GetTransactions(transactions []types.TransactionID) (txs []*types.Transaction, missing map[types.TransactionID]struct{})
GetTransactions retrieves a list of txs by their id's
func (*DB) GetTransactionsByDestination ¶ added in v0.1.11
func (m *DB) GetTransactionsByDestination(l types.LayerID, account types.Address) (txs []types.TransactionID, err error)
GetTransactionsByDestination retrieves txs by destination and layer
func (*DB) GetTransactionsByOrigin ¶ added in v0.1.11
func (m *DB) GetTransactionsByOrigin(l types.LayerID, account types.Address) (txs []types.TransactionID, err error)
GetTransactionsByOrigin retrieves txs by origin and layer
func (*DB) InvalidateLayer ¶
InvalidateLayer receives notification from Hare that it failed for a layer. If Hare explicitly fails for a layer, we consider all blocks in that layer to be invalid. Note that simply not having received a layer from Hare as _validated_ is not sufficient information since we might still be waiting for Hare to finish for the layer. This method lets us know that Hare has given up. Note: this method is only called from the Hare's outputCollectionLoop, and there should only ever be one of those running. If it is called on any other code paths, it will need to be made goroutine safe.
func (*DB) LayerBlockIds ¶ added in v0.1.11
LayerBlockIds retrieves all block ids from a layer by layer index
func (*DB) LayerBlocks ¶ added in v0.1.11
LayerBlocks retrieves all blocks from a layer by layer index
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
PersistentData checks to see if db is empty
func (*DB) RecordCoinflip ¶
RecordCoinflip saves the weak coinflip result to memory for the given layer
func (*DB) SaveContextualValidity ¶ added in v0.1.11
SaveContextualValidity persists opinion on block to the database
func (*DB) SaveLayerInputVector ¶
SaveLayerInputVector saves the input vote vector for a layer (hare results)
func (*DB) SaveLayerInputVectorByID ¶
func (m *DB) SaveLayerInputVectorByID(ctx context.Context, id types.LayerID, blks []types.BlockID) error
SaveLayerInputVectorByID gets the input vote vector for a layer (hare results)
func (*DB) SetInputVectorBackupFunc ¶
func (m *DB) SetInputVectorBackupFunc(fn InputVectorBackupFunc)
SetInputVectorBackupFunc sets the backup function for testing
func (*DB) Transactions ¶
Transactions exports the transactions DB
type DbTransaction ¶
type DbTransaction struct { *types.Transaction Origin types.Address BlockID types.BlockID LayerID types.LayerID }
DbTransaction is the transaction type stored in DB
type InputVectorBackupFunc ¶
InputVectorBackupFunc specifies a backup function for testing
type Mesh ¶
Mesh is the logic layer above our mesh.DB database
func NewMesh ¶
func NewMesh(db *DB, atxDb AtxDB, rewardConfig Config, trtl tortoise, txPool txMemPool, pr txProcessor, logger log.Log) *Mesh
NewMesh creates a new instant of a mesh
func NewRecoveredMesh ¶
func NewRecoveredMesh(ctx context.Context, db *DB, atxDb AtxDB, rewardConfig Config, trtl tortoise, txPool txMemPool, pr txProcessor, logger log.Log) *Mesh
NewRecoveredMesh creates new instance of mesh with recovered mesh data fom database
func (*Mesh) AddBlockWithTxs ¶
AddBlockWithTxs adds a block to the database blk - the block to add txs - block txs that we dont have in our tx database yet
func (*Mesh) CacheWarmUp ¶ added in v0.1.4
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 ¶
GetAggregatedLayerHash returns the aggregated layer hash up to the specified layer
func (*Mesh) GetLayerHash ¶
GetLayerHash returns layer hash for received blocks
func (*Mesh) GetOrphanBlocksBefore ¶
GetOrphanBlocksBefore returns all known orphan blocks with layerID < l
func (*Mesh) HandleLateBlock ¶
HandleLateBlock process a late (contextually invalid) block.
func (*Mesh) HandleValidatedLayer ¶ added in v0.1.11
func (msh *Mesh) HandleValidatedLayer(ctx context.Context, validatedLayer types.LayerID, layer []types.BlockID)
HandleValidatedLayer receives hare output once it finishes running for a given layer
func (*Mesh) LatestLayer ¶
LatestLayer - returns the latest layer we saw from the network
func (*Mesh) LatestLayerInState ¶
LatestLayerInState returns the latest layer we applied to state
func (*Mesh) ProcessedLayer ¶
ProcessedLayer returns the last processed layer ID
func (*Mesh) SetZeroBlockLayer ¶ added in v0.1.6
SetZeroBlockLayer tags lyr as a layer without blocks