Skip to content

Commit

Permalink
add custom log for process block
Browse files Browse the repository at this point in the history
  • Loading branch information
ssd04 committed Jan 9, 2025
1 parent 44d5ab0 commit ec5be33
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 252 deletions.
2 changes: 2 additions & 0 deletions process/block/argProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"
"github.com/multiversx/mx-chain-go/state"
logger "github.com/multiversx/mx-chain-logger-go"
)

type coreComponentsHolder interface {
Expand Down Expand Up @@ -94,6 +95,7 @@ type ArgBaseProcessor struct {
BlockProcessingCutoffHandler cutoff.BlockProcessingCutoffHandler
ManagedPeersHolder common.ManagedPeersHolder
SentSignaturesTracker process.SentSignaturesTracker
Logger logger.Logger
}

// ArgShardProcessor holds all dependencies required by the process data factory in order to create
Expand Down
123 changes: 62 additions & 61 deletions process/block/baseProcess.go

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions process/block/displayBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
)

type transactionCounter struct {
log logger.Logger
mutex sync.RWMutex
currentBlockTxs uint64
totalTxs uint64
Expand All @@ -31,6 +32,7 @@ type transactionCounter struct {

// ArgsTransactionCounter represents the arguments needed to create a new transaction counter
type ArgsTransactionCounter struct {
Logger logger.Logger
AppStatusHandler core.AppStatusHandler
Hasher hashing.Hasher
Marshalizer marshal.Marshalizer
Expand All @@ -50,7 +52,14 @@ func NewTransactionCounter(args ArgsTransactionCounter) (*transactionCounter, er
return nil, process.ErrNilMarshalizer
}

var log logger.Logger
log = logger.GetOrCreate("process/block")
if args.Logger != nil {
log = args.Logger
}

return &transactionCounter{
log: log,
mutex: sync.RWMutex{},
appStatusHandler: args.AppStatusHandler,
currentBlockTxs: 0,
Expand All @@ -71,7 +80,7 @@ func (txc *transactionCounter) getPoolCounts(poolsHolder dataRetriever.PoolsHold
// headerReverted updates the total processed txs in case of restore. It also sets the current block txs to 0
func (txc *transactionCounter) headerReverted(hdr data.HeaderHandler) {
if check.IfNil(hdr) {
log.Warn("programming error: nil header in transactionCounter.headerReverted function")
txc.log.Warn("programming error: nil header in transactionCounter.headerReverted function")
return
}

Expand All @@ -95,7 +104,7 @@ func (txc *transactionCounter) safeSubtractTotalTxs(delta uint64) {

func (txc *transactionCounter) headerExecuted(hdr data.HeaderHandler) {
if check.IfNil(hdr) {
log.Warn("programming error: nil header in transactionCounter.headerExecuted function")
txc.log.Warn("programming error: nil header in transactionCounter.headerExecuted function")
return
}

Expand Down Expand Up @@ -141,7 +150,7 @@ func (txc *transactionCounter) displayLogInfo(

tblString, err := display.CreateTableString(dispHeader, dispLines)
if err != nil {
log.Debug("CreateTableString", "error", err.Error())
txc.log.Debug("CreateTableString", "error", err.Error())
return
}

Expand All @@ -154,7 +163,7 @@ func (txc *transactionCounter) displayLogInfo(
"shard", selfId,
}
txc.mutex.RUnlock()
log.Debug(message, arguments...)
txc.log.Debug(message, arguments...)

blockTracker.DisplayTrackedHeaders()
}
Expand Down Expand Up @@ -330,6 +339,7 @@ func getConstructionStateAsString(miniBlockHeader data.MiniBlockHeaderHandler) s

// DisplayLastNotarized will display information about last notarized block
func DisplayLastNotarized(
log logger.Logger,
marshalizer marshal.Marshalizer,
hasher hashing.Hasher,
lastNotarizedHdrForShard data.HeaderHandler,
Expand Down
14 changes: 8 additions & 6 deletions process/block/displayMetaBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/display"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-logger-go"
logger "github.com/multiversx/mx-chain-logger-go"
)

type transactionCountersProvider interface {
Expand All @@ -19,15 +19,17 @@ type transactionCountersProvider interface {
}

type headersCounter struct {
log logger.Logger
shardMBHeaderCounterMutex sync.RWMutex
shardMBHeadersCurrentBlockProcessed uint64
shardMBHeadersTotalProcessed uint64
}

// NewHeaderCounter returns a new object that keeps track of how many headers
// were processed in total, and in the current block
func NewHeaderCounter() *headersCounter {
func NewHeaderCounter(log logger.Logger) *headersCounter {
return &headersCounter{
log: log,
shardMBHeaderCounterMutex: sync.RWMutex{},
shardMBHeadersCurrentBlockProcessed: 0,
shardMBHeadersTotalProcessed: 0,
Expand Down Expand Up @@ -72,7 +74,7 @@ func (hc *headersCounter) displayLogInfo(
blockTracker process.BlockTracker,
) {
if check.IfNil(countersProvider) {
log.Warn("programming error in headersCounter.displayLogInfo - nil countersProvider")
hc.log.Warn("programming error in headersCounter.displayLogInfo - nil countersProvider")
return
}

Expand All @@ -83,7 +85,7 @@ func (hc *headersCounter) displayLogInfo(

tblString, err := display.CreateTableString(dispHeader, dispLines)
if err != nil {
log.Debug("CreateTableString", "error", err.Error())
hc.log.Debug("CreateTableString", "error", err.Error())
return
}

Expand All @@ -96,9 +98,9 @@ func (hc *headersCounter) displayLogInfo(
}
hc.shardMBHeaderCounterMutex.RUnlock()

log.Debug(message, arguments...)
hc.log.Debug(message, arguments...)

log.Debug("metablock metrics info",
hc.log.Debug("metablock metrics info",
"total txs processed", countersProvider.TotalTxs(),
"block txs processed", countersProvider.CurrentBlockTxs(),
"hash", headerHash,
Expand Down
18 changes: 14 additions & 4 deletions process/block/headerValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ import (
"github.com/multiversx/mx-chain-core-go/hashing"
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-go/process"
logger "github.com/multiversx/mx-chain-logger-go"
)

var _ process.HeaderConstructionValidator = (*headerValidator)(nil)

// ArgsHeaderValidator are the arguments needed to create a new header validator
type ArgsHeaderValidator struct {
Logger logger.Logger
Hasher hashing.Hasher
Marshalizer marshal.Marshalizer
}

type headerValidator struct {
log logger.Logger
hasher hashing.Hasher
marshalizer marshal.Marshalizer
}
Expand All @@ -33,7 +36,14 @@ func NewHeaderValidator(args ArgsHeaderValidator) (*headerValidator, error) {
return nil, process.ErrNilMarshalizer
}

var log logger.Logger
log = logger.GetOrCreate("process/block")
if args.Logger != nil {
log = args.Logger
}

return &headerValidator{
log: log,
hasher: args.Hasher,
marshalizer: args.Marshalizer,
}, nil
Expand All @@ -49,15 +59,15 @@ func (h *headerValidator) IsHeaderConstructionValid(currHeader, prevHeader data.
}

if prevHeader.GetRound() >= currHeader.GetRound() {
log.Trace("round does not match",
h.log.Trace("round does not match",
"shard", currHeader.GetShardID(),
"local header round", prevHeader.GetRound(),
"received round", currHeader.GetRound())
return process.ErrLowerRoundInBlock
}

if currHeader.GetNonce() != prevHeader.GetNonce()+1 {
log.Trace("nonce does not match",
h.log.Trace("nonce does not match",
"shard", currHeader.GetShardID(),
"local header nonce", prevHeader.GetNonce(),
"received nonce", currHeader.GetNonce())
Expand All @@ -70,7 +80,7 @@ func (h *headerValidator) IsHeaderConstructionValid(currHeader, prevHeader data.
}

if !bytes.Equal(currHeader.GetPrevHash(), prevHeaderHash) {
log.Trace("header hash does not match",
h.log.Trace("header hash does not match",
"shard", currHeader.GetShardID(),
"local header hash", prevHeaderHash,
"received header with prev hash", currHeader.GetPrevHash(),
Expand All @@ -79,7 +89,7 @@ func (h *headerValidator) IsHeaderConstructionValid(currHeader, prevHeader data.
}

if !bytes.Equal(currHeader.GetPrevRandSeed(), prevHeader.GetRandSeed()) {
log.Trace("header random seed does not match",
h.log.Trace("header random seed does not match",
"shard", currHeader.GetShardID(),
"local header random seed", prevHeader.GetRandSeed(),
"received header with prev random seed", currHeader.GetPrevRandSeed(),
Expand Down
Loading

0 comments on commit ec5be33

Please sign in to comment.