3

What is the default txpool memory size in geth? How can I change the txpool memory size?

According to What is the max size of transactions can clients like geth keep in txpool?, "The number of transactions in the pending transaction pool is effectively limited by memory." I wonder what the default setting is and how to change it.

4

Geth

The default config values associated with the transaction pool can now be changed from Geth's CLI:

TRANSACTION POOL OPTIONS:
  --txpool.pricelimit value    Minimum gas price limit to enforce for acceptance into the pool (
default: 1)
  --txpool.pricebump value     Price bump percentage to replace an already existing transaction (default: 10)
  --txpool.accountslots value  Minimum number of executable transaction slots guaranteed per account (default: 16)
  --txpool.globalslots value   Maximum number of executable transaction slots for all accounts (default: 4096)
  --txpool.accountqueue value  Maximum number of non-executable transaction slots permitted per account (default: 64)
  --txpool.globalqueue value   Maximum number of non-executable transaction slots for all accounts (default: 1024)
  --txpool.lifetime value      Maximum amount of time non-executable transaction are queued (default: 3h0m0s)

While this doesn't allow you to limit exactly how much memory is used, increasing, for example, accountslots or globalslots will lead to an increase in used memory, and vice versa.


Parity

Similarly, Parity has the following CLI option:

 --tx-queue-size LIMIT          Maximum amount of transactions in the queue (waiting
                                 to be included in next block) (default: 1024).
1

grepping around geth's code I found the following:

core/tx_pool.go

const (
    maxQueued = 64 // max limit of queued txs per address
)

type stateFn func() (*state.StateDB, error)

// 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       *ChainConfig
    currentState stateFn // The state function which will allow us to do some pre checks
    pendingState *state.ManagedState
    gasLimit     func() *big.Int // The current gas limit function callback
    minGasPrice  *big.Int
    eventMux     *event.TypeMux
    events       event.Subscription
    localTx      *txSet
    mu           sync.RWMutex
    pending      map[common.Hash]*types.Transaction // processable transactions
    queue        map[common.Address]map[common.Hash]*types.Transaction

    wg sync.WaitGroup // for shutdown sync

    homestead bool
}

func NewTxPool(config *ChainConfig, eventMux *event.TypeMux, currentStateFn stateFn, gasLimitFn func() *big.Int) *TxPool {
    pool := &TxPool{
        config:       config,
        pending:      make(map[common.Hash]*types.Transaction),
        queue:        make(map[common.Address]map[common.Hash]*types.Transaction),
        eventMux:     eventMux,
        currentState: currentStateFn,
        gasLimit:     gasLimitFn,
        minGasPrice:  new(big.Int),
        pendingState: nil,
        localTx:      newTxSet(),
        events:       eventMux.Subscribe(ChainHeadEvent{}, GasPriceChanged{}, RemovedTransactionEvent{}),
    }

    pool.wg.Add(1)
    go pool.eventLoop()

    return pool
}

You can change the number of max queued TXs per address.

  • I'd like to know how to change the memory size, not max queued txs. – Satoshi Nakanishi Aug 11 '16 at 16:12
  • I'm not sure what you mean by memory size. geth like most applications will use as much memory as available to store transactions. – Sebi Aug 12 '16 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.