func (pool *TxPool) resetState() { currentState, err := pool.currentState() if err != nil { glog.V(logger.Error).Infof("Failed to get current state: %v", err) return } managedState := state.ManageState(currentState) if err != nil { glog.V(logger.Error).Infof("Failed to get managed state: %v", err) return } pool.pendingState = managedState // validate the pool of pending transactions, this will remove // any transactions that have been included in the block or // have been invalidated because of another transaction (e.g. // higher gas price) pool.demoteUnexecutables() // Update all accounts to the latest known pending nonce for addr, list := range pool.pending { txs := list.Flatten() // Heavy but will be cached and is needed by the miner anyway pool.pendingState.SetNonce(addr, txs[len(txs)-1].Nonce()+1) } // Check the queue and move transactions over to the pending if possible // or remove those that have become invalid pool.promoteExecutables() }
func (pool *TxPool) resetState() { currentState, err := pool.currentState() if err != nil { glog.V(logger.Info).Infoln("failed to get current state: %v", err) return } managedState := state.ManageState(currentState) if err != nil { glog.V(logger.Info).Infoln("failed to get managed state: %v", err) return } pool.pendingState = managedState // validate the pool of pending transactions, this will remove // any transactions that have been included in the block or // have been invalidated because of another transaction (e.g. // higher gas price) pool.validatePool() // Loop over the pending transactions and base the nonce of the new // pending transaction set. for _, tx := range pool.pending { if addr, err := tx.From(); err == nil { // Set the nonce. Transaction nonce can never be lower // than the state nonce; validatePool took care of that. if pool.pendingState.GetNonce(addr) <= tx.Nonce() { pool.pendingState.SetNonce(addr, tx.Nonce()+1) } } } // Check the queue and move transactions over to the pending if possible // or remove those that have become invalid pool.checkQueue() }
func (pool *TxPool) resetState() { pool.pendingState = state.ManageState(pool.currentState()) // validate the pool of pending transactions, this will remove // any transactions that have been included in the block or // have been invalidated because of another transaction (e.g. // higher gas price) pool.validatePool() // Loop over the pending transactions and base the nonce of the new // pending transaction set. for _, tx := range pool.pending { if addr, err := tx.From(); err == nil { // Set the nonce. Transaction nonce can never be lower // than the state nonce; validatePool took care of that. if pool.pendingState.GetNonce(addr) < tx.Nonce() { pool.pendingState.SetNonce(addr, tx.Nonce()) } } } // Check the queue and move transactions over to the pending if possible // or remove those that have become invalid pool.checkQueue() }
func NewTxPool(eventMux *event.TypeMux, currentStateFn stateFn, gasLimitFn func() *big.Int) *TxPool { pool := &TxPool{ pending: make(map[common.Hash]*types.Transaction), queue: make(map[common.Address]map[common.Hash]*types.Transaction), quit: make(chan bool), eventMux: eventMux, currentState: currentStateFn, gasLimit: gasLimitFn, minGasPrice: new(big.Int), pendingState: state.ManageState(currentStateFn()), events: eventMux.Subscribe(ChainHeadEvent{}, GasPriceChanged{}), } go pool.eventLoop() return pool }