Skip to content

Commit

Permalink
feat: avoid log full certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Nov 27, 2024
1 parent 144cfee commit db935d0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 35 deletions.
31 changes: 9 additions & 22 deletions agglayer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions aggsender/aggsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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
}
Expand Down
18 changes: 9 additions & 9 deletions aggsender/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit db935d0

Please sign in to comment.