diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-06 00:58:13 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-06 00:58:13 +0800 |
commit | fbb307cca075b9a253316434f016a4820783a02d (patch) | |
tree | bf34aeb28c4955394aba794187e3e55bcbec0ebc | |
parent | a75af474f71606ed4572db216d9440b7c14a8a37 (diff) | |
download | go-tangerine-fbb307cca075b9a253316434f016a4820783a02d.tar.gz go-tangerine-fbb307cca075b9a253316434f016a4820783a02d.tar.zst go-tangerine-fbb307cca075b9a253316434f016a4820783a02d.zip |
Added eth.chain.new_head
-rw-r--r-- | core/chain_manager.go | 11 | ||||
-rw-r--r-- | logger/types.go | 8 |
2 files changed, 13 insertions, 6 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/logger/types.go b/logger/types.go index 86408620e..b04ff4fd0 100644 --- a/logger/types.go +++ b/logger/types.go @@ -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 } |