mirror of https://github.com/status-im/op-geth.git
Merge branch 'jsonlogs' of https://github.com/ethersphere/go-ethereum into ethersphere-jsonlogs
Conflicts: eth/block_pool.go eth/block_pool_test.go eth/protocol_test.go miner/worker.go
This commit is contained in:
commit
f0b2ea64fc
|
@ -14,7 +14,10 @@ import (
|
|||
"github.com/ethereum/go-ethereum/state"
|
||||
)
|
||||
|
||||
var chainlogger = logger.NewLogger("CHAIN")
|
||||
var (
|
||||
chainlogger = logger.NewLogger("CHAIN")
|
||||
jsonlogger = logger.NewJsonLogger()
|
||||
)
|
||||
|
||||
type ChainEvent struct {
|
||||
Block *types.Block
|
||||
|
@ -124,7 +127,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) {
|
||||
|
@ -397,11 +400,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 {
|
||||
|
@ -419,6 +422,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})
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
ethlogger "github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/miner"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
|
@ -25,8 +25,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
logger = ethlogger.NewLogger("SERV")
|
||||
jsonlogger = ethlogger.NewJsonLogger()
|
||||
ethlogger = logger.NewLogger("SERV")
|
||||
jsonlogger = logger.NewJsonLogger()
|
||||
|
||||
defaultBootNodes = []*discover.Node{
|
||||
// ETH/DEV cmd/bootnode
|
||||
|
@ -76,7 +76,7 @@ func (cfg *Config) parseBootNodes() []*discover.Node {
|
|||
}
|
||||
n, err := discover.ParseNode(url)
|
||||
if err != nil {
|
||||
logger.Errorf("Bootstrap URL %s: %v\n", url, err)
|
||||
ethlogger.Errorf("Bootstrap URL %s: %v\n", url, err)
|
||||
continue
|
||||
}
|
||||
ns = append(ns, n)
|
||||
|
@ -100,7 +100,7 @@ func (cfg *Config) nodeKey() (*ecdsa.PrivateKey, error) {
|
|||
return nil, fmt.Errorf("could not generate server key: %v", err)
|
||||
}
|
||||
if err := ioutil.WriteFile(keyfile, crypto.FromECDSA(key), 0600); err != nil {
|
||||
logger.Errorln("could not persist nodekey: ", err)
|
||||
ethlogger.Errorln("could not persist nodekey: ", err)
|
||||
}
|
||||
return key, nil
|
||||
}
|
||||
|
@ -132,14 +132,14 @@ type Ethereum struct {
|
|||
WsServer rpc.RpcServer
|
||||
keyManager *crypto.KeyManager
|
||||
|
||||
logger ethlogger.LogSystem
|
||||
logger logger.LogSystem
|
||||
|
||||
Mining bool
|
||||
}
|
||||
|
||||
func New(config *Config) (*Ethereum, error) {
|
||||
// Boostrap database
|
||||
logger := ethlogger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat)
|
||||
ethlogger := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat)
|
||||
db, err := ethdb.NewLDBDatabase("blockchain")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -176,7 +176,7 @@ func New(config *Config) (*Ethereum, error) {
|
|||
keyManager: keyManager,
|
||||
blacklist: p2p.NewBlacklist(),
|
||||
eventMux: &event.TypeMux{},
|
||||
logger: logger,
|
||||
logger: ethlogger,
|
||||
}
|
||||
|
||||
eth.chainManager = core.NewChainManager(db, eth.EventMux())
|
||||
|
@ -220,7 +220,7 @@ func New(config *Config) (*Ethereum, error) {
|
|||
}
|
||||
|
||||
func (s *Ethereum) KeyManager() *crypto.KeyManager { return s.keyManager }
|
||||
func (s *Ethereum) Logger() ethlogger.LogSystem { return s.logger }
|
||||
func (s *Ethereum) Logger() logger.LogSystem { return s.logger }
|
||||
func (s *Ethereum) Name() string { return s.net.Name }
|
||||
func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager }
|
||||
func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor }
|
||||
|
@ -238,7 +238,7 @@ func (s *Ethereum) Coinbase() []byte { return nil } // TODO
|
|||
|
||||
// Start the ethereum
|
||||
func (s *Ethereum) Start() error {
|
||||
jsonlogger.LogJson(ðlogger.LogStarting{
|
||||
jsonlogger.LogJson(&logger.LogStarting{
|
||||
ClientString: s.net.Name,
|
||||
ProtocolVersion: ProtocolVersion,
|
||||
})
|
||||
|
@ -264,7 +264,7 @@ func (s *Ethereum) Start() error {
|
|||
s.blockSub = s.eventMux.Subscribe(core.NewMinedBlockEvent{})
|
||||
go s.blockBroadcastLoop()
|
||||
|
||||
logger.Infoln("Server started")
|
||||
ethlogger.Infoln("Server started")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -299,7 +299,7 @@ func (s *Ethereum) Stop() {
|
|||
s.whisper.Stop()
|
||||
}
|
||||
|
||||
logger.Infoln("Server stopped")
|
||||
ethlogger.Infoln("Server stopped")
|
||||
close(s.shutdownChan)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/errs"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
@ -165,6 +166,12 @@ func (self *ethProtocol) handle() error {
|
|||
if err := msg.Decode(&txs); err != nil {
|
||||
return self.protoError(ErrDecode, "msg %v: %v", msg, err)
|
||||
}
|
||||
for _, tx := range txs {
|
||||
jsonlogger.LogJson(&logger.EthTxReceived{
|
||||
TxHash: ethutil.Bytes2Hex(tx.Hash()),
|
||||
RemoteId: self.peer.ID().String(),
|
||||
})
|
||||
}
|
||||
self.txPool.AddTransactions(txs)
|
||||
|
||||
case GetBlockHashesMsg:
|
||||
|
@ -243,6 +250,15 @@ 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 AddBlock only if peer is the best peer
|
||||
// (or selected as new best peer)
|
||||
|
|
|
@ -13,7 +13,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/errs"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
ethlogger "github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package logger
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -53,10 +54,10 @@ func (l *P2PDisconnected) EventName() string {
|
|||
}
|
||||
|
||||
type EthMinerNewBlock 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
|
||||
}
|
||||
|
||||
|
@ -65,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
|
||||
}
|
||||
|
||||
|
@ -78,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
|
||||
}
|
||||
|
||||
|
|
|
@ -11,11 +11,14 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/pow"
|
||||
"github.com/ethereum/go-ethereum/state"
|
||||
"gopkg.in/fatih/set.v0"
|
||||
)
|
||||
|
||||
var jsonlogger = logger.NewJsonLogger()
|
||||
|
||||
type environment struct {
|
||||
totalUsedGas *big.Int
|
||||
state *state.StateDB
|
||||
|
@ -152,6 +155,13 @@ func (self *worker) wait() {
|
|||
self.current.block.Header().MixDigest = work.MixDigest
|
||||
self.current.block.Header().SeedHash = work.SeedHash
|
||||
|
||||
jsonlogger.LogJson(&logger.EthMinerNewBlock{
|
||||
BlockHash: ethutil.Bytes2Hex(block.Hash()),
|
||||
BlockNumber: block.Number(),
|
||||
ChainHeadHash: ethutil.Bytes2Hex(block.ParentHeaderHash),
|
||||
BlockPrevHash: ethutil.Bytes2Hex(block.ParentHeaderHash),
|
||||
})
|
||||
|
||||
if err := self.chain.InsertChain(types.Blocks{self.current.block}); err == nil {
|
||||
self.mux.Post(core.NewMinedBlockEvent{self.current.block})
|
||||
fmt.Println("GOOD BLOCK", self.current.block)
|
||||
|
|
Loading…
Reference in New Issue