Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve aggsender logs #186

Merged
merged 9 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 149 additions & 1 deletion agglayer/mock_agglayer_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion agglayer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func (c CertificateHeader) String() string {
errors = c.Error.String()
}

return fmt.Sprintf("Height: %d, CertificateID: %s, NewLocalExitRoot: %s. Status: %s. Errors: %s",
return fmt.Sprintf("Height: %d, CertificateID: %s, NewLocalExitRoot: %s. Status: %s. Errors: [%s]",
c.Height, c.CertificateID.String(), c.NewLocalExitRoot.String(), c.Status.String(), errors)
}

Expand Down
43 changes: 23 additions & 20 deletions aggsender/aggsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func New(
cfg Config,
aggLayerClient agglayer.AgglayerClientInterface,
l1InfoTreeSyncer *l1infotreesync.L1InfoTreeSync,
l2Syncer *bridgesync.BridgeSync,
l2Syncer types.L2BridgeSyncer,
epochNotifier types.EpochNotifier) (*AggSender, error) {
storage, err := db.NewAggSenderSQLStorage(logger, cfg.StoragePath)
if err != nil {
Expand Down Expand Up @@ -93,14 +93,14 @@ func (a *AggSender) sendCertificates(ctx context.Context) {
select {
case epoch := <-chEpoch:
a.log.Infof("Epoch received: %s", epoch.String())
thereArePendingCerts, err := a.checkPendingCertificatesStatus(ctx)
if err == nil && !thereArePendingCerts {
thereArePendingCerts := a.checkPendingCertificatesStatus(ctx)
if !thereArePendingCerts {
if _, err := a.sendCertificate(ctx); err != nil {
log.Error(err)
}
} else {
log.Warnf("Skipping epoch %s because there are pending certificates %v or error: %w",
epoch.String(), thereArePendingCerts, err)
log.Infof("Skipping epoch %s because there are pending certificates",
epoch.String())
}
case <-ctx.Done():
a.log.Info("AggSender stopped")
Expand Down Expand Up @@ -177,7 +177,7 @@ func (a *AggSender) sendCertificate(ctx context.Context) (*agglayer.SignedCertif
}

a.saveCertificateToFile(signedCertificate)
a.log.Debugf("certificate ready to be send to AggLayer: %s", signedCertificate.String())
a.log.Infof("certificate ready to be send to AggLayer: %s", signedCertificate.String())

certificateHash, err := a.aggLayerClient.SendCertificate(signedCertificate)
if err != nil {
Expand Down Expand Up @@ -488,46 +488,49 @@ func (a *AggSender) signCertificate(certificate *agglayer.Certificate) (*agglaye
// and updates in the storage if it changed on agglayer
// It returns:
// bool -> if there are pending certificates
// error -> if there was an error
func (a *AggSender) checkPendingCertificatesStatus(ctx context.Context) (bool, error) {
func (a *AggSender) checkPendingCertificatesStatus(ctx context.Context) bool {
pendingCertificates, err := a.storage.GetCertificatesByStatus(nonSettledStatuses)
if err != nil {
err = fmt.Errorf("error getting pending certificates: %w", err)
a.log.Error(err)
return true, err
return true
}
thereArePendingCertificates := false
thereArePendingCerts := false
a.log.Debugf("checkPendingCertificatesStatus num of pendingCertificates: %d", len(pendingCertificates))
for _, certificate := range pendingCertificates {
certificateHeader, err := a.aggLayerClient.GetCertificateHeader(certificate.CertificateID)
if err != nil {
err = fmt.Errorf("error getting certificate header of %d/%s from agglayer: %w",
certificate.Height, certificate.String(), err)
a.log.Error(err)
return true, err
return true
}
if slices.Contains(nonSettledStatuses, certificateHeader.Status) {
thereArePendingCertificates = true
}
a.log.Debugf("aggLayerClient.GetCertificateHeader status [%s] of certificate %s ",
elapsedTime := time.Now().UTC().Sub(time.UnixMilli(certificate.CreatedAt))
a.log.Debugf("aggLayerClient.GetCertificateHeader status [%s] of certificate %s elapsed time:%s",
certificateHeader.Status,
certificateHeader.String())
certificateHeader.String(),
Dismissed Show dismissed Hide dismissed
elapsedTime)

if certificateHeader.Status != certificate.Status {
a.log.Infof("certificate %s changed status from [%s] to [%s]",
certificateHeader.String(), certificate.Status, certificateHeader.Status)
a.log.Infof("certificate %s changed status from [%s] to [%s] elapsed time: %s",
certificateHeader.String(), certificate.Status, certificateHeader.Status, elapsedTime)
Dismissed Show dismissed Hide dismissed

certificate.Status = certificateHeader.Status
certificate.UpdatedAt = time.Now().UTC().UnixMilli()

if err := a.storage.UpdateCertificateStatus(ctx, *certificate); err != nil {
err = fmt.Errorf("error updating certificate %s status in storage: %w", certificateHeader.String(), err)
a.log.Error(err)
return true, err
return true
}
}
if slices.Contains(nonSettledStatuses, certificateHeader.Status) {
a.log.Infof("certificate %s is still pending, elapsed time:%s ",
certificateHeader.String(), elapsedTime)
Dismissed Show dismissed Hide dismissed
thereArePendingCerts = true
}
}
return thereArePendingCertificates, nil
return thereArePendingCerts
}

// shouldSendCertificate checks if a certificate should be sent at given time
Expand Down
Loading
Loading