txspool

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: GPL-3.0, GPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package txspool is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidSender is returned if the transaction contains an invalid signature.
	ErrInvalidSender = errors.New("invalid sender")

	// ErrNonceTooLow is returned if the nonce of a transaction is lower than the
	// one present in the local chain.
	ErrNonceTooLow = errors.New("nonce too low")

	// ErrTxFeeTooLow is returned if a transaction's tx_fee is below the value of TXFEE.
	ErrTxFeeTooLow = errors.New("txfee too low")

	// ErrUnderpriced is returned if a transaction's gas price is below the minimum
	// configured for the transaction pool.
	ErrUnderpriced = errors.New("transaction underpriced")

	// ErrReplaceUnderpriced is returned if a transaction is attempted to be replaced
	// with a different one without the required price bump.
	ErrReplaceUnderpriced = errors.New("replacement transaction underpriced")

	// ErrInsufficientFunds is returned if the total cost of executing a transaction
	// is higher than the balance of the user's account.
	ErrInsufficientFunds = errors.New("insufficient funds for gas * price + value")

	// ErrNegativeValue is a sanity error to ensure noone is able to specify a
	// transaction with a negative value.
	ErrNegativeValue = errors.New("negative value")

	// ErrOversizedData is returned if the input data of a transaction is greater
	// than some meaningful limit a user might use. This is not a consensus error
	// making the transaction invalid, rather a DOS protection.
	ErrOversizedData = errors.New("oversized data")
)
View Source
var DefaultTxPoolConfig = TxPoolConfig{
	Version:   2,
	NoLocals:  false,
	Journal:   "transactions.rlp",
	Rejournal: time.Hour,

	FeeLimit:  1,
	PriceBump: 10,

	GlobalSlots: 48192,
	GlobalQueue: 12048,

	Lifetime:        3 * time.Hour,
	Removetime:      30 * time.Minute,
	OrphanTTL:       20 * time.Minute,
	MaxOrphanTxs:    10000,
	MaxOrphanTxSize: 2000000,
}

DefaultTxPoolConfig contains the default configurations for the transaction pool.

Functions

func CheckTransactionSanity

func CheckTransactionSanity(tx *modules.Transaction) error

func IsCoinBase

func IsCoinBase(tx *modules.Transaction) bool

Types

type ErrorCode

type ErrorCode uint8

ErrorCode identifies a kind of error.

type IDag added in v1.0.7

type IDag interface {
	GetDb() ptndb.Database
	CurrentUnit(token modules.AssetId) *modules.Unit
	GetUnitByHash(hash common.Hash) (*modules.Unit, error)
	//GetTxFromAddress(tx *modules.Transaction) ([]common.Address, error)
	GetTransactionOnly(hash common.Hash) (*modules.Transaction, error)
	IsTransactionExist(hash common.Hash) (bool, error)
	GetTxHashByReqId(reqid common.Hash) (common.Hash, error)
	GetHeaderByHash(common.Hash) (*modules.Header, error)
	GetUtxoEntry(outpoint *modules.OutPoint) (*modules.Utxo, error)
	SubscribeChainHeadEvent(ch chan<- modules.ChainHeadEvent) event.Subscription
	//getTxfee
	//GetTxFee(pay *modules.Transaction) (*modules.AmountAsset, error)
	GetStxoEntry(outpoint *modules.OutPoint) (*modules.Stxo, error)
	GetTxOutput(outpoint *modules.OutPoint) (*modules.Utxo, error)

	GetContractTpl(tplId []byte) (*modules.ContractTemplate, error)
	GetContractJury(contractId []byte) (*modules.ElectionNode, error)
	GetContractState(id []byte, field string) ([]byte, *modules.StateVersion, error)
	GetContractStatesByPrefix(id []byte, prefix string) (map[string]*modules.ContractStateValue, error)
	//GetTxRequesterAddress(tx *modules.Transaction) (common.Address, error)
	IsContractDeveloper(addr common.Address) bool

	GetMediators() map[common.Address]bool
	GetChainParameters() *core.ChainParameters
	GetNewestUnit(token modules.AssetId) (common.Hash, *modules.ChainIndex, error)
	GetNewestUnitTimestamp(token modules.AssetId) (int64, error)
	GetScheduledMediator(slotNum uint32) common.Address
	GetSlotAtTime(when time.Time) uint32
	GetMediator(add common.Address) *core.Mediator

	GetBlacklistAddress() ([]common.Address, *modules.StateVersion, error)
	GetJurorByAddrHash(addrHash common.Hash) (*modules.JurorDeposit, error)
	GetJurorReward(jurorAdd common.Address) common.Address
	GetAddrUtxoAndReqMapping(addr common.Address, asset *modules.Asset) (map[modules.OutPoint]*modules.Utxo, map[common.Hash]common.Hash, error)
	CheckReadSetValid(contractId []byte, readSet []modules.ContractReadSet) bool
}

type ITxPool

type ITxPool interface {
	Stop()
	Clear()
	AddLocal(tx *modules.Transaction) error

	// AddRemotes should add the given transactions to the pool.
	AddRemote(tx *modules.Transaction) error
	//AddRemotes([]*modules.Transaction) []error
	//ProcessTransaction(tx *modules.Transaction, allowOrphan bool, rateLimit bool, tag Tag) ([]*TxDesc, error)
	//查询已打包的交易,以UnitHash为Key
	Packed() (map[common.Hash][]*TxPoolTransaction, error)
	//查询孤儿交易
	Orphan() ([]*TxPoolTransaction, error)
	//未打包的交易
	Unpack() ([]*TxPoolTransaction, error)
	//将一堆交易修改状态为已打包
	SetPendingTxs(unit_hash common.Hash, num uint64, txs []*modules.Transaction) error
	//将一堆交易设置为未打包
	ResetPendingTxs(txs []*modules.Transaction) error
	//SendStoredTxs(hashs []common.Hash) error
	//将一堆交易标记为删除
	DiscardTxs(txs []*modules.Transaction) error
	//查询交易池所有的UTXO,比如有A,B,C连续交易,那么ABC的UTXO都会被查询
	GetUtxoFromAll(outpoint *modules.OutPoint) (*modules.Utxo, error)
	//查询交易池中未被使用的UTXO,比如有ABC连续交易,那么只有C的UTXO会被查询,而AB的已经被使用了
	//GetUtxoFromFree(outpoint *modules.OutPoint) (*modules.Utxo, error)
	//订阅事件
	SubscribeTxPreEvent(chan<- modules.TxPreEvent) event.Subscription
	//GetSortedTxs(hash common.Hash, index uint64) ([]*TxPoolTransaction, common.StorageSize)
	//迭代获取未打包的排序好的Tx,迭代执行函数时,如果返回true就继续迭代,如果false停止迭代
	//GetSortedTxs(processor func(tx *TxPoolTransaction) (getNext bool, err error)) error
	GetSortedTxs() ([]*TxPoolTransaction, error)
	//从交易池获取某个交易
	GetTx(hash common.Hash) (*TxPoolTransaction, error)
	DeleteTx(hash common.Hash) error
	//获取交易池中某个地址的所有交易
	//GetPoolTxsByAddr(addr string) ([]*TxPoolTransaction, error)
	//获得一个地址的未打包的交易
	GetUnpackedTxsByAddr(addr common.Address) ([]*TxPoolTransaction, error)
	//返回交易池中几种状态的交易数量
	Status() (int, int, int)
	//返回交易池中交易的内容
	Content() (map[common.Hash]*TxPoolTransaction, map[common.Hash]*TxPoolTransaction)
	//获取某地址针对某Token的UTXO
	GetAddrUtxos(addr common.Address, token *modules.Asset) (map[modules.OutPoint]*modules.Utxo, error)
}
var Instance ITxPool

type IValidator

type IValidator interface {
	ValidateTx(tx *modules.Transaction, isFullTx bool) ([]*modules.Addition, validator.ValidationCode, error)
	SetUtxoQuery(query validator.IUtxoQuery)
}

type MockITxPool

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

MockITxPool is a mock of ITxPool interface

func NewMockITxPool

func NewMockITxPool(ctrl *gomock.Controller) *MockITxPool

NewMockITxPool creates a new mock instance

func (*MockITxPool) AddLocal

func (m *MockITxPool) AddLocal(tx *modules.Transaction) error

AddLocal mocks base method

func (*MockITxPool) AddRemote

func (m *MockITxPool) AddRemote(tx *modules.Transaction) error

AddRemote mocks base method

func (*MockITxPool) Clear added in v1.0.7

func (m *MockITxPool) Clear()

Clear mocks base method

func (*MockITxPool) Content

Content mocks base method

func (*MockITxPool) DeleteTx added in v1.0.9

func (m *MockITxPool) DeleteTx(hash common.Hash) error

DeleteTx mocks base method

func (*MockITxPool) DiscardTxs

func (m *MockITxPool) DiscardTxs(txs []*modules.Transaction) error

DiscardTxs mocks base method

func (*MockITxPool) EXPECT

func (m *MockITxPool) EXPECT() *MockITxPoolMockRecorder

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

func (*MockITxPool) GetAddrUtxos added in v1.0.7

func (m *MockITxPool) GetAddrUtxos(addr common.Address, token *modules.Asset) (map[modules.OutPoint]*modules.Utxo, error)

GetAddrUtxos mocks base method

func (*MockITxPool) GetSortedTxs

func (m *MockITxPool) GetSortedTxs() ([]*TxPoolTransaction, error)

GetSortedTxs mocks base method

func (*MockITxPool) GetTx added in v1.0.7

func (m *MockITxPool) GetTx(hash common.Hash) (*TxPoolTransaction, error)

GetTx mocks base method

func (*MockITxPool) GetUnpackedTxsByAddr added in v1.0.6

func (m *MockITxPool) GetUnpackedTxsByAddr(addr common.Address) ([]*TxPoolTransaction, error)

GetUnpackedTxsByAddr mocks base method

func (*MockITxPool) GetUtxoFromAll added in v1.0.7

func (m *MockITxPool) GetUtxoFromAll(outpoint *modules.OutPoint) (*modules.Utxo, error)

GetUtxoFromAll mocks base method

func (*MockITxPool) Orphan added in v1.0.9

func (m *MockITxPool) Orphan() ([]*TxPoolTransaction, error)

Orphan mocks base method

func (*MockITxPool) Packed added in v1.0.9

func (m *MockITxPool) Packed() (map[common.Hash][]*TxPoolTransaction, error)

Packed mocks base method

func (*MockITxPool) ResetPendingTxs

func (m *MockITxPool) ResetPendingTxs(txs []*modules.Transaction) error

ResetPendingTxs mocks base method

func (*MockITxPool) SetPendingTxs

func (m *MockITxPool) SetPendingTxs(unit_hash common.Hash, num uint64, txs []*modules.Transaction) error

SetPendingTxs mocks base method

func (*MockITxPool) Status added in v1.0.7

func (m *MockITxPool) Status() (int, int, int)

Status mocks base method

func (*MockITxPool) Stop

func (m *MockITxPool) Stop()

Stop mocks base method

func (*MockITxPool) SubscribeTxPreEvent

func (m *MockITxPool) SubscribeTxPreEvent(arg0 chan<- modules.TxPreEvent) event.Subscription

SubscribeTxPreEvent mocks base method

func (*MockITxPool) Unpack added in v1.0.9

func (m *MockITxPool) Unpack() ([]*TxPoolTransaction, error)

Unpack mocks base method

type MockITxPoolMockRecorder

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

MockITxPoolMockRecorder is the mock recorder for MockITxPool

func (*MockITxPoolMockRecorder) AddLocal

func (mr *MockITxPoolMockRecorder) AddLocal(tx interface{}) *gomock.Call

AddLocal indicates an expected call of AddLocal

func (*MockITxPoolMockRecorder) AddRemote

func (mr *MockITxPoolMockRecorder) AddRemote(tx interface{}) *gomock.Call

AddRemote indicates an expected call of AddRemote

func (*MockITxPoolMockRecorder) Clear added in v1.0.7

func (mr *MockITxPoolMockRecorder) Clear() *gomock.Call

Clear indicates an expected call of Clear

func (*MockITxPoolMockRecorder) Content

func (mr *MockITxPoolMockRecorder) Content() *gomock.Call

Content indicates an expected call of Content

func (*MockITxPoolMockRecorder) DeleteTx added in v1.0.9

func (mr *MockITxPoolMockRecorder) DeleteTx(hash interface{}) *gomock.Call

DeleteTx indicates an expected call of DeleteTx

func (*MockITxPoolMockRecorder) DiscardTxs

func (mr *MockITxPoolMockRecorder) DiscardTxs(txs interface{}) *gomock.Call

DiscardTxs indicates an expected call of DiscardTxs

func (*MockITxPoolMockRecorder) GetAddrUtxos added in v1.0.7

func (mr *MockITxPoolMockRecorder) GetAddrUtxos(addr, token interface{}) *gomock.Call

GetAddrUtxos indicates an expected call of GetAddrUtxos

func (*MockITxPoolMockRecorder) GetSortedTxs

func (mr *MockITxPoolMockRecorder) GetSortedTxs() *gomock.Call

GetSortedTxs indicates an expected call of GetSortedTxs

func (*MockITxPoolMockRecorder) GetTx added in v1.0.7

func (mr *MockITxPoolMockRecorder) GetTx(hash interface{}) *gomock.Call

GetTx indicates an expected call of GetTx

func (*MockITxPoolMockRecorder) GetUnpackedTxsByAddr added in v1.0.6

func (mr *MockITxPoolMockRecorder) GetUnpackedTxsByAddr(addr interface{}) *gomock.Call

GetUnpackedTxsByAddr indicates an expected call of GetUnpackedTxsByAddr

func (*MockITxPoolMockRecorder) GetUtxoFromAll added in v1.0.7

func (mr *MockITxPoolMockRecorder) GetUtxoFromAll(outpoint interface{}) *gomock.Call

GetUtxoFromAll indicates an expected call of GetUtxoFromAll

func (*MockITxPoolMockRecorder) Orphan added in v1.0.9

func (mr *MockITxPoolMockRecorder) Orphan() *gomock.Call

Orphan indicates an expected call of Orphan

func (*MockITxPoolMockRecorder) Packed added in v1.0.9

func (mr *MockITxPoolMockRecorder) Packed() *gomock.Call

Packed indicates an expected call of Packed

func (*MockITxPoolMockRecorder) ResetPendingTxs

func (mr *MockITxPoolMockRecorder) ResetPendingTxs(txs interface{}) *gomock.Call

ResetPendingTxs indicates an expected call of ResetPendingTxs

func (*MockITxPoolMockRecorder) SetPendingTxs

func (mr *MockITxPoolMockRecorder) SetPendingTxs(unit_hash, num, txs interface{}) *gomock.Call

SetPendingTxs indicates an expected call of SetPendingTxs

func (*MockITxPoolMockRecorder) Status added in v1.0.7

func (mr *MockITxPoolMockRecorder) Status() *gomock.Call

Status indicates an expected call of Status

func (*MockITxPoolMockRecorder) Stop

func (mr *MockITxPoolMockRecorder) Stop() *gomock.Call

Stop indicates an expected call of Stop

func (*MockITxPoolMockRecorder) SubscribeTxPreEvent

func (mr *MockITxPoolMockRecorder) SubscribeTxPreEvent(arg0 interface{}) *gomock.Call

SubscribeTxPreEvent indicates an expected call of SubscribeTxPreEvent

func (*MockITxPoolMockRecorder) Unpack added in v1.0.9

func (mr *MockITxPoolMockRecorder) Unpack() *gomock.Call

Unpack indicates an expected call of Unpack

type ProcessorFunc added in v1.0.7

type ProcessorFunc func(tx *TxPoolTransaction) (getNext bool, err error)

type RejectCode

type RejectCode uint8
const (
	RejectMalformed       RejectCode = 0x01
	RejectInvalid         RejectCode = 0x10
	RejectObsolete        RejectCode = 0x11
	RejectDuplicate       RejectCode = 0x12
	RejectNonstandard     RejectCode = 0x40
	RejectDust            RejectCode = 0x41
	RejectInsufficientFee RejectCode = 0x42
	RejectCheckpoint      RejectCode = 0x43
)

These constants define the various supported reject codes.

type RuleError

type RuleError struct {
	ErrorCode   RejectCode // Describes the kind of error
	Description string     // Human readable description of the issue
}

RuleError identifies a rule violation. It is used to indicate that processing of a block or transaction failed due to one of the many validation rules. The caller can use type assertions to determine if a failure was specifically due to a rule violation and access the ErrorCode field to ascertain the specific reason for the rule violation.

type RuleError struct {
	ErrorCode   ErrorCode // Describes the kind of error
	Description string    // Human readable description of the issue
}

type SequeueTxPoolTxs

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

func (*SequeueTxPoolTxs) Add

func (seqTxs *SequeueTxPoolTxs) Add(newPoolTx *TxPoolTransaction)

func (*SequeueTxPoolTxs) AddPriority

func (seqTxs *SequeueTxPoolTxs) AddPriority(newPoolTx *TxPoolTransaction)

add priority

func (*SequeueTxPoolTxs) All

func (seqTxs *SequeueTxPoolTxs) All() []*TxPoolTransaction

get all

func (*SequeueTxPoolTxs) Get

func (seqTxs *SequeueTxPoolTxs) Get() *TxPoolTransaction

get

func (*SequeueTxPoolTxs) Len

func (seqTxs *SequeueTxPoolTxs) Len() int

add

type TxByCreationDate

type TxByCreationDate []*TxPoolTransaction

func (TxByCreationDate) Len

func (tc TxByCreationDate) Len() int

func (TxByCreationDate) Less

func (tc TxByCreationDate) Less(i, j int) bool

func (TxByCreationDate) Swap

func (tc TxByCreationDate) Swap(i, j int)

type TxByPrice

type TxByPrice TxPoolTxs

TxByPrice implements both the sort and the heap interface, making it useful for all at once sorting as well as individually adding and removing elements.

func (TxByPrice) Len

func (s TxByPrice) Len() int

func (*TxByPrice) Pop

func (s *TxByPrice) Pop() interface{}

func (*TxByPrice) Push

func (s *TxByPrice) Push(x interface{})

func (TxByPrice) Swap

func (s TxByPrice) Swap(i, j int)

type TxByPriority

type TxByPriority []*TxPoolTransaction

func (TxByPriority) Len

func (s TxByPriority) Len() int

func (TxByPriority) Less

func (s TxByPriority) Less(i, j int) bool

func (*TxByPriority) Pop

func (s *TxByPriority) Pop() interface{}

func (*TxByPriority) Push

func (s *TxByPriority) Push(x interface{})

func (TxByPriority) Swap

func (s TxByPriority) Swap(i, j int)

type TxPool

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

func NewTxPool

func NewTxPool(config TxPoolConfig, cachedb palletcache.ICache, unit IDag, enableGasFee bool) *TxPool

NewTxPool creates a new transaction pool to gather, sort and filter inbound transactions from the network.

func NewTxPool4DI

func NewTxPool4DI(config TxPoolConfig, cachedb palletcache.ICache, unit IDag,
	tokenEngine tokenengine.ITokenEngine, validator IValidator, enableGasFee bool) *TxPool

构造函数的依赖注入,主要用于UT

func (*TxPool) AddLocal

func (pool *TxPool) AddLocal(tx *modules.Transaction) error

AddLocal enqueues a single transaction into the pool if it is valid, marking the sender as a local one in the mean time, ensuring it goes around the local pricing constraints.

func (*TxPool) AddLocals

func (pool *TxPool) AddLocals(txs []*modules.Transaction) []error

AddLocals enqueues a batch of transactions into the pool if they are valid, marking the senders as a local ones in the mean time, ensuring they go around the local pricing constraints.

func (*TxPool) AddRemote

func (pool *TxPool) AddRemote(tx *modules.Transaction) error

AddRemote enqueues a single transaction into the pool if it is valid. If the sender is not among the locally tracked ones, full pricing constraints will apply.

func (*TxPool) AddRemotes

func (pool *TxPool) AddRemotes(txs []*modules.Transaction) []error

AddRemotes enqueues a batch of transactions into the pool if they are valid. If the senders are not among the locally tracked ones, full pricing constraints will apply.

func (*TxPool) AddSequenTx

func (pool *TxPool) AddSequenTx(tx *modules.Transaction) error

func (*TxPool) AddSequenTxs

func (pool *TxPool) AddSequenTxs(txs []*modules.Transaction) error

func (*TxPool) AllHashs

func (pool *TxPool) AllHashs() []*common.Hash

AllHashs returns a slice of hashes for all of the transactions in the txpool.

func (*TxPool) AllLength

func (pool *TxPool) AllLength() int

func (*TxPool) AllOrphanTxs

func (pool *TxPool) AllOrphanTxs() map[common.Hash]*TxPoolTransaction

func (*TxPool) AllTxpoolTxs

func (pool *TxPool) AllTxpoolTxs() map[common.Hash]*TxPoolTransaction

func (*TxPool) AllTxs

func (pool *TxPool) AllTxs() []*modules.Transaction

func (*TxPool) CheckSpend

func (pool *TxPool) CheckSpend(output modules.OutPoint) *modules.Transaction

CheckSpend checks whether the passed outpoint is already spent by a transaction in the txpool

func (*TxPool) Clear added in v1.0.7

func (pool *TxPool) Clear()

func (*TxPool) Content

func (pool *TxPool) Content() (map[common.Hash]*TxPoolTransaction, map[common.Hash]*TxPoolTransaction)

Content retrieves the data content of the transaction pool, returning all the pending as well as queued transactions, grouped by account and sorted by nonce.

func (*TxPool) Count

func (pool *TxPool) Count() int

func (*TxPool) DeleteTx

func (pool *TxPool) DeleteTx(hash common.Hash) error

func (*TxPool) DeleteTxByHash

func (pool *TxPool) DeleteTxByHash(hash common.Hash) error

func (*TxPool) DiscardTx

func (pool *TxPool) DiscardTx(hash common.Hash) error

func (*TxPool) DiscardTxs

func (pool *TxPool) DiscardTxs(txs []*modules.Transaction) error

打包后的没有被最终确认的交易,废弃处理

func (*TxPool) FetchInputUtxos

func (pool *TxPool) FetchInputUtxos(tx *modules.Transaction) (*UtxoViewpoint, error)

func (*TxPool) GetAddrUtxos added in v1.0.7

func (pool *TxPool) GetAddrUtxos(addr common.Address, token *modules.Asset) (
	map[modules.OutPoint]*modules.Utxo, error)

func (*TxPool) GetPoolTxsByAddr

func (pool *TxPool) GetPoolTxsByAddr(addr common.Address) ([]*TxPoolTransaction, error)

GetUnpackedTxsByAddr returns all tx by addr.

func (*TxPool) GetSequenTxs

func (pool *TxPool) GetSequenTxs() []*TxPoolTransaction

func (*TxPool) GetSortedTxs

func (pool *TxPool) GetSortedTxs() ([]*TxPoolTransaction, error)

***** end utxoSet **** GetSortedTxs returns 根据优先级返回list

func (*TxPool) GetStxoEntry

func (pool *TxPool) GetStxoEntry(outpoint *modules.OutPoint) (*modules.Stxo, error)

return a stxo by the outpoint in txpool

func (*TxPool) GetTx added in v1.0.7

func (pool *TxPool) GetTx(hash common.Hash) (*TxPoolTransaction, error)

Get returns a transaction if it is contained in the pool and nil otherwise.

func (*TxPool) GetTxFee

func (pool *TxPool) GetTxFee(tx *modules.Transaction) (*modules.AmountAsset, error)

func (*TxPool) GetTxOutput added in v1.0.6

func (pool *TxPool) GetTxOutput(outpoint *modules.OutPoint) (*modules.Utxo, error)

func (*TxPool) GetUnpackedTxsByAddr added in v1.0.6

func (pool *TxPool) GetUnpackedTxsByAddr(addr common.Address) ([]*TxPoolTransaction, error)

func (*TxPool) GetUtxoEntry

func (pool *TxPool) GetUtxoEntry(outpoint *modules.OutPoint) (*modules.Utxo, error)

func (*TxPool) GetUtxoFromAll added in v1.0.7

func (pool *TxPool) GetUtxoFromAll(outpoint *modules.OutPoint) (*modules.Utxo, error)

return a utxo by the outpoint in txpool

func (*TxPool) GetUtxoView

func (pool *TxPool) GetUtxoView(tx *modules.Transaction) (*UtxoViewpoint, error)

func (*TxPool) IsOrphanInPool

func (pool *TxPool) IsOrphanInPool(hash common.Hash) bool

func (*TxPool) IsTransactionInPool

func (pool *TxPool) IsTransactionInPool(hash common.Hash) bool

IsTransactionInPool returns whether or not the passed transaction already exists in the main pool.

func (*TxPool) Orphan added in v1.0.9

func (pool *TxPool) Orphan() ([]*TxPoolTransaction, error)

TxPoolOrphan txs

func (*TxPool) OutPointIsSpend

func (pool *TxPool) OutPointIsSpend(outPoint *modules.OutPoint) (bool, error)

func (*TxPool) Packed added in v1.0.9

func (pool *TxPool) Packed() (map[common.Hash][]*TxPoolTransaction, error)

Pending retrieves all currently processable transactions, groupped by origin account and sorted by priority level. The returned transaction set is a copy and can be freely modified by calling code.

func (*TxPool) ProcessTransaction

func (pool *TxPool) ProcessTransaction(tx *modules.Transaction) error

func (*TxPool) RemoveDoubleSpends

func (pool *TxPool) RemoveDoubleSpends(tx *modules.Transaction)

RemoveDoubleSpends removes all transactions whitch spend outpoints spent by the passed transaction from the memory pool. Removing those transactions then leads to removing all transaction whitch rely on them, recursively. This is necessary when a blocks is connected to the main chain because the block may contain transactions whitch were previously unknow to the memory pool.

func (*TxPool) RemoveOrphan

func (pool *TxPool) RemoveOrphan(tx *TxPoolTransaction)

This function is safe for concurrent access.

func (*TxPool) RemoveTransaction

func (pool *TxPool) RemoveTransaction(hash common.Hash, removeRedeemers bool)

func (*TxPool) RemoveTxs

func (pool *TxPool) RemoveTxs(hashs []common.Hash)

func (*TxPool) ResetPendingTxs

func (pool *TxPool) ResetPendingTxs(txs []*modules.Transaction) error

func (*TxPool) SendStoredTxs

func (pool *TxPool) SendStoredTxs(hashs []common.Hash) error

func (*TxPool) SetPendingTxs

func (pool *TxPool) SetPendingTxs(unit_hash common.Hash, num uint64, txs []*modules.Transaction) error

func (*TxPool) Status

func (pool *TxPool) Status() (int, int, int)

Stats retrieves the current pool stats, namely the number of pending and the number of queued (non-executable) transactions.

func (*TxPool) Stop

func (pool *TxPool) Stop()

Stop terminates the transaction pool.

func (*TxPool) SubscribeTxPreEvent

func (pool *TxPool) SubscribeTxPreEvent(ch chan<- modules.TxPreEvent) event.Subscription

SubscribeTxPreEvent registers a subscription of TxPreEvent and starts sending event to the given channel.

func (*TxPool) Unpack added in v1.0.9

func (pool *TxPool) Unpack() ([]*TxPoolTransaction, error)

func (*TxPool) ValidateOrphanTx

func (pool *TxPool) ValidateOrphanTx(tx *modules.Transaction) (bool, error)

validate tx is an orphanTx or not.

type TxPoolConfig

type TxPoolConfig struct {
	Version   int
	NoLocals  bool          // Whether local transaction handling should be disabled
	Journal   string        // Journal of local transactions to survive node restarts
	Rejournal time.Duration // Time interval to regenerate the local transaction journal

	FeeLimit  uint64 // Minimum tx's fee  to enforce for acceptance into the pool
	PriceBump uint64 // Minimum price bump percentage to replace an already existing transaction (nonce)

	GlobalSlots uint64 // Maximum number of executable transaction slots for all accounts
	GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts

	Lifetime   time.Duration // Maximum amount of time non-executable transaction are queued
	Removetime time.Duration // Maximum amount of time txpool transaction are removed
	OrphanTTL  time.Duration // Orpthan expiration
	// MaxOrphanTxs is the maximum number of orphan transactions
	// that can be queued.
	MaxOrphanTxs int

	// MaxOrphanTxSize is the maximum size allowed for orphan transactions.
	// This helps prevent memory exhaustion attacks from sending a lot of
	// of big orphans.
	MaxOrphanTxSize int
}

TxPoolConfig are the configuration parameters of the transaction pool.

type TxPoolTransaction

type TxPoolTransaction struct {
	Tx *modules.Transaction

	From         []*modules.OutPoint
	CreationDate time.Time `json:"creation_date"`
	Priority_lvl string    `json:"priority_lvl"` // 打包的优先级
	UnitHash     common.Hash
	UnitIndex    uint64
	Pending      bool //in unit
	Confirmed    bool //in unit and stable
	IsOrphan     bool
	Discarded    bool                // will remove
	TxFee        []*modules.Addition `json:"tx_fee"`
	Index        uint64              `json:"index"` // index 是该Unit位置。
	Extra        []byte
	Tag          uint64
	Expiration   time.Time

	TxHash               common.Hash
	ReqHash              common.Hash
	FromAddr             []common.Address
	ToAddr               []common.Address
	IsSysContractRequest bool
	IsUserContractFullTx bool

	Status TxPoolTxStatus
	//该Tx依赖于哪些TxId作为先决条件,value是表示该依赖的Tx是否已经在Dag或者交易池找到
	DependOnTxs map[common.Hash]bool
}

func TxtoTxpoolTx

func TxtoTxpoolTx(tx *modules.Transaction) *TxPoolTransaction

交易池缓存时需要将tx转化为PoolTx

func (*TxPoolTransaction) DecodeRLP added in v1.0.4

func (pooltx *TxPoolTransaction) DecodeRLP(s *rlp.Stream) error

func (*TxPoolTransaction) EncodeRLP added in v1.0.4

func (pooltx *TxPoolTransaction) EncodeRLP(w io.Writer) error

func (*TxPoolTransaction) GetPriorityLvl

func (tx *TxPoolTransaction) GetPriorityLvl() string

func (*TxPoolTransaction) GetPriorityfloat64

func (tx *TxPoolTransaction) GetPriorityfloat64() float64

func (*TxPoolTransaction) GetTxFee

func (tx *TxPoolTransaction) GetTxFee() *big.Int

func (*TxPoolTransaction) GetTxFee2 added in v1.0.7

func (tx *TxPoolTransaction) GetTxFee2() uint64

func (*TxPoolTransaction) IsDependOnTx added in v1.0.7

func (tx *TxPoolTransaction) IsDependOnTx(hash common.Hash) bool

func (*TxPoolTransaction) IsFineToNormal added in v1.0.7

func (tx *TxPoolTransaction) IsFineToNormal(hash common.Hash) bool

对于孤儿Tx来说,现在有一个新的Tx到来,那么本Tx是否可以判断为普通交易

func (*TxPoolTransaction) IsFrom added in v1.0.7

func (tx *TxPoolTransaction) IsFrom(addr common.Address) bool

func (*TxPoolTransaction) IsTo added in v1.0.7

func (tx *TxPoolTransaction) IsTo(addr common.Address) bool

func (*TxPoolTransaction) Less

func (tx *TxPoolTransaction) Less(otherTx interface{}) bool

func (*TxPoolTransaction) SetPriorityLvl

func (tx *TxPoolTransaction) SetPriorityLvl(priority float64)

type TxPoolTxStatus added in v1.0.7

type TxPoolTxStatus byte
const (
	//未打包
	TxPoolTxStatus_Unpacked TxPoolTxStatus = iota
	//已打包,未稳定
	TxPoolTxStatus_Packed
	//已丢弃
	TxPoolTxStatus_Discarded
	//孤儿交易
	TxPoolTxStatus_Orphan
)

type TxPoolTxs

type TxPoolTxs []*TxPoolTransaction

type Transactions []*Transaction

type TxRuleError

type TxRuleError struct {
	RejectCode  RejectCode // The code to send with reject messages
	Description string     // Human readable description of the issue
}

TxRuleError identifies a rule violation. It is used to indicate that processing of a transaction failed due to one of the many validation rules. The caller can use type assertions to determine if a failure was specifically due to a rule violation and access the ErrorCode field to ascertain the specific reason for the rule violation.

type TxStatus

type TxStatus uint
const (
	TxStatusNotIncluded TxStatus = iota
	TxStatusIncluded
	TxStatusQueued
	TxStatusPending
	TxStatusConfirmed
	TxStatusUnKnow
)

type UtxoViewpoint

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

UtxoViewpoint

func NewUtxoViewpoint

func NewUtxoViewpoint() *UtxoViewpoint

func (*UtxoViewpoint) AddTxOut

func (view *UtxoViewpoint) AddTxOut(tx *modules.Transaction, msgIdx, txoutIdx uint32)

func (*UtxoViewpoint) AddTxOuts

func (view *UtxoViewpoint) AddTxOuts(tx *modules.Transaction)

func (*UtxoViewpoint) AddUtxo

func (view *UtxoViewpoint) AddUtxo(key modules.OutPoint, utxo *modules.Utxo)

func (*UtxoViewpoint) BestHash

func (view *UtxoViewpoint) BestHash() *common.Hash

func (*UtxoViewpoint) Entries

func (view *UtxoViewpoint) Entries() map[modules.OutPoint]*modules.Utxo

func (*UtxoViewpoint) FetchUnitUtxos

func (view *UtxoViewpoint) FetchUnitUtxos(db utxoBaseGetOp, unit *modules.Unit) error
func (view *UtxoViewpoint) SpentUtxo(db utxoBaseOp, outpoints map[modules.OutPoint]struct{}) error {
	if len(outpoints) == 0 {
		return nil
	}
	for outpoint := range outpoints {
		item := new(modules.OutPoint)
		item.TxHash = outpoint.TxHash
		item.MessageIndex = outpoint.MessageIndex
		item.OutIndex = outpoint.OutIndex
		if utxo, has := view.entries[outpoint]; has {
			utxo.Spend()
			db.SaveUtxoEntity(item, utxo)
		} else {
			utxo, err := db.GetUtxoEntry(item)
			if err == nil {
				utxo.Spend()
				db.SaveUtxoEntity(item, utxo)
			}
		}
		delete(view.entries, outpoint)
	}
	return nil
}

func (*UtxoViewpoint) FetchUtxos

func (view *UtxoViewpoint) FetchUtxos(db utxoBaseGetOp, outpoints map[modules.OutPoint]struct{}) error

func (*UtxoViewpoint) LookupUtxo

func (view *UtxoViewpoint) LookupUtxo(outpoint modules.OutPoint) *modules.Utxo

func (*UtxoViewpoint) RemoveUtxo

func (view *UtxoViewpoint) RemoveUtxo(outpoint modules.OutPoint)

func (*UtxoViewpoint) SetBestHash

func (view *UtxoViewpoint) SetBestHash(hash *common.Hash)

func (*UtxoViewpoint) SetEntries

func (view *UtxoViewpoint) SetEntries(key modules.OutPoint, utxo *modules.Utxo)

Jump to

Keyboard shortcuts

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