aboutsummaryrefslogtreecommitdiffstats
path: root/light
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-03-03 17:41:52 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-03-03 17:41:52 +0800
commite7030c4bf59e8e148822c50ae1a5896c604c38c1 (patch)
tree4403290e84761608e8437d23ecef4d934406dd46 /light
parentfaf713632c307e3fd77a492481846b858ad991f9 (diff)
downloaddexon-e7030c4bf59e8e148822c50ae1a5896c604c38c1.tar
dexon-e7030c4bf59e8e148822c50ae1a5896c604c38c1.tar.gz
dexon-e7030c4bf59e8e148822c50ae1a5896c604c38c1.tar.bz2
dexon-e7030c4bf59e8e148822c50ae1a5896c604c38c1.tar.lz
dexon-e7030c4bf59e8e148822c50ae1a5896c604c38c1.tar.xz
dexon-e7030c4bf59e8e148822c50ae1a5896c604c38c1.tar.zst
dexon-e7030c4bf59e8e148822c50ae1a5896c604c38c1.zip
all: update light logs (and a few others) to the new model
Diffstat (limited to 'light')
-rw-r--r--light/lightchain.go30
-rw-r--r--light/odr_util.go6
-rw-r--r--light/state.go6
-rw-r--r--light/state_object.go13
-rw-r--r--light/txpool.go25
5 files changed, 16 insertions, 64 deletions
diff --git a/light/lightchain.go b/light/lightchain.go
index 1f0fb9c34..773c0f38b 100644
--- a/light/lightchain.go
+++ b/light/lightchain.go
@@ -17,11 +17,9 @@
package light
import (
- "fmt"
"math/big"
"sync"
"sync/atomic"
- "time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
@@ -101,7 +99,7 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, pow pow.PoW, mux
if err != nil {
return nil, err
}
- log.Info(fmt.Sprint("WARNING: Wrote default ethereum genesis block"))
+ log.Warn("Wrote default ethereum genesis block")
}
if bc.genesisBlock.Hash() == (common.Hash{212, 229, 103, 64, 248, 118, 174, 248, 192, 16, 184, 106, 64, 213, 245, 103, 69, 161, 24, 208, 144, 106, 52, 230, 154, 236, 140, 13, 177, 203, 143, 163}) {
@@ -117,7 +115,7 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, pow pow.PoW, mux
Root: common.HexToHash("c035076523faf514038f619715de404a65398c51899b5dccca9c05b00bc79315"),
})
}
- log.Info(fmt.Sprint("Added trusted CHT for mainnet"))
+ log.Info("Added trusted CHT for mainnet")
} else {
if bc.genesisBlock.Hash() == (common.Hash{12, 215, 134, 162, 66, 93, 22, 241, 82, 198, 88, 49, 108, 66, 62, 108, 225, 24, 30, 21, 195, 41, 88, 38, 215, 201, 144, 76, 186, 156, 227, 3}) {
// add trusted CHT for testnet
@@ -125,7 +123,7 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, pow pow.PoW, mux
Number: 452,
Root: common.HexToHash("511da2c88e32b14cf4a4e62f7fcbb297139faebc260a4ab5eb43cce6edcba324"),
})
- log.Info(fmt.Sprint("Added trusted CHT for testnet"))
+ log.Info("Added trusted CHT for testnet")
} else {
DeleteTrustedCht(bc.chainDb)
}
@@ -137,9 +135,9 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, pow pow.PoW, mux
// Check the current state of the block hashes and make sure that we do not have any of the bad blocks in our chain
for hash := range core.BadHashes {
if header := bc.GetHeaderByHash(hash); header != nil {
- log.Error(fmt.Sprintf("Found bad hash, rewinding chain to block #%d [%x…]", header.Number, header.ParentHash[:4]))
+ log.Error("Found bad hash, rewinding chain", "number", header.Number, "hash", header.ParentHash)
bc.SetHead(header.Number.Uint64() - 1)
- log.Error(fmt.Sprint("Chain rewind was successful, resuming normal operation"))
+ log.Error("Chain rewind was successful, resuming normal operation")
}
}
return bc, nil
@@ -169,7 +167,7 @@ func (self *LightChain) loadLastState() error {
// Issue a status log and return
header := self.hc.CurrentHeader()
headerTd := self.GetTd(header.Hash(), header.Number.Uint64())
- log.Info(fmt.Sprintf("Last header: #%d [%x…] TD=%v", self.hc.CurrentHeader().Number, self.hc.CurrentHeader().Hash().Bytes()[:4], headerTd))
+ log.Info("Loaded most recent local header", "number", header.Number, "hash", header.Hash(), "td", headerTd)
return nil
}
@@ -246,10 +244,10 @@ func (bc *LightChain) ResetWithGenesisBlock(genesis *types.Block) {
// Prepare the genesis block and reinitialise the chain
if err := core.WriteTd(bc.chainDb, genesis.Hash(), genesis.NumberU64(), genesis.Difficulty()); err != nil {
- log.Crit(fmt.Sprintf("failed to write genesis block TD: %v", err))
+ log.Crit("Failed to write genesis block TD", "err", err)
}
if err := core.WriteBlock(bc.chainDb, genesis); err != nil {
- log.Crit(fmt.Sprintf("failed to write genesis block: %v", err))
+ log.Crit("Failed to write genesis block", "err", err)
}
bc.genesisBlock = genesis
bc.hc.SetGenesis(bc.genesisBlock.Header())
@@ -345,8 +343,7 @@ func (bc *LightChain) Stop() {
atomic.StoreInt32(&bc.procInterrupt, 1)
bc.wg.Wait()
-
- log.Info(fmt.Sprint("Chain manager stopped"))
+ log.Info("Blockchain manager stopped")
}
// Rollback is designed to remove a chain of links from the database that aren't
@@ -406,21 +403,16 @@ func (self *LightChain) InsertHeaderChain(chain []*types.Header, checkFreq int)
switch status {
case core.CanonStatTy:
- log.Debug("", "msg", log.Lazy{Fn: func() string {
- return fmt.Sprintf("[%v] inserted header #%d (%x...).\n", time.Now().UnixNano(), header.Number, header.Hash().Bytes()[0:4])
- }})
+ log.Debug("Inserted new header", "number", header.Number, "hash", header.Hash())
events = append(events, core.ChainEvent{Block: types.NewBlockWithHeader(header), Hash: header.Hash()})
case core.SideStatTy:
- log.Trace("", "msg", log.Lazy{Fn: func() string {
- return fmt.Sprintf("inserted forked header #%d (TD=%v) (%x...).\n", header.Number, header.Difficulty, header.Hash().Bytes()[0:4])
- }})
+ log.Debug("Inserted forked header", "number", header.Number, "hash", header.Hash())
events = append(events, core.ChainSideEvent{Block: types.NewBlockWithHeader(header)})
case core.SplitStatTy:
events = append(events, core.ChainSplitEvent{Block: types.NewBlockWithHeader(header)})
}
-
return err
}
i, err := self.hc.InsertHeaderChain(chain, checkFreq, whFunc)
diff --git a/light/odr_util.go b/light/odr_util.go
index e7f94db10..17e9aadcb 100644
--- a/light/odr_util.go
+++ b/light/odr_util.go
@@ -19,7 +19,6 @@ package light
import (
"bytes"
"errors"
- "fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
@@ -27,7 +26,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
- "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/net/context"
)
@@ -149,7 +147,6 @@ func GetBody(ctx context.Context, odr OdrBackend, hash common.Hash, number uint6
}
body := new(types.Body)
if err := rlp.Decode(bytes.NewReader(data), body); err != nil {
- log.Error(fmt.Sprintf("invalid block body RLP for hash %x: %v", hash, err))
return nil, err
}
return body, nil
@@ -181,7 +178,6 @@ func GetBlockReceipts(ctx context.Context, odr OdrBackend, hash common.Hash, num
r := &ReceiptsRequest{Hash: hash, Number: number}
if err := odr.Retrieve(ctx, r); err != nil {
return nil, err
- } else {
- return r.Receipts, nil
}
+ return r.Receipts, nil
}
diff --git a/light/state.go b/light/state.go
index 1fb583c1d..d3e047ef4 100644
--- a/light/state.go
+++ b/light/state.go
@@ -17,12 +17,10 @@
package light
import (
- "fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/log"
"golang.org/x/net/context"
)
@@ -239,10 +237,6 @@ func (self *LightState) GetOrNewStateObject(ctx context.Context, addr common.Add
// newStateObject creates a state object whether it exists in the state or not
func (self *LightState) newStateObject(addr common.Address) *StateObject {
- log.Debug("", "msg", log.Lazy{Fn: func() string {
- return fmt.Sprintf("(+) %x\n", addr)
- }})
-
stateObject := NewStateObject(addr, self.odr)
self.stateObjects[addr.Str()] = stateObject
diff --git a/light/state_object.go b/light/state_object.go
index d023270d5..f33ba217e 100644
--- a/light/state_object.go
+++ b/light/state_object.go
@@ -23,7 +23,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/net/context"
)
@@ -107,10 +106,6 @@ func NewStateObject(address common.Address, odr OdrBackend) *StateObject {
func (self *StateObject) MarkForDeletion() {
self.remove = true
self.dirty = true
-
- log.Debug("", "msg", log.Lazy{Fn: func() string {
- return fmt.Sprintf("%x: #%d %v X\n", self.Address(), self.nonce, self.balance)
- }})
}
// getAddr gets the storage value at the given address from the trie
@@ -156,19 +151,11 @@ func (self *StateObject) SetState(k, value common.Hash) {
// AddBalance adds the given amount to the account balance
func (c *StateObject) AddBalance(amount *big.Int) {
c.SetBalance(new(big.Int).Add(c.balance, amount))
-
- log.Debug("", "msg", log.Lazy{Fn: func() string {
- return fmt.Sprintf("%x: #%d %v (+ %v)\n", c.Address(), c.nonce, c.balance, amount)
- }})
}
// SubBalance subtracts the given amount from the account balance
func (c *StateObject) SubBalance(amount *big.Int) {
c.SetBalance(new(big.Int).Sub(c.balance, amount))
-
- log.Debug("", "msg", log.Lazy{Fn: func() string {
- return fmt.Sprintf("%x: #%d %v (- %v)\n", c.Address(), c.nonce, c.balance, amount)
- }})
}
// SetBalance sets the account balance to the given amount
diff --git a/light/txpool.go b/light/txpool.go
index ecd6cfa26..28c8d8ca5 100644
--- a/light/txpool.go
+++ b/light/txpool.go
@@ -320,7 +320,7 @@ func (pool *TxPool) eventLoop() {
func (pool *TxPool) Stop() {
close(pool.quit)
pool.events.Unsubscribe()
- log.Info(fmt.Sprint("Transaction pool stopped"))
+ log.Info("Transaction pool stopped")
}
// Stats returns the number of currently pending (locally created) transactions
@@ -416,20 +416,8 @@ func (self *TxPool) add(ctx context.Context, tx *types.Transaction) error {
go self.eventMux.Post(core.TxPreEvent{Tx: tx})
}
- log.Debug("", "msg", log.Lazy{Fn: func() string {
- var toname string
- if to := tx.To(); to != nil {
- toname = common.Bytes2Hex(to[:4])
- } else {
- toname = "[NEW_CONTRACT]"
- }
- // we can ignore the error here because From is
- // verified in ValidateTransaction.
- f, _ := types.Sender(self.signer, tx)
- from := common.Bytes2Hex(f[:4])
- return fmt.Sprintf("(t) %x => %s (%v) %x\n", from, toname, tx.Value(), hash)
- }})
-
+ // Print a log message if low enough level is set
+ log.Debug("Pooled new transaction", "hash", hash, "from", log.Lazy{Fn: func() common.Address { from, _ := types.Sender(self.signer, tx); return from }}, "to", tx.To())
return nil
}
@@ -462,15 +450,10 @@ func (self *TxPool) AddBatch(ctx context.Context, txs []*types.Transaction) {
var sendTx types.Transactions
for _, tx := range txs {
- if err := self.add(ctx, tx); err != nil {
- log.Debug(fmt.Sprint("tx error:", err))
- } else {
+ if err := self.add(ctx, tx); err == nil {
sendTx = append(sendTx, tx)
- h := tx.Hash()
- log.Debug(fmt.Sprintf("tx %x\n", h[:4]))
}
}
-
if len(sendTx) > 0 {
self.relay.Send(sendTx)
}