Skip to content

Commit

Permalink
add custom logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ssd04 committed Jan 8, 2025
1 parent 84c0b98 commit 9f69a3e
Show file tree
Hide file tree
Showing 36 changed files with 381 additions and 197 deletions.
4 changes: 2 additions & 2 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

# ChainParametersByEpoch defines chain operation configurable values that can be modified based on epochs
ChainParametersByEpoch = [
{ EnableEpoch = 0, RoundDuration = 6000, ShardConsensusGroupSize = 7, ShardMinNumNodes = 10, MetachainConsensusGroupSize = 10, MetachainMinNumNodes = 10, Hysteresis = 0.2, Adaptivity = false }
{ EnableEpoch = 0, RoundDuration = 6000, ShardConsensusGroupSize = 3, ShardMinNumNodes = 3, MetachainConsensusGroupSize = 3, MetachainMinNumNodes = 3, Hysteresis = 0.2, Adaptivity = false }
]

[HardwareRequirements]
Expand Down Expand Up @@ -628,7 +628,7 @@
[EpochStartConfig]
GenesisEpoch = 0
MinRoundsBetweenEpochs = 20
RoundsPerEpoch = 200
RoundsPerEpoch = 21
# Min and Max ShuffledOutRestartThreshold represents the minimum and maximum duration of an epoch (in percentage) after a node which
# has been shuffled out has to restart its process in order to start in a new shard
MinShuffledOutRestartThreshold = 0.05
Expand Down
2 changes: 2 additions & 0 deletions consensus/chronology/argChronology.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-go/consensus"
"github.com/multiversx/mx-chain-go/ntp"
logger "github.com/multiversx/mx-chain-logger-go"
)

// ArgChronology holds all dependencies required by the chronology component
type ArgChronology struct {
Logger logger.Logger
GenesisTime time.Time
RoundHandler consensus.RoundHandler
SyncTimer ntp.SyncTimer
Expand Down
18 changes: 12 additions & 6 deletions consensus/chronology/chronology.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/core/closing"
"github.com/multiversx/mx-chain-core-go/display"
"github.com/multiversx/mx-chain-logger-go"
logger "github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/consensus"
Expand All @@ -20,8 +20,6 @@ import (
var _ consensus.ChronologyHandler = (*chronology)(nil)
var _ closing.Closer = (*chronology)(nil)

var log = logger.GetOrCreate("consensus/chronology")

// srBeforeStartRound defines the state which exist before the start of the round
const srBeforeStartRound = -1

Expand All @@ -30,6 +28,7 @@ const chronologyAlarmID = "chronology"

// chronology defines the data needed by the chronology
type chronology struct {
log logger.Logger
genesisTime time.Time

roundHandler consensus.RoundHandler
Expand All @@ -48,13 +47,19 @@ type chronology struct {

// NewChronology creates a new chronology object
func NewChronology(arg ArgChronology) (*chronology, error) {
var log logger.Logger
log = logger.GetOrCreate("consensus/chronology")
if arg.Logger != nil {
log = arg.Logger
}

err := checkNewChronologyParams(arg)
if err != nil {
return nil, err
}

chr := chronology{
log: log,
genesisTime: arg.GenesisTime,
roundHandler: arg.RoundHandler,
syncTimer: arg.SyncTimer,
Expand Down Expand Up @@ -122,7 +127,7 @@ func (chr *chronology) startRounds(ctx context.Context) {
for {
select {
case <-ctx.Done():
log.Debug("chronology's go routine is stopping...")
chr.log.Debug("chronology's go routine is stopping...")
return
case <-time.After(time.Millisecond):
}
Expand All @@ -143,11 +148,12 @@ func (chr *chronology) startRound(ctx context.Context) {

sr := chr.loadSubroundHandler(chr.subroundId)
if sr == nil {
// chr.log.Trace("chronology: nil subround handler", "subroundId", chr.subroundId)
return
}

msg := fmt.Sprintf("SUBROUND %s BEGINS", sr.Name())
log.Debug(display.Headline(msg, chr.syncTimer.FormattedCurrentTime(), "."))
chr.log.Debug(display.Headline(msg, chr.syncTimer.FormattedCurrentTime(), "."))
logger.SetCorrelationSubround(sr.Name())

if !sr.DoWork(ctx, chr.roundHandler) {
Expand All @@ -166,7 +172,7 @@ func (chr *chronology) updateRound() {
if oldRoundIndex != chr.roundHandler.Index() {
chr.watchdog.Reset(chronologyAlarmID)
msg := fmt.Sprintf("ROUND %d BEGINS (%d)", chr.roundHandler.Index(), chr.roundHandler.TimeStamp().Unix())
log.Debug(display.Headline(msg, chr.syncTimer.FormattedCurrentTime(), "#"))
chr.log.Debug(display.Headline(msg, chr.syncTimer.FormattedCurrentTime(), "#"))
logger.SetCorrelationRound(chr.roundHandler.Index())

chr.initRound()
Expand Down
5 changes: 5 additions & 0 deletions consensus/spos/bls/proxy/subroundsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var log = logger.GetOrCreate("consensus/spos/bls/proxy")

// SubroundsHandlerArgs struct contains the needed data for the SubroundsHandler
type SubroundsHandlerArgs struct {
Logger logger.Logger
Chronology consensus.ChronologyHandler
ConsensusCoreHandler spos.ConsensusCoreHandler
ConsensusState spos.ConsensusStateHandler
Expand All @@ -42,6 +43,7 @@ type consensusStateMachineType int

// SubroundsHandler struct contains the needed data for the SubroundsHandler
type SubroundsHandler struct {
log logger.Logger
chronology consensus.ChronologyHandler
consensusCoreHandler spos.ConsensusCoreHandler
consensusState spos.ConsensusStateHandler
Expand Down Expand Up @@ -77,6 +79,7 @@ func NewSubroundsHandler(args *SubroundsHandlerArgs) (*SubroundsHandler, error)
}

subroundHandler := &SubroundsHandler{
log: args.Logger,
chronology: args.Chronology,
consensusCoreHandler: args.ConsensusCoreHandler,
consensusState: args.ConsensusState,
Expand Down Expand Up @@ -150,6 +153,7 @@ func (s *SubroundsHandler) initSubroundsForEpoch(epoch uint32) error {

s.currentConsensusType = consensusV2
fct, err = v2.NewSubroundsFactory(
s.log,
s.consensusCoreHandler,
s.consensusState,
s.worker,
Expand All @@ -175,6 +179,7 @@ func (s *SubroundsHandler) initSubroundsForEpoch(epoch uint32) error {
s.appStatusHandler,
s.sentSignatureTracker,
s.outportHandler,
s.log,
)
}
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions consensus/spos/bls/v1/blsSubroundsFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

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

"github.com/multiversx/mx-chain-go/consensus/spos"
"github.com/multiversx/mx-chain-go/consensus/spos/bls"
Expand All @@ -23,6 +24,7 @@ type factory struct {
sentSignaturesTracker spos.SentSignaturesTracker
chainID []byte
currentPid core.PeerID
log logger.Logger
}

// NewSubroundsFactory creates a new consensusState object
Expand All @@ -35,6 +37,7 @@ func NewSubroundsFactory(
appStatusHandler core.AppStatusHandler,
sentSignaturesTracker spos.SentSignaturesTracker,
outportHandler outport.OutportHandler,
logger logger.Logger,
) (*factory, error) {
// no need to check the outportHandler, it can be nil
err := checkNewFactoryParams(
Expand Down Expand Up @@ -147,6 +150,7 @@ func (fct *factory) generateStartRoundSubround() error {
fct.chainID,
fct.currentPid,
fct.appStatusHandler,
fct.log,
)
if err != nil {
return err
Expand Down Expand Up @@ -189,6 +193,7 @@ func (fct *factory) generateBlockSubround() error {
fct.chainID,
fct.currentPid,
fct.appStatusHandler,
fct.log,
)
if err != nil {
return err
Expand Down Expand Up @@ -227,6 +232,7 @@ func (fct *factory) generateSignatureSubround() error {
fct.chainID,
fct.currentPid,
fct.appStatusHandler,
fct.log,
)
if err != nil {
return err
Expand Down Expand Up @@ -263,6 +269,7 @@ func (fct *factory) generateEndRoundSubround() error {
fct.chainID,
fct.currentPid,
fct.appStatusHandler,
fct.log,
)
if err != nil {
return err
Expand Down
8 changes: 8 additions & 0 deletions consensus/spos/bls/v2/blsSubroundsFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

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

"github.com/multiversx/mx-chain-go/consensus/spos"
"github.com/multiversx/mx-chain-go/consensus/spos/bls"
Expand All @@ -14,6 +15,7 @@ import (
// factory defines the data needed by this factory to create all the subrounds and give them their specific
// functionality
type factory struct {
log logger.Logger
consensusCore spos.ConsensusCoreHandler
consensusState spos.ConsensusStateHandler
worker spos.WorkerHandler
Expand All @@ -28,6 +30,7 @@ type factory struct {

// NewSubroundsFactory creates a new consensusState object
func NewSubroundsFactory(
logger logger.Logger,
consensusDataContainer spos.ConsensusCoreHandler,
consensusState spos.ConsensusStateHandler,
worker spos.WorkerHandler,
Expand All @@ -53,6 +56,7 @@ func NewSubroundsFactory(
}

fct := factory{
log: logger,
consensusCore: consensusDataContainer,
consensusState: consensusState,
worker: worker,
Expand Down Expand Up @@ -155,6 +159,7 @@ func (fct *factory) generateStartRoundSubround() error {
fct.chainID,
fct.currentPid,
fct.appStatusHandler,
fct.log,
)
if err != nil {
return err
Expand Down Expand Up @@ -195,6 +200,7 @@ func (fct *factory) generateBlockSubround() error {
fct.chainID,
fct.currentPid,
fct.appStatusHandler,
fct.log,
)
if err != nil {
return err
Expand Down Expand Up @@ -231,6 +237,7 @@ func (fct *factory) generateSignatureSubround() error {
fct.chainID,
fct.currentPid,
fct.appStatusHandler,
fct.log,
)
if err != nil {
return err
Expand Down Expand Up @@ -267,6 +274,7 @@ func (fct *factory) generateEndRoundSubround() error {
fct.chainID,
fct.currentPid,
fct.appStatusHandler,
fct.log,
)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 9f69a3e

Please sign in to comment.