txs

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT Imports: 30 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 *zap.Logger,
	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 *zap.Logger) *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 *zap.Logger) 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 database.

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 *zap.Logger) 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 *zap.Logger) map[types.Address][]*NanoTX

GetMempool mocks base method.

type MockconStateCacheGetMempoolCall added in v1.4.0

type MockconStateCacheGetMempoolCall struct {
	*gomock.Call
}

MockconStateCacheGetMempoolCall wrap *gomock.Call

func (*MockconStateCacheGetMempoolCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockconStateCacheGetMempoolCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockconStateCacheGetMempoolCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

type MockconStateCacheMockRecorder

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

MockconStateCacheMockRecorder is the mock recorder for MockconStateCache.

func (*MockconStateCacheMockRecorder) GetMempool

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 MockconservativeStateAddToCacheCall added in v1.4.0

type MockconservativeStateAddToCacheCall struct {
	*gomock.Call
}

MockconservativeStateAddToCacheCall wrap *gomock.Call

func (*MockconservativeStateAddToCacheCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockconservativeStateAddToCacheCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockconservativeStateAddToCacheCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

type MockconservativeStateAddToDBCall added in v1.4.0

type MockconservativeStateAddToDBCall struct {
	*gomock.Call
}

MockconservativeStateAddToDBCall wrap *gomock.Call

func (*MockconservativeStateAddToDBCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockconservativeStateAddToDBCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockconservativeStateAddToDBCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

type MockconservativeStateGetMeshTransactionCall added in v1.4.0

type MockconservativeStateGetMeshTransactionCall struct {
	*gomock.Call
}

MockconservativeStateGetMeshTransactionCall wrap *gomock.Call

func (*MockconservativeStateGetMeshTransactionCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockconservativeStateGetMeshTransactionCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockconservativeStateGetMeshTransactionCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

type MockconservativeStateHasTxCall added in v1.4.0

type MockconservativeStateHasTxCall struct {
	*gomock.Call
}

MockconservativeStateHasTxCall wrap *gomock.Call

func (*MockconservativeStateHasTxCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockconservativeStateHasTxCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockconservativeStateHasTxCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

type MockconservativeStateMockRecorder

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

MockconservativeStateMockRecorder is the mock recorder for MockconservativeState.

func (*MockconservativeStateMockRecorder) AddToCache

AddToCache indicates an expected call of AddToCache.

func (*MockconservativeStateMockRecorder) AddToDB

AddToDB indicates an expected call of AddToDB.

func (*MockconservativeStateMockRecorder) GetMeshTransaction

GetMeshTransaction indicates an expected call of GetMeshTransaction.

func (*MockconservativeStateMockRecorder) HasTx

HasTx indicates an expected call of HasTx.

func (*MockconservativeStateMockRecorder) Validation

Validation indicates an expected call of Validation.

type MockconservativeStateValidationCall added in v1.4.0

type MockconservativeStateValidationCall struct {
	*gomock.Call
}

MockconservativeStateValidationCall wrap *gomock.Call

func (*MockconservativeStateValidationCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockconservativeStateValidationCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockconservativeStateValidationCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

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 MockvmStateGetAllAccountsCall added in v1.4.0

type MockvmStateGetAllAccountsCall struct {
	*gomock.Call
}

MockvmStateGetAllAccountsCall wrap *gomock.Call

func (*MockvmStateGetAllAccountsCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockvmStateGetAllAccountsCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockvmStateGetAllAccountsCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

type MockvmStateGetBalanceCall added in v1.4.0

type MockvmStateGetBalanceCall struct {
	*gomock.Call
}

MockvmStateGetBalanceCall wrap *gomock.Call

func (*MockvmStateGetBalanceCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockvmStateGetBalanceCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockvmStateGetBalanceCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

type MockvmStateGetLayerAppliedCall added in v1.4.0

type MockvmStateGetLayerAppliedCall struct {
	*gomock.Call
}

MockvmStateGetLayerAppliedCall wrap *gomock.Call

func (*MockvmStateGetLayerAppliedCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockvmStateGetLayerAppliedCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockvmStateGetLayerAppliedCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

type MockvmStateGetLayerStateRootCall added in v1.4.0

type MockvmStateGetLayerStateRootCall struct {
	*gomock.Call
}

MockvmStateGetLayerStateRootCall wrap *gomock.Call

func (*MockvmStateGetLayerStateRootCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockvmStateGetLayerStateRootCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockvmStateGetLayerStateRootCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

type MockvmStateGetNonceCall added in v1.4.0

type MockvmStateGetNonceCall struct {
	*gomock.Call
}

MockvmStateGetNonceCall wrap *gomock.Call

func (*MockvmStateGetNonceCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockvmStateGetNonceCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockvmStateGetNonceCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

type MockvmStateGetStateRootCall added in v1.4.0

type MockvmStateGetStateRootCall struct {
	*gomock.Call
}

MockvmStateGetStateRootCall wrap *gomock.Call

func (*MockvmStateGetStateRootCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockvmStateGetStateRootCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockvmStateGetStateRootCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

type MockvmStateMockRecorder

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

MockvmStateMockRecorder is the mock recorder for MockvmState.

func (*MockvmStateMockRecorder) GetAllAccounts

GetAllAccounts indicates an expected call of GetAllAccounts.

func (*MockvmStateMockRecorder) GetBalance

GetBalance indicates an expected call of GetBalance.

func (*MockvmStateMockRecorder) GetLayerApplied

func (mr *MockvmStateMockRecorder) GetLayerApplied(arg0 any) *MockvmStateGetLayerAppliedCall

GetLayerApplied indicates an expected call of GetLayerApplied.

func (*MockvmStateMockRecorder) GetLayerStateRoot

func (mr *MockvmStateMockRecorder) GetLayerStateRoot(arg0 any) *MockvmStateGetLayerStateRootCall

GetLayerStateRoot indicates an expected call of GetLayerStateRoot.

func (*MockvmStateMockRecorder) GetNonce

GetNonce indicates an expected call of GetNonce.

func (*MockvmStateMockRecorder) GetStateRoot

GetStateRoot indicates an expected call of GetStateRoot.

func (*MockvmStateMockRecorder) Validation

Validation indicates an expected call of Validation.

type MockvmStateValidationCall added in v1.4.0

type MockvmStateValidationCall struct {
	*gomock.Call
}

MockvmStateValidationCall wrap *gomock.Call

func (*MockvmStateValidationCall) Do added in v1.4.0

Do rewrite *gomock.Call.Do

func (*MockvmStateValidationCall) DoAndReturn added in v1.4.0

DoAndReturn rewrite *gomock.Call.DoAndReturn

func (*MockvmStateValidationCall) Return added in v1.4.0

Return rewrite *gomock.Call.Return

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 *zap.Logger) *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