mesh

package
v0.1.10-docs-prerelease Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (

	// Genesis layer index
	Genesis = types.LayerID(0)
)

Variables

View Source
var ErrAlreadyExist = errors.New("block already exist in database")

ErrAlreadyExist error returned when adding an existing value to the database

View Source
var GenesisBlock = types.NewExistingBlock(0, []byte("genesis"))

GenesisBlock is a mock genesis block used until genesis flow is implemented

View Source
var TORTOISE = []byte("tortoise")

TORTOISE key for tortoise persistence in database

View Source
var VERIFIED = []byte("verified")

VERIFIED refers to layers we pushed into the state

Functions

func GenesisLayer

func GenesisLayer() *types.Layer

GenesisLayer generates layer 0 should be removed after the genesis flow is implemented

func NewSignedTx

func NewSignedTx(nonce uint64, rec types.Address, amount, gas, fee uint64, signer *signing.EdSigner) (*types.Transaction, error)

NewSignedTx is used in TESTS ONLY to generate signed txs

Types

type AtxDB

type AtxDB interface {
	ProcessAtxs(atxs []*types.ActivationTx) error
	GetAtxHeader(id types.ATXID) (*types.ActivationTxHeader, error)
	GetFullAtx(id types.ATXID) (*types.ActivationTx, error)
	SyntacticallyValidateAtx(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 NewAtxDbMock

func NewAtxDbMock() *AtxDbMock

NewAtxDbMock returns a new AtxDbMock

func (*AtxDbMock) AddAtx

func (t *AtxDbMock) AddAtx(id types.ATXID, atx *types.ActivationTx)

AddAtx stores an ATX for later retrieval

func (*AtxDbMock) GetAtxHeader

func (t *AtxDbMock) GetAtxHeader(id types.ATXID) (*types.ActivationTxHeader, error)

GetAtxHeader returns a new ActivationTxHeader

func (*AtxDbMock) GetFullAtx

func (t *AtxDbMock) GetFullAtx(id types.ATXID) (*types.ActivationTx, error)

GetFullAtx returns a full ATX

func (*AtxDbMock) ProcessAtxs

func (t *AtxDbMock) ProcessAtxs(atxs []*types.ActivationTx) error

ProcessAtxs counts how many ATXs were processed

func (AtxDbMock) SyntacticallyValidateAtx

func (AtxDbMock) SyntacticallyValidateAtx(*types.ActivationTx) error

SyntacticallyValidateAtx always returns no error

type Config

type Config struct {
	BaseReward *big.Int `mapstructure:"base-reward"`
}

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
	// contains filtered or unexported fields
}

DB represents a mesh database instance

func NewMemMeshDB

func NewMemMeshDB(log log.Log) *DB

NewMemMeshDB is a mock used for testing

func NewPersistentMeshDB

func NewPersistentMeshDB(path string, blockCacheSize int, log log.Log) (*DB, error)

NewPersistentMeshDB creates an instance of a mesh database

func (*DB) AddBlock added in v0.1.11

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

AddBlock adds a block to the database

func (*DB) BlocksByValidity added in v0.1.11

func (m *DB) BlocksByValidity(blocks []*types.Block) (validBlocks, invalidBlocks []*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) ContextuallyValidBlock added in v0.1.11

func (m *DB) ContextuallyValidBlock(layer types.LayerID) (map[types.BlockID]struct{}, error)

ContextuallyValidBlock - returns the contextually valid blocks for the provided layer

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) GetBlock added in v0.1.11

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

GetBlock gets a block from the database by id

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

func (m *DB) GetRewards(account types.Address) (rewards []types.Reward, err error)

GetRewards retrieves account's rewards by address

func (*DB) GetTransaction added in v0.1.11

func (m *DB) GetTransaction(id types.TransactionID) (*types.Transaction, error)

GetTransaction retrieves a tx by its id

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) GetTransactionsByDestination added in v0.1.11

func (m *DB) GetTransactionsByDestination(l types.LayerID, account types.Address) (txs []types.TransactionID)

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)

GetTransactionsByOrigin retrieves txs by origin and layer

func (*DB) LayerBlockIds added in v0.1.11

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

LayerBlockIds retrieves all block ids from a layer by layer index

func (*DB) LayerBlocks added in v0.1.11

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

LayerBlocks retrieves all blocks from a layer by layer index

func (*DB) Persist added in v0.1.11

func (m *DB) Persist(key []byte, v interface{}) error

Persist persists an item v into the database using key as its id

func (*DB) PersistentData added in v0.1.11

func (m *DB) PersistentData() bool

PersistentData checks to see if db is empty

func (*DB) Retrieve added in v0.1.11

func (m *DB) Retrieve(key []byte, v interface{}) (interface{}, error)

Retrieve retrieves item by key into v

func (*DB) SaveContextualValidity added in v0.1.11

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

SaveContextualValidity persists opinion on block to the database

type Mesh

type Mesh struct {
	log.Log
	*DB
	AtxDB

	Validator
	// contains filtered or unexported fields
}

Mesh is the logic layer above our mesh.DB database

func NewMesh

func NewMesh(db *DB, atxDb AtxDB, rewardConfig Config, mesh tortoise, txInvalidator txMemPoolInValidator, atxInvalidator atxMemPoolInValidator, pr txProcessor, logger log.Log) *Mesh

NewMesh creates a new instant of a mesh

func NewRecoveredMesh

func NewRecoveredMesh(db *DB, atxDb AtxDB, rewardConfig Config, mesh tortoise, txInvalidator txMemPoolInValidator, atxInvalidator atxMemPoolInValidator, pr txProcessor, logger log.Log) *Mesh

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

func (*Mesh) AddBlock

func (msh *Mesh) AddBlock(blk *types.Block) error

AddBlock adds a block to the database ignoring the block txs/atxs ***USED ONLY FOR TESTS***

func (*Mesh) AddBlockWithTxs

func (msh *Mesh) AddBlockWithTxs(blk *types.Block, txs []*types.Transaction, atxs []*types.ActivationTx) error

AddBlockWithTxs adds a block to the database blk - the block to add txs - block txs that we dont have in our tx database yet atxs - block atxs that we dont have in our atx database yet

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(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) GetLayer

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

GetLayer returns Layer i from the database

func (*Mesh) GetOrphanBlocksBefore

func (msh *Mesh) GetOrphanBlocksBefore(l types.LayerID) ([]types.BlockID, error)

GetOrphanBlocksBefore returns all known orphan blocks with layerID < l

func (*Mesh) GetProcessedLayer added in v0.1.11

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

GetProcessedLayer returns a layer only if it has already been processed

func (*Mesh) HandleValidatedLayer added in v0.1.11

func (msh *Mesh) HandleValidatedLayer(validatedLayer types.LayerID, layer []types.BlockID)

HandleValidatedLayer handles layer valid blocks as decided by hare

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

func (msh *Mesh) SetBlockBuilder(blockBuilder blockBuilder)

SetBlockBuilder sets the block builder in use by mesh

func (*Mesh) SetLatestLayer

func (msh *Mesh) SetLatestLayer(idx types.LayerID)

SetLatestLayer sets the latest layer we saw from the network

func (*Mesh) SetZeroBlockLayer added in v0.1.6

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

SetZeroBlockLayer tags lyr as a layer without blocks

type Validator added in v0.1.6

type Validator interface {
	ValidateLayer(layer *types.Layer)
	HandleLateBlock(bl *types.Block)
	ProcessedLayer() types.LayerID
	SetProcessedLayer(lyr types.LayerID)
}

Validator interface to be used in tests to mock validation flow

Jump to

Keyboard shortcuts

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