aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-06 04:32:41 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-06 04:32:41 +0800
commit94e543bc398efbb5c712b6e4cb48d8a57eb3400d (patch)
tree39a88885789b52d1d5addf8e28d859e55aeeeb52
parentf01d745d70ceb724d015a5d7fcd9516168286b78 (diff)
parent5948adfa10e9ba1069974839140b594ba902cce2 (diff)
downloaddexon-94e543bc398efbb5c712b6e4cb48d8a57eb3400d.tar
dexon-94e543bc398efbb5c712b6e4cb48d8a57eb3400d.tar.gz
dexon-94e543bc398efbb5c712b6e4cb48d8a57eb3400d.tar.bz2
dexon-94e543bc398efbb5c712b6e4cb48d8a57eb3400d.tar.lz
dexon-94e543bc398efbb5c712b6e4cb48d8a57eb3400d.tar.xz
dexon-94e543bc398efbb5c712b6e4cb48d8a57eb3400d.tar.zst
dexon-94e543bc398efbb5c712b6e4cb48d8a57eb3400d.zip
Merge pull request #431 from tgerring/jsonlogs
Structured logging updates
-rw-r--r--core/chain_manager.go11
-rw-r--r--eth/protocol.go8
-rw-r--r--logger/types.go18
3 files changed, 26 insertions, 11 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 959bfd398..81f085c47 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -15,6 +15,7 @@ import (
)
var chainlogger = logger.NewLogger("CHAIN")
+var jsonlogger = logger.NewJsonLogger()
type ChainEvent struct {
Block *types.Block
@@ -122,7 +123,7 @@ func (self *ChainManager) Status() (td *big.Int, currentBlock []byte, genesisBlo
self.mu.RLock()
defer self.mu.RUnlock()
- return self.td, self.currentBlock.Hash(), self.Genesis().Hash()
+ return self.td, self.currentBlock.Hash(), self.genesisBlock.Hash()
}
func (self *ChainManager) SetProcessor(proc types.BlockProcessor) {
@@ -395,11 +396,11 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
var canonical, split bool
self.mu.Lock()
+ cblock := self.currentBlock
{
// Write block to database. Eventually we'll have to improve on this and throw away blocks that are
// not in the canonical chain.
self.write(block)
- cblock := self.currentBlock
// Compare the TD of the last known block in the canonical chain to make sure it's greater.
// At this point it's possible that a different chain (fork) becomes the new canonical chain.
if td.Cmp(self.td) > 0 {
@@ -417,6 +418,12 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
self.mu.Unlock()
if canonical {
+ jsonlogger.LogJson(&logger.EthChainNewHead{
+ BlockHash: ethutil.Bytes2Hex(block.Hash()),
+ BlockNumber: block.Number(),
+ ChainHeadHash: ethutil.Bytes2Hex(cblock.Hash()),
+ BlockPrevHash: ethutil.Bytes2Hex(block.ParentHash()),
+ })
self.setTransState(state.New(block.Root(), self.db))
self.eventMux.Post(ChainEvent{block, td})
}
diff --git a/eth/protocol.go b/eth/protocol.go
index a5cc8ee1a..ec5a5b6ba 100644
--- a/eth/protocol.go
+++ b/eth/protocol.go
@@ -224,6 +224,14 @@ func (self *ethProtocol) handle() error {
return self.protoError(ErrDecode, "msg %v: %v", msg, err)
}
hash := request.Block.Hash()
+ _, chainHead, _ := self.chainManager.Status()
+ jsonlogger.LogJson(&logger.EthChainReceivedNewBlock{
+ BlockHash: ethutil.Bytes2Hex(hash),
+ BlockNumber: request.Block.Number(), // this surely must be zero
+ ChainHeadHash: ethutil.Bytes2Hex(chainHead),
+ BlockPrevHash: ethutil.Bytes2Hex(request.Block.ParentHash()),
+ RemoteId: self.peer.ID().String(),
+ })
// to simplify backend interface adding a new block
// uses AddPeer followed by AddHashes, AddBlock only if peer is the best peer
// (or selected as new best peer)
diff --git a/logger/types.go b/logger/types.go
index 86408620e..d98f0874a 100644
--- a/logger/types.go
+++ b/logger/types.go
@@ -66,11 +66,11 @@ func (l *EthMinerNewBlock) EventName() string {
}
type EthChainReceivedNewBlock struct {
- BlockHash string `json:"block_hash"`
- BlockNumber int `json:"block_number"`
- ChainHeadHash string `json:"chain_head_hash"`
- BlockPrevHash string `json:"block_prev_hash"`
- RemoteId int `json:"remote_id"`
+ 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
}
@@ -79,10 +79,10 @@ func (l *EthChainReceivedNewBlock) EventName() string {
}
type EthChainNewHead struct {
- BlockHash string `json:"block_hash"`
- BlockNumber int `json:"block_number"`
- ChainHeadHash string `json:"chain_head_hash"`
- BlockPrevHash string `json:"block_prev_hash"`
+ BlockHash string `json:"block_hash"`
+ BlockNumber *big.Int `json:"block_number"`
+ ChainHeadHash string `json:"chain_head_hash"`
+ BlockPrevHash string `json:"block_prev_hash"`
LogEvent
}