mesh

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Genesis = types.LayerID(0)
)

Variables

View Source
var ErrAlreadyExist = errors.New("block already exist in database")
View Source
var FALSE = []byte{0}
View Source
var GenesisBlock = types.NewExistingBlock(0, []byte("genesis"))
View Source
var LATEST = []byte("latest")
View Source
var LAYERHASH = []byte("layer hash")
View Source
var PROCESSED = []byte("proccessed")
View Source
var TORTOISE = []byte("tortoise")
View Source
var TRUE = []byte{1}
View Source
var VERIFIED = []byte("verified") //refers to layers we pushed into the state

Functions

func CalculateLayerReward

func CalculateLayerReward(id types.LayerID, params Config) *big.Int

func GenesisLayer

func GenesisLayer() *types.Layer

func NewSignedTx

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

TEST ONLY

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
}

type AtxDbMock

type AtxDbMock struct {
	ProcCnt int
	// contains filtered or unexported fields
}

func NewAtxDbMock

func NewAtxDbMock() *AtxDbMock

func (*AtxDbMock) AddAtx

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

func (*AtxDbMock) GetAtxHeader

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

func (*AtxDbMock) GetFullAtx

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

func (*AtxDbMock) ProcessAtxs

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

func (AtxDbMock) SyntacticallyValidateAtx

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

type AtxMemPoolInValidator

type AtxMemPoolInValidator interface {
	Invalidate(id types.AtxId)
}

type BlockBuilder

type BlockBuilder interface {
	ValidateAndAddTxToPool(tx *types.Transaction) error
}

type BlockCache

type BlockCache struct {
	*lru.Cache
	// contains filtered or unexported fields
}

func NewBlockCache

func NewBlockCache(cap int) BlockCache

func (BlockCache) Cap added in v0.1.2

func (bc BlockCache) Cap() int

func (BlockCache) Get

func (bc BlockCache) Get(id types.BlockID) *types.Block

type Config

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

func DefaultMeshConfig

func DefaultMeshConfig() Config

type DbTransaction

type DbTransaction struct {
	*types.Transaction
	Origin types.Address
}

func NewDbTransaction

func NewDbTransaction(tx *types.Transaction) *DbTransaction

func (DbTransaction) GetTransaction

func (t DbTransaction) GetTransaction() *types.Transaction

type Mesh

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

func NewMesh

func NewMesh(db *MeshDB, atxDb AtxDB, rewardConfig Config, mesh MeshValidator, txInvalidator TxMemPoolInValidator, atxInvalidator AtxMemPoolInValidator, pr TxProcessor, logger log.Log) *Mesh

func NewRecoveredMesh

func NewRecoveredMesh(db *MeshDB, atxDb AtxDB, rewardConfig Config, mesh MeshValidator, txInvalidator TxMemPoolInValidator, atxInvalidator AtxMemPoolInValidator, pr TxProcessor, logger log.Log) *Mesh

func (*Mesh) AccumulateRewards

func (m *Mesh) AccumulateRewards(l *types.Layer, params Config)

func (*Mesh) AddBlock

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

func (*Mesh) AddBlockWithTxs

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

func (*Mesh) CacheWarmUp added in v0.1.4

func (msh *Mesh) CacheWarmUp()

func (*Mesh) ExtractUniqueOrderedTransactions

func (m *Mesh) ExtractUniqueOrderedTransactions(l *types.Layer) (validBlockTxs, invalidBlockTxs []*types.Transaction)

func (*Mesh) GetATXs

func (m *Mesh) GetATXs(atxIds []types.AtxId) (map[types.AtxId]*types.ActivationTx, []types.AtxId)

func (*Mesh) GetLatestView

func (m *Mesh) GetLatestView() []types.BlockID

func (*Mesh) GetLayer

func (m *Mesh) GetLayer(index types.LayerID) (*types.Layer, error)

func (*Mesh) GetOrphanBlocksBefore

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

func (*Mesh) GetVerifiedLayer

func (m *Mesh) GetVerifiedLayer(i types.LayerID) (*types.Layer, error)

todo consider adding a boolean for layer validity instead error

func (*Mesh) HandleLateBlock

func (m *Mesh) HandleLateBlock(b *types.Block)

func (*Mesh) LatestLayer

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

LatestLayer - returns the latest layer we saw from the network

func (*Mesh) LatestLayerInState

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

func (*Mesh) ProcessedLayer

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

func (*Mesh) PushTransactions

func (m *Mesh) PushTransactions(l *types.Layer)

func (*Mesh) SetBlockBuilder

func (m *Mesh) SetBlockBuilder(blockBuilder BlockBuilder)

func (*Mesh) SetLatestLayer

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

func (*Mesh) ValidateLayer

func (m *Mesh) ValidateLayer(lyr *types.Layer)

type MeshDB

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

func NewMemMeshDB

func NewMemMeshDB(log log.Log) *MeshDB

func NewPersistentMeshDB

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

func (*MeshDB) AddBlock

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

func (*MeshDB) BlocksByValidity

func (m *MeshDB) BlocksByValidity(blocks []*types.Block) (validBlocks, invalidBlocks []*types.Block)

func (*MeshDB) Close

func (m *MeshDB) Close()

func (*MeshDB) ContextualValidity

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

func (*MeshDB) ContextuallyValidBlock

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

ContextuallyValidBlock - returns the contextually valid blocks for the provided layer

func (*MeshDB) ForBlockInView

func (m *MeshDB) ForBlockInView(view map[types.BlockID]struct{}, layer types.LayerID, blockHandler func(block *types.Block) (bool, error)) error

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 (*MeshDB) GetBlock

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

func (*MeshDB) GetProjection

func (m *MeshDB) GetProjection(addr types.Address, prevNonce, prevBalance uint64) (nonce, balance uint64, err error)

func (*MeshDB) GetRewards

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

func (*MeshDB) GetTransaction

func (m *MeshDB) GetTransaction(id types.TransactionId) (*types.Transaction, error)

func (*MeshDB) GetTransactions

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

func (*MeshDB) GetTransactionsByDestination

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

func (*MeshDB) GetTransactionsByOrigin

func (m *MeshDB) GetTransactionsByOrigin(l types.LayerID, account types.Address) (txs []types.TransactionId)

func (*MeshDB) LayerBlockIds

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

func (*MeshDB) LayerBlocks

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

func (*MeshDB) Persist

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

func (*MeshDB) PersistentData

func (m *MeshDB) PersistentData() bool

func (*MeshDB) Retrieve

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

func (*MeshDB) SaveContextualValidity

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

type MeshValidator

type MeshValidator interface {
	HandleIncomingLayer(layer *types.Layer) (types.LayerID, types.LayerID)
	LatestComplete() types.LayerID
	PersistTortoise() error
	HandleLateBlock(bl *types.Block) (types.LayerID, types.LayerID)
}

type StateObj

type StateObj interface {
	Address() types.Address
	Nonce() uint64
	Balance() *big.Int
}

type TxMemPoolInValidator

type TxMemPoolInValidator interface {
	Invalidate(id types.TransactionId)
}

type TxProcessor

type TxProcessor interface {
	ApplyTransactions(layer types.LayerID, txs []*types.Transaction) (int, error)
	ApplyRewards(layer types.LayerID, miners []types.Address, reward *big.Int)
	ValidateSignature(s types.Signed) (types.Address, error)
	AddressExists(addr types.Address) bool
	ValidateNonceAndBalance(transaction *types.Transaction) error
	GetLayerApplied(txId types.TransactionId) *types.LayerID
	GetStateRoot() types.Hash32
	LoadState(layer types.LayerID) error
}

Jump to

Keyboard shortcuts

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