core

TxPool

// TxPool contains all currently known transactions. Transactions
// enter the pool when they are received from the network or submitted
// locally. They exit the pool when they are included in the blockchain.
//
// The pool separates processable transactions (which can be applied to the
// current state) and future transactions. Transactions move between those
// two states over time as they are received and processed.
type TxPool struct {
    config       TxPoolConfig
    chainconfig  *params.ChainConfig
    chain        blockChain
    gasPrice     *big.Int
    txFeed       event.Feed
    scope        event.SubscriptionScope
    chainHeadCh  chan ChainHeadEvent
    chainHeadSub event.Subscription
    //abi       types.Signer
    mu sync.RWMutex

    currentState  *state.StateDB      // Current state in the blockchain head
    pendingState  *state.ManagedState // Pending state tracking virtual nonces
    currentMaxGas uint64              // Current gas limit for transaction caps

    locals *accountSet // Set of local transaction to exempt from eviction rules
    //journal *txJournal  // Journal of local transaction to back up to disk

    all        *txLookup     // All transactions to allow lookups
    priced     *txPricedList // All transactions sorted by priced
    newQueue   *txPricedList
    newPending *txPricedList
    beats      map[common.Hash]time.Time

    wg sync.WaitGroup // for shutdown sync

    homestead bool
}

TxPoolConfig

// TxPoolConfig are the configuration parameters of the transaction pool.
type TxPoolConfig struct {
    NoLocals bool // Whether local transaction handling should be disabled

    PriceLimit uint64 // Minimum gas priced to enforce for acceptance into the pool

    AccountSlots uint64 // Number of executable transaction slots guaranteed per account
    GlobalSlots  uint64 // Maximum number of executable transaction slots for all accounts
    AccountQueue uint64 // Maximum number of non-executable transaction slots permitted per account
    GlobalQueue  uint64 // Maximum number of non-executable transaction slots for all accounts

    Lifetime time.Duration // Maximum amount of time non-executable transaction are queued
}

accountSet

// accountSet is simply a set of addresses to check for existence, and a abi
// capable of deriving addresses from transactions.
type accountSet struct {
    accounts map[common.Address]struct{}
    //abi   types.Signer
}

txLookup

// txLookup is used internally by TxPool to track transactions while allowing lookup without
// mutex contention.
//
// Note, although this type is properly protected against concurrent access, it
// is **not** a type that should ever be mutated or even exposed outside of the
// transaction pool, since its internal state is tightly coupled with the pools
// internal mechanisms. The sole purpose of the type is to permit out-of-bound
// peeking into the pool in TxPool.Get without having to acquire the widely scoped
// TxPool.mu mutex.
type txLookup struct {
    all  map[common.Hash]*types.Transaction
    lock sync.RWMutex
}

Last updated

Was this helpful?