From db935d048b56d06d90c6d6c6499c8a18ef632872 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:24:00 +0100 Subject: [PATCH] feat: avoid log full certificate --- agglayer/types.go | 31 +++++++++---------------------- aggsender/aggsender.go | 8 ++++---- aggsender/types/types.go | 18 +++++++++--------- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/agglayer/types.go b/agglayer/types.go index c910beac8..9f8a8b597 100644 --- a/agglayer/types.go +++ b/agglayer/types.go @@ -112,27 +112,14 @@ type Certificate struct { Metadata common.Hash `json:"metadata"` } -func (c *Certificate) String() string { - res := fmt.Sprintf("NetworkID: %d, Height: %d, PrevLocalExitRoot: %s, NewLocalExitRoot: %s, Metadata: %s\n", - c.NetworkID, c.Height, common.Bytes2Hex(c.PrevLocalExitRoot[:]), - common.Bytes2Hex(c.NewLocalExitRoot[:]), common.Bytes2Hex(c.Metadata[:])) - - if c.BridgeExits == nil { - res += " BridgeExits: nil\n" - } else { - for i, bridgeExit := range c.BridgeExits { - res += fmt.Sprintf(", BridgeExit[%d]: %s\n", i, bridgeExit.String()) - } - } - - if c.ImportedBridgeExits == nil { - res += " ImportedBridgeExits: nil\n" - } else { - for i, importedBridgeExit := range c.ImportedBridgeExits { - res += fmt.Sprintf(" ImportedBridgeExit[%d]: %s\n", i, importedBridgeExit.String()) - } +// Brief returns a string with a brief cert +func (c *Certificate) Brief() string { + if c == nil { + return nilStr } - + res := fmt.Sprintf("agglayer.Cert {height: %d prevLER: %s newLER:%s exits:%d imported_exits:%d}", c.Height, + common.Bytes2Hex(c.PrevLocalExitRoot[:]), common.Bytes2Hex(c.NewLocalExitRoot[:]), + len(c.BridgeExits), len(c.ImportedBridgeExits)) return res } @@ -181,8 +168,8 @@ type SignedCertificate struct { Signature *Signature `json:"signature"` } -func (s *SignedCertificate) String() string { - return fmt.Sprintf("Certificate:%s,\nSignature: %s", s.Certificate.String(), s.Signature.String()) +func (s *SignedCertificate) Brief() string { + return fmt.Sprintf("Certificate:%s,\nSignature: %s", s.Certificate.Brief(), s.Signature.String()) } // CopyWithDefaulting returns a shallow copy of the signed certificate diff --git a/aggsender/aggsender.go b/aggsender/aggsender.go index 9856a3bf3..700425eb5 100644 --- a/aggsender/aggsender.go +++ b/aggsender/aggsender.go @@ -199,7 +199,7 @@ func (a *AggSender) sendCertificate(ctx context.Context) (*agglayer.SignedCertif } a.saveCertificateToFile(signedCertificate) - a.log.Infof("certificate ready to be send to AggLayer: %s", signedCertificate.String()) + a.log.Infof("certificate ready to be send to AggLayer: %s", signedCertificate.Brief()) certificateHash, err := a.aggLayerClient.SendCertificate(signedCertificate) if err != nil { return nil, fmt.Errorf("error sending certificate: %w", err) @@ -209,7 +209,7 @@ func (a *AggSender) sendCertificate(ctx context.Context) (*agglayer.SignedCertif raw, err := json.Marshal(signedCertificate) if err != nil { - return nil, fmt.Errorf("error marshalling signed certificate: %w", err) + return nil, fmt.Errorf("error marshalling signed certificate. Cert:%s. Err: %w", signedCertificate.Brief(), err) } createdTime := time.Now().UTC().UnixMilli() @@ -228,12 +228,12 @@ func (a *AggSender) sendCertificate(ctx context.Context) (*agglayer.SignedCertif // TODO: Improve this case, if a cert is not save in the storage, we are going to settle a unknown certificate err = a.saveCertificateToStorage(ctx, certInfo, a.cfg.MaxRetriesStoreCertificate) if err != nil { - a.log.Errorf("error saving certificate to storage: %w", err) + a.log.Errorf("error saving certificate to storage. Cert:%s Err: %w", certInfo.String(), err) return nil, fmt.Errorf("error saving last sent certificate %s in db: %w", certInfo.String(), err) } a.log.Infof("certificate: %s sent successfully for range of l2 blocks (from block: %d, to block: %d) cert:%s", - certificateHash, fromBlock, toBlock, signedCertificate.String()) + certificateHash, fromBlock, toBlock, signedCertificate.Brief()) return signedCertificate, nil } diff --git a/aggsender/types/types.go b/aggsender/types/types.go index 3199932b4..1c0d8353e 100644 --- a/aggsender/types/types.go +++ b/aggsender/types/types.go @@ -77,16 +77,16 @@ func (c *CertificateInfo) String() string { if c.PreviousLocalExitRoot != nil { previousLocalExitRoot = c.PreviousLocalExitRoot.String() } - return fmt.Sprintf( + return fmt.Sprintf("aggsender.CertificateInfo: "+ "Height: %d "+ - "CertificateID: %s "+ - "PreviousLocalExitRoot: %s "+ - "NewLocalExitRoot: %s "+ - "Status: %s "+ - "FromBlock: %d "+ - "ToBlock: %d "+ - "CreatedAt: %s "+ - "UpdatedAt: %s", + "CertificateID: %s "+ + "PreviousLocalExitRoot: %s "+ + "NewLocalExitRoot: %s "+ + "Status: %s "+ + "FromBlock: %d "+ + "ToBlock: %d "+ + "CreatedAt: %s "+ + "UpdatedAt: %s", c.Height, c.CertificateID.String(), previousLocalExitRoot,