示例#1
0
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()
}
示例#2
0
func NewTxPool(eventMux *event.TypeMux, currentStateFn stateFn, gasLimitFn func() *big.Int) *TxPool {
	pool := &TxPool{
		pending:      make(map[common.Hash]*poolTx),
		queue:        make(map[common.Address]map[common.Hash]*poolTx),
		quit:         make(chan bool),
		eventMux:     eventMux,
		currentState: currentStateFn,
		gasLimit:     gasLimitFn,
		minGasPrice:  new(big.Int),
		pendingState: state.ManageState(currentStateFn()),
		events:       eventMux.Subscribe(ChainHeadEvent{}, GasPriceChanged{}, RemovedTransactionEvent{}),
	}
	go pool.eventLoop()

	return pool
}
示例#3
0
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())
			}

			if tx.owned && pool.currentState().GetNonce(addr) == tx.Nonce() { // only resend first to prevent spam
				if time.Since(tx.sentAt) > resendTime {
					/*
						In the future we can do something like the following
						and let the user take some action if the frontend is
						capable (e.g. higher gas price).
						if tx.tries > 10 {
							post(FailedTx{tx})
							delete(tx)
						}
					*/
					glog.V(logger.Debug).Infof("resending tx: %x\n", tx.Hash())
					go pool.postTx(tx)
				}
			}
		}
	}

	// Check the queue and move transactions over to the pending if possible
	// or remove those that have become invalid
	pool.checkQueue()
}