Skip to content

Commit

Permalink
extend custom logging in block tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
ssd04 committed Jan 8, 2025
1 parent 9f69a3e commit 44d5ab0
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 26 deletions.
1 change: 1 addition & 0 deletions integrationTests/sync/basicSync/basicSync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func TestSyncWorksInShard_EmptyBlocksNoForks_With_EquivalentProofs(t *testing.T)
}

_ = logger.SetLogLevel("*:DEBUG,process:TRACE,consensus:TRACE")
logger.ToggleLoggerName(true)

// 3 shard nodes and 1 metachain node
maxShards := uint32(1)
Expand Down
8 changes: 8 additions & 0 deletions integrationTests/testProcessorNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -3105,7 +3105,15 @@ func (tpn *TestProcessorNode) initRequestedItemsHandler() {
}

func (tpn *TestProcessorNode) initBlockTracker() {
id := hex.EncodeToString(tpn.NodesCoordinator.GetOwnPublicKey())
if len(id) > 8 {
id = id[0:8]
}

log := logger.GetOrCreate(fmt.Sprintf("p/track/%s", id))

argBaseTracker := track.ArgBaseTracker{
Logger: log,
Hasher: TestHasher,
HeaderValidator: tpn.HeaderValidator,
Marshalizer: TestMarshalizer,
Expand Down
18 changes: 18 additions & 0 deletions integrationTests/testSyncNode.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package integrationTests

import (
"encoding/hex"
"fmt"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data"
logger "github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-go/common/enablers"
"github.com/multiversx/mx-chain-go/common/forking"
Expand Down Expand Up @@ -147,7 +149,15 @@ func (tpn *TestProcessorNode) initBlockProcessorWithSync() {
}

func (tpn *TestProcessorNode) createShardBootstrapper() (TestBootstrapper, error) {
id := hex.EncodeToString(tpn.NodesCoordinator.GetOwnPublicKey())
if len(id) > 8 {
id = id[0:8]
}

logger := logger.GetOrCreate(fmt.Sprintf("p/sync/%s", id))

argsBaseBootstrapper := sync.ArgBaseBootstrapper{
Logger: logger,
PoolsHolder: tpn.DataPool,
Store: tpn.Storage,
ChainHandler: tpn.BlockChain,
Expand Down Expand Up @@ -194,7 +204,15 @@ func (tpn *TestProcessorNode) createShardBootstrapper() (TestBootstrapper, error
}

func (tpn *TestProcessorNode) createMetaChainBootstrapper() (TestBootstrapper, error) {
id := hex.EncodeToString(tpn.NodesCoordinator.GetOwnPublicKey())
if len(id) > 8 {
id = id[0:8]
}

logger := logger.GetOrCreate(fmt.Sprintf("p/sync/%s", id))

argsBaseBootstrapper := sync.ArgBaseBootstrapper{
Logger: logger,
PoolsHolder: tpn.DataPool,
Store: tpn.Storage,
ChainHandler: tpn.BlockChain,
Expand Down
1 change: 0 additions & 1 deletion process/block/interceptedBlocks/interceptedBlockHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package interceptedBlocks
import (
"fmt"

"github.com/google/martian/log"
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/hashing"
Expand Down
2 changes: 2 additions & 0 deletions process/track/argBlockTrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/sharding"
logger "github.com/multiversx/mx-chain-logger-go"
)

// ArgBaseTracker holds all dependencies required by the process data factory in order to create
// new instances of shard/meta block tracker
type ArgBaseTracker struct {
Logger logger.Logger
Hasher hashing.Hasher
HeaderValidator process.HeaderConstructionValidator
Marshalizer marshal.Marshalizer
Expand Down
54 changes: 31 additions & 23 deletions process/track/baseBlockTrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-logger-go"
logger "github.com/multiversx/mx-chain-logger-go"
)

var _ process.ValidityAttester = (*baseBlockTrack)(nil)
Expand All @@ -29,6 +29,7 @@ type HeaderInfo struct {
}

type baseBlockTrack struct {
log logger.Logger
hasher hashing.Hasher
headerValidator process.HeaderConstructionValidator
marshalizer marshal.Marshalizer
Expand Down Expand Up @@ -61,12 +62,12 @@ func createBaseBlockTrack(arguments ArgBaseTracker) (*baseBlockTrack, error) {

maxNumHeadersToKeepPerShard := arguments.PoolsHolder.Headers().MaxSize()

crossNotarizer, err := NewBlockNotarizer(arguments.Hasher, arguments.Marshalizer, arguments.ShardCoordinator)
crossNotarizer, err := NewBlockNotarizer(arguments.Logger, arguments.Hasher, arguments.Marshalizer, arguments.ShardCoordinator)
if err != nil {
return nil, err
}

selfNotarizer, err := NewBlockNotarizer(arguments.Hasher, arguments.Marshalizer, arguments.ShardCoordinator)
selfNotarizer, err := NewBlockNotarizer(arguments.Logger, arguments.Hasher, arguments.Marshalizer, arguments.ShardCoordinator)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -96,7 +97,14 @@ func createBaseBlockTrack(arguments ArgBaseTracker) (*baseBlockTrack, error) {
return nil, err
}

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

bbt := &baseBlockTrack{
log: log,
hasher: arguments.Hasher,
headerValidator: arguments.HeaderValidator,
marshalizer: arguments.Marshalizer,
Expand Down Expand Up @@ -131,11 +139,11 @@ func (bbt *baseBlockTrack) receivedHeader(headerHandler data.HeaderHandler, head
func (bbt *baseBlockTrack) receivedShardHeader(headerHandler data.HeaderHandler, shardHeaderHash []byte) {
shardHeader, ok := headerHandler.(data.ShardHeaderHandler)
if !ok {
log.Warn("cannot convert data.HeaderHandler in data.ShardHeaderHandler")
bbt.log.Warn("cannot convert data.HeaderHandler in data.ShardHeaderHandler")
return
}

log.Debug("received shard header from network in block tracker",
bbt.log.Debug("received shard header from network in block tracker",
"shard", shardHeader.GetShardID(),
"epoch", shardHeader.GetEpoch(),
"round", shardHeader.GetRound(),
Expand All @@ -144,12 +152,12 @@ func (bbt *baseBlockTrack) receivedShardHeader(headerHandler data.HeaderHandler,
)

if !bbt.ShouldAddHeader(headerHandler) {
log.Trace("received shard header is out of range", "nonce", headerHandler.GetNonce())
bbt.log.Trace("received shard header is out of range", "nonce", headerHandler.GetNonce())
return
}

if !bbt.addHeader(shardHeader, shardHeaderHash) {
log.Trace("received shard header was not added", "nonce", headerHandler.GetNonce())
bbt.log.Trace("received shard header was not added", "nonce", headerHandler.GetNonce())
return
}

Expand All @@ -160,11 +168,11 @@ func (bbt *baseBlockTrack) receivedShardHeader(headerHandler data.HeaderHandler,
func (bbt *baseBlockTrack) receivedMetaBlock(headerHandler data.HeaderHandler, metaBlockHash []byte) {
metaBlock, ok := headerHandler.(*block.MetaBlock)
if !ok {
log.Warn("cannot convert data.HeaderHandler in *block.Metablock")
bbt.log.Warn("cannot convert data.HeaderHandler in *block.Metablock")
return
}

log.Debug("received meta block from network in block tracker",
bbt.log.Debug("received meta block from network in block tracker",
"shard", metaBlock.GetShardID(),
"epoch", metaBlock.GetEpoch(),
"round", metaBlock.GetRound(),
Expand All @@ -173,12 +181,12 @@ func (bbt *baseBlockTrack) receivedMetaBlock(headerHandler data.HeaderHandler, m
)

if !bbt.ShouldAddHeader(headerHandler) {
log.Trace("received meta block is out of range", "nonce", headerHandler.GetNonce())
bbt.log.Trace("received meta block is out of range", "nonce", headerHandler.GetNonce())
return
}

if !bbt.addHeader(metaBlock, metaBlockHash) {
log.Trace("received meta block was not added", "nonce", headerHandler.GetNonce())
bbt.log.Trace("received meta block was not added", "nonce", headerHandler.GetNonce())
return
}

Expand All @@ -203,7 +211,7 @@ func (bbt *baseBlockTrack) shouldAddHeaderForShard(
) bool {
lastNotarizedHeader, _, err := blockNotarizer.GetLastNotarizedHeader(headerHandler.GetShardID())
if err != nil {
log.Debug("shouldAddHeaderForShard.GetLastNotarizedHeader",
bbt.log.Debug("shouldAddHeaderForShard.GetLastNotarizedHeader",
"shard", headerHandler.GetShardID(),
"error", err.Error())
return false
Expand Down Expand Up @@ -386,12 +394,12 @@ func (bbt *baseBlockTrack) displayTrackedHeadersForShard(shardID uint32, message
return
}

log.Debug(message,
bbt.log.Debug(message,
"shard", shardID,
"nb", len(headers))

for index, header := range headers {
log.Trace("tracked header info",
bbt.log.Trace("tracked header info",
"round", header.GetRound(),
"nonce", header.GetNonce(),
"hash", hashes[index])
Expand Down Expand Up @@ -572,7 +580,7 @@ func (bbt *baseBlockTrack) SortHeadersFromNonce(shardID uint32, nonce uint64) ([
func (bbt *baseBlockTrack) AddHeaderFromPool(shardID uint32, nonce uint64) {
headers, hashes, err := bbt.headersPool.GetHeadersByNonceAndShardId(nonce, shardID)
if err != nil {
log.Trace("baseBlockTrack.AddHeaderFromPool", "error", err.Error())
bbt.log.Trace("baseBlockTrack.AddHeaderFromPool", "error", err.Error())
return
}

Expand Down Expand Up @@ -680,15 +688,15 @@ func (bbt *baseBlockTrack) computeMetaBlocksDifferenceForShard(shardID uint32) i
func (bbt *baseBlockTrack) computeMetaBlocksBehind() int64 {
selfHdrNotarizedByItself, _, err := bbt.GetLastSelfNotarizedHeader(bbt.shardCoordinator.SelfId())
if err != nil {
log.Debug("isMetaStuck.GetLastSelfNotarizedHeader",
bbt.log.Debug("isMetaStuck.GetLastSelfNotarizedHeader",
"shard", bbt.shardCoordinator.SelfId(),
"error", err.Error())
return 0
}

selfHdrNotarizedByMeta, _, err := bbt.GetLastSelfNotarizedHeader(core.MetachainShardId)
if err != nil {
log.Debug("isMetaStuck.GetLastSelfNotarizedHeader",
bbt.log.Debug("isMetaStuck.GetLastSelfNotarizedHeader",
"shard", core.MetachainShardId,
"error", err.Error())
return 0
Expand Down Expand Up @@ -829,7 +837,7 @@ func (bbt *baseBlockTrack) doWhitelistWithMetaBlockIfNeeded(metablock data.MetaH
miniBlockHdrs := metablock.GetMiniBlockHeaderHandlers()
keys := make([][]byte, 0)

crossMbKeysMeta := getCrossShardMiniblockKeys(miniBlockHdrs, selfShardID, core.MetachainShardId)
crossMbKeysMeta := bbt.getCrossShardMiniblockKeys(miniBlockHdrs, selfShardID, core.MetachainShardId)
if len(crossMbKeysMeta) > 0 {
keys = append(keys, crossMbKeysMeta...)
}
Expand All @@ -839,7 +847,7 @@ func (bbt *baseBlockTrack) doWhitelistWithMetaBlockIfNeeded(metablock data.MetaH
continue
}

crossMbKeysShard := getCrossShardMiniblockKeys(shardData.GetShardMiniBlockHeaderHandlers(), selfShardID, shardData.GetShardID())
crossMbKeysShard := bbt.getCrossShardMiniblockKeys(shardData.GetShardMiniBlockHeaderHandlers(), selfShardID, shardData.GetShardID())
if len(crossMbKeysShard) > 0 {
keys = append(keys, crossMbKeysShard...)
}
Expand All @@ -863,23 +871,23 @@ func (bbt *baseBlockTrack) doWhitelistWithShardHeaderIfNeeded(shardHeader data.H
miniBlockHdrs := shardHeader.GetMiniBlockHeaderHandlers()
keys := make([][]byte, 0)

crossMbKeysShard := getCrossShardMiniblockKeys(miniBlockHdrs, selfShardID, shardHeader.GetShardID())
crossMbKeysShard := bbt.getCrossShardMiniblockKeys(miniBlockHdrs, selfShardID, shardHeader.GetShardID())
if len(crossMbKeysShard) > 0 {
keys = append(keys, crossMbKeysShard...)
}

bbt.whitelistHandler.Add(keys)
}

func getCrossShardMiniblockKeys(miniBlockHdrs []data.MiniBlockHeaderHandler, selfShardID uint32, processingShard uint32) [][]byte {
func (bbt *baseBlockTrack) getCrossShardMiniblockKeys(miniBlockHdrs []data.MiniBlockHeaderHandler, selfShardID uint32, processingShard uint32) [][]byte {
keys := make([][]byte, 0)
for _, miniBlockHdr := range miniBlockHdrs {
receiverShard := miniBlockHdr.GetReceiverShardID()
receiverIsSelfShard := receiverShard == selfShardID || (receiverShard == core.AllShardId && processingShard == core.MetachainShardId)
senderIsCrossShard := miniBlockHdr.GetSenderShardID() != selfShardID
if receiverIsSelfShard && senderIsCrossShard {
keys = append(keys, miniBlockHdr.GetHash())
log.Trace(
bbt.log.Trace(
"getCrossShardMiniblockKeys",
"type", miniBlockHdr.GetTypeInt32(),
"sender", miniBlockHdr.GetSenderShardID(),
Expand All @@ -894,7 +902,7 @@ func getCrossShardMiniblockKeys(miniBlockHdrs []data.MiniBlockHeaderHandler, sel
func (bbt *baseBlockTrack) isHeaderOutOfRange(headerHandler data.HeaderHandler) bool {
lastCrossNotarizedHeader, _, err := bbt.GetLastCrossNotarizedHeader(headerHandler.GetShardID())
if err != nil {
log.Debug("isHeaderOutOfRange.GetLastCrossNotarizedHeader",
bbt.log.Debug("isHeaderOutOfRange.GetLastCrossNotarizedHeader",
"shard", headerHandler.GetShardID(),
"error", err.Error())
return true
Expand Down
8 changes: 6 additions & 2 deletions process/track/blockNotarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/sharding"
logger "github.com/multiversx/mx-chain-logger-go"
)

type blockNotarizer struct {
log logger.Logger
hasher hashing.Hasher
marshalizer marshal.Marshalizer
shardCoordinator sharding.Coordinator
Expand All @@ -24,6 +26,7 @@ type blockNotarizer struct {

// NewBlockNotarizer creates a block notarizer object which implements blockNotarizerHandler interface
func NewBlockNotarizer(
logger logger.Logger,
hasher hashing.Hasher,
marshalizer marshal.Marshalizer,
shardCoordinator sharding.Coordinator,
Expand All @@ -39,6 +42,7 @@ func NewBlockNotarizer(
}

bn := blockNotarizer{
log: logger,
hasher: hasher,
marshalizer: marshalizer,
shardCoordinator: shardCoordinator,
Expand Down Expand Up @@ -124,12 +128,12 @@ func (bn *blockNotarizer) DisplayNotarizedHeaders(shardID uint32, message string
return
}

log.Debug(message,
bn.log.Debug(message,
"shard", shardID,
"nb", len(notarizedHeaders))

for _, hdrInfo := range notarizedHeaders {
log.Trace("notarized header info",
bn.log.Trace("notarized header info",
"round", hdrInfo.Header.GetRound(),
"nonce", hdrInfo.Header.GetNonce(),
"hash", hdrInfo.Hash)
Expand Down

0 comments on commit 44d5ab0

Please sign in to comment.