Skip to content

Commit

Permalink
fix: bug first cert is InError, improved logs
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Nov 22, 2024
1 parent 98f0126 commit 4d82a4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions agglayer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func (c CertificateStatus) IsSettled() bool {
return c == Settled
}

// IsInError returns true if the certificate is in error
func (c CertificateStatus) IsInError() bool {
return c == InError
}

// IsOpen returns true if the certificate is open (pending, candidate or proven)
func (c CertificateStatus) IsOpen() bool {
return slices.Contains(NonSettledStatuses, c)
Expand Down
15 changes: 10 additions & 5 deletions aggsender/aggsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func New(

// Start starts the AggSender
func (a *AggSender) Start(ctx context.Context) {
a.log.Info("AggSender started")
a.checkInitialStatus(ctx)
a.sendCertificates(ctx)
}
Expand Down Expand Up @@ -280,15 +281,16 @@ func (a *AggSender) saveCertificateToFile(signedCertificate *agglayer.SignedCert
func (a *AggSender) getNextHeightAndPreviousLER(
lastSentCertificateInfo *types.CertificateInfo) (uint64, common.Hash) {
height := lastSentCertificateInfo.Height + 1
if lastSentCertificateInfo.Status == agglayer.InError {
if lastSentCertificateInfo.Status.IsInError() {
// previous certificate was in error, so we need to resend it
a.log.Debugf("Last certificate %s failed so reusing height %d",
lastSentCertificateInfo.CertificateID, lastSentCertificateInfo.Height)
height = lastSentCertificateInfo.Height
}

previousLER := lastSentCertificateInfo.NewLocalExitRoot
if lastSentCertificateInfo.NewLocalExitRoot == (common.Hash{}) {
if lastSentCertificateInfo.NewLocalExitRoot == (common.Hash{}) ||
lastSentCertificateInfo.Height == 0 && lastSentCertificateInfo.Status.IsInError() {
// meaning this is the first certificate
height = 0
previousLER = zeroLER
Expand Down Expand Up @@ -577,8 +579,9 @@ func (a *AggSender) updateCertificateStatus(ctx context.Context,
if localCert.Status == agglayerCert.Status {
return nil
}
a.log.Infof("certificate %s changed status from [%s] to [%s] elapsed time: %s",
localCert.ID(), localCert.Status, agglayerCert.Status, localCert.ElapsedTimeSinceCreation())
a.log.Infof("certificate %s changed status from [%s] to [%s] elapsed time: %s full_cert: %s",
localCert.ID(), localCert.Status, agglayerCert.Status, localCert.ElapsedTimeSinceCreation(),
localCert.String())

// That is a strange situation
if agglayerCert.Status.IsOpen() == localCert.Status.IsClosed() {
Expand Down Expand Up @@ -614,11 +617,13 @@ func (a *AggSender) checkLastCertificateFromAgglayer(ctx context.Context) error
if err != nil {
return fmt.Errorf("recovery: error getting latest known certificate header from agglayer: %w", err)
}

a.log.Infof("recovery: last certificate from AggLayer: %s", aggLayerLastCert.String())
localLastCert, err := a.storage.GetLastSentCertificate()
if err != nil {
return fmt.Errorf("recovery: error getting last sent certificate from local storage: %w", err)
}
a.log.Infof("recovery: last certificate in storage: %s", localLastCert.String())

// CASE 1: No certificates in local storage and agglayer
if localLastCert == nil && aggLayerLastCert == nil {
a.log.Info("recovery: No certificates in local storage and agglayer: initial state")
Expand Down

0 comments on commit 4d82a4d

Please sign in to comment.