diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 332e1ae8d..766e49f49 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -168,7 +168,6 @@ func init() {
}
app.After = func(ctx *cli.Context) error {
- logger.Flush()
debug.Exit()
console.Stdin.Close() // Resets terminal mode.
return nil
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 287efc9c8..8666f3775 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -67,7 +67,6 @@ func Fatalf(format string, args ...interface{}) {
}
}
fmt.Fprintf(w, "Fatal: "+format+"\n", args...)
- logger.Flush()
os.Exit(1)
}
diff --git a/core/block_validator_test.go b/core/block_validator_test.go
index 054686612..413c3cc8e 100644
--- a/core/block_validator_test.go
+++ b/core/block_validator_test.go
@@ -27,7 +27,6 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/params"
- "github.com/ethereum/go-ethereum/pow/ezp"
)
func testChainConfig() *params.ChainConfig {
@@ -48,20 +47,19 @@ func proc() (Validator, *BlockChain) {
}
func TestNumber(t *testing.T) {
- pow := ezp.New()
_, chain := proc()
statedb, _ := state.New(chain.Genesis().Root(), chain.chainDb)
cfg := testChainConfig()
header := makeHeader(cfg, chain.Genesis(), statedb)
header.Number = big.NewInt(3)
- err := ValidateHeader(cfg, pow, header, chain.Genesis().Header(), false, false)
+ err := ValidateHeader(cfg, FakePow{}, header, chain.Genesis().Header(), false, false)
if err != BlockNumberErr {
t.Errorf("expected block number error, got %q", err)
}
header = makeHeader(cfg, chain.Genesis(), statedb)
- err = ValidateHeader(cfg, pow, header, chain.Genesis().Header(), false, false)
+ err = ValidateHeader(cfg, FakePow{}, header, chain.Genesis().Header(), false, false)
if err == BlockNumberErr {
t.Errorf("didn't expect block number error")
}
diff --git a/core/blockchain.go b/core/blockchain.go
index 8c2be7231..c3530b93c 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -46,9 +46,6 @@ import (
)
var (
- chainlogger = logger.NewLogger("CHAIN")
- jsonlogger = logger.NewJsonLogger()
-
blockInsertTimer = metrics.NewTimer("chain/inserts")
ErrNoGenesis = errors.New("Genesis not found in chain")
diff --git a/errs/errors.go b/errs/errors.go
index 675649efa..daa814db7 100644
--- a/errs/errors.go
+++ b/errs/errors.go
@@ -19,7 +19,6 @@ package errs
import (
"fmt"
- "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
)
@@ -32,15 +31,10 @@ Fields:
Package:
name of the package/component
-
- Level:
- a function mapping error code to logger.LogLevel (severity)
- if not given, errors default to logger.InfoLevel
*/
type Errors struct {
Errors map[int]string
Package string
- Level func(code int) logger.LogLevel
}
/*
@@ -58,7 +52,6 @@ type Error struct {
Code int
Name string
Package string
- level logger.LogLevel
message string
format string
params []interface{}
@@ -69,15 +62,10 @@ func (self *Errors) New(code int, format string, params ...interface{}) *Error {
if !ok {
panic("invalid error code")
}
- level := logger.InfoLevel
- if self.Level != nil {
- level = self.Level(code)
- }
return &Error{
Code: code,
Name: name,
Package: self.Package,
- level: level,
format: format,
params: params,
}
@@ -98,13 +86,3 @@ func (self Error) Log(v glog.Verbose) {
v.Infoln(self)
}
}
-
-/*
-err.Fatal() is true if err's severity level is 0 or 1 (logger.ErrorLevel or logger.Silence)
-*/
-func (self *Error) Fatal() (fatal bool) {
- if self.level < logger.WarnLevel {
- fatal = true
- }
- return
-}
diff --git a/errs/errors_test.go b/errs/errors_test.go
index d6d14b45e..5a2ffbec3 100644
--- a/errs/errors_test.go
+++ b/errs/errors_test.go
@@ -19,8 +19,6 @@ package errs
import (
"fmt"
"testing"
-
- "github.com/ethereum/go-ethereum/logger"
)
func testErrors() *Errors {
@@ -30,14 +28,6 @@ func testErrors() *Errors {
0: "zero",
1: "one",
},
- Level: func(i int) (l logger.LogLevel) {
- if i == 0 {
- l = logger.ErrorLevel
- } else {
- l = logger.WarnLevel
- }
- return
- },
}
}
@@ -49,14 +39,3 @@ func TestErrorMessage(t *testing.T) {
t.Errorf("error message incorrect. expected %v, got %v", exp, message)
}
}
-
-func TestErrorSeverity(t *testing.T) {
- err0 := testErrors().New(0, "zero detail")
- if !err0.Fatal() {
- t.Errorf("error should be fatal")
- }
- err1 := testErrors().New(1, "one detail")
- if err1.Fatal() {
- t.Errorf("error should not be fatal")
- }
-}
diff --git a/logger/example_test.go b/logger/example_test.go
deleted file mode 100644
index ce5f9da67..000000000
--- a/logger/example_test.go
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2014 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 .
-
-package logger
-
-import "os"
-
-func ExampleLogger() {
- logger := NewLogger("TAG")
- logger.Infoln("so awesome") // prints [TAG] so awesome
- logger.Infof("this %q is raw", "coin") // prints [TAG] this "coin" is raw
-}
-
-func ExampleLogSystem() {
- filename := "test.log"
- file, _ := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, os.ModePerm)
- fileLog := NewStdLogSystem(file, 0, WarnLevel)
- AddLogSystem(fileLog)
-
- stdoutLog := NewStdLogSystem(os.Stdout, 0, WarnLevel)
- AddLogSystem(stdoutLog)
-
- NewLogger("TAG").Warnln("reactor meltdown") // writes to both logs
-}
diff --git a/logger/log.go b/logger/log.go
deleted file mode 100644
index 38a6ce139..000000000
--- a/logger/log.go
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2015 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 .
-
-package logger
-
-import (
- "fmt"
- "io"
- "log"
- "os"
-
- "github.com/ethereum/go-ethereum/common"
-)
-
-func openLogFile(datadir string, filename string) *os.File {
- path := common.AbsolutePath(datadir, filename)
- file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
- if err != nil {
- panic(fmt.Sprintf("error opening log file '%s': %v", filename, err))
- }
- return file
-}
-
-func New(datadir string, logFile string, logLevel int) LogSystem {
- var writer io.Writer
- if logFile == "" {
- writer = os.Stdout
- } else {
- writer = openLogFile(datadir, logFile)
- }
-
- var sys LogSystem
- sys = NewStdLogSystem(writer, log.LstdFlags, LogLevel(logLevel))
- AddLogSystem(sys)
-
- return sys
-}
-
-func NewJSONsystem(datadir string, logFile string) LogSystem {
- var writer io.Writer
- if logFile == "-" {
- writer = os.Stdout
- } else {
- writer = openLogFile(datadir, logFile)
- }
-
- var sys LogSystem
- sys = NewJsonLogSystem(writer)
- AddLogSystem(sys)
-
- return sys
-}
diff --git a/logger/loggers.go b/logger/loggers.go
deleted file mode 100644
index e63355d0b..000000000
--- a/logger/loggers.go
+++ /dev/null
@@ -1,149 +0,0 @@
-// Copyright 2014 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 .
-
-/*
-Package logger implements a multi-output leveled logger.
-
-Other packages use tagged logger to send log messages to shared
-(process-wide) logging engine. The shared logging engine dispatches to
-multiple log systems. The log level can be set separately per log
-system.
-
-Logging is asynchronous and does not block the caller. Message
-formatting is performed by the caller goroutine to avoid incorrect
-logging of mutable state.
-*/
-package logger
-
-import (
- "encoding/json"
- "fmt"
- "os"
-)
-
-type LogLevel uint32
-
-const (
- // Standard log levels
- Silence LogLevel = iota
- ErrorLevel
- WarnLevel
- InfoLevel
- DebugLevel
- DebugDetailLevel
-)
-
-// A Logger prints messages prefixed by a given tag. It provides named
-// Printf and Println style methods for all loglevels. Each ethereum
-// component should have its own logger with a unique prefix.
-type Logger struct {
- tag string
-}
-
-func NewLogger(tag string) *Logger {
- return &Logger{"[" + tag + "] "}
-}
-
-func (logger *Logger) Sendln(level LogLevel, v ...interface{}) {
- logMessageC <- stdMsg{level, logger.tag + fmt.Sprintln(v...)}
-}
-
-func (logger *Logger) Sendf(level LogLevel, format string, v ...interface{}) {
- logMessageC <- stdMsg{level, logger.tag + fmt.Sprintf(format, v...)}
-}
-
-// Errorln writes a message with ErrorLevel.
-func (logger *Logger) Errorln(v ...interface{}) {
- logger.Sendln(ErrorLevel, v...)
-}
-
-// Warnln writes a message with WarnLevel.
-func (logger *Logger) Warnln(v ...interface{}) {
- logger.Sendln(WarnLevel, v...)
-}
-
-// Infoln writes a message with InfoLevel.
-func (logger *Logger) Infoln(v ...interface{}) {
- logger.Sendln(InfoLevel, v...)
-}
-
-// Debugln writes a message with DebugLevel.
-func (logger *Logger) Debugln(v ...interface{}) {
- logger.Sendln(DebugLevel, v...)
-}
-
-// DebugDetailln writes a message with DebugDetailLevel.
-func (logger *Logger) DebugDetailln(v ...interface{}) {
- logger.Sendln(DebugDetailLevel, v...)
-}
-
-// Errorf writes a message with ErrorLevel.
-func (logger *Logger) Errorf(format string, v ...interface{}) {
- logger.Sendf(ErrorLevel, format, v...)
-}
-
-// Warnf writes a message with WarnLevel.
-func (logger *Logger) Warnf(format string, v ...interface{}) {
- logger.Sendf(WarnLevel, format, v...)
-}
-
-// Infof writes a message with InfoLevel.
-func (logger *Logger) Infof(format string, v ...interface{}) {
- logger.Sendf(InfoLevel, format, v...)
-}
-
-// Debugf writes a message with DebugLevel.
-func (logger *Logger) Debugf(format string, v ...interface{}) {
- logger.Sendf(DebugLevel, format, v...)
-}
-
-// DebugDetailf writes a message with DebugDetailLevel.
-func (logger *Logger) DebugDetailf(format string, v ...interface{}) {
- logger.Sendf(DebugDetailLevel, format, v...)
-}
-
-// Fatalln writes a message with ErrorLevel and exits the program.
-func (logger *Logger) Fatalln(v ...interface{}) {
- logger.Sendln(ErrorLevel, v...)
- Flush()
- os.Exit(0)
-}
-
-// Fatalf writes a message with ErrorLevel and exits the program.
-func (logger *Logger) Fatalf(format string, v ...interface{}) {
- logger.Sendf(ErrorLevel, format, v...)
- Flush()
- os.Exit(0)
-}
-
-type JsonLogger struct {
- Coinbase string
-}
-
-func NewJsonLogger() *JsonLogger {
- return &JsonLogger{}
-}
-
-func (logger *JsonLogger) LogJson(v JsonLog) {
- msgname := v.EventName()
- obj := map[string]interface{}{
- msgname: v,
- }
-
- jsontxt, _ := json.Marshal(obj)
- logMessageC <- (jsonMsg(jsontxt))
-
-}
diff --git a/logger/loggers_test.go b/logger/loggers_test.go
deleted file mode 100644
index 85564698b..000000000
--- a/logger/loggers_test.go
+++ /dev/null
@@ -1,192 +0,0 @@
-// Copyright 2014 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 .
-
-package logger
-
-import (
- "io/ioutil"
- "math/rand"
- "os"
- "sync"
- "testing"
- "time"
-)
-
-type TestLogSystem struct {
- mutex sync.Mutex
- output string
- level LogLevel
-}
-
-func (ls *TestLogSystem) LogPrint(msg LogMsg) {
- ls.mutex.Lock()
- if ls.level >= msg.Level() {
- ls.output += msg.String()
- }
- ls.mutex.Unlock()
-}
-
-func (ls *TestLogSystem) SetLogLevel(i LogLevel) {
- ls.mutex.Lock()
- ls.level = i
- ls.mutex.Unlock()
-}
-
-func (ls *TestLogSystem) GetLogLevel() LogLevel {
- ls.mutex.Lock()
- defer ls.mutex.Unlock()
- return ls.level
-}
-
-func (ls *TestLogSystem) CheckOutput(t *testing.T, expected string) {
- ls.mutex.Lock()
- output := ls.output
- ls.mutex.Unlock()
- if output != expected {
- t.Errorf("log output mismatch:\n got: %q\n want: %q\n", output, expected)
- }
-}
-
-type blockedLogSystem struct {
- LogSystem
- unblock chan struct{}
-}
-
-func (ls blockedLogSystem) LogPrint(msg LogMsg) {
- <-ls.unblock
- ls.LogSystem.LogPrint(msg)
-}
-
-func TestLoggerFlush(t *testing.T) {
- Reset()
-
- logger := NewLogger("TEST")
- ls := blockedLogSystem{&TestLogSystem{level: WarnLevel}, make(chan struct{})}
- AddLogSystem(ls)
- for i := 0; i < 5; i++ {
- // these writes shouldn't hang even though ls is blocked
- logger.Errorf(".")
- }
-
- beforeFlush := time.Now()
- time.AfterFunc(80*time.Millisecond, func() { close(ls.unblock) })
- Flush() // this should hang for approx. 80ms
- if blockd := time.Now().Sub(beforeFlush); blockd < 80*time.Millisecond {
- t.Errorf("Flush didn't block long enough, blocked for %v, should've been >= 80ms", blockd)
- }
-
- ls.LogSystem.(*TestLogSystem).CheckOutput(t, "[TEST] .[TEST] .[TEST] .[TEST] .[TEST] .")
-}
-
-func TestLoggerPrintln(t *testing.T) {
- Reset()
-
- logger := NewLogger("TEST")
- testLogSystem := &TestLogSystem{level: WarnLevel}
- AddLogSystem(testLogSystem)
- logger.Errorln("error")
- logger.Warnln("warn")
- logger.Infoln("info")
- logger.Debugln("debug")
- Flush()
-
- testLogSystem.CheckOutput(t, "[TEST] error\n[TEST] warn\n")
-}
-
-func TestLoggerPrintf(t *testing.T) {
- Reset()
-
- logger := NewLogger("TEST")
- testLogSystem := &TestLogSystem{level: WarnLevel}
- AddLogSystem(testLogSystem)
- logger.Errorf("error to %v\n", []int{1, 2, 3})
- logger.Warnf("warn %%d %d", 5)
- logger.Infof("info")
- logger.Debugf("debug")
- Flush()
- testLogSystem.CheckOutput(t, "[TEST] error to [1 2 3]\n[TEST] warn %d 5")
-}
-
-func TestMultipleLogSystems(t *testing.T) {
- Reset()
-
- logger := NewLogger("TEST")
- testLogSystem0 := &TestLogSystem{level: ErrorLevel}
- testLogSystem1 := &TestLogSystem{level: WarnLevel}
- AddLogSystem(testLogSystem0)
- AddLogSystem(testLogSystem1)
- logger.Errorln("error")
- logger.Warnln("warn")
- Flush()
-
- testLogSystem0.CheckOutput(t, "[TEST] error\n")
- testLogSystem1.CheckOutput(t, "[TEST] error\n[TEST] warn\n")
-}
-
-func TestFileLogSystem(t *testing.T) {
- Reset()
-
- logger := NewLogger("TEST")
- filename := "test.log"
- file, _ := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, os.ModePerm)
- testLogSystem := NewStdLogSystem(file, 0, WarnLevel)
- AddLogSystem(testLogSystem)
- logger.Errorf("error to %s\n", filename)
- logger.Warnln("warn")
- Flush()
- contents, _ := ioutil.ReadFile(filename)
- output := string(contents)
- if output != "[TEST] error to test.log\n[TEST] warn\n" {
- t.Error("Expected contents of file 'test.log': '[TEST] error to test.log\\n[TEST] warn\\n', got ", output)
- } else {
- os.Remove(filename)
- }
-}
-
-func TestNoLogSystem(t *testing.T) {
- Reset()
-
- logger := NewLogger("TEST")
- logger.Warnln("warn")
- Flush()
-}
-
-func TestConcurrentAddSystem(t *testing.T) {
- rand.Seed(time.Now().Unix())
- Reset()
-
- logger := NewLogger("TEST")
- stop := make(chan struct{})
- writer := func() {
- select {
- case <-stop:
- return
- default:
- logger.Infoln("foo")
- Flush()
- }
- }
-
- go writer()
- go writer()
-
- stopTime := time.Now().Add(100 * time.Millisecond)
- for time.Now().Before(stopTime) {
- time.Sleep(time.Duration(rand.Intn(20)) * time.Millisecond)
- AddLogSystem(NewStdLogSystem(ioutil.Discard, 0, InfoLevel))
- }
- close(stop)
-}
diff --git a/logger/logsystem.go b/logger/logsystem.go
deleted file mode 100644
index 24f4351d4..000000000
--- a/logger/logsystem.go
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright 2015 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 .
-
-package logger
-
-import (
- "io"
- "log"
- "sync/atomic"
-)
-
-// LogSystem is implemented by log output devices.
-// All methods can be called concurrently from multiple goroutines.
-type LogSystem interface {
- LogPrint(LogMsg)
-}
-
-// NewStdLogSystem creates a LogSystem that prints to the given writer.
-// The flag values are defined package log.
-func NewStdLogSystem(writer io.Writer, flags int, level LogLevel) *StdLogSystem {
- logger := log.New(writer, "", flags)
- return &StdLogSystem{logger, uint32(level)}
-}
-
-type StdLogSystem struct {
- logger *log.Logger
- level uint32
-}
-
-func (t *StdLogSystem) LogPrint(msg LogMsg) {
- stdmsg, ok := msg.(stdMsg)
- if ok {
- if t.GetLogLevel() >= stdmsg.Level() {
- t.logger.Print(stdmsg.String())
- }
- }
-}
-
-func (t *StdLogSystem) SetLogLevel(i LogLevel) {
- atomic.StoreUint32(&t.level, uint32(i))
-}
-
-func (t *StdLogSystem) GetLogLevel() LogLevel {
- return LogLevel(atomic.LoadUint32(&t.level))
-}
-
-// NewJSONLogSystem creates a LogSystem that prints to the given writer without
-// adding extra information irrespective of loglevel only if message is JSON type
-func NewJsonLogSystem(writer io.Writer) LogSystem {
- logger := log.New(writer, "", 0)
- return &jsonLogSystem{logger}
-}
-
-type jsonLogSystem struct {
- logger *log.Logger
-}
-
-func (t *jsonLogSystem) LogPrint(msg LogMsg) {
- jsonmsg, ok := msg.(jsonMsg)
- if ok {
- t.logger.Print(jsonmsg.String())
- }
-}
diff --git a/logger/sys.go b/logger/sys.go
deleted file mode 100644
index 18d4ea641..000000000
--- a/logger/sys.go
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright 2015 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 .
-
-package logger
-
-import (
- "fmt"
- "sync"
-)
-
-type stdMsg struct {
- level LogLevel
- msg string
-}
-
-type jsonMsg []byte
-
-func (m jsonMsg) Level() LogLevel {
- return 0
-}
-
-func (m jsonMsg) String() string {
- return string(m)
-}
-
-type LogMsg interface {
- Level() LogLevel
- fmt.Stringer
-}
-
-func (m stdMsg) Level() LogLevel {
- return m.level
-}
-
-func (m stdMsg) String() string {
- return m.msg
-}
-
-var (
- logMessageC = make(chan LogMsg)
- addSystemC = make(chan LogSystem)
- flushC = make(chan chan struct{})
- resetC = make(chan chan struct{})
-)
-
-func init() {
- go dispatchLoop()
-}
-
-// each system can buffer this many messages before
-// blocking incoming log messages.
-const sysBufferSize = 500
-
-func dispatchLoop() {
- var (
- systems []LogSystem
- systemIn []chan LogMsg
- systemWG sync.WaitGroup
- )
- bootSystem := func(sys LogSystem) {
- in := make(chan LogMsg, sysBufferSize)
- systemIn = append(systemIn, in)
- systemWG.Add(1)
- go sysLoop(sys, in, &systemWG)
- }
-
- for {
- select {
- case msg := <-logMessageC:
- for _, c := range systemIn {
- c <- msg
- }
-
- case sys := <-addSystemC:
- systems = append(systems, sys)
- bootSystem(sys)
-
- case waiter := <-resetC:
- // reset means terminate all systems
- for _, c := range systemIn {
- close(c)
- }
- systems = nil
- systemIn = nil
- systemWG.Wait()
- close(waiter)
-
- case waiter := <-flushC:
- // flush means reboot all systems
- for _, c := range systemIn {
- close(c)
- }
- systemIn = nil
- systemWG.Wait()
- for _, sys := range systems {
- bootSystem(sys)
- }
- close(waiter)
- }
- }
-}
-
-func sysLoop(sys LogSystem, in <-chan LogMsg, wg *sync.WaitGroup) {
- for msg := range in {
- sys.LogPrint(msg)
- }
- wg.Done()
-}
-
-// Reset removes all active log systems.
-// It blocks until all current messages have been delivered.
-func Reset() {
- waiter := make(chan struct{})
- resetC <- waiter
- <-waiter
-}
-
-// Flush waits until all current log messages have been dispatched to
-// the active log systems.
-func Flush() {
- waiter := make(chan struct{})
- flushC <- waiter
- <-waiter
-}
-
-// AddLogSystem starts printing messages to the given LogSystem.
-func AddLogSystem(sys LogSystem) {
- addSystemC <- sys
-}
diff --git a/logger/types.go b/logger/types.go
deleted file mode 100644
index ee7e845de..000000000
--- a/logger/types.go
+++ /dev/null
@@ -1,381 +0,0 @@
-// Copyright 2015 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 .
-
-package logger
-
-import (
- "math/big"
- "time"
-)
-
-type utctime8601 struct{}
-
-func (utctime8601) MarshalJSON() ([]byte, error) {
- timestr := time.Now().UTC().Format(time.RFC3339Nano)
- // Bounds check
- if len(timestr) > 26 {
- timestr = timestr[:26]
- }
- return []byte(`"` + timestr + `Z"`), nil
-}
-
-type JsonLog interface {
- EventName() string
-}
-
-type LogEvent struct {
- // Guid string `json:"guid"`
- Ts utctime8601 `json:"ts"`
- // Level string `json:"level"`
-}
-
-type LogStarting struct {
- ClientString string `json:"client_impl"`
- ProtocolVersion int `json:"eth_version"`
- LogEvent
-}
-
-func (l *LogStarting) EventName() string {
- return "starting"
-}
-
-type P2PConnected struct {
- RemoteId string `json:"remote_id"`
- RemoteAddress string `json:"remote_addr"`
- RemoteVersionString string `json:"remote_version_string"`
- NumConnections int `json:"num_connections"`
- LogEvent
-}
-
-func (l *P2PConnected) EventName() string {
- return "p2p.connected"
-}
-
-type P2PDisconnected struct {
- NumConnections int `json:"num_connections"`
- RemoteId string `json:"remote_id"`
- LogEvent
-}
-
-func (l *P2PDisconnected) EventName() string {
- return "p2p.disconnected"
-}
-
-type EthMinerNewBlock struct {
- BlockHash string `json:"block_hash"`
- BlockNumber *big.Int `json:"block_number"`
- ChainHeadHash string `json:"chain_head_hash"`
- BlockPrevHash string `json:"block_prev_hash"`
- LogEvent
-}
-
-func (l *EthMinerNewBlock) EventName() string {
- return "eth.miner.new_block"
-}
-
-type EthChainReceivedNewBlock struct {
- BlockHash string `json:"block_hash"`
- BlockNumber *big.Int `json:"block_number"`
- ChainHeadHash string `json:"chain_head_hash"`
- BlockPrevHash string `json:"block_prev_hash"`
- RemoteId string `json:"remote_id"`
- LogEvent
-}
-
-func (l *EthChainReceivedNewBlock) EventName() string {
- return "eth.chain.received.new_block"
-}
-
-type EthChainNewHead struct {
- BlockHash string `json:"block_hash"`
- BlockNumber *big.Int `json:"block_number"`
- ChainHeadHash string `json:"chain_head_hash"`
- BlockPrevHash string `json:"block_prev_hash"`
- LogEvent
-}
-
-func (l *EthChainNewHead) EventName() string {
- return "eth.chain.new_head"
-}
-
-type EthTxReceived struct {
- TxHash string `json:"tx_hash"`
- RemoteId string `json:"remote_id"`
- LogEvent
-}
-
-func (l *EthTxReceived) EventName() string {
- return "eth.tx.received"
-}
-
-//
-//
-// The types below are legacy and need to be converted to new format or deleted
-//
-//
-
-// type P2PConnecting struct {
-// RemoteId string `json:"remote_id"`
-// RemoteEndpoint string `json:"remote_endpoint"`
-// NumConnections int `json:"num_connections"`
-// LogEvent
-// }
-
-// func (l *P2PConnecting) EventName() string {
-// return "p2p.connecting"
-// }
-
-// type P2PHandshaked struct {
-// RemoteCapabilities []string `json:"remote_capabilities"`
-// RemoteId string `json:"remote_id"`
-// NumConnections int `json:"num_connections"`
-// LogEvent
-// }
-
-// func (l *P2PHandshaked) EventName() string {
-// return "p2p.handshaked"
-// }
-
-// type P2PDisconnecting struct {
-// Reason string `json:"reason"`
-// RemoteId string `json:"remote_id"`
-// NumConnections int `json:"num_connections"`
-// LogEvent
-// }
-
-// func (l *P2PDisconnecting) EventName() string {
-// return "p2p.disconnecting"
-// }
-
-// type P2PDisconnectingBadHandshake struct {
-// Reason string `json:"reason"`
-// RemoteId string `json:"remote_id"`
-// NumConnections int `json:"num_connections"`
-// LogEvent
-// }
-
-// func (l *P2PDisconnectingBadHandshake) EventName() string {
-// return "p2p.disconnecting.bad_handshake"
-// }
-
-// type P2PDisconnectingBadProtocol struct {
-// Reason string `json:"reason"`
-// RemoteId string `json:"remote_id"`
-// NumConnections int `json:"num_connections"`
-// LogEvent
-// }
-
-// func (l *P2PDisconnectingBadProtocol) EventName() string {
-// return "p2p.disconnecting.bad_protocol"
-// }
-
-// type P2PDisconnectingReputation struct {
-// Reason string `json:"reason"`
-// RemoteId string `json:"remote_id"`
-// NumConnections int `json:"num_connections"`
-// LogEvent
-// }
-
-// func (l *P2PDisconnectingReputation) EventName() string {
-// return "p2p.disconnecting.reputation"
-// }
-
-// type P2PDisconnectingDHT struct {
-// Reason string `json:"reason"`
-// RemoteId string `json:"remote_id"`
-// NumConnections int `json:"num_connections"`
-// LogEvent
-// }
-
-// func (l *P2PDisconnectingDHT) EventName() string {
-// return "p2p.disconnecting.dht"
-// }
-
-// type P2PEthDisconnectingBadBlock struct {
-// Reason string `json:"reason"`
-// RemoteId string `json:"remote_id"`
-// NumConnections int `json:"num_connections"`
-// LogEvent
-// }
-
-// func (l *P2PEthDisconnectingBadBlock) EventName() string {
-// return "p2p.eth.disconnecting.bad_block"
-// }
-
-// type P2PEthDisconnectingBadTx struct {
-// Reason string `json:"reason"`
-// RemoteId string `json:"remote_id"`
-// NumConnections int `json:"num_connections"`
-// LogEvent
-// }
-
-// func (l *P2PEthDisconnectingBadTx) EventName() string {
-// return "p2p.eth.disconnecting.bad_tx"
-// }
-
-// type EthNewBlockBroadcasted struct {
-// BlockNumber int `json:"block_number"`
-// HeadHash string `json:"head_hash"`
-// BlockHash string `json:"block_hash"`
-// BlockDifficulty int `json:"block_difficulty"`
-// BlockPrevHash string `json:"block_prev_hash"`
-// LogEvent
-// }
-
-// func (l *EthNewBlockBroadcasted) EventName() string {
-// return "eth.newblock.broadcasted"
-// }
-
-// type EthNewBlockIsKnown struct {
-// BlockNumber int `json:"block_number"`
-// HeadHash string `json:"head_hash"`
-// BlockHash string `json:"block_hash"`
-// BlockDifficulty int `json:"block_difficulty"`
-// BlockPrevHash string `json:"block_prev_hash"`
-// LogEvent
-// }
-
-// func (l *EthNewBlockIsKnown) EventName() string {
-// return "eth.newblock.is_known"
-// }
-
-// type EthNewBlockIsNew struct {
-// BlockNumber int `json:"block_number"`
-// HeadHash string `json:"head_hash"`
-// BlockHash string `json:"block_hash"`
-// BlockDifficulty int `json:"block_difficulty"`
-// BlockPrevHash string `json:"block_prev_hash"`
-// LogEvent
-// }
-
-// func (l *EthNewBlockIsNew) EventName() string {
-// return "eth.newblock.is_new"
-// }
-
-// type EthNewBlockMissingParent struct {
-// BlockNumber int `json:"block_number"`
-// HeadHash string `json:"head_hash"`
-// BlockHash string `json:"block_hash"`
-// BlockDifficulty int `json:"block_difficulty"`
-// BlockPrevHash string `json:"block_prev_hash"`
-// LogEvent
-// }
-
-// func (l *EthNewBlockMissingParent) EventName() string {
-// return "eth.newblock.missing_parent"
-// }
-
-// type EthNewBlockIsInvalid struct {
-// BlockNumber int `json:"block_number"`
-// HeadHash string `json:"head_hash"`
-// BlockHash string `json:"block_hash"`
-// BlockDifficulty int `json:"block_difficulty"`
-// BlockPrevHash string `json:"block_prev_hash"`
-// LogEvent
-// }
-
-// func (l *EthNewBlockIsInvalid) EventName() string {
-// return "eth.newblock.is_invalid"
-// }
-
-// type EthNewBlockChainIsOlder struct {
-// BlockNumber int `json:"block_number"`
-// HeadHash string `json:"head_hash"`
-// BlockHash string `json:"block_hash"`
-// BlockDifficulty int `json:"block_difficulty"`
-// BlockPrevHash string `json:"block_prev_hash"`
-// LogEvent
-// }
-
-// func (l *EthNewBlockChainIsOlder) EventName() string {
-// return "eth.newblock.chain.is_older"
-// }
-
-// type EthNewBlockChainIsCanonical struct {
-// BlockNumber int `json:"block_number"`
-// HeadHash string `json:"head_hash"`
-// BlockHash string `json:"block_hash"`
-// BlockDifficulty int `json:"block_difficulty"`
-// BlockPrevHash string `json:"block_prev_hash"`
-// LogEvent
-// }
-
-// func (l *EthNewBlockChainIsCanonical) EventName() string {
-// return "eth.newblock.chain.is_cannonical"
-// }
-
-// type EthNewBlockChainNotCanonical struct {
-// BlockNumber int `json:"block_number"`
-// HeadHash string `json:"head_hash"`
-// BlockHash string `json:"block_hash"`
-// BlockDifficulty int `json:"block_difficulty"`
-// BlockPrevHash string `json:"block_prev_hash"`
-// LogEvent
-// }
-
-// func (l *EthNewBlockChainNotCanonical) EventName() string {
-// return "eth.newblock.chain.not_cannonical"
-// }
-
-// type EthTxCreated struct {
-// TxHash string `json:"tx_hash"`
-// TxSender string `json:"tx_sender"`
-// TxAddress string `json:"tx_address"`
-// TxHexRLP string `json:"tx_hexrlp"`
-// TxNonce int `json:"tx_nonce"`
-// LogEvent
-// }
-
-// func (l *EthTxCreated) EventName() string {
-// return "eth.tx.created"
-// }
-
-// type EthTxBroadcasted struct {
-// TxHash string `json:"tx_hash"`
-// TxSender string `json:"tx_sender"`
-// TxAddress string `json:"tx_address"`
-// TxNonce int `json:"tx_nonce"`
-// LogEvent
-// }
-
-// func (l *EthTxBroadcasted) EventName() string {
-// return "eth.tx.broadcasted"
-// }
-
-// type EthTxValidated struct {
-// TxHash string `json:"tx_hash"`
-// TxSender string `json:"tx_sender"`
-// TxAddress string `json:"tx_address"`
-// TxNonce int `json:"tx_nonce"`
-// LogEvent
-// }
-
-// func (l *EthTxValidated) EventName() string {
-// return "eth.tx.validated"
-// }
-
-// type EthTxIsInvalid struct {
-// TxHash string `json:"tx_hash"`
-// TxSender string `json:"tx_sender"`
-// TxAddress string `json:"tx_address"`
-// Reason string `json:"reason"`
-// TxNonce int `json:"tx_nonce"`
-// LogEvent
-// }
-
-// func (l *EthTxIsInvalid) EventName() string {
-// return "eth.tx.is_invalid"
-// }
diff --git a/miner/worker.go b/miner/worker.go
index 68ce44db0..56fd4ea66 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -39,8 +39,6 @@ import (
"gopkg.in/fatih/set.v0"
)
-var jsonlogger = logger.NewJsonLogger()
-
const (
resultQueueSize = 10
miningLogAtDepth = 5
diff --git a/node/node_test.go b/node/node_test.go
index 95fa53b06..408d4cfcb 100644
--- a/node/node_test.go
+++ b/node/node_test.go
@@ -218,7 +218,7 @@ func TestServiceRestarts(t *testing.T) {
}
defer stack.Stop()
- if running || started != 1 {
+ if !running || started != 1 {
t.Fatalf("running/started mismatch: have %v/%d, want true/1", running, started)
}
// Restart the stack a few times and check successful service restarts
diff --git a/p2p/server.go b/p2p/server.go
index cf9672e2d..298148d3e 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -54,8 +54,6 @@ const (
var errServerStopped = errors.New("server stopped")
-var srvjslog = logger.NewJsonLogger()
-
// Config holds Server options.
type Config struct {
// This field must be set to a valid secp256k1 private key.
@@ -737,12 +735,6 @@ func (srv *Server) checkpoint(c *conn, stage chan<- *conn) error {
// the peer.
func (srv *Server) runPeer(p *Peer) {
glog.V(logger.Debug).Infof("Added %v\n", p)
- srvjslog.LogJson(&logger.P2PConnected{
- RemoteId: p.ID().String(),
- RemoteAddress: p.RemoteAddr().String(),
- RemoteVersionString: p.Name(),
- NumConnections: srv.PeerCount(),
- })
if srv.newPeerHook != nil {
srv.newPeerHook(p)
@@ -753,10 +745,6 @@ func (srv *Server) runPeer(p *Peer) {
srv.delpeer <- p
glog.V(logger.Debug).Infof("Removed %v (%v)\n", p, discreason)
- srvjslog.LogJson(&logger.P2PDisconnected{
- RemoteId: p.ID().String(),
- NumConnections: srv.PeerCount(),
- })
}
// NodeInfo represents a short summary of the information known about the host.
diff --git a/pow/dagger/dagger.go b/pow/dagger/dagger.go
deleted file mode 100644
index f54ba71ca..000000000
--- a/pow/dagger/dagger.go
+++ /dev/null
@@ -1,176 +0,0 @@
-// Copyright 2014 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 .
-
-package dagger
-
-import (
- "hash"
- "math/big"
- "math/rand"
- "time"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/crypto/sha3"
- "github.com/ethereum/go-ethereum/logger"
-)
-
-var powlogger = logger.NewLogger("POW")
-
-type Dagger struct {
- hash *big.Int
- xn *big.Int
-}
-
-var Found bool
-
-func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
- r := rand.New(rand.NewSource(time.Now().UnixNano()))
-
- for i := 0; i < 1000; i++ {
- rnd := r.Int63()
-
- res := dag.Eval(big.NewInt(rnd))
- powlogger.Infof("rnd %v\nres %v\nobj %v\n", rnd, res, obj)
- if res.Cmp(obj) < 0 {
- // Post back result on the channel
- resChan <- rnd
- // Notify other threads we've found a valid nonce
- Found = true
- }
-
- // Break out if found
- if Found {
- break
- }
- }
-
- resChan <- 0
-}
-
-func (dag *Dagger) Search(hash, diff *big.Int) (uint64, []byte) {
- // TODO fix multi threading. Somehow it results in the wrong nonce
- amountOfRoutines := 1
-
- dag.hash = hash
-
- obj := common.BigPow(2, 256)
- obj = obj.Div(obj, diff)
-
- Found = false
- resChan := make(chan int64, 3)
- var res int64
-
- for k := 0; k < amountOfRoutines; k++ {
- go dag.Find(obj, resChan)
-
- // Wait for each go routine to finish
- }
- for k := 0; k < amountOfRoutines; k++ {
- // Get the result from the channel. 0 = quit
- if r := <-resChan; r != 0 {
- res = r
- }
- }
-
- return uint64(res), nil
-}
-
-func (dag *Dagger) Verify(hash, diff, nonce *big.Int) bool {
- dag.hash = hash
-
- obj := common.BigPow(2, 256)
- obj = obj.Div(obj, diff)
-
- return dag.Eval(nonce).Cmp(obj) < 0
-}
-
-func DaggerVerify(hash, diff, nonce *big.Int) bool {
- dagger := &Dagger{}
- dagger.hash = hash
-
- obj := common.BigPow(2, 256)
- obj = obj.Div(obj, diff)
-
- return dagger.Eval(nonce).Cmp(obj) < 0
-}
-
-func (dag *Dagger) Node(L uint64, i uint64) *big.Int {
- if L == i {
- return dag.hash
- }
-
- var m *big.Int
- if L == 9 {
- m = big.NewInt(16)
- } else {
- m = big.NewInt(3)
- }
-
- sha := sha3.NewKeccak256()
- sha.Reset()
- d := sha3.NewKeccak256()
- b := new(big.Int)
- ret := new(big.Int)
-
- for k := 0; k < int(m.Uint64()); k++ {
- d.Reset()
- d.Write(dag.hash.Bytes())
- d.Write(dag.xn.Bytes())
- d.Write(big.NewInt(int64(L)).Bytes())
- d.Write(big.NewInt(int64(i)).Bytes())
- d.Write(big.NewInt(int64(k)).Bytes())
-
- b.SetBytes(Sum(d))
- pk := b.Uint64() & ((1 << ((L - 1) * 3)) - 1)
- sha.Write(dag.Node(L-1, pk).Bytes())
- }
-
- ret.SetBytes(Sum(sha))
-
- return ret
-}
-
-func Sum(sha hash.Hash) []byte {
- //in := make([]byte, 32)
- return sha.Sum(nil)
-}
-
-func (dag *Dagger) Eval(N *big.Int) *big.Int {
- pow := common.BigPow(2, 26)
- dag.xn = pow.Div(N, pow)
-
- sha := sha3.NewKeccak256()
- sha.Reset()
- ret := new(big.Int)
-
- for k := 0; k < 4; k++ {
- d := sha3.NewKeccak256()
- b := new(big.Int)
-
- d.Reset()
- d.Write(dag.hash.Bytes())
- d.Write(dag.xn.Bytes())
- d.Write(N.Bytes())
- d.Write(big.NewInt(int64(k)).Bytes())
-
- b.SetBytes(Sum(d))
- pk := (b.Uint64() & 0x1ffffff)
-
- sha.Write(dag.Node(9, pk).Bytes())
- }
-
- return ret.SetBytes(Sum(sha))
-}
diff --git a/pow/dagger/dagger_test.go b/pow/dagger/dagger_test.go
deleted file mode 100644
index 39b74df30..000000000
--- a/pow/dagger/dagger_test.go
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2014 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 .
-
-package dagger
-
-import (
- "math/big"
- "testing"
-
- "github.com/ethereum/go-ethereum/common"
-)
-
-func BenchmarkDaggerSearch(b *testing.B) {
- hash := big.NewInt(0)
- diff := common.BigPow(2, 36)
- o := big.NewInt(0) // nonce doesn't matter. We're only testing against speed, not validity
-
- // Reset timer so the big generation isn't included in the benchmark
- b.ResetTimer()
- // Validate
- DaggerVerify(hash, diff, o)
-}
diff --git a/pow/ezp/pow.go b/pow/ezp/pow.go
deleted file mode 100644
index 0f7ee3570..000000000
--- a/pow/ezp/pow.go
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright 2014 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 .
-
-package ezp
-
-import (
- "encoding/binary"
- "math/big"
- "math/rand"
- "time"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/crypto/sha3"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/pow"
-)
-
-var powlogger = logger.NewLogger("POW")
-
-type EasyPow struct {
- hash *big.Int
- HashRate int64
- turbo bool
-}
-
-func New() *EasyPow {
- return &EasyPow{turbo: false}
-}
-
-func (pow *EasyPow) GetHashrate() int64 {
- return pow.HashRate
-}
-
-func (pow *EasyPow) Turbo(on bool) {
- pow.turbo = on
-}
-
-func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}, index int) (uint64, []byte) {
- r := rand.New(rand.NewSource(time.Now().UnixNano()))
- hash := block.HashNoNonce()
- diff := block.Difficulty()
- //i := int64(0)
- // TODO fix offset
- i := rand.Int63()
- starti := i
- start := time.Now().UnixNano()
-
- defer func() { pow.HashRate = 0 }()
-
- // Make sure stop is empty
-empty:
- for {
- select {
- case <-stop:
- default:
- break empty
- }
- }
-
- for {
- select {
- case <-stop:
- return 0, nil
- default:
- i++
-
- elapsed := time.Now().UnixNano() - start
- hashes := ((float64(1e9) / float64(elapsed)) * float64(i-starti)) / 1000
- pow.HashRate = int64(hashes)
-
- sha := uint64(r.Int63())
- if verify(hash, diff, sha) {
- return sha, nil
- }
- }
-
- if !pow.turbo {
- time.Sleep(20 * time.Microsecond)
- }
- }
-}
-
-func (pow *EasyPow) Verify(block pow.Block) bool {
- return Verify(block)
-}
-
-func verify(hash common.Hash, diff *big.Int, nonce uint64) bool {
- sha := sha3.NewKeccak256()
- n := make([]byte, 8)
- binary.PutUvarint(n, nonce)
- sha.Write(n)
- sha.Write(hash[:])
- verification := new(big.Int).Div(common.BigPow(2, 256), diff)
- res := common.BigD(sha.Sum(nil))
- return res.Cmp(verification) <= 0
-}
-
-func Verify(block pow.Block) bool {
- return verify(block.HashNoNonce(), block.Difficulty(), block.Nonce())
-}
diff --git a/swarm/network/protocol.go b/swarm/network/protocol.go
index 4fffaac6d..763fb0b8e 100644
--- a/swarm/network/protocol.go
+++ b/swarm/network/protocol.go
@@ -538,13 +538,6 @@ func (self *bzz) protoError(code int, format string, params ...interface{}) (err
return
}
-func (self *bzz) protoErrorDisconnect(err *errs.Error) {
- err.Log(glog.V(logger.Info))
- if err.Fatal() {
- self.peer.Disconnect(p2p.DiscSubprotocolError)
- }
-}
-
func (self *bzz) send(msg uint64, data interface{}) error {
if self.hive.blockWrite {
return fmt.Errorf("network write blocked")