Skip to content

Commit 7907447

Browse files
committed
moved safe tag calculation to tracker
1 parent 426d268 commit 7907447

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

chains/heads/tracker.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type ChainConfig interface {
5151
FinalityDepth() uint32
5252
SafeDepth() uint32
5353
FinalityTagEnabled() bool
54+
SafeTagEnabled() bool
5455
FinalizedBlockOffset() uint32
5556
}
5657

@@ -402,9 +403,19 @@ func (t *tracker[HTH, S, ID, BHASH]) backfillLoop(ctx context.Context) {
402403

403404
func (t *tracker[HTH, S, ID, BHASH]) LatestSafeBlock(ctx context.Context) (safe HTH, err error) {
404405
if t.config.FinalityTagEnabled() {
405-
latestSafe, err2 := t.client.LatestSafeBlock(ctx)
406-
if err2 != nil {
407-
return latestSafe, fmt.Errorf("failed to get latest finalized block: %w", err2)
406+
var latestSafe HTH
407+
if t.config.SafeTagEnabled() {
408+
latestSafe, err = t.client.LatestSafeBlock(ctx)
409+
if err != nil {
410+
return latestSafe, fmt.Errorf("failed to get latest finalized block: %w", err)
411+
}
412+
} else {
413+
// return latest finalized block if safe tag is not enabled
414+
_, finalized, err := t.LatestAndFinalizedBlock(ctx)
415+
if err != nil {
416+
return finalized, fmt.Errorf("failed to get latest finalized block: %w", err)
417+
}
418+
latestSafe = finalized
408419
}
409420

410421
if !latestSafe.IsValid() {

0 commit comments

Comments
 (0)