txs

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package txs is a generated GoMock package.

Index

Constants

View Source
const (
	MinTXGas = uint64(1) // gas required for the most basic transaction
)
View Source
const (
	RawFromDB = "raw"
)

Variables

View Source
var (
	RawTxCount = metrics.NewCounter(
		"raw_txs",
		namespace,
		"number of unparsed/raw transactions",
		[]string{"outcome"},
	)
)

Functions

func ShuffleWithNonceOrder

func ShuffleWithNonceOrder(
	logger log.Log,
	rng *rand.Rand,
	numTXs int,
	ntxs []*NanoTX,
	byAddrAndNonce map[types.Address][]*NanoTX,
) []types.TransactionID

ShuffleWithNonceOrder perform a Fisher-Yates shuffle on the transactions. note that after shuffling, the original list of transactions are no longer in nonce order within the same principal. we simply check which principal occupies the spot after the shuffle and retrieve their transactions in nonce order.

Types

type CSConfig

type CSConfig struct {
	BlockGasLimit     uint64
	NumTXsPerProposal int
}

CSConfig is the config for the conservative state/cache.

type Cache

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

func NewCache

func NewCache(s stateFunc, logger log.Log) *Cache

func (*Cache) Add

func (c *Cache) Add(ctx context.Context, db *sql.Database, tx *types.Transaction, received time.Time, mustPersist bool) error

func (*Cache) ApplyLayer

func (c *Cache) ApplyLayer(
	ctx context.Context,
	db *sql.Database,
	lid types.LayerID,
	bid types.BlockID,
	results []types.TransactionWithResult,
	ineffective []types.Transaction,
) error

ApplyLayer retires the applied transactions from the cache and updates the balances.

func (*Cache) BuildFromTXs

func (c *Cache) BuildFromTXs(rst []*types.MeshTransaction, blockSeed []byte) error

BuildFromTXs builds the cache from the provided transactions.

func (*Cache) Get

func (c *Cache) Get(tid types.TransactionID) *NanoTX

Get gets a transaction from the cache.

func (*Cache) GetMempool

func (c *Cache) GetMempool(logger log.Log) map[types.Address][]*NanoTX

GetMempool returns all the transactions that eligible for a proposal/block.

func (*Cache) GetProjection

func (c *Cache) GetProjection(addr types.Address) (uint64, uint64)

GetProjection returns the projected nonce and balance for an account, including pending transactions that are paced in proposals/blocks but not yet applied to the state.

func (*Cache) Has

func (c *Cache) Has(tid types.TransactionID) bool

Has returns true if transaction exists in the cache.

func (*Cache) LinkTXsWithBlock

func (c *Cache) LinkTXsWithBlock(db *sql.Database, lid types.LayerID, bid types.BlockID, tids []types.TransactionID) error

LinkTXsWithBlock associates the transactions to a block.

func (*Cache) LinkTXsWithProposal

func (c *Cache) LinkTXsWithProposal(db *sql.Database, lid types.LayerID, pid types.ProposalID, tids []types.TransactionID) error

LinkTXsWithProposal associates the transactions to a proposal.

func (*Cache) MoreInDB

func (c *Cache) MoreInDB(addr types.Address) bool

func (*Cache) RevertToLayer

func (c *Cache) RevertToLayer(db *sql.Database, revertTo types.LayerID) error

type ConservativeState

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

ConservativeState provides the conservative version of the VM state by taking into accounts of nonce and balances for pending transactions in un-applied blocks and mempool.

func NewConservativeState

func NewConservativeState(state vmState, db *sql.Database, opts ...ConservativeStateOpt) *ConservativeState

NewConservativeState returns a ConservativeState.

func (*ConservativeState) AddToCache

func (cs *ConservativeState) AddToCache(ctx context.Context, tx *types.Transaction, received time.Time) error

AddToCache adds the provided transaction to the conservative cache.

func (*ConservativeState) AddToDB

func (cs *ConservativeState) AddToDB(tx *types.Transaction) error

AddToDB adds a transaction to the database.

func (*ConservativeState) GetMeshHash

func (cs *ConservativeState) GetMeshHash(lid types.LayerID) (types.Hash32, error)

GetMeshHash gets the aggregated layer hash at the specified layer.

func (*ConservativeState) GetMeshTransaction

func (cs *ConservativeState) GetMeshTransaction(tid types.TransactionID) (*types.MeshTransaction, error)

GetMeshTransaction retrieves a tx by its id.

func (*ConservativeState) GetMeshTransactions

func (cs *ConservativeState) GetMeshTransactions(ids []types.TransactionID) ([]*types.MeshTransaction, map[types.TransactionID]struct{})

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

func (*ConservativeState) GetProjection

func (cs *ConservativeState) GetProjection(addr types.Address) (uint64, uint64)

GetProjection returns the projected nonce and balance for an account, including pending transactions that are paced in proposals/blocks but not yet applied to the state.

func (*ConservativeState) GetTransactionsByAddress

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

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

func (*ConservativeState) HasTx

func (cs *ConservativeState) HasTx(tid types.TransactionID) (bool, error)

HasTx returns true if transaction exists in the cache.

func (*ConservativeState) LinkTXsWithBlock

func (cs *ConservativeState) LinkTXsWithBlock(lid types.LayerID, bid types.BlockID, tids []types.TransactionID) error

LinkTXsWithBlock associates the transactions to a block.

func (*ConservativeState) LinkTXsWithProposal

func (cs *ConservativeState) LinkTXsWithProposal(lid types.LayerID, pid types.ProposalID, tids []types.TransactionID) error

LinkTXsWithProposal associates the transactions to a proposal.

func (*ConservativeState) RevertCache

func (cs *ConservativeState) RevertCache(revertTo types.LayerID) error

RevertCache reverts the conservative cache to the given layer.

func (*ConservativeState) SelectProposalTXs

func (cs *ConservativeState) SelectProposalTXs(lid types.LayerID, numEligibility int) []types.TransactionID

SelectProposalTXs picks a specific number of random txs for miner to pack in a proposal.

func (*ConservativeState) UpdateCache

func (cs *ConservativeState) UpdateCache(
	ctx context.Context,
	lid types.LayerID,
	bid types.BlockID,
	results []types.TransactionWithResult,
	ineffective []types.Transaction,
) error

func (*ConservativeState) Validation

Validation initializes validation request.

type ConservativeStateOpt

type ConservativeStateOpt func(cs *ConservativeState)

ConservativeStateOpt for configuring conservative state.

func WithCSConfig

func WithCSConfig(cfg CSConfig) ConservativeStateOpt

WithCSConfig defines the config used for the conservative state.

func WithLogger

func WithLogger(logger log.Log) ConservativeStateOpt

WithLogger defines logger for conservative state.

type MockconStateCache

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

MockconStateCache is a mock of conStateCache interface.

func NewMockconStateCache

func NewMockconStateCache(ctrl *gomock.Controller) *MockconStateCache

NewMockconStateCache creates a new mock instance.

func (*MockconStateCache) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockconStateCache) GetMempool

func (m *MockconStateCache) GetMempool(arg0 log.Log) map[types.Address][]*NanoTX

GetMempool mocks base method.

type MockconStateCacheMockRecorder

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

MockconStateCacheMockRecorder is the mock recorder for MockconStateCache.

func (*MockconStateCacheMockRecorder) GetMempool

func (mr *MockconStateCacheMockRecorder) GetMempool(arg0 interface{}) *conStateCacheGetMempoolCall

GetMempool indicates an expected call of GetMempool.

type MockconservativeState

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

MockconservativeState is a mock of conservativeState interface.

func NewMockconservativeState

func NewMockconservativeState(ctrl *gomock.Controller) *MockconservativeState

NewMockconservativeState creates a new mock instance.

func (*MockconservativeState) AddToCache

func (m *MockconservativeState) AddToCache(arg0 context.Context, arg1 *types.Transaction, arg2 time.Time) error

AddToCache mocks base method.

func (*MockconservativeState) AddToDB

func (m *MockconservativeState) AddToDB(arg0 *types.Transaction) error

AddToDB mocks base method.

func (*MockconservativeState) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockconservativeState) GetMeshTransaction

func (m *MockconservativeState) GetMeshTransaction(arg0 types.TransactionID) (*types.MeshTransaction, error)

GetMeshTransaction mocks base method.

func (*MockconservativeState) HasTx

HasTx mocks base method.

func (*MockconservativeState) Validation

Validation mocks base method.

type MockconservativeStateMockRecorder

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

MockconservativeStateMockRecorder is the mock recorder for MockconservativeState.

func (*MockconservativeStateMockRecorder) AddToCache

func (mr *MockconservativeStateMockRecorder) AddToCache(arg0, arg1, arg2 interface{}) *conservativeStateAddToCacheCall

AddToCache indicates an expected call of AddToCache.

func (*MockconservativeStateMockRecorder) AddToDB

func (mr *MockconservativeStateMockRecorder) AddToDB(arg0 interface{}) *conservativeStateAddToDBCall

AddToDB indicates an expected call of AddToDB.

func (*MockconservativeStateMockRecorder) GetMeshTransaction

func (mr *MockconservativeStateMockRecorder) GetMeshTransaction(arg0 interface{}) *conservativeStateGetMeshTransactionCall

GetMeshTransaction indicates an expected call of GetMeshTransaction.

func (*MockconservativeStateMockRecorder) HasTx

func (mr *MockconservativeStateMockRecorder) HasTx(arg0 interface{}) *conservativeStateHasTxCall

HasTx indicates an expected call of HasTx.

func (*MockconservativeStateMockRecorder) Validation

func (mr *MockconservativeStateMockRecorder) Validation(arg0 interface{}) *conservativeStateValidationCall

Validation indicates an expected call of Validation.

type MockvmState

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

MockvmState is a mock of vmState interface.

func NewMockvmState

func NewMockvmState(ctrl *gomock.Controller) *MockvmState

NewMockvmState creates a new mock instance.

func (*MockvmState) EXPECT

func (m *MockvmState) EXPECT() *MockvmStateMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockvmState) GetAllAccounts

func (m *MockvmState) GetAllAccounts() ([]*types.Account, error)

GetAllAccounts mocks base method.

func (*MockvmState) GetBalance

func (m *MockvmState) GetBalance(arg0 types.Address) (uint64, error)

GetBalance mocks base method.

func (*MockvmState) GetLayerApplied

func (m *MockvmState) GetLayerApplied(arg0 types.TransactionID) (types.LayerID, error)

GetLayerApplied mocks base method.

func (*MockvmState) GetLayerStateRoot

func (m *MockvmState) GetLayerStateRoot(arg0 types.LayerID) (types.Hash32, error)

GetLayerStateRoot mocks base method.

func (*MockvmState) GetNonce

func (m *MockvmState) GetNonce(arg0 types.Address) (types.Nonce, error)

GetNonce mocks base method.

func (*MockvmState) GetStateRoot

func (m *MockvmState) GetStateRoot() (types.Hash32, error)

GetStateRoot mocks base method.

func (*MockvmState) Validation

func (m *MockvmState) Validation(arg0 types.RawTx) system.ValidationRequest

Validation mocks base method.

type MockvmStateMockRecorder

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

MockvmStateMockRecorder is the mock recorder for MockvmState.

func (*MockvmStateMockRecorder) GetAllAccounts

func (mr *MockvmStateMockRecorder) GetAllAccounts() *vmStateGetAllAccountsCall

GetAllAccounts indicates an expected call of GetAllAccounts.

func (*MockvmStateMockRecorder) GetBalance

func (mr *MockvmStateMockRecorder) GetBalance(arg0 interface{}) *vmStateGetBalanceCall

GetBalance indicates an expected call of GetBalance.

func (*MockvmStateMockRecorder) GetLayerApplied

func (mr *MockvmStateMockRecorder) GetLayerApplied(arg0 interface{}) *vmStateGetLayerAppliedCall

GetLayerApplied indicates an expected call of GetLayerApplied.

func (*MockvmStateMockRecorder) GetLayerStateRoot

func (mr *MockvmStateMockRecorder) GetLayerStateRoot(arg0 interface{}) *vmStateGetLayerStateRootCall

GetLayerStateRoot indicates an expected call of GetLayerStateRoot.

func (*MockvmStateMockRecorder) GetNonce

func (mr *MockvmStateMockRecorder) GetNonce(arg0 interface{}) *vmStateGetNonceCall

GetNonce indicates an expected call of GetNonce.

func (*MockvmStateMockRecorder) GetStateRoot

func (mr *MockvmStateMockRecorder) GetStateRoot() *vmStateGetStateRootCall

GetStateRoot indicates an expected call of GetStateRoot.

func (*MockvmStateMockRecorder) Validation

func (mr *MockvmStateMockRecorder) Validation(arg0 interface{}) *vmStateValidationCall

Validation indicates an expected call of Validation.

type NanoTX

type NanoTX struct {
	types.TxHeader
	ID types.TransactionID

	Received time.Time

	Block types.BlockID
	Layer types.LayerID
}

NanoTX represents minimal info about a transaction for the conservative cache/mempool.

func NewNanoTX

func NewNanoTX(mtx *types.MeshTransaction) *NanoTX

NewNanoTX converts a NanoTX instance from a MeshTransaction.

func (*NanoTX) Better

func (n *NanoTX) Better(other *NanoTX, blockSeed []byte) bool

Better returns true if this transaction takes priority than `other`. when the block seed is non-empty, this tx is being considered for a block. the block seed then is used to tie-break (deterministically) transactions for the same account/nonce.

func (*NanoTX) MaxSpending

func (n *NanoTX) MaxSpending() uint64

MaxSpending returns the maximal amount a transaction can spend.

func (*NanoTX) UpdateLayer

func (n *NanoTX) UpdateLayer(lid types.LayerID, bid types.BlockID)

UpdateLayer updates the layer of a transaction.

func (*NanoTX) UpdateLayerMaybe

func (n *NanoTX) UpdateLayerMaybe(lid types.LayerID, bid types.BlockID)

UpdateLayerMaybe updates the layer of a transaction if it's lower than the current value.

type TxHandler

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

TxHandler handles the transactions received via gossip or sync.

func NewTxHandler

func NewTxHandler(s conservativeState, id peer.ID, l log.Log) *TxHandler

NewTxHandler returns a new TxHandler.

func (*TxHandler) HandleBlockTransaction

func (th *TxHandler) HandleBlockTransaction(_ context.Context, expHash types.Hash32, _ p2p.Peer, data []byte) error

HandleBlockTransaction handles transactions received as a reference to a block.

func (*TxHandler) HandleGossipTransaction

func (th *TxHandler) HandleGossipTransaction(ctx context.Context, peer p2p.Peer, msg []byte) error

HandleGossipTransaction handles data received on the transactions gossip channel.

func (*TxHandler) HandleProposalTransaction

func (th *TxHandler) HandleProposalTransaction(ctx context.Context, expHash types.Hash32, _ p2p.Peer, msg []byte) error

HandleProposalTransaction handles data received on the transactions synced as a part of proposal.

func (*TxHandler) VerifyAndCacheTx

func (th *TxHandler) VerifyAndCacheTx(ctx context.Context, msg []byte) error

Jump to

Keyboard shortcuts

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