aboutsummaryrefslogtreecommitdiffstats
path: root/light
diff options
context:
space:
mode:
Diffstat (limited to 'light')
-rw-r--r--light/lightchain.go2
-rw-r--r--light/lightchain_test.go2
-rw-r--r--light/odr.go2
-rw-r--r--light/odr_test.go7
-rw-r--r--light/odr_util.go2
-rw-r--r--light/state.go2
-rw-r--r--light/state_object.go2
-rw-r--r--light/state_test.go2
-rw-r--r--light/trie.go3
-rw-r--r--light/txpool.go34
-rw-r--r--light/txpool_test.go5
-rw-r--r--light/vm_env.go2
12 files changed, 39 insertions, 26 deletions
diff --git a/light/lightchain.go b/light/lightchain.go
index 4715d47ab..82b7a5866 100644
--- a/light/lightchain.go
+++ b/light/lightchain.go
@@ -17,6 +17,7 @@
package light
import (
+ "context"
"math/big"
"sync"
"sync/atomic"
@@ -32,7 +33,6 @@ import (
"github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/rlp"
"github.com/hashicorp/golang-lru"
- "golang.org/x/net/context"
)
var (
diff --git a/light/lightchain_test.go b/light/lightchain_test.go
index 8a99c69f1..7460fd1a3 100644
--- a/light/lightchain_test.go
+++ b/light/lightchain_test.go
@@ -17,6 +17,7 @@
package light
import (
+ "context"
"fmt"
"math/big"
"runtime"
@@ -30,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/pow"
"github.com/hashicorp/golang-lru"
- "golang.org/x/net/context"
)
// So we can deterministically seed different blockchains
diff --git a/light/odr.go b/light/odr.go
index 4f6ef6b9e..ca6364f28 100644
--- a/light/odr.go
+++ b/light/odr.go
@@ -19,6 +19,7 @@
package light
import (
+ "context"
"math/big"
"github.com/ethereum/go-ethereum/common"
@@ -27,7 +28,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
- "golang.org/x/net/context"
)
// NoOdr is the default context passed to an ODR capable function when the ODR
diff --git a/light/odr_test.go b/light/odr_test.go
index e2eced346..ba82ec04f 100644
--- a/light/odr_test.go
+++ b/light/odr_test.go
@@ -18,6 +18,7 @@ package light
import (
"bytes"
+ "context"
"errors"
"math/big"
"testing"
@@ -36,7 +37,6 @@ import (
"github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
- "golang.org/x/net/context"
)
var (
@@ -277,8 +277,11 @@ func testChainOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) {
for i := uint64(0); i <= blockchain.CurrentHeader().Number.Uint64(); i++ {
bhash := core.GetCanonicalHash(sdb, i)
b1 := fn(NoOdr, sdb, blockchain, nil, bhash)
- ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
+
+ ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
+ defer cancel()
b2 := fn(ctx, ldb, nil, lightchain, bhash)
+
eq := bytes.Equal(b1, b2)
exp := i < expFail
if exp && !eq {
diff --git a/light/odr_util.go b/light/odr_util.go
index 17e9aadcb..d7f8458f1 100644
--- a/light/odr_util.go
+++ b/light/odr_util.go
@@ -18,6 +18,7 @@ package light
import (
"bytes"
+ "context"
"errors"
"math/big"
@@ -27,7 +28,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
- "golang.org/x/net/context"
)
var sha3_nil = crypto.Keccak256Hash(nil)
diff --git a/light/state.go b/light/state.go
index d3e047ef4..b184dc3a5 100644
--- a/light/state.go
+++ b/light/state.go
@@ -17,11 +17,11 @@
package light
import (
+ "context"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
- "golang.org/x/net/context"
)
// LightState is a memory representation of a state.
diff --git a/light/state_object.go b/light/state_object.go
index f33ba217e..a54ea1d9f 100644
--- a/light/state_object.go
+++ b/light/state_object.go
@@ -18,13 +18,13 @@ package light
import (
"bytes"
+ "context"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
- "golang.org/x/net/context"
)
var emptyCodeHash = crypto.Keccak256(nil)
diff --git a/light/state_test.go b/light/state_test.go
index d594ab9ff..e776efec8 100644
--- a/light/state_test.go
+++ b/light/state_test.go
@@ -18,6 +18,7 @@ package light
import (
"bytes"
+ "context"
"math/big"
"testing"
@@ -26,7 +27,6 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
- "golang.org/x/net/context"
)
func makeTestState() (common.Hash, ethdb.Database) {
diff --git a/light/trie.go b/light/trie.go
index c5525358a..1440f2fbf 100644
--- a/light/trie.go
+++ b/light/trie.go
@@ -17,9 +17,10 @@
package light
import (
+ "context"
+
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/trie"
- "golang.org/x/net/context"
)
// LightTrie is an ODR-capable wrapper around trie.SecureTrie
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)
diff --git a/light/txpool_test.go b/light/txpool_test.go
index 980c7c898..e93955511 100644
--- a/light/txpool_test.go
+++ b/light/txpool_test.go
@@ -17,6 +17,7 @@
package light
import (
+ "context"
"math"
"math/big"
"testing"
@@ -30,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/pow"
- "golang.org/x/net/context"
)
type testTxRelay struct {
@@ -107,10 +107,11 @@ func TestTxPool(t *testing.T) {
lightchain.SetValidator(bproc{})
txPermanent = 50
pool := NewTxPool(testChainConfig(), evmux, lightchain, relay)
+ ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
+ defer cancel()
for ii, block := range gchain {
i := ii + 1
- ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
s := sentTx(i - 1)
e := sentTx(i)
for i := s; i < e; i++ {
diff --git a/light/vm_env.go b/light/vm_env.go
index ebd229de8..54aa12875 100644
--- a/light/vm_env.go
+++ b/light/vm_env.go
@@ -17,12 +17,12 @@
package light
import (
+ "context"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
- "golang.org/x/net/context"
)
// VMState is a wrapper for the light state that holds the actual context and