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.
This commit is contained in:
Felix Lange
2017-03-22 18:20:33 +01:00
parent 525116dbff
commit c213fd1fd8
69 changed files with 187 additions and 437 deletions

View File

@ -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 (

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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)

View File

@ -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.

View File

@ -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)

View File

@ -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) {

View File

@ -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

View File

@ -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)

View File

@ -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++ {

View File

@ -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