From c213fd1fd8bb624241da7fc98cf25098d8b92761 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 22 Mar 2017 18:20:33 +0100 Subject: 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. --- contracts/chequebook/cheque.go | 2 +- contracts/release/release.go | 74 ++++++++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 37 deletions(-) (limited to 'contracts') diff --git a/contracts/chequebook/cheque.go b/contracts/chequebook/cheque.go index 945e56e86..7e0f7eafc 100644 --- a/contracts/chequebook/cheque.go +++ b/contracts/chequebook/cheque.go @@ -26,6 +26,7 @@ package chequebook import ( "bytes" + "context" "crypto/ecdsa" "encoding/json" "fmt" @@ -43,7 +44,6 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/swarm/services/swap/swap" - "golang.org/x/net/context" ) // TODO(zelig): watch peer solvency and notify of bouncing cheques diff --git a/contracts/release/release.go b/contracts/release/release.go index 613e62aa9..28a35381d 100644 --- a/contracts/release/release.go +++ b/contracts/release/release.go @@ -20,6 +20,7 @@ package release //go:generate abigen --sol ./contract.sol --pkg release --out ./contract.go import ( + "context" "fmt" "strings" "time" @@ -33,7 +34,6 @@ import ( "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/rpc" - "golang.org/x/net/context" ) // Interval to check for new releases @@ -116,47 +116,49 @@ func (r *ReleaseService) checker() { for { select { - // If the time arrived, check for a new release case <-timer.C: // Rechedule the timer before continuing timer.Reset(releaseRecheckInterval) - - // Retrieve the current version, and handle missing contracts gracefully - ctx, _ := context.WithTimeout(context.Background(), time.Second*5) - opts := &bind.CallOpts{Context: ctx} - version, err := r.oracle.CurrentVersion(opts) - if err != nil { - if err == bind.ErrNoCode { - log.Debug("Release oracle not found", "contract", r.config.Oracle) - continue - } - log.Error("Failed to retrieve current release", "err", err) - continue - } - // Version was successfully retrieved, notify if newer than ours - if version.Major > r.config.Major || - (version.Major == r.config.Major && version.Minor > r.config.Minor) || - (version.Major == r.config.Major && version.Minor == r.config.Minor && version.Patch > r.config.Patch) { - - warning := fmt.Sprintf("Client v%d.%d.%d-%x seems older than the latest upstream release v%d.%d.%d-%x", - r.config.Major, r.config.Minor, r.config.Patch, r.config.Commit[:4], version.Major, version.Minor, version.Patch, version.Commit[:4]) - howtofix := fmt.Sprintf("Please check https://github.com/ethereum/go-ethereum/releases for new releases") - separator := strings.Repeat("-", len(warning)) - - log.Warn(separator) - log.Warn(warning) - log.Warn(howtofix) - log.Warn(separator) - } else { - log.Debug("Client seems up to date with upstream", - "local", fmt.Sprintf("v%d.%d.%d-%x", r.config.Major, r.config.Minor, r.config.Patch, r.config.Commit[:4]), - "upstream", fmt.Sprintf("v%d.%d.%d-%x", version.Major, version.Minor, version.Patch, version.Commit[:4])) - } - - // If termination was requested, return + r.checkVersion() case errc := <-r.quit: errc <- nil return } } } + +func (r *ReleaseService) checkVersion() { + // Retrieve the current version, and handle missing contracts gracefully + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) + opts := &bind.CallOpts{Context: ctx} + defer cancel() + + version, err := r.oracle.CurrentVersion(opts) + if err != nil { + if err == bind.ErrNoCode { + log.Debug("Release oracle not found", "contract", r.config.Oracle) + } else { + log.Error("Failed to retrieve current release", "err", err) + } + return + } + // Version was successfully retrieved, notify if newer than ours + if version.Major > r.config.Major || + (version.Major == r.config.Major && version.Minor > r.config.Minor) || + (version.Major == r.config.Major && version.Minor == r.config.Minor && version.Patch > r.config.Patch) { + + warning := fmt.Sprintf("Client v%d.%d.%d-%x seems older than the latest upstream release v%d.%d.%d-%x", + r.config.Major, r.config.Minor, r.config.Patch, r.config.Commit[:4], version.Major, version.Minor, version.Patch, version.Commit[:4]) + howtofix := fmt.Sprintf("Please check https://github.com/ethereum/go-ethereum/releases for new releases") + separator := strings.Repeat("-", len(warning)) + + log.Warn(separator) + log.Warn(warning) + log.Warn(howtofix) + log.Warn(separator) + } else { + log.Debug("Client seems up to date with upstream", + "local", fmt.Sprintf("v%d.%d.%d-%x", r.config.Major, r.config.Minor, r.config.Patch, r.config.Commit[:4]), + "upstream", fmt.Sprintf("v%d.%d.%d-%x", version.Major, version.Minor, version.Patch, version.Commit[:4])) + } +} -- cgit