MCPcopy Create free account
hub / github.com/CPChain/chain / NewTxPool

Function NewTxPool

core/tx_pool.go:304–344  ·  view source on GitHub ↗

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

(config TxPoolConfig, chainconfig *configs.ChainConfig, chain blockChain)

Source from the content-addressed store, hash-verified

302// NewTxPool creates a new transaction pool to gather, sort and filter inbound
303// transactions from the network.
304func NewTxPool(config TxPoolConfig, chainconfig *configs.ChainConfig, chain blockChain) *TxPool {
305 // Sanitize the input to ensure no vulnerable gas prices are set
306 config = (&config).sanitize()
307
308 // Create the transaction pool with its initial settings
309 pool := &TxPool{
310 config: config,
311 chainconfig: chainconfig,
312 chain: chain,
313 signer: types.NewCep1Signer(chainconfig.ChainID),
314 pending: make(map[common.Address]*txList),
315 queue: make(map[common.Address]*txList),
316 beats: make(map[common.Address]time.Time),
317 all: newTxLookup(),
318 chainHeadCh: make(chan ChainHeadEvent, chainHeadChanSize),
319 gasPrice: new(big.Int).SetUint64(config.PriceLimit),
320 }
321 pool.locals = newAccountSet(pool.signer)
322 pool.priced = newTxPricedList(pool.all)
323 pool.reset(nil, chain.CurrentBlock().Header())
324
325 // If local transactions and journaling is enabled, load from disk
326 if !config.NoLocals && config.Journal != "" {
327 pool.journal = newTxJournal(config.Journal)
328
329 if err := pool.journal.load(pool.AddLocals); err != nil {
330 log.Warn("Failed to load transaction journal", "err", err)
331 }
332 if err := pool.journal.rotate(pool.local()); err != nil {
333 log.Warn("Failed to rotate transaction journal", "err", err)
334 }
335 }
336 // Subscribe events from blockchain
337 pool.chainHeadSub = pool.chain.SubscribeChainHeadEvent(pool.chainHeadCh)
338
339 // Start the event loop and return
340 pool.wg.Add(1)
341 go pool.loop()
342
343 return pool
344}
345
346// loop is the transaction pool's main event loop, waiting for and reacting to
347// outside blockchain events as well as for various reporting and transaction

Calls 15

resetMethod · 0.95
localMethod · 0.95
loopMethod · 0.95
newTxLookupFunction · 0.85
newAccountSetFunction · 0.85
newTxPricedListFunction · 0.85
newTxJournalFunction · 0.85
sanitizeMethod · 0.80
HeaderMethod · 0.80
loadMethod · 0.80
rotateMethod · 0.80
CurrentBlockMethod · 0.65