Skip to content

Commit 417e2fc

Browse files
committed
proof: enhance backoff procedure locator logging
1 parent 730bc75 commit 417e2fc

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

proof/archive.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,34 @@ func (l *Locator) Hash() ([32]byte, error) {
119119
}
120120
}
121121

122-
// Hash the buffer.
123122
return sha256.Sum256(buf.Bytes()), nil
124123
}
125124

125+
// LogString returns a human-readable representation of the locator. This is
126+
// primarily used for logging purposes.
127+
func (l *Locator) LogString() (string, error) {
128+
var zero string
129+
130+
assetSpec, err := asset.NewSpecifier(l.AssetID, l.GroupKey, nil, true)
131+
if err != nil {
132+
return zero, fmt.Errorf("unable to create asset specifier: %w",
133+
err)
134+
}
135+
136+
var outpointStr string
137+
if l.OutPoint != nil {
138+
outpointStr = l.OutPoint.String()
139+
}
140+
141+
locatorHash, err := l.Hash()
142+
if err != nil {
143+
return zero, fmt.Errorf("hashing locator: %w", err)
144+
}
145+
146+
return fmt.Sprintf("Locator(asset_spec=%s, outpoint=%s, hash=%x)",
147+
assetSpec.String(), outpointStr, locatorHash), nil
148+
}
149+
126150
// AnnotatedProof an annotated proof contains the raw proof blob along with a
127151
// locator that may convey additional information related to the proof.
128152
type AnnotatedProof struct {

proof/courier.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"crypto/sha512"
77
"crypto/tls"
8-
"encoding/hex"
98
"fmt"
109
"net/url"
1110
"sync"
@@ -615,12 +614,12 @@ func (b *BackoffHandler) initialDelay(ctx context.Context,
615614
return nil
616615
}
617616

618-
locatorHash, err := proofLocator.Hash()
617+
locatorStr, err := proofLocator.LogString()
619618
if err != nil {
620619
return err
621620
}
622-
log.Debugf("Handling initial proof transfer delay (locator_hash=%x)",
623-
locatorHash[:])
621+
log.DebugS(ctx, "Handling initial proof transfer delay", "locator",
622+
locatorStr)
624623

625624
// Query delivery log to ensure a sensible rate of delivery attempts.
626625
timestamps, err := b.transferLog.QueryProofTransferLog(
@@ -632,8 +631,8 @@ func (b *BackoffHandler) initialDelay(ctx context.Context,
632631
}
633632

634633
if len(timestamps) == 0 {
635-
log.Debugf("No previous transfer attempts found for proof "+
636-
"(locator_hash=%x)", locatorHash[:])
634+
log.DebugS(ctx, "No previous transfer attempts found for proof",
635+
"locator", locatorStr)
637636
return nil
638637
}
639638

@@ -650,9 +649,9 @@ func (b *BackoffHandler) initialDelay(ctx context.Context,
650649
backoffResetWait := b.cfg.BackoffResetWait
651650
if timeSinceLastAttempt < backoffResetWait {
652651
waitDuration := backoffResetWait - timeSinceLastAttempt
653-
log.Debugf("Waiting %v before attempting to transfer proof "+
654-
"(locator_hash=%x) using backoff procedure",
655-
waitDuration, locatorHash[:])
652+
log.DebugS(ctx, "Backoff: waiting before attempting to "+
653+
"transfer proof", "wait_duration", waitDuration,
654+
"locator", locatorStr)
656655

657656
err := b.wait(ctx, waitDuration)
658657
if err != nil {
@@ -674,13 +673,13 @@ func (b *BackoffHandler) Exec(ctx context.Context, proofLocator Locator,
674673
return fmt.Errorf("backoff config not specified")
675674
}
676675

677-
locatorHash, err := proofLocator.Hash()
676+
locatorStr, err := proofLocator.LogString()
678677
if err != nil {
679-
return err
678+
return fmt.Errorf("generate locator log string: %w", err)
680679
}
680+
681681
log.InfoS(ctx, "Starting proof transfer backoff procedure",
682-
"transfer_type", transferType, "locator_hash",
683-
hex.EncodeToString(locatorHash[:]))
682+
"transfer_type", transferType, "locator", locatorStr)
684683

685684
// Conditionally perform an initial delay based on the transfer log to
686685
// ensure that we don't spam the courier service with proof transfer
@@ -735,9 +734,9 @@ func (b *BackoffHandler) Exec(ctx context.Context, proofLocator Locator,
735734
subscriberEvent(waitEvent)
736735

737736
log.DebugS(ctx, "Backing off: proof transfer failed",
738-
"transfer_type", transferType, "locator_hash",
739-
hex.EncodeToString(locatorHash[:]), "backoff", backoff,
740-
"attempt", i, "err", errExec)
737+
"transfer_type", transferType, "locator",
738+
locatorStr, "backoff", backoff, "attempt", i, "err",
739+
errExec)
741740

742741
// Wait before reattempting execution.
743742
err := b.wait(ctx, backoff)

0 commit comments

Comments
 (0)