Documentation ¶
Overview ¶
Package miner is responsible for creating valid blocks that contain valid activation transactions and transactions
Index ¶
- Constants
- type AtxMemPool
- type BlockBuilder
- type TxMempool
- func (t *TxMempool) Get(id types.TransactionID) (*types.Transaction, error)
- func (t *TxMempool) GetProjection(addr types.Address, prevNonce, prevBalance uint64) (nonce, balance uint64)
- func (t *TxMempool) GetTxIdsByAddress(addr types.Address) []types.TransactionID
- func (t *TxMempool) GetTxsForBlock(numOfTxs int, ...) ([]types.TransactionID, error)
- func (t *TxMempool) Invalidate(id types.TransactionID)
- func (t *TxMempool) Put(id types.TransactionID, tx *types.Transaction)
Constants ¶
const AtxsPerBlockLimit = 100
AtxsPerBlockLimit indicates the maximum number of atxs a block can reference
const IncomingTxProtocol = "TxGossip"
IncomingTxProtocol is the protocol identifier for tx received by gossip that is used by the p2p
const MaxTransactionsPerBlock = 200 //todo: move to config (#1924)
MaxTransactionsPerBlock indicates the maximum transactions a block can reference
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AtxMemPool ¶
type AtxMemPool struct {
// contains filtered or unexported fields
}
AtxMemPool is a memory store that holds all received ATXs from gossip network by their ids
func NewAtxMemPool ¶
func NewAtxMemPool() *AtxMemPool
NewAtxMemPool creates a struct holding atxs by id
func (*AtxMemPool) Get ¶
func (mem *AtxMemPool) Get(id types.ATXID) (*types.ActivationTx, error)
Get retrieves the atx by the provided id id, it returns a reference to the found atx struct or an error if not
func (*AtxMemPool) GetAllItems ¶
func (mem *AtxMemPool) GetAllItems() []*types.ActivationTx
GetAllItems creates and returns a list of all items found in cache
func (*AtxMemPool) Invalidate ¶
func (mem *AtxMemPool) Invalidate(id types.ATXID)
Invalidate removes the provided atx by its id. it does not return error if id is not found
func (*AtxMemPool) Put ¶
func (mem *AtxMemPool) Put(atx *types.ActivationTx)
Put insets an atx into the mempool
type BlockBuilder ¶
type BlockBuilder struct { log.Log AtxPool *AtxMemPool TransactionPool txPool // contains filtered or unexported fields }
BlockBuilder is the struct that orchestrates the building of blocks, it is responsible for receiving hare results. referencing txs and atxs from mem pool and referencing them in the created block it is also responsible for listening to the clock and querying when a block should be created according to the block oracle
func NewBlockBuilder ¶
func NewBlockBuilder(minerID types.NodeID, sgn signer, net p2p.Service, beginRoundEvent chan types.LayerID, hdist int, txPool txPool, atxPool *AtxMemPool, weakCoin weakCoinProvider, orph meshProvider, hare hareResultProvider, blockOracle blockOracle, txValidator txValidator, atxValidator atxValidator, syncer syncer, atxsPerBlock int, projector projector, lg log.Log) *BlockBuilder
NewBlockBuilder creates a struct of block builder type.
func (*BlockBuilder) Close ¶
func (t *BlockBuilder) Close() error
Close stops listeners and stops trying to create block in layers
func (*BlockBuilder) Start ¶
func (t *BlockBuilder) Start() error
Start starts the process of creating a block, it listens for txs and atxs received by gossip, and starts querying block oracle when it should create a block. This function returns an error if Start was already called once
func (*BlockBuilder) ValidateAndAddTxToPool ¶
func (t *BlockBuilder) ValidateAndAddTxToPool(tx *types.Transaction) error
ValidateAndAddTxToPool validates the provided tx nonce and balance with projector and puts it in the transaction pool it returns an error if the provided tx is not valid
type TxMempool ¶
type TxMempool struct {
// contains filtered or unexported fields
}
TxMempool is a struct that holds txs received via gossip network
func (*TxMempool) Get ¶
func (t *TxMempool) Get(id types.TransactionID) (*types.Transaction, error)
Get returns transaction by provided id, it returns an error if transaction is not found
func (*TxMempool) GetProjection ¶
func (t *TxMempool) GetProjection(addr types.Address, prevNonce, prevBalance uint64) (nonce, balance uint64)
GetProjection returns the estimated nonce and balance for the provided address addr and previous nonce and balance projecting state is done by applying transactions from the pool
func (*TxMempool) GetTxIdsByAddress ¶
func (t *TxMempool) GetTxIdsByAddress(addr types.Address) []types.TransactionID
GetTxIdsByAddress returns all transactions from/to a specific address
func (*TxMempool) GetTxsForBlock ¶
func (t *TxMempool) GetTxsForBlock(numOfTxs int, getState func(addr types.Address) (nonce, balance uint64, err error)) ([]types.TransactionID, error)
GetTxsForBlock gets a specific number of random txs for a block. This function also receives a state calculation function to allow returning only transactions that will probably be valid
func (*TxMempool) Invalidate ¶
func (t *TxMempool) Invalidate(id types.TransactionID)
Invalidate removes transaction from pool
func (*TxMempool) Put ¶
func (t *TxMempool) Put(id types.TransactionID, tx *types.Transaction)
Put inserts a transaction into the mem pool. It indexes it by source and dest addresses as well