aboutsummaryrefslogtreecommitdiffstats
path: root/light/txpool.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2017-03-23 01:20:33 +0800
committerFelix Lange <fjl@twurst.com>2017-03-23 03:49:15 +0800
commitc213fd1fd8bb624241da7fc98cf25098d8b92761 (patch)
tree7b109b0962b34d90d275a1dd1f64fbdba588bf9f /light/txpool.go
parent525116dbff916825463931361f75e75e955c12e2 (diff)
downloaddexon-c213fd1fd8bb624241da7fc98cf25098d8b92761.tar
dexon-c213fd1fd8bb624241da7fc98cf25098d8b92761.tar.gz
dexon-c213fd1fd8bb624241da7fc98cf25098d8b92761.tar.bz2
dexon-c213fd1fd8bb624241da7fc98cf25098d8b92761.tar.lz
dexon-c213fd1fd8bb624241da7fc98cf25098d8b92761.tar.xz
dexon-c213fd1fd8bb624241da7fc98cf25098d8b92761.tar.zst
dexon-c213fd1fd8bb624241da7fc98cf25098d8b92761.zip
all: import "context" instead of "golang.org/x/net/context"
There is no need to depend on the old context package now that the minimum Go version is 1.7. The move to "context" eliminates our weird vendoring setup. Some vendored code still uses golang.org/x/net/context and it is now vendored in the normal way. This change triggered new vet checks around context.WithTimeout which didn't fire with golang.org/x/net/context.
Diffstat (limited to 'light/txpool.go')
-rw-r--r--light/txpool.go34
1 files changed, 21 insertions, 13 deletions
diff --git a/light/txpool.go b/light/txpool.go
index 5eb1ba801..446195806 100644
--- a/light/txpool.go
+++ b/light/txpool.go
@@ -17,6 +17,7 @@
package light
import (
+ "context"
"fmt"
"sync"
"time"
@@ -29,7 +30,6 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
- "golang.org/x/net/context"
)
// txPermanent is the number of mined blocks after a mined transaction is
@@ -230,13 +230,13 @@ func (pool *TxPool) rollbackTxs(hash common.Hash, txc txStateChanges) {
}
}
-// setNewHead sets a new head header, processing (and rolling back if necessary)
+// reorgOnNewHead sets a new head header, processing (and rolling back if necessary)
// the blocks since the last known head and returns a txStateChanges map containing
// the recently mined and rolled back transaction hashes. If an error (context
// timeout) occurs during checking new blocks, it leaves the locally known head
// at the latest checked block and still returns a valid txStateChanges, making it
// possible to continue checking the missing blocks at the next chain head event
-func (pool *TxPool) setNewHead(ctx context.Context, newHeader *types.Header) (txStateChanges, error) {
+func (pool *TxPool) reorgOnNewHead(ctx context.Context, newHeader *types.Header) (txStateChanges, error) {
txc := make(txStateChanges)
oldh := pool.chain.GetHeaderByHash(pool.head)
newh := newHeader
@@ -305,20 +305,28 @@ func (pool *TxPool) eventLoop() {
for ev := range pool.events.Chan() {
switch ev.Data.(type) {
case core.ChainHeadEvent:
- head := pool.chain.CurrentHeader()
- pool.mu.Lock()
- ctx, _ := context.WithTimeout(context.Background(), blockCheckTimeout)
- txc, _ := pool.setNewHead(ctx, head)
- m, r := txc.getLists()
- pool.relay.NewHead(pool.head, m, r)
- pool.homestead = pool.config.IsHomestead(head.Number)
- pool.signer = types.MakeSigner(pool.config, head.Number)
- pool.mu.Unlock()
- time.Sleep(time.Millisecond) // hack in order to avoid hogging the lock; this part will be replaced by a subsequent PR
+ pool.setNewHead(ev.Data.(core.ChainHeadEvent).Block.Header())
+ // hack in order to avoid hogging the lock; this part will
+ // be replaced by a subsequent PR.
+ time.Sleep(time.Millisecond)
}
}
}
+func (pool *TxPool) setNewHead(head *types.Header) {
+ pool.mu.Lock()
+ defer pool.mu.Unlock()
+
+ ctx, cancel := context.WithTimeout(context.Background(), blockCheckTimeout)
+ defer cancel()
+
+ txc, _ := pool.reorgOnNewHead(ctx, head)
+ m, r := txc.getLists()
+ pool.relay.NewHead(pool.head, m, r)
+ pool.homestead = pool.config.IsHomestead(head.Number)
+ pool.signer = types.MakeSigner(pool.config, head.Number)
+}
+
// Stop stops the light transaction pool
func (pool *TxPool) Stop() {
close(pool.quit)