cleanup logging

This commit is contained in:
Roy Crihfield 2023-06-23 16:41:43 +08:00
parent 0fabb5a35d
commit a80ce5abcf

View File

@ -272,10 +272,10 @@ func (sds *Service) writeLoopWorker(params workerParams) {
defer params.wg.Done()
for {
select {
case chainEvent := <-params.chainEventCh:
log.Debug("Chain event received", "event", chainEvent)
case event := <-params.chainEventCh:
block := event.Block
log.Debug("Chain event received", "number", block.Number(), "hash", event.Hash)
block := chainEvent.Block
parent := sds.BlockCache.getParentBlock(block, sds.BlockChain)
if parent == nil {
log.Error("Parent block is nil, skipping this block", "number", block.Number())
@ -287,14 +287,14 @@ func (sds *Service) writeLoopWorker(params workerParams) {
sds.writeGenesisStateDiff(parent, log)
}
log.Info("Writing state diff", "number", block.Number().Uint64())
log.Info("Writing state diff", "number", block.Number())
sds.writeLoopParams.RLock()
err := sds.writeStateDiffWithRetry(block, parent.Root(), sds.writeLoopParams.Params)
sds.writeLoopParams.RUnlock()
if err != nil {
log.Error("failed to write state diff",
"number", block.Number().Uint64(),
"hash", block.Hash().String(),
"number", block.Number(),
"hash", block.Hash(),
"error", err.Error())
continue
}
@ -329,13 +329,13 @@ func (sds *Service) PublishLoop(chainEventCh chan core.ChainEvent) {
log.Debug("Chain event received", "number", block.Number(), "hash", event.Hash)
// if we don't have any subscribers, do not process a statediff
if atomic.LoadInt32(&sds.subscribers) == 0 {
log.Debug("Currently no subscribers; processing is halted")
log.Debug("Currently no subscribers, skipping block")
continue
}
parent := sds.BlockCache.getParentBlock(block, sds.BlockChain)
if parent == nil {
log.Error("Parent block is nil, skipping this block", "number", block.Number())
log.Error("Parent block is nil, skipping block", "number", block.Number())
continue
}
@ -371,13 +371,14 @@ func (sds *Service) streamStateDiff(currentBlock *types.Block, parentRoot common
// create payload for this subscription type
payload, err := sds.processStateDiff(currentBlock, parentRoot, params)
if err != nil {
log.Error("statediff processing error", "number", currentBlock.Number().Uint64(), "parameters", params, "error", err.Error())
log.Error("statediff processing error",
"number", currentBlock.Number(), "parameters", params, "error", err.Error())
continue
}
for id, sub := range subs {
select {
case sub.PayloadChan <- *payload:
log.Debug("sending statediff payload at head", "height", currentBlock.Number(), "sub.id", id)
log.Debug("sending statediff payload at head", "number", currentBlock.Number(), "sub.id", id)
default:
log.Info("unable to send statediff payload; channel has no receiver", "sub.id", id)
}
@ -390,7 +391,7 @@ func (sds *Service) streamStateDiff(currentBlock *types.Block, parentRoot common
// This operation cannot be performed back past the point of db pruning; it requires an archival
// node for historical data
func (sds *Service) StateDiffAt(blockNumber uint64, params Params) (*Payload, error) {
log.Info("sending state diff", "number", blockNumber)
log.Info("Sending state diff", "number", blockNumber)
currentBlock := sds.BlockChain.GetBlockByNumber(blockNumber)
parentRoot := common.Hash{}
@ -404,7 +405,7 @@ func (sds *Service) StateDiffAt(blockNumber uint64, params Params) (*Payload, er
// This operation cannot be performed back past the point of db pruning; it requires an archival
// node for historical data
func (sds *Service) StateDiffFor(blockHash common.Hash, params Params) (*Payload, error) {
log.Info("sending state diff", "hash", blockHash)
log.Info("Sending state diff", "hash", blockHash)
currentBlock := sds.BlockChain.GetBlockByHash(blockHash)
parentRoot := common.Hash{}
@ -445,7 +446,7 @@ func (sds *Service) processStateDiff(currentBlock *types.Block, parentRoot commo
return nil, err
}
log.Debug("statediff RLP payload for block",
"number", currentBlock.Number().Uint64(), "byte size", len(stateDiffRlp))
"number", currentBlock.Number(), "byte size", len(stateDiffRlp))
return sds.newPayload(stateDiffRlp, currentBlock, params)
}
@ -738,7 +739,7 @@ func (sds *Service) writeStateDiffWithRetry(block *types.Block, parentRoot commo
if err != nil && strings.Contains(err.Error(), pgDeadlockDetected) {
// Retry only when the deadlock is detected.
if i+1 < sds.maxRetry {
log.Warn("dead lock detected while writing statediff", "error", err, "retry number", i)
log.Warn("deadlock detected while writing statediff", "error", err, "retry number", i)
}
continue
}