mempool

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: MIT Imports: 21 Imported by: 14

Documentation

Index

Constants

View Source
const (
	SlotRechargeToSidechainTxHash = "RechargeToSidechainTxHash"
	SlotTxInputsReferKeys         = "TxInputsReferKeys"
)

Variables

View Source
var ErrBreak = fmt.Errorf("break out from here")
View Source
var (
	FuncNames = funcNames{
		CheckTransactionSize:                    "checktransactionsize",
		CheckTransactionInput:                   "checktransactioninput",
		CheckTransactionOutput:                  "checktransactionoutput",
		CheckAssetPrecision:                     "checkassetprecision",
		CheckAttributeProgram:                   "checkattributeprogram",
		CheckTransactionPayload:                 "checktransactionpayload",
		CheckTransactionDuplicate:               "checktransactionduplicate",
		CheckTransactionCoinBase:                "checktransactioncoinbase",
		CheckTransactionDoubleSpend:             "checktransactiondoublespend",
		CheckTransactionSignature:               "checktransactionsignature",
		CheckRechargeToSideChainTransaction:     "checkrechargetosidechaintransaction",
		CheckTransferCrossChainAssetTransaction: "checktransfercrosschainassettransaction",
		CheckTransactionUTXOLock:                "checktransactionutxolock",
		CheckTransactionBalance:                 "checktransactionbalance",
		CheckReferencedOutput:                   "checkreferencedoutput",
	}
)

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func ErrToRejectErr added in v0.1.3

func ErrToRejectErr(err error) (msg.RejectCode, string)

ErrToRejectErr examines the underlying type of the error and returns a reject code and string appropriate to be sent in a wire.MsgReject message.

func GenesisToProgramHash

func GenesisToProgramHash(genesisHash *common.Uint256) (*common.Uint168, error)

func NewConflictSlot added in v0.1.7

func NewConflictSlot(t KeyType, conflictTypes ...KeyTypeFuncPair) *conflictSlot

func RunPrograms

func RunPrograms(tx *types.Transaction, hashes []common.Uint168, programs []*types.Program) error

func SortPrograms

func SortPrograms(programs []*types.Program) (err error)

func UseLogger

func UseLogger(logger elalog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using elalog.

Types

type Config

type Config struct {
	ChainParams *config.Params
	Chain       *blockchain.BlockChain
	ChainStore  *blockchain.ChainStore
	SpvService  *spv.Service
	Validator   *Validator
	FeeHelper   *FeeHelper
}

type Conflict added in v0.1.7

type Conflict struct {
	Name string
	Slot *conflictSlot
}

type ErrorCode

type ErrorCode int
const (
	ErrInvalidInput         ErrorCode = 45003
	ErrInvalidOutput        ErrorCode = 45004
	ErrAssetPrecision       ErrorCode = 45005
	ErrTransactionBalance   ErrorCode = 45006
	ErrAttributeProgram     ErrorCode = 45007
	ErrTransactionSignature ErrorCode = 45008
	ErrTransactionPayload   ErrorCode = 45009
	ErrDoubleSpend          ErrorCode = 45010
	ErrTxHashDuplicate      ErrorCode = 45011
	ErrMainchainTxDuplicate ErrorCode = 45013
	ErrTransactionSize      ErrorCode = 45015
	ErrUnknownReferedTx     ErrorCode = 45016
	ErrInvalidReferedTx     ErrorCode = 45017
	ErrIneffectiveCoinbase  ErrorCode = 45018
	ErrUTXOLocked           ErrorCode = 45019
	ErrRechargeToSideChain  ErrorCode = 45020
	ErrCrossChain           ErrorCode = 45021
)

func (ErrorCode) String

func (e ErrorCode) String() string

String returns the ErrorCode as a human-readable name.

type FeeHelper

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

func NewFeeHelper

func NewFeeHelper(cfg *Config) *FeeHelper

func (*FeeHelper) GetTxFee

func (h *FeeHelper) GetTxFee(tx *types.Transaction, assetId common.Uint256) (common.Fixed64, error)

func (*FeeHelper) GetTxFeeMap

func (h *FeeHelper) GetTxFeeMap(tx *types.Transaction) (map[common.Uint256]common.Fixed64, error)

type FuncName

type FuncName string

type GetKeyFunc added in v0.1.7

type GetKeyFunc func(*blockchain.BlockChain, *types.Transaction) (interface{}, error)

GetKeyFunc defines the general function about get key from a tx.

type KeyType added in v0.1.7

type KeyType byte

KeyType defines the conflictSlot supported key types.

const (
	// Str KeyType will treat key as type of string.
	Str KeyType = iota

	// Hash KeyType will treat key as type of Uint256.
	Hash

	// ProgramHash KeyType will treat key as type of Uint168.
	ProgramHash

	// Hash KeyType will treat key as type of string array.
	StrArray

	// Hash KeyType will treat key as type of Uint256 array.
	HashArray

	// ProgramHash KeyType will treat key as type of Uint168 array.
	ProgramHashArray
)

type KeyTypeFuncPair added in v0.1.7

type KeyTypeFuncPair struct {
	Type types.TxType
	Func GetKeyFunc
}

KeyTypeFuncPair defines a pair about tx type and related GetKeyFunc.

type RuleError

type RuleError struct {
	ErrorCode   ErrorCode // 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.

func (RuleError) Error

func (e RuleError) Error() string

Error satisfies the error interface and prints human-readable errors.

type TxPool

type TxPool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New(cfg *Config) *TxPool

func (*TxPool) AddConflictSlot added in v0.1.7

func (m *TxPool) AddConflictSlot(conflict *Conflict)

func (*TxPool) AppendToTxPool

func (p *TxPool) AppendToTxPool(tx *types.Transaction) error

append transaction to txnpool when check ok. 1.check 2.check with ledger(db) 3.check with pool

func (*TxPool) AppendTx added in v0.1.7

func (m *TxPool) AppendTx(tx *types.Transaction) error

func (*TxPool) CleanSubmittedTransactions

func (p *TxPool) CleanSubmittedTransactions(block *types.Block) error

clean the trasaction Pool with committed block.

func (*TxPool) ContainsKey added in v0.1.7

func (m *TxPool) ContainsKey(key interface{}, slotName string) bool

func (*TxPool) Empty added in v0.1.7

func (m *TxPool) Empty() bool

func (*TxPool) GetTransaction

func (p *TxPool) GetTransaction(hash common.Uint256) *types.Transaction

get the transaction by hash

func (*TxPool) GetTx added in v0.1.7

func (m *TxPool) GetTx(key interface{},
	slotName string) *types.Transaction

func (*TxPool) GetTxsInPool

func (p *TxPool) GetTxsInPool() map[common.Uint256]*types.Transaction

GetTxsInPool returns a copy of the transactions in transaction pool, It is safe to modify the returned map.

func (*TxPool) HaveTransaction

func (p *TxPool) HaveTransaction(txId common.Uint256) bool

HaveTransaction returns if a transaction is in transaction pool by the given transaction id. If no transaction match the transaction id, return false

func (*TxPool) IsDuplicateMainChainTx added in v0.1.7

func (mp *TxPool) IsDuplicateMainChainTx(mainchainTxHash common.Uint256) bool

func (*TxPool) MaybeAcceptTransaction

func (p *TxPool) MaybeAcceptTransaction(txn *types.Transaction) error

func (*TxPool) RemoveKey added in v0.1.7

func (m *TxPool) RemoveKey(key interface{},
	slotName string) error

func (*TxPool) RemoveTransaction

func (p *TxPool) RemoveTransaction(txn *types.Transaction)

func (*TxPool) VerifyTx added in v0.1.7

func (m *TxPool) VerifyTx(tx *types.Transaction) error

type TxValidateAction

type TxValidateAction struct {
	Name    FuncName
	Handler func(txn *types.Transaction, height uint32, mainChainHeight uint32) error
}

type Validator

type Validator struct {
	Chain *blockchain.BlockChain
	// contains filtered or unexported fields
}

func NewValidator

func NewValidator(cfg *Config) *Validator

func (*Validator) CheckTransactionContext

func (v *Validator) CheckTransactionContext(txn *types.Transaction, height uint32, mainChainHeight uint32) error

CheckTransactionContext verifys a transaction with history transaction in ledger

func (*Validator) CheckTransactionSanity

func (v *Validator) CheckTransactionSanity(txn *types.Transaction, height uint32, mainChainHeight uint32) error

CheckTransactionSanity verifys received single transaction

func (*Validator) GetFeeHelper added in v0.2.0

func (v *Validator) GetFeeHelper() *FeeHelper

func (*Validator) GetParams added in v0.1.8

func (v *Validator) GetParams() *config.Params

func (*Validator) RegisterContextFunc

func (v *Validator) RegisterContextFunc(name FuncName, function func(txn *types.Transaction, height uint32, mainChainHeight uint32) error)

func (*Validator) RegisterSanityFunc

func (v *Validator) RegisterSanityFunc(name FuncName, function func(txn *types.Transaction, height uint32, mainChainHeight uint32) error)

func (*Validator) TxProgramHashes

func (v *Validator) TxProgramHashes(tx *types.Transaction) ([]common.Uint168, error)

Jump to

Keyboard shortcuts

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