Skip to content

Commit

Permalink
feat: Add module names to component loggers (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal authored Sep 16, 2024
1 parent ee78b49 commit 803540b
Show file tree
Hide file tree
Showing 40 changed files with 645 additions and 614 deletions.
9 changes: 6 additions & 3 deletions aggoracle/chaingersender/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type EthTxManager interface {
}

type EVMChainGERSender struct {
logger *log.Logger
gerContract *pessimisticglobalexitroot.Pessimisticglobalexitroot
gerAddr common.Address
sender common.Address
Expand All @@ -60,6 +61,7 @@ type EVMConfig struct {
}

func NewEVMChainGERSender(
logger *log.Logger,
l2GlobalExitRoot, sender common.Address,
l2Client EthClienter,
ethTxMan EthTxManager,
Expand All @@ -72,6 +74,7 @@ func NewEVMChainGERSender(
}

return &EVMChainGERSender{
logger: logger,
gerContract: gerContract,
gerAddr: l2GlobalExitRoot,
sender: sender,
Expand Down Expand Up @@ -106,10 +109,10 @@ func (c *EVMChainGERSender) UpdateGERWaitUntilMined(ctx context.Context, ger com
}
for {
time.Sleep(c.waitPeriodMonitorTx)
log.Debugf("waiting for tx %s to be mined", id.Hex())
c.logger.Debugf("waiting for tx %s to be mined", id.Hex())
res, err := c.ethTxMan.Result(ctx, id)
if err != nil {
log.Error("error calling ethTxMan.Result: ", err)
c.logger.Error("error calling ethTxMan.Result: ", err)
}
switch res.Status {
case ethtxmanager.MonitoredTxStatusCreated,
Expand All @@ -122,7 +125,7 @@ func (c *EVMChainGERSender) UpdateGERWaitUntilMined(ctx context.Context, ger com
ethtxmanager.MonitoredTxStatusFinalized:
return nil
default:
log.Error("unexpected tx status: ", res.Status)
c.logger.Error("unexpected tx status: ", res.Status)
}
}
}
22 changes: 11 additions & 11 deletions aggoracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ChainSender interface {
}

type AggOracle struct {
logger *log.Logger
ticker *time.Ticker
l1Client ethereum.ChainReader
l1Info L1InfoTreer
Expand All @@ -31,6 +32,7 @@ type AggOracle struct {
}

func New(
logger *log.Logger,
chainSender ChainSender,
l1Client ethereum.ChainReader,
l1InfoTreeSyncer L1InfoTreer,
Expand All @@ -44,6 +46,7 @@ func New(
}

return &AggOracle{
logger: logger,
ticker: ticker,
l1Client: l1Client,
l1Info: l1InfoTreeSyncer,
Expand All @@ -64,32 +67,29 @@ func (a *AggOracle) Start(ctx context.Context) {
blockNumToFetch, gerToInject, err = a.getLastFinalisedGER(ctx, blockNumToFetch)
if err != nil {
if errors.Is(err, l1infotreesync.ErrBlockNotProcessed) {
log.Debugf("syncer is not ready for the block %d", blockNumToFetch)
a.logger.Debugf("syncer is not ready for the block %d", blockNumToFetch)
} else if errors.Is(err, l1infotreesync.ErrNotFound) {
blockNumToFetch = 0
log.Debugf("syncer has not found any GER until block %d", blockNumToFetch)
a.logger.Debugf("syncer has not found any GER until block %d", blockNumToFetch)
} else {
log.Error("error calling getLastFinalisedGER: ", err)
a.logger.Error("error calling getLastFinalisedGER: ", err)
}

continue
}
if alreadyInjected, err := a.chainSender.IsGERAlreadyInjected(gerToInject); err != nil {
log.Error("error calling isGERAlreadyInjected: ", err)

a.logger.Error("error calling isGERAlreadyInjected: ", err)
continue
} else if alreadyInjected {
log.Debugf("GER %s already injected", gerToInject.Hex())

a.logger.Debugf("GER %s already injected", gerToInject.Hex())
continue
}
log.Infof("injecting new GER: %s", gerToInject.Hex())
a.logger.Infof("injecting new GER: %s", gerToInject.Hex())
if err := a.chainSender.UpdateGERWaitUntilMined(ctx, gerToInject); err != nil {
log.Errorf("error calling updateGERWaitUntilMined, when trying to inject GER %s: %v", gerToInject.Hex(), err)

a.logger.Errorf("error calling updateGERWaitUntilMined, when trying to inject GER %s: %v", gerToInject.Hex(), err)
continue
}
log.Infof("GER %s injected", gerToInject.Hex())
a.logger.Infof("GER %s injected", gerToInject.Hex())
case <-ctx.Done():
return
}
Expand Down
Loading

0 comments on commit 803540b

Please sign in to comment.