mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
all: import "context" instead of "golang.org/x/net/context"
This commit is contained in:
parent
d9d9df5511
commit
806b56b5ab
74 changed files with 161 additions and 952 deletions
|
|
@ -17,13 +17,13 @@
|
||||||
package bind
|
package bind
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq"
|
"github.com/ubiq/go-ubiq"
|
||||||
"github.com/ubiq/go-ubiq/common"
|
"github.com/ubiq/go-ubiq/common"
|
||||||
"github.com/ubiq/go-ubiq/core/types"
|
"github.com/ubiq/go-ubiq/core/types"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package backends
|
package backends
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -32,7 +33,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/ethdb"
|
"github.com/ubiq/go-ubiq/ethdb"
|
||||||
"github.com/ubiq/go-ubiq/event"
|
"github.com/ubiq/go-ubiq/event"
|
||||||
"github.com/ubiq/go-ubiq/params"
|
"github.com/ubiq/go-ubiq/params"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Default chain configuration which sets homestead phase at block 0 (i.e. no frontier)
|
// Default chain configuration which sets homestead phase at block 0 (i.e. no frontier)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package bind
|
package bind
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -26,7 +27,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/common"
|
"github.com/ubiq/go-ubiq/common"
|
||||||
"github.com/ubiq/go-ubiq/core/types"
|
"github.com/ubiq/go-ubiq/core/types"
|
||||||
"github.com/ubiq/go-ubiq/crypto"
|
"github.com/ubiq/go-ubiq/crypto"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SignerFn is a signer function callback when a contract requires a method to
|
// SignerFn is a signer function callback when a contract requires a method to
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package bind
|
package bind
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -24,7 +25,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/core/types"
|
"github.com/ubiq/go-ubiq/core/types"
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// WaitMined waits for tx to be mined on the blockchain.
|
// WaitMined waits for tx to be mined on the blockchain.
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package bind_test
|
package bind_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -27,7 +28,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/core"
|
"github.com/ubiq/go-ubiq/core"
|
||||||
"github.com/ubiq/go-ubiq/core/types"
|
"github.com/ubiq/go-ubiq/core/types"
|
||||||
"github.com/ubiq/go-ubiq/crypto"
|
"github.com/ubiq/go-ubiq/crypto"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
package usbwallet
|
package usbwallet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
@ -38,7 +39,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"github.com/ubiq/go-ubiq/rlp"
|
"github.com/ubiq/go-ubiq/rlp"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Maximum time between wallet health checks to detect USB unplugs.
|
// Maximum time between wallet health checks to detect USB unplugs.
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are
|
|
||||||
met:
|
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
* Neither the name of Google Inc. nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
@ -1,156 +0,0 @@
|
||||||
// Copyright 2014 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Package context defines the Context type, which carries deadlines,
|
|
||||||
// cancelation signals, and other request-scoped values across API boundaries
|
|
||||||
// and between processes.
|
|
||||||
//
|
|
||||||
// Incoming requests to a server should create a Context, and outgoing calls to
|
|
||||||
// servers should accept a Context. The chain of function calls between must
|
|
||||||
// propagate the Context, optionally replacing it with a modified copy created
|
|
||||||
// using WithDeadline, WithTimeout, WithCancel, or WithValue.
|
|
||||||
//
|
|
||||||
// Programs that use Contexts should follow these rules to keep interfaces
|
|
||||||
// consistent across packages and enable static analysis tools to check context
|
|
||||||
// propagation:
|
|
||||||
//
|
|
||||||
// Do not store Contexts inside a struct type; instead, pass a Context
|
|
||||||
// explicitly to each function that needs it. The Context should be the first
|
|
||||||
// parameter, typically named ctx:
|
|
||||||
//
|
|
||||||
// func DoSomething(ctx context.Context, arg Arg) error {
|
|
||||||
// // ... use ctx ...
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Do not pass a nil Context, even if a function permits it. Pass context.TODO
|
|
||||||
// if you are unsure about which Context to use.
|
|
||||||
//
|
|
||||||
// Use context Values only for request-scoped data that transits processes and
|
|
||||||
// APIs, not for passing optional parameters to functions.
|
|
||||||
//
|
|
||||||
// The same Context may be passed to functions running in different goroutines;
|
|
||||||
// Contexts are safe for simultaneous use by multiple goroutines.
|
|
||||||
//
|
|
||||||
// See http://blog.golang.org/context for example code for a server that uses
|
|
||||||
// Contexts.
|
|
||||||
package context // import "golang.org/x/net/context"
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
// A Context carries a deadline, a cancelation signal, and other values across
|
|
||||||
// API boundaries.
|
|
||||||
//
|
|
||||||
// Context's methods may be called by multiple goroutines simultaneously.
|
|
||||||
type Context interface {
|
|
||||||
// Deadline returns the time when work done on behalf of this context
|
|
||||||
// should be canceled. Deadline returns ok==false when no deadline is
|
|
||||||
// set. Successive calls to Deadline return the same results.
|
|
||||||
Deadline() (deadline time.Time, ok bool)
|
|
||||||
|
|
||||||
// Done returns a channel that's closed when work done on behalf of this
|
|
||||||
// context should be canceled. Done may return nil if this context can
|
|
||||||
// never be canceled. Successive calls to Done return the same value.
|
|
||||||
//
|
|
||||||
// WithCancel arranges for Done to be closed when cancel is called;
|
|
||||||
// WithDeadline arranges for Done to be closed when the deadline
|
|
||||||
// expires; WithTimeout arranges for Done to be closed when the timeout
|
|
||||||
// elapses.
|
|
||||||
//
|
|
||||||
// Done is provided for use in select statements:
|
|
||||||
//
|
|
||||||
// // Stream generates values with DoSomething and sends them to out
|
|
||||||
// // until DoSomething returns an error or ctx.Done is closed.
|
|
||||||
// func Stream(ctx context.Context, out chan<- Value) error {
|
|
||||||
// for {
|
|
||||||
// v, err := DoSomething(ctx)
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// select {
|
|
||||||
// case <-ctx.Done():
|
|
||||||
// return ctx.Err()
|
|
||||||
// case out <- v:
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// See http://blog.golang.org/pipelines for more examples of how to use
|
|
||||||
// a Done channel for cancelation.
|
|
||||||
Done() <-chan struct{}
|
|
||||||
|
|
||||||
// Err returns a non-nil error value after Done is closed. Err returns
|
|
||||||
// Canceled if the context was canceled or DeadlineExceeded if the
|
|
||||||
// context's deadline passed. No other values for Err are defined.
|
|
||||||
// After Done is closed, successive calls to Err return the same value.
|
|
||||||
Err() error
|
|
||||||
|
|
||||||
// Value returns the value associated with this context for key, or nil
|
|
||||||
// if no value is associated with key. Successive calls to Value with
|
|
||||||
// the same key returns the same result.
|
|
||||||
//
|
|
||||||
// Use context values only for request-scoped data that transits
|
|
||||||
// processes and API boundaries, not for passing optional parameters to
|
|
||||||
// functions.
|
|
||||||
//
|
|
||||||
// A key identifies a specific value in a Context. Functions that wish
|
|
||||||
// to store values in Context typically allocate a key in a global
|
|
||||||
// variable then use that key as the argument to context.WithValue and
|
|
||||||
// Context.Value. A key can be any type that supports equality;
|
|
||||||
// packages should define keys as an unexported type to avoid
|
|
||||||
// collisions.
|
|
||||||
//
|
|
||||||
// Packages that define a Context key should provide type-safe accessors
|
|
||||||
// for the values stores using that key:
|
|
||||||
//
|
|
||||||
// // Package user defines a User type that's stored in Contexts.
|
|
||||||
// package user
|
|
||||||
//
|
|
||||||
// import "golang.org/x/net/context"
|
|
||||||
//
|
|
||||||
// // User is the type of value stored in the Contexts.
|
|
||||||
// type User struct {...}
|
|
||||||
//
|
|
||||||
// // key is an unexported type for keys defined in this package.
|
|
||||||
// // This prevents collisions with keys defined in other packages.
|
|
||||||
// type key int
|
|
||||||
//
|
|
||||||
// // userKey is the key for user.User values in Contexts. It is
|
|
||||||
// // unexported; clients use user.NewContext and user.FromContext
|
|
||||||
// // instead of using this key directly.
|
|
||||||
// var userKey key = 0
|
|
||||||
//
|
|
||||||
// // NewContext returns a new Context that carries value u.
|
|
||||||
// func NewContext(ctx context.Context, u *User) context.Context {
|
|
||||||
// return context.WithValue(ctx, userKey, u)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // FromContext returns the User value stored in ctx, if any.
|
|
||||||
// func FromContext(ctx context.Context) (*User, bool) {
|
|
||||||
// u, ok := ctx.Value(userKey).(*User)
|
|
||||||
// return u, ok
|
|
||||||
// }
|
|
||||||
Value(key interface{}) interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Background returns a non-nil, empty Context. It is never canceled, has no
|
|
||||||
// values, and has no deadline. It is typically used by the main function,
|
|
||||||
// initialization, and tests, and as the top-level Context for incoming
|
|
||||||
// requests.
|
|
||||||
func Background() Context {
|
|
||||||
return background
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO returns a non-nil, empty Context. Code should use context.TODO when
|
|
||||||
// it's unclear which Context to use or it is not yet available (because the
|
|
||||||
// surrounding function has not yet been extended to accept a Context
|
|
||||||
// parameter). TODO is recognized by static analysis tools that determine
|
|
||||||
// whether Contexts are propagated correctly in a program.
|
|
||||||
func TODO() Context {
|
|
||||||
return todo
|
|
||||||
}
|
|
||||||
|
|
||||||
// A CancelFunc tells an operation to abandon its work.
|
|
||||||
// A CancelFunc does not wait for the work to stop.
|
|
||||||
// After the first call, subsequent calls to a CancelFunc do nothing.
|
|
||||||
type CancelFunc func()
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
||||||
// Copyright 2016 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build go1.7
|
|
||||||
|
|
||||||
package context
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context" // standard library's context, as of Go 1.7
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
todo = context.TODO()
|
|
||||||
background = context.Background()
|
|
||||||
)
|
|
||||||
|
|
||||||
// Canceled is the error returned by Context.Err when the context is canceled.
|
|
||||||
var Canceled = context.Canceled
|
|
||||||
|
|
||||||
// DeadlineExceeded is the error returned by Context.Err when the context's
|
|
||||||
// deadline passes.
|
|
||||||
var DeadlineExceeded = context.DeadlineExceeded
|
|
||||||
|
|
||||||
// WithCancel returns a copy of parent with a new Done channel. The returned
|
|
||||||
// context's Done channel is closed when the returned cancel function is called
|
|
||||||
// or when the parent context's Done channel is closed, whichever happens first.
|
|
||||||
//
|
|
||||||
// Canceling this context releases resources associated with it, so code should
|
|
||||||
// call cancel as soon as the operations running in this Context complete.
|
|
||||||
func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
|
|
||||||
ctx, f := context.WithCancel(parent)
|
|
||||||
return ctx, CancelFunc(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDeadline returns a copy of the parent context with the deadline adjusted
|
|
||||||
// to be no later than d. If the parent's deadline is already earlier than d,
|
|
||||||
// WithDeadline(parent, d) is semantically equivalent to parent. The returned
|
|
||||||
// context's Done channel is closed when the deadline expires, when the returned
|
|
||||||
// cancel function is called, or when the parent context's Done channel is
|
|
||||||
// closed, whichever happens first.
|
|
||||||
//
|
|
||||||
// Canceling this context releases resources associated with it, so code should
|
|
||||||
// call cancel as soon as the operations running in this Context complete.
|
|
||||||
func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) {
|
|
||||||
ctx, f := context.WithDeadline(parent, deadline)
|
|
||||||
return ctx, CancelFunc(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
|
|
||||||
//
|
|
||||||
// Canceling this context releases resources associated with it, so code should
|
|
||||||
// call cancel as soon as the operations running in this Context complete:
|
|
||||||
//
|
|
||||||
// func slowOperationWithTimeout(ctx context.Context) (Result, error) {
|
|
||||||
// ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
|
|
||||||
// defer cancel() // releases resources if slowOperation completes before timeout elapses
|
|
||||||
// return slowOperation(ctx)
|
|
||||||
// }
|
|
||||||
func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
|
|
||||||
return WithDeadline(parent, time.Now().Add(timeout))
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithValue returns a copy of parent in which the value associated with key is
|
|
||||||
// val.
|
|
||||||
//
|
|
||||||
// Use context Values only for request-scoped data that transits processes and
|
|
||||||
// APIs, not for passing optional parameters to functions.
|
|
||||||
func WithValue(parent Context, key interface{}, val interface{}) Context {
|
|
||||||
return context.WithValue(parent, key, val)
|
|
||||||
}
|
|
||||||
|
|
@ -1,300 +0,0 @@
|
||||||
// Copyright 2014 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build !go1.7
|
|
||||||
|
|
||||||
package context
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// An emptyCtx is never canceled, has no values, and has no deadline. It is not
|
|
||||||
// struct{}, since vars of this type must have distinct addresses.
|
|
||||||
type emptyCtx int
|
|
||||||
|
|
||||||
func (*emptyCtx) Deadline() (deadline time.Time, ok bool) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*emptyCtx) Done() <-chan struct{} {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*emptyCtx) Err() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*emptyCtx) Value(key interface{}) interface{} {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *emptyCtx) String() string {
|
|
||||||
switch e {
|
|
||||||
case background:
|
|
||||||
return "context.Background"
|
|
||||||
case todo:
|
|
||||||
return "context.TODO"
|
|
||||||
}
|
|
||||||
return "unknown empty Context"
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
background = new(emptyCtx)
|
|
||||||
todo = new(emptyCtx)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Canceled is the error returned by Context.Err when the context is canceled.
|
|
||||||
var Canceled = errors.New("context canceled")
|
|
||||||
|
|
||||||
// DeadlineExceeded is the error returned by Context.Err when the context's
|
|
||||||
// deadline passes.
|
|
||||||
var DeadlineExceeded = errors.New("context deadline exceeded")
|
|
||||||
|
|
||||||
// WithCancel returns a copy of parent with a new Done channel. The returned
|
|
||||||
// context's Done channel is closed when the returned cancel function is called
|
|
||||||
// or when the parent context's Done channel is closed, whichever happens first.
|
|
||||||
//
|
|
||||||
// Canceling this context releases resources associated with it, so code should
|
|
||||||
// call cancel as soon as the operations running in this Context complete.
|
|
||||||
func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
|
|
||||||
c := newCancelCtx(parent)
|
|
||||||
propagateCancel(parent, c)
|
|
||||||
return c, func() { c.cancel(true, Canceled) }
|
|
||||||
}
|
|
||||||
|
|
||||||
// newCancelCtx returns an initialized cancelCtx.
|
|
||||||
func newCancelCtx(parent Context) *cancelCtx {
|
|
||||||
return &cancelCtx{
|
|
||||||
Context: parent,
|
|
||||||
done: make(chan struct{}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// propagateCancel arranges for child to be canceled when parent is.
|
|
||||||
func propagateCancel(parent Context, child canceler) {
|
|
||||||
if parent.Done() == nil {
|
|
||||||
return // parent is never canceled
|
|
||||||
}
|
|
||||||
if p, ok := parentCancelCtx(parent); ok {
|
|
||||||
p.mu.Lock()
|
|
||||||
if p.err != nil {
|
|
||||||
// parent has already been canceled
|
|
||||||
child.cancel(false, p.err)
|
|
||||||
} else {
|
|
||||||
if p.children == nil {
|
|
||||||
p.children = make(map[canceler]bool)
|
|
||||||
}
|
|
||||||
p.children[child] = true
|
|
||||||
}
|
|
||||||
p.mu.Unlock()
|
|
||||||
} else {
|
|
||||||
go func() {
|
|
||||||
select {
|
|
||||||
case <-parent.Done():
|
|
||||||
child.cancel(false, parent.Err())
|
|
||||||
case <-child.Done():
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parentCancelCtx follows a chain of parent references until it finds a
|
|
||||||
// *cancelCtx. This function understands how each of the concrete types in this
|
|
||||||
// package represents its parent.
|
|
||||||
func parentCancelCtx(parent Context) (*cancelCtx, bool) {
|
|
||||||
for {
|
|
||||||
switch c := parent.(type) {
|
|
||||||
case *cancelCtx:
|
|
||||||
return c, true
|
|
||||||
case *timerCtx:
|
|
||||||
return c.cancelCtx, true
|
|
||||||
case *valueCtx:
|
|
||||||
parent = c.Context
|
|
||||||
default:
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// removeChild removes a context from its parent.
|
|
||||||
func removeChild(parent Context, child canceler) {
|
|
||||||
p, ok := parentCancelCtx(parent)
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.mu.Lock()
|
|
||||||
if p.children != nil {
|
|
||||||
delete(p.children, child)
|
|
||||||
}
|
|
||||||
p.mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// A canceler is a context type that can be canceled directly. The
|
|
||||||
// implementations are *cancelCtx and *timerCtx.
|
|
||||||
type canceler interface {
|
|
||||||
cancel(removeFromParent bool, err error)
|
|
||||||
Done() <-chan struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A cancelCtx can be canceled. When canceled, it also cancels any children
|
|
||||||
// that implement canceler.
|
|
||||||
type cancelCtx struct {
|
|
||||||
Context
|
|
||||||
|
|
||||||
done chan struct{} // closed by the first cancel call.
|
|
||||||
|
|
||||||
mu sync.Mutex
|
|
||||||
children map[canceler]bool // set to nil by the first cancel call
|
|
||||||
err error // set to non-nil by the first cancel call
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cancelCtx) Done() <-chan struct{} {
|
|
||||||
return c.done
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cancelCtx) Err() error {
|
|
||||||
c.mu.Lock()
|
|
||||||
defer c.mu.Unlock()
|
|
||||||
return c.err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cancelCtx) String() string {
|
|
||||||
return fmt.Sprintf("%v.WithCancel", c.Context)
|
|
||||||
}
|
|
||||||
|
|
||||||
// cancel closes c.done, cancels each of c's children, and, if
|
|
||||||
// removeFromParent is true, removes c from its parent's children.
|
|
||||||
func (c *cancelCtx) cancel(removeFromParent bool, err error) {
|
|
||||||
if err == nil {
|
|
||||||
panic("context: internal error: missing cancel error")
|
|
||||||
}
|
|
||||||
c.mu.Lock()
|
|
||||||
if c.err != nil {
|
|
||||||
c.mu.Unlock()
|
|
||||||
return // already canceled
|
|
||||||
}
|
|
||||||
c.err = err
|
|
||||||
close(c.done)
|
|
||||||
for child := range c.children {
|
|
||||||
// NOTE: acquiring the child's lock while holding parent's lock.
|
|
||||||
child.cancel(false, err)
|
|
||||||
}
|
|
||||||
c.children = nil
|
|
||||||
c.mu.Unlock()
|
|
||||||
|
|
||||||
if removeFromParent {
|
|
||||||
removeChild(c.Context, c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDeadline returns a copy of the parent context with the deadline adjusted
|
|
||||||
// to be no later than d. If the parent's deadline is already earlier than d,
|
|
||||||
// WithDeadline(parent, d) is semantically equivalent to parent. The returned
|
|
||||||
// context's Done channel is closed when the deadline expires, when the returned
|
|
||||||
// cancel function is called, or when the parent context's Done channel is
|
|
||||||
// closed, whichever happens first.
|
|
||||||
//
|
|
||||||
// Canceling this context releases resources associated with it, so code should
|
|
||||||
// call cancel as soon as the operations running in this Context complete.
|
|
||||||
func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) {
|
|
||||||
if cur, ok := parent.Deadline(); ok && cur.Before(deadline) {
|
|
||||||
// The current deadline is already sooner than the new one.
|
|
||||||
return WithCancel(parent)
|
|
||||||
}
|
|
||||||
c := &timerCtx{
|
|
||||||
cancelCtx: newCancelCtx(parent),
|
|
||||||
deadline: deadline,
|
|
||||||
}
|
|
||||||
propagateCancel(parent, c)
|
|
||||||
d := deadline.Sub(time.Now())
|
|
||||||
if d <= 0 {
|
|
||||||
c.cancel(true, DeadlineExceeded) // deadline has already passed
|
|
||||||
return c, func() { c.cancel(true, Canceled) }
|
|
||||||
}
|
|
||||||
c.mu.Lock()
|
|
||||||
defer c.mu.Unlock()
|
|
||||||
if c.err == nil {
|
|
||||||
c.timer = time.AfterFunc(d, func() {
|
|
||||||
c.cancel(true, DeadlineExceeded)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return c, func() { c.cancel(true, Canceled) }
|
|
||||||
}
|
|
||||||
|
|
||||||
// A timerCtx carries a timer and a deadline. It embeds a cancelCtx to
|
|
||||||
// implement Done and Err. It implements cancel by stopping its timer then
|
|
||||||
// delegating to cancelCtx.cancel.
|
|
||||||
type timerCtx struct {
|
|
||||||
*cancelCtx
|
|
||||||
timer *time.Timer // Under cancelCtx.mu.
|
|
||||||
|
|
||||||
deadline time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *timerCtx) Deadline() (deadline time.Time, ok bool) {
|
|
||||||
return c.deadline, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *timerCtx) String() string {
|
|
||||||
return fmt.Sprintf("%v.WithDeadline(%s [%s])", c.cancelCtx.Context, c.deadline, c.deadline.Sub(time.Now()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *timerCtx) cancel(removeFromParent bool, err error) {
|
|
||||||
c.cancelCtx.cancel(false, err)
|
|
||||||
if removeFromParent {
|
|
||||||
// Remove this timerCtx from its parent cancelCtx's children.
|
|
||||||
removeChild(c.cancelCtx.Context, c)
|
|
||||||
}
|
|
||||||
c.mu.Lock()
|
|
||||||
if c.timer != nil {
|
|
||||||
c.timer.Stop()
|
|
||||||
c.timer = nil
|
|
||||||
}
|
|
||||||
c.mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
|
|
||||||
//
|
|
||||||
// Canceling this context releases resources associated with it, so code should
|
|
||||||
// call cancel as soon as the operations running in this Context complete:
|
|
||||||
//
|
|
||||||
// func slowOperationWithTimeout(ctx context.Context) (Result, error) {
|
|
||||||
// ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
|
|
||||||
// defer cancel() // releases resources if slowOperation completes before timeout elapses
|
|
||||||
// return slowOperation(ctx)
|
|
||||||
// }
|
|
||||||
func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
|
|
||||||
return WithDeadline(parent, time.Now().Add(timeout))
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithValue returns a copy of parent in which the value associated with key is
|
|
||||||
// val.
|
|
||||||
//
|
|
||||||
// Use context Values only for request-scoped data that transits processes and
|
|
||||||
// APIs, not for passing optional parameters to functions.
|
|
||||||
func WithValue(parent Context, key interface{}, val interface{}) Context {
|
|
||||||
return &valueCtx{parent, key, val}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A valueCtx carries a key-value pair. It implements Value for that key and
|
|
||||||
// delegates all other calls to the embedded Context.
|
|
||||||
type valueCtx struct {
|
|
||||||
Context
|
|
||||||
key, val interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *valueCtx) String() string {
|
|
||||||
return fmt.Sprintf("%v.WithValue(%#v, %#v)", c.Context, c.key, c.val)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *valueCtx) Value(key interface{}) interface{} {
|
|
||||||
if c.key == key {
|
|
||||||
return c.val
|
|
||||||
}
|
|
||||||
return c.Context.Value(key)
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +1,3 @@
|
||||||
# Vendored Dependencies
|
|
||||||
|
|
||||||
Dependencies are almost all vendored in at the standard Go `/vendor` path. This allows
|
|
||||||
people to build go-ubiq using the standard toolchain without any particular package
|
|
||||||
manager. It also plays nicely with `go get`, not requiring external code to be relied on.
|
|
||||||
|
|
||||||
The one single dependent package missing from `vendor` is `golang.org/x/net/context`. As
|
|
||||||
this is a package exposed via public library APIs, it must not be vendored as dependent
|
|
||||||
code woulnd't be able to instantiate.
|
|
||||||
|
|
||||||
To allow reproducible builds of go-ubiq nonetheless that don't need network access
|
|
||||||
during build time to fetch `golang.org/x/net/context`, a version was copied into our repo
|
|
||||||
at the very specific `/build/_vendor` path, which is added automatically by all CI build
|
|
||||||
scripts and the makefile too.
|
|
||||||
|
|
||||||
# Debian Packaging
|
# Debian Packaging
|
||||||
|
|
||||||
Tagged releases and develop branch commits are available as installable Debian packages
|
Tagged releases and develop branch commits are available as installable Debian packages
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ package chequebook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -43,7 +44,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"github.com/ubiq/go-ubiq/swarm/services/swap/swap"
|
"github.com/ubiq/go-ubiq/swarm/services/swap/swap"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO(zelig): watch peer solvency and notify of bouncing cheques
|
// TODO(zelig): watch peer solvency and notify of bouncing cheques
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ package release
|
||||||
//go:generate abigen --sol ./contract.sol --pkg release --out ./contract.go
|
//go:generate abigen --sol ./contract.sol --pkg release --out ./contract.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -34,7 +35,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/node"
|
"github.com/ubiq/go-ubiq/node"
|
||||||
"github.com/ubiq/go-ubiq/p2p"
|
"github.com/ubiq/go-ubiq/p2p"
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Interval to check for new releases
|
// Interval to check for new releases
|
||||||
|
|
@ -117,46 +117,48 @@ func (r *ReleaseService) checker() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
// If the time arrived, check for a new release
|
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
// Rechedule the timer before continuing
|
// Rechedule the timer before continuing
|
||||||
timer.Reset(releaseRecheckInterval)
|
timer.Reset(releaseRecheckInterval)
|
||||||
|
r.checkVersion()
|
||||||
// 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 {
|
|
||||||
glog.V(logger.Debug).Infof("Release oracle not found at %x", r.config.Oracle)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
glog.V(logger.Error).Infof("Failed to retrieve current release: %v", 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/ubiq/go-ubiq/releases for new releases")
|
|
||||||
separator := strings.Repeat("-", len(warning))
|
|
||||||
|
|
||||||
glog.V(logger.Warn).Info(separator)
|
|
||||||
glog.V(logger.Warn).Info(warning)
|
|
||||||
glog.V(logger.Warn).Info(howtofix)
|
|
||||||
glog.V(logger.Warn).Info(separator)
|
|
||||||
} else {
|
|
||||||
glog.V(logger.Debug).Infof("Client v%d.%d.%d-%x seems up to date with upstream 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])
|
|
||||||
}
|
|
||||||
|
|
||||||
// If termination was requested, return
|
|
||||||
case errc := <-r.quit:
|
case errc := <-r.quit:
|
||||||
errc <- nil
|
errc <- nil
|
||||||
return
|
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 {
|
||||||
|
glog.V(logger.Debug).Infof("Release oracle not found at %x", r.config.Oracle)
|
||||||
|
} else {
|
||||||
|
glog.V(logger.Error).Infof("Failed to retrieve current release: %v", 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))
|
||||||
|
|
||||||
|
glog.V(logger.Warn).Info(separator)
|
||||||
|
glog.V(logger.Warn).Info(warning)
|
||||||
|
glog.V(logger.Warn).Info(howtofix)
|
||||||
|
glog.V(logger.Warn).Info(separator)
|
||||||
|
} else {
|
||||||
|
glog.V(logger.Debug).Infof("Client v%d.%d.%d-%x seems up to date with upstream 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])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package eth
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
@ -43,7 +44,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/params"
|
"github.com/ubiq/go-ubiq/params"
|
||||||
"github.com/ubiq/go-ubiq/rlp"
|
"github.com/ubiq/go-ubiq/rlp"
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultTraceTimeout = 5 * time.Second
|
const defaultTraceTimeout = 5 * time.Second
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package eth
|
package eth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/accounts"
|
"github.com/ubiq/go-ubiq/accounts"
|
||||||
|
|
@ -32,7 +33,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/internal/ethapi"
|
"github.com/ubiq/go-ubiq/internal/ethapi"
|
||||||
"github.com/ubiq/go-ubiq/params"
|
"github.com/ubiq/go-ubiq/params"
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// EthApiBackend implements ethapi.Backend for full nodes
|
// EthApiBackend implements ethapi.Backend for full nodes
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package eth
|
package eth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq"
|
"github.com/ubiq/go-ubiq"
|
||||||
|
|
@ -26,7 +27,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/internal/ethapi"
|
"github.com/ubiq/go-ubiq/internal/ethapi"
|
||||||
"github.com/ubiq/go-ubiq/rlp"
|
"github.com/ubiq/go-ubiq/rlp"
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContractBackend implements bind.ContractBackend with direct calls to Ethereum
|
// ContractBackend implements bind.ContractBackend with direct calls to Ethereum
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,12 @@
|
||||||
package downloader
|
package downloader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
ethereum "github.com/ubiq/go-ubiq"
|
ethereum "github.com/ubiq/go-ubiq"
|
||||||
"github.com/ubiq/go-ubiq/event"
|
"github.com/ubiq/go-ubiq/event"
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// PublicDownloaderAPI provides an API which gives information about the current synchronisation status.
|
// PublicDownloaderAPI provides an API which gives information about the current synchronisation status.
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package filters
|
package filters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -24,8 +25,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/common"
|
"github.com/ubiq/go-ubiq/common"
|
||||||
"github.com/ubiq/go-ubiq/common/hexutil"
|
"github.com/ubiq/go-ubiq/common/hexutil"
|
||||||
"github.com/ubiq/go-ubiq/core/types"
|
"github.com/ubiq/go-ubiq/core/types"
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package filters
|
package filters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -27,7 +28,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/ethdb"
|
"github.com/ubiq/go-ubiq/ethdb"
|
||||||
"github.com/ubiq/go-ubiq/event"
|
"github.com/ubiq/go-ubiq/event"
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Backend interface {
|
type Backend interface {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
package filters
|
package filters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -29,7 +30,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/core/types"
|
"github.com/ubiq/go-ubiq/core/types"
|
||||||
"github.com/ubiq/go-ubiq/event"
|
"github.com/ubiq/go-ubiq/event"
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Type determines the kind of filter and is used to put the filter in to
|
// Type determines the kind of filter and is used to put the filter in to
|
||||||
|
|
@ -372,7 +372,8 @@ func (es *EventSystem) lightFilterNewHead(newHeader *types.Header, callBack func
|
||||||
func (es *EventSystem) lightFilterLogs(header *types.Header, addresses []common.Address, topics [][]common.Hash, remove bool) []*types.Log {
|
func (es *EventSystem) lightFilterLogs(header *types.Header, addresses []common.Address, topics [][]common.Hash, remove bool) []*types.Log {
|
||||||
if bloomFilter(header.Bloom, addresses, topics) {
|
if bloomFilter(header.Bloom, addresses, topics) {
|
||||||
// Get the logs of the block
|
// Get the logs of the block
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||||
|
defer cancel()
|
||||||
receipts, err := es.backend.GetReceipts(ctx, header.Hash())
|
receipts, err := es.backend.GetReceipts(ctx, header.Hash())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,12 @@
|
||||||
package filters
|
package filters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/common"
|
"github.com/ubiq/go-ubiq/common"
|
||||||
"github.com/ubiq/go-ubiq/core"
|
"github.com/ubiq/go-ubiq/core"
|
||||||
"github.com/ubiq/go-ubiq/core/types"
|
"github.com/ubiq/go-ubiq/core/types"
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,12 @@
|
||||||
package filters
|
package filters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/common"
|
"github.com/ubiq/go-ubiq/common"
|
||||||
"github.com/ubiq/go-ubiq/core"
|
"github.com/ubiq/go-ubiq/core"
|
||||||
"github.com/ubiq/go-ubiq/core/types"
|
"github.com/ubiq/go-ubiq/core/types"
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package gasprice
|
package gasprice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -24,7 +25,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/common"
|
"github.com/ubiq/go-ubiq/common"
|
||||||
"github.com/ubiq/go-ubiq/internal/ethapi"
|
"github.com/ubiq/go-ubiq/internal/ethapi"
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
package ethclient
|
package ethclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -28,7 +29,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/core/types"
|
"github.com/ubiq/go-ubiq/core/types"
|
||||||
"github.com/ubiq/go-ubiq/rlp"
|
"github.com/ubiq/go-ubiq/rlp"
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client defines typed wrappers for the Ethereum RPC API.
|
// Client defines typed wrappers for the Ethereum RPC API.
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@
|
||||||
package event
|
package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/common/mclock"
|
"github.com/ubiq/go-ubiq/common/mclock"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Subscription represents a stream of events. The carrier of the events is typically a
|
// Subscription represents a stream of events. The carrier of the events is typically a
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,10 @@
|
||||||
package event
|
package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var errInts = errors.New("error in subscribeInts")
|
var errInts = errors.New("error in subscribeInts")
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,12 @@
|
||||||
package ethereum
|
package ethereum
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/common"
|
"github.com/ubiq/go-ubiq/common"
|
||||||
"github.com/ubiq/go-ubiq/core/types"
|
"github.com/ubiq/go-ubiq/core/types"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NotFound is returned by API methods if the requested item does not exist.
|
// NotFound is returned by API methods if the requested item does not exist.
|
||||||
|
|
|
||||||
|
|
@ -52,19 +52,10 @@ func MustRunCommand(cmd string, args ...string) {
|
||||||
// GOPATH returns the value that the GOPATH environment
|
// GOPATH returns the value that the GOPATH environment
|
||||||
// variable should be set to.
|
// variable should be set to.
|
||||||
func GOPATH() string {
|
func GOPATH() string {
|
||||||
path := filepath.SplitList(os.Getenv("GOPATH"))
|
if os.Getenv("GOPATH") == "" {
|
||||||
if len(path) == 0 {
|
|
||||||
log.Fatal("GOPATH is not set")
|
log.Fatal("GOPATH is not set")
|
||||||
}
|
}
|
||||||
// Ensure that our internal vendor folder is on GOPATH
|
return os.Getenv("GOPATH")
|
||||||
vendor, _ := filepath.Abs(filepath.Join("build", "_vendor"))
|
|
||||||
for _, dir := range path {
|
|
||||||
if dir == vendor {
|
|
||||||
return strings.Join(path, string(filepath.ListSeparator))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newpath := append(path[:1], append([]string{vendor}, path[1:]...)...)
|
|
||||||
return strings.Join(newpath, string(filepath.ListSeparator))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VERSION returns the content of the VERSION file.
|
// VERSION returns the content of the VERSION file.
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package ethapi
|
package ethapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -41,7 +42,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/p2p"
|
"github.com/ubiq/go-ubiq/p2p"
|
||||||
"github.com/ubiq/go-ubiq/rlp"
|
"github.com/ubiq/go-ubiq/rlp"
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultGas = 90000
|
const defaultGas = 90000
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
package ethapi
|
package ethapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/accounts"
|
"github.com/ubiq/go-ubiq/accounts"
|
||||||
|
|
@ -30,7 +31,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/event"
|
"github.com/ubiq/go-ubiq/event"
|
||||||
"github.com/ubiq/go-ubiq/params"
|
"github.com/ubiq/go-ubiq/params"
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Backend interface provides the common API services (that are provided by
|
// Backend interface provides the common API services (that are provided by
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package les
|
package les
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/accounts"
|
"github.com/ubiq/go-ubiq/accounts"
|
||||||
|
|
@ -32,7 +33,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/light"
|
"github.com/ubiq/go-ubiq/light"
|
||||||
"github.com/ubiq/go-ubiq/params"
|
"github.com/ubiq/go-ubiq/params"
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type LesApiBackend struct {
|
type LesApiBackend struct {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package les
|
package les
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -27,7 +28,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/light"
|
"github.com/ubiq/go-ubiq/light"
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package les
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -31,7 +32,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/light"
|
"github.com/ubiq/go-ubiq/light"
|
||||||
"github.com/ubiq/go-ubiq/params"
|
"github.com/ubiq/go-ubiq/params"
|
||||||
"github.com/ubiq/go-ubiq/rlp"
|
"github.com/ubiq/go-ubiq/rlp"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type odrTestFn func(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte
|
type odrTestFn func(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte
|
||||||
|
|
@ -177,7 +177,8 @@ func testOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) {
|
||||||
for i := uint64(0); i <= pm.blockchain.CurrentHeader().Number.Uint64(); i++ {
|
for i := uint64(0); i <= pm.blockchain.CurrentHeader().Number.Uint64(); i++ {
|
||||||
bhash := core.GetCanonicalHash(db, i)
|
bhash := core.GetCanonicalHash(db, i)
|
||||||
b1 := fn(light.NoOdr, db, pm.chainConfig, pm.blockchain.(*core.BlockChain), nil, bhash)
|
b1 := fn(light.NoOdr, db, pm.chainConfig, pm.blockchain.(*core.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, lpm.chainConfig, nil, lpm.blockchain.(*light.LightChain), bhash)
|
b2 := fn(ctx, ldb, lpm.chainConfig, nil, lpm.blockchain.(*light.LightChain), bhash)
|
||||||
eq := bytes.Equal(b1, b2)
|
eq := bytes.Equal(b1, b2)
|
||||||
exp := i < expFail
|
exp := i < expFail
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package les
|
package les
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -25,7 +26,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/crypto"
|
"github.com/ubiq/go-ubiq/crypto"
|
||||||
"github.com/ubiq/go-ubiq/ethdb"
|
"github.com/ubiq/go-ubiq/ethdb"
|
||||||
"github.com/ubiq/go-ubiq/light"
|
"github.com/ubiq/go-ubiq/light"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var testBankSecureTrieKey = secAddr(testBankAddress)
|
var testBankSecureTrieKey = secAddr(testBankAddress)
|
||||||
|
|
@ -88,7 +88,9 @@ func testAccess(t *testing.T, protocol int, fn accessTestFn) {
|
||||||
for i := uint64(0); i <= pm.blockchain.CurrentHeader().Number.Uint64(); i++ {
|
for i := uint64(0); i <= pm.blockchain.CurrentHeader().Number.Uint64(); i++ {
|
||||||
bhash := core.GetCanonicalHash(db, i)
|
bhash := core.GetCanonicalHash(db, i)
|
||||||
if req := fn(ldb, bhash, i); req != nil {
|
if req := fn(ldb, bhash, i); req != nil {
|
||||||
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
err := odr.Retrieve(ctx, req)
|
err := odr.Retrieve(ctx, req)
|
||||||
got := err == nil
|
got := err == nil
|
||||||
exp := i < expFail
|
exp := i < expFail
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,12 @@
|
||||||
package les
|
package les
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/core"
|
"github.com/ubiq/go-ubiq/core"
|
||||||
"github.com/ubiq/go-ubiq/eth/downloader"
|
"github.com/ubiq/go-ubiq/eth/downloader"
|
||||||
"github.com/ubiq/go-ubiq/light"
|
"github.com/ubiq/go-ubiq/light"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -77,8 +77,8 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||||
|
defer cancel()
|
||||||
pm.blockchain.(*light.LightChain).SyncCht(ctx)
|
pm.blockchain.(*light.LightChain).SyncCht(ctx)
|
||||||
|
|
||||||
pm.downloader.Synchronise(peer.id, peer.Head(), peer.Td(), downloader.LightSync)
|
pm.downloader.Synchronise(peer.id, peer.Head(), peer.Td(), downloader.LightSync)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package light
|
package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
@ -33,7 +34,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/params"
|
"github.com/ubiq/go-ubiq/params"
|
||||||
"github.com/ubiq/go-ubiq/pow"
|
"github.com/ubiq/go-ubiq/pow"
|
||||||
"github.com/ubiq/go-ubiq/rlp"
|
"github.com/ubiq/go-ubiq/rlp"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package light
|
package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -31,7 +32,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/params"
|
"github.com/ubiq/go-ubiq/params"
|
||||||
"github.com/ubiq/go-ubiq/pow"
|
"github.com/ubiq/go-ubiq/pow"
|
||||||
"github.com/hashicorp/golang-lru"
|
"github.com/hashicorp/golang-lru"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// So we can deterministically seed different blockchains
|
// So we can deterministically seed different blockchains
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
package light
|
package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/common"
|
"github.com/ubiq/go-ubiq/common"
|
||||||
|
|
@ -27,7 +28,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/crypto"
|
"github.com/ubiq/go-ubiq/crypto"
|
||||||
"github.com/ubiq/go-ubiq/ethdb"
|
"github.com/ubiq/go-ubiq/ethdb"
|
||||||
"github.com/ubiq/go-ubiq/rlp"
|
"github.com/ubiq/go-ubiq/rlp"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NoOdr is the default context passed to an ODR capable function when the ODR
|
// NoOdr is the default context passed to an ODR capable function when the ODR
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -34,7 +35,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/params"
|
"github.com/ubiq/go-ubiq/params"
|
||||||
"github.com/ubiq/go-ubiq/rlp"
|
"github.com/ubiq/go-ubiq/rlp"
|
||||||
"github.com/ubiq/go-ubiq/trie"
|
"github.com/ubiq/go-ubiq/trie"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -273,7 +273,8 @@ func testChainOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) {
|
||||||
for i := uint64(0); i <= blockchain.CurrentHeader().Number.Uint64(); i++ {
|
for i := uint64(0); i <= blockchain.CurrentHeader().Number.Uint64(); i++ {
|
||||||
bhash := core.GetCanonicalHash(sdb, i)
|
bhash := core.GetCanonicalHash(sdb, i)
|
||||||
b1 := fn(NoOdr, sdb, blockchain, nil, bhash)
|
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)
|
b2 := fn(ctx, ldb, nil, lightchain, bhash)
|
||||||
eq := bytes.Equal(b1, b2)
|
eq := bytes.Equal(b1, b2)
|
||||||
exp := i < expFail
|
exp := i < expFail
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
|
@ -29,7 +30,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"github.com/ubiq/go-ubiq/rlp"
|
"github.com/ubiq/go-ubiq/rlp"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var sha3_nil = crypto.Keccak256Hash(nil)
|
var sha3_nil = crypto.Keccak256Hash(nil)
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,13 @@
|
||||||
package light
|
package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/common"
|
"github.com/ubiq/go-ubiq/common"
|
||||||
"github.com/ubiq/go-ubiq/crypto"
|
"github.com/ubiq/go-ubiq/crypto"
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// LightState is a memory representation of a state.
|
// LightState is a memory representation of a state.
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
|
@ -26,7 +27,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"github.com/ubiq/go-ubiq/rlp"
|
"github.com/ubiq/go-ubiq/rlp"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var emptyCodeHash = crypto.Keccak256(nil)
|
var emptyCodeHash = crypto.Keccak256(nil)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -26,7 +27,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/core/state"
|
"github.com/ubiq/go-ubiq/core/state"
|
||||||
"github.com/ubiq/go-ubiq/core/types"
|
"github.com/ubiq/go-ubiq/core/types"
|
||||||
"github.com/ubiq/go-ubiq/ethdb"
|
"github.com/ubiq/go-ubiq/ethdb"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeTestState() (common.Hash, ethdb.Database) {
|
func makeTestState() (common.Hash, ethdb.Database) {
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@
|
||||||
package light
|
package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"github.com/ubiq/go-ubiq/ethdb"
|
"github.com/ubiq/go-ubiq/ethdb"
|
||||||
"github.com/ubiq/go-ubiq/trie"
|
"github.com/ubiq/go-ubiq/trie"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// LightTrie is an ODR-capable wrapper around trie.SecureTrie
|
// LightTrie is an ODR-capable wrapper around trie.SecureTrie
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package light
|
package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -30,7 +31,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"github.com/ubiq/go-ubiq/params"
|
"github.com/ubiq/go-ubiq/params"
|
||||||
"github.com/ubiq/go-ubiq/rlp"
|
"github.com/ubiq/go-ubiq/rlp"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// txPermanent is the number of mined blocks after a mined transaction is
|
// txPermanent is the number of mined blocks after a mined transaction is
|
||||||
|
|
@ -207,13 +207,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 blocks since the last known head and returns a txStateChanges map containing
|
||||||
// the recently mined and rolled back transaction hashes. If an error (context
|
// the recently mined and rolled back transaction hashes. If an error (context
|
||||||
// timeout) occurs during checking new blocks, it leaves the locally known head
|
// 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
|
// 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
|
// 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)
|
txc := make(txStateChanges)
|
||||||
oldh := pool.chain.GetHeaderByHash(pool.head)
|
oldh := pool.chain.GetHeaderByHash(pool.head)
|
||||||
newh := newHeader
|
newh := newHeader
|
||||||
|
|
@ -253,15 +253,17 @@ func (pool *TxPool) setNewHead(ctx context.Context, newHeader *types.Header) (tx
|
||||||
// clear old mined tx entries of old blocks
|
// clear old mined tx entries of old blocks
|
||||||
if idx := newHeader.Number.Uint64(); idx > pool.clearIdx+txPermanent {
|
if idx := newHeader.Number.Uint64(); idx > pool.clearIdx+txPermanent {
|
||||||
idx2 := idx - txPermanent
|
idx2 := idx - txPermanent
|
||||||
for i := pool.clearIdx; i < idx2; i++ {
|
if len(pool.mined) > 0 {
|
||||||
hash := core.GetCanonicalHash(pool.chainDb, i)
|
for i := pool.clearIdx; i < idx2; i++ {
|
||||||
if list, ok := pool.mined[hash]; ok {
|
hash := core.GetCanonicalHash(pool.chainDb, i)
|
||||||
hashes := make([]common.Hash, len(list))
|
if list, ok := pool.mined[hash]; ok {
|
||||||
for i, tx := range list {
|
hashes := make([]common.Hash, len(list))
|
||||||
hashes[i] = tx.Hash()
|
for i, tx := range list {
|
||||||
|
hashes[i] = tx.Hash()
|
||||||
|
}
|
||||||
|
pool.relay.Discard(hashes)
|
||||||
|
delete(pool.mined, hash)
|
||||||
}
|
}
|
||||||
pool.relay.Discard(hashes)
|
|
||||||
delete(pool.mined, hash)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pool.clearIdx = idx2
|
pool.clearIdx = idx2
|
||||||
|
|
@ -280,19 +282,28 @@ func (pool *TxPool) eventLoop() {
|
||||||
for ev := range pool.events.Chan() {
|
for ev := range pool.events.Chan() {
|
||||||
switch ev.Data.(type) {
|
switch ev.Data.(type) {
|
||||||
case core.ChainHeadEvent:
|
case core.ChainHeadEvent:
|
||||||
pool.mu.Lock()
|
pool.setNewHead(ev.Data.(core.ChainHeadEvent).Block.Header())
|
||||||
ctx, _ := context.WithTimeout(context.Background(), blockCheckTimeout)
|
// hack in order to avoid hogging the lock; this part will
|
||||||
head := pool.chain.CurrentHeader()
|
// be replaced by a subsequent PR.
|
||||||
txc, _ := pool.setNewHead(ctx, head)
|
time.Sleep(time.Millisecond)
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// Stop stops the light transaction pool
|
||||||
func (pool *TxPool) Stop() {
|
func (pool *TxPool) Stop() {
|
||||||
close(pool.quit)
|
close(pool.quit)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package light
|
package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -29,7 +30,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/ethdb"
|
"github.com/ubiq/go-ubiq/ethdb"
|
||||||
"github.com/ubiq/go-ubiq/event"
|
"github.com/ubiq/go-ubiq/event"
|
||||||
"github.com/ubiq/go-ubiq/params"
|
"github.com/ubiq/go-ubiq/params"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type testTxRelay struct {
|
type testTxRelay struct {
|
||||||
|
|
@ -106,10 +106,11 @@ func TestTxPool(t *testing.T) {
|
||||||
lightchain.SetValidator(bproc{})
|
lightchain.SetValidator(bproc{})
|
||||||
txPermanent = 50
|
txPermanent = 50
|
||||||
pool := NewTxPool(testChainConfig(), evmux, lightchain, relay)
|
pool := NewTxPool(testChainConfig(), evmux, lightchain, relay)
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
for ii, block := range gchain {
|
for ii, block := range gchain {
|
||||||
i := ii + 1
|
i := ii + 1
|
||||||
ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
|
||||||
s := sentTx(i - 1)
|
s := sentTx(i - 1)
|
||||||
e := sentTx(i)
|
e := sentTx(i)
|
||||||
for i := s; i < e; i++ {
|
for i := s; i < e; i++ {
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,13 @@
|
||||||
package light
|
package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/common"
|
"github.com/ubiq/go-ubiq/common"
|
||||||
"github.com/ubiq/go-ubiq/core/types"
|
"github.com/ubiq/go-ubiq/core/types"
|
||||||
"github.com/ubiq/go-ubiq/core/vm"
|
"github.com/ubiq/go-ubiq/core/vm"
|
||||||
"github.com/ubiq/go-ubiq/crypto"
|
"github.com/ubiq/go-ubiq/crypto"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// VMState is a wrapper for the light state that holds the actual context and
|
// VMState is a wrapper for the light state that holds the actual context and
|
||||||
|
|
|
||||||
|
|
@ -14,15 +14,11 @@
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// Contains all the wrappers from the golang.org/x/net/context package to support
|
|
||||||
// client side context management on mobile platforms.
|
|
||||||
|
|
||||||
package gubiq
|
package gubiq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Context carries a deadline, a cancelation signal, and other values across API
|
// Context carries a deadline, a cancelation signal, and other values across API
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package rpc
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"container/list"
|
"container/list"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -32,7 +33,6 @@ import (
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
// Copyright 2016 The go-ethereum Authors
|
|
||||||
// This file is part of the go-ethereum library.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
|
||||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
// +build !go1.5
|
|
||||||
|
|
||||||
package rpc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
// In older versions of Go (below 1.5), dials cannot be canceled
|
|
||||||
// via a channel or context. The context deadline can still applied.
|
|
||||||
|
|
||||||
// contextDialer returns a dialer that applies the deadline value from the given context.
|
|
||||||
func contextDialer(ctx context.Context) *net.Dialer {
|
|
||||||
dialer := &net.Dialer{KeepAlive: tcpKeepAliveInterval}
|
|
||||||
if deadline, ok := ctx.Deadline(); ok {
|
|
||||||
dialer.Deadline = deadline
|
|
||||||
} else {
|
|
||||||
dialer.Deadline = time.Now().Add(defaultDialTimeout)
|
|
||||||
}
|
|
||||||
return dialer
|
|
||||||
}
|
|
||||||
|
|
||||||
// dialContext connects to the given address, aborting the dial if ctx is canceled.
|
|
||||||
func dialContext(ctx context.Context, network, addr string) (net.Conn, error) {
|
|
||||||
return contextDialer(ctx).Dial(network, addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// requestWithContext copies req, adding the cancelation channel and deadline from ctx.
|
|
||||||
func requestWithContext(c *http.Client, req *http.Request, ctx context.Context) (*http.Client, *http.Request) {
|
|
||||||
// Set Timeout on the client if the context has a deadline.
|
|
||||||
// Note that there is no default timeout (unlike in contextDialer) because
|
|
||||||
// the timeout applies to the entire request, including reads from body.
|
|
||||||
if deadline, ok := ctx.Deadline(); ok {
|
|
||||||
c2 := *c
|
|
||||||
c2.Timeout = deadline.Sub(time.Now())
|
|
||||||
c = &c2
|
|
||||||
}
|
|
||||||
req2 := *req
|
|
||||||
return c, &req2
|
|
||||||
}
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
// Copyright 2016 The go-ethereum Authors
|
|
||||||
// This file is part of the go-ethereum library.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
|
||||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
// +build go1.5,!go1.6
|
|
||||||
|
|
||||||
package rpc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
// In Go 1.5, dials cannot be canceled via a channel or context. The context deadline can
|
|
||||||
// still be applied. Go 1.5 adds the ability to cancel HTTP requests via a channel.
|
|
||||||
|
|
||||||
// contextDialer returns a dialer that applies the deadline value from the given context.
|
|
||||||
func contextDialer(ctx context.Context) *net.Dialer {
|
|
||||||
dialer := &net.Dialer{KeepAlive: tcpKeepAliveInterval}
|
|
||||||
if deadline, ok := ctx.Deadline(); ok {
|
|
||||||
dialer.Deadline = deadline
|
|
||||||
} else {
|
|
||||||
dialer.Deadline = time.Now().Add(defaultDialTimeout)
|
|
||||||
}
|
|
||||||
return dialer
|
|
||||||
}
|
|
||||||
|
|
||||||
// dialContext connects to the given address, aborting the dial if ctx is canceled.
|
|
||||||
func dialContext(ctx context.Context, network, addr string) (net.Conn, error) {
|
|
||||||
return contextDialer(ctx).Dial(network, addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// requestWithContext copies req, adding the cancelation channel and deadline from ctx.
|
|
||||||
func requestWithContext(c *http.Client, req *http.Request, ctx context.Context) (*http.Client, *http.Request) {
|
|
||||||
// Set Timeout on the client if the context has a deadline.
|
|
||||||
// Note that there is no default timeout (unlike in contextDialer) because
|
|
||||||
// the timeout applies to the entire request, including reads from body.
|
|
||||||
if deadline, ok := ctx.Deadline(); ok {
|
|
||||||
c2 := *c
|
|
||||||
c2.Timeout = deadline.Sub(time.Now())
|
|
||||||
c = &c2
|
|
||||||
}
|
|
||||||
req2 := *req
|
|
||||||
req2.Cancel = ctx.Done()
|
|
||||||
return c, &req2
|
|
||||||
}
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
// Copyright 2016 The go-ethereum Authors
|
|
||||||
// This file is part of the go-ethereum library.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
|
||||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
// +build go1.6,!go1.7
|
|
||||||
|
|
||||||
package rpc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
// In Go 1.6, net.Dialer gained the ability to cancel via a channel.
|
|
||||||
|
|
||||||
// contextDialer returns a dialer that applies the deadline value from the given context.
|
|
||||||
func contextDialer(ctx context.Context) *net.Dialer {
|
|
||||||
dialer := &net.Dialer{Cancel: ctx.Done(), KeepAlive: tcpKeepAliveInterval}
|
|
||||||
if deadline, ok := ctx.Deadline(); ok {
|
|
||||||
dialer.Deadline = deadline
|
|
||||||
} else {
|
|
||||||
dialer.Deadline = time.Now().Add(defaultDialTimeout)
|
|
||||||
}
|
|
||||||
return dialer
|
|
||||||
}
|
|
||||||
|
|
||||||
// dialContext connects to the given address, aborting the dial if ctx is canceled.
|
|
||||||
func dialContext(ctx context.Context, network, addr string) (net.Conn, error) {
|
|
||||||
return contextDialer(ctx).Dial(network, addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// requestWithContext copies req, adding the cancelation channel and deadline from ctx.
|
|
||||||
func requestWithContext(c *http.Client, req *http.Request, ctx context.Context) (*http.Client, *http.Request) {
|
|
||||||
// We set Timeout on the client for Go <= 1.5. There
|
|
||||||
// is no need to do that here because the dial will be canceled
|
|
||||||
// by package http.
|
|
||||||
req2 := *req
|
|
||||||
req2.Cancel = ctx.Done()
|
|
||||||
return c, &req2
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
// Copyright 2016 The go-ethereum Authors
|
|
||||||
// This file is part of the go-ethereum library.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
|
||||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
// +build go1.7
|
|
||||||
|
|
||||||
package rpc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// In Go 1.7, context moved into the standard library and support
|
|
||||||
// for cancelation via context was added to net.Dialer and http.Request.
|
|
||||||
|
|
||||||
// contextDialer returns a dialer that applies the deadline value from the given context.
|
|
||||||
func contextDialer(ctx context.Context) *net.Dialer {
|
|
||||||
dialer := &net.Dialer{Cancel: ctx.Done(), KeepAlive: tcpKeepAliveInterval}
|
|
||||||
if deadline, ok := ctx.Deadline(); ok {
|
|
||||||
dialer.Deadline = deadline
|
|
||||||
} else {
|
|
||||||
dialer.Deadline = time.Now().Add(defaultDialTimeout)
|
|
||||||
}
|
|
||||||
return dialer
|
|
||||||
}
|
|
||||||
|
|
||||||
// dialContext connects to the given address, aborting the dial if ctx is canceled.
|
|
||||||
func dialContext(ctx context.Context, network, addr string) (net.Conn, error) {
|
|
||||||
d := &net.Dialer{KeepAlive: tcpKeepAliveInterval}
|
|
||||||
return d.DialContext(ctx, network, addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// requestWithContext copies req, adding the cancelation channel and deadline from ctx.
|
|
||||||
func requestWithContext(c *http.Client, req *http.Request, ctx context.Context) (*http.Client, *http.Request) {
|
|
||||||
return c, req.WithContext(ctx)
|
|
||||||
}
|
|
||||||
|
|
@ -17,12 +17,12 @@
|
||||||
package rpc_test
|
package rpc_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/rpc"
|
"github.com/ubiq/go-ubiq/rpc"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// In this example, our client whishes to track the latest 'block number'
|
// In this example, our client whishes to track the latest 'block number'
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
|
@ -32,7 +33,6 @@ import (
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestClientRequest(t *testing.T) {
|
func TestClientRequest(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
@ -29,7 +30,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/cors"
|
"github.com/rs/cors"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -115,11 +115,11 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
client, req := requestWithContext(hc.client, hc.req, ctx)
|
req := hc.req.WithContext(ctx)
|
||||||
req.Body = ioutil.NopCloser(bytes.NewReader(body))
|
req.Body = ioutil.NopCloser(bytes.NewReader(body))
|
||||||
req.ContentLength = int64(len(body))
|
req.ContentLength = int64(len(body))
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := hc.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,8 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewInProcClient attaches an in-process connection to the given RPC server.
|
// NewInProcClient attaches an in-process connection to the given RPC server.
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateIPCListener creates an listener, on Unix platforms this is a unix socket, on
|
// CreateIPCListener creates an listener, on Unix platforms this is a unix socket, on
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,10 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ipcListen will create a Unix socket on the given endpoint.
|
// ipcListen will create a Unix socket on the given endpoint.
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,10 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"gopkg.in/natefinch/npipe.v2"
|
"gopkg.in/natefinch/npipe.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -24,7 +25,6 @@ import (
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"golang.org/x/net/context"
|
|
||||||
"gopkg.in/fatih/set.v0"
|
"gopkg.in/fatih/set.v0"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,12 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service struct{}
|
type Service struct{}
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,9 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,12 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type NotificationTestService struct {
|
type NotificationTestService struct {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"context"
|
||||||
crand "crypto/rand"
|
crand "crypto/rand"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|
@ -29,8 +30,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
@ -24,10 +25,10 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"golang.org/x/net/context"
|
|
||||||
"golang.org/x/net/websocket"
|
"golang.org/x/net/websocket"
|
||||||
"gopkg.in/fatih/set.v0"
|
"gopkg.in/fatih/set.v0"
|
||||||
)
|
)
|
||||||
|
|
@ -150,3 +151,18 @@ func wsDialAddress(location *url.URL) string {
|
||||||
}
|
}
|
||||||
return location.Host
|
return location.Host
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dialContext(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
|
d := &net.Dialer{KeepAlive: tcpKeepAliveInterval}
|
||||||
|
return d.DialContext(ctx, network, addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func contextDialer(ctx context.Context) *net.Dialer {
|
||||||
|
dialer := &net.Dialer{Cancel: ctx.Done(), KeepAlive: tcpKeepAliveInterval}
|
||||||
|
if deadline, ok := ctx.Deadline(); ok {
|
||||||
|
dialer.Deadline = deadline
|
||||||
|
} else {
|
||||||
|
dialer.Deadline = time.Now().Add(defaultDialTimeout)
|
||||||
|
}
|
||||||
|
return dialer
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package swap
|
package swap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -34,7 +35,6 @@ import (
|
||||||
"github.com/ubiq/go-ubiq/logger"
|
"github.com/ubiq/go-ubiq/logger"
|
||||||
"github.com/ubiq/go-ubiq/logger/glog"
|
"github.com/ubiq/go-ubiq/logger/glog"
|
||||||
"github.com/ubiq/go-ubiq/swarm/services/swap/swap"
|
"github.com/ubiq/go-ubiq/swarm/services/swap/swap"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SwAP Swarm Accounting Protocol with
|
// SwAP Swarm Accounting Protocol with
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package swarm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
|
@ -36,7 +37,6 @@ import (
|
||||||
httpapi "github.com/ubiq/go-ubiq/swarm/api/http"
|
httpapi "github.com/ubiq/go-ubiq/swarm/api/http"
|
||||||
"github.com/ubiq/go-ubiq/swarm/network"
|
"github.com/ubiq/go-ubiq/swarm/network"
|
||||||
"github.com/ubiq/go-ubiq/swarm/storage"
|
"github.com/ubiq/go-ubiq/swarm/storage"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// the swarm stack
|
// the swarm stack
|
||||||
|
|
|
||||||
|
|
@ -40,5 +40,3 @@ gopkg.in/natefinch/npipe.v2 c1b8fa8
|
||||||
gopkg.in/sourcemap.v1 v1.0.3
|
gopkg.in/sourcemap.v1 v1.0.3
|
||||||
gopkg.in/urfave/cli.v1 v1.19.1
|
gopkg.in/urfave/cli.v1 v1.19.1
|
||||||
|
|
||||||
# exclude
|
|
||||||
-golang.org/x/net/context
|
|
||||||
|
|
|
||||||
1
vendor/github.com/Azure/azure-sdk-for-go/.travis.yml
generated
vendored
1
vendor/github.com/Azure/azure-sdk-for-go/.travis.yml
generated
vendored
|
|
@ -7,7 +7,6 @@ go: 1.7
|
||||||
install:
|
install:
|
||||||
- go get -u github.com/golang/lint/golint
|
- go get -u github.com/golang/lint/golint
|
||||||
- go get -u github.com/Masterminds/glide
|
- go get -u github.com/Masterminds/glide
|
||||||
- go get -u golang.org/x/net/context
|
|
||||||
- go get -u github.com/HewlettPackard/gas
|
- go get -u github.com/HewlettPackard/gas
|
||||||
- go get -u gopkg.in/godo.v2/cmd/godo
|
- go get -u gopkg.in/godo.v2/cmd/godo
|
||||||
- export GO15VENDOREXPERIMENT=1
|
- export GO15VENDOREXPERIMENT=1
|
||||||
|
|
|
||||||
2
vendor/github.com/rs/cors/cors.go
generated
vendored
2
vendor/github.com/rs/cors/cors.go
generated
vendored
|
|
@ -21,6 +21,7 @@ The resulting handler is a standard net/http handler.
|
||||||
package cors
|
package cors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -28,7 +29,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/rs/xhandler"
|
"github.com/rs/xhandler"
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options is a configuration container to setup the CORS middleware.
|
// Options is a configuration container to setup the CORS middleware.
|
||||||
|
|
|
||||||
3
vendor/github.com/rs/xhandler/chain.go
generated
vendored
3
vendor/github.com/rs/xhandler/chain.go
generated
vendored
|
|
@ -1,9 +1,8 @@
|
||||||
package xhandler
|
package xhandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Chain is a helper for chaining middleware handlers together for easier
|
// Chain is a helper for chaining middleware handlers together for easier
|
||||||
|
|
|
||||||
3
vendor/github.com/rs/xhandler/middleware.go
generated
vendored
3
vendor/github.com/rs/xhandler/middleware.go
generated
vendored
|
|
@ -1,10 +1,9 @@
|
||||||
package xhandler
|
package xhandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// CloseHandler returns a Handler, cancelling the context when the client
|
// CloseHandler returns a Handler, cancelling the context when the client
|
||||||
|
|
|
||||||
3
vendor/github.com/rs/xhandler/xhandler.go
generated
vendored
3
vendor/github.com/rs/xhandler/xhandler.go
generated
vendored
|
|
@ -12,9 +12,8 @@
|
||||||
package xhandler // import "github.com/rs/xhandler"
|
package xhandler // import "github.com/rs/xhandler"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandlerC is a net/context aware http.Handler
|
// HandlerC is a net/context aware http.Handler
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue