Skip to content

Commit 0c9c651

Browse files
committed
debug logs for advancing/receding
1 parent 64c84c4 commit 0c9c651

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

store/store.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/ipfs/go-datastore"
1313
"github.com/ipfs/go-datastore/namespace"
1414
logging "github.com/ipfs/go-log/v2"
15+
"go.uber.org/zap/zapcore"
1516

1617
"github.com/celestiaorg/go-header"
1718
)
@@ -583,6 +584,14 @@ func (s *Store[H]) get(ctx context.Context, hash header.Hash) ([]byte, error) {
583584
// advanceHead moves contiguous Head forward if a newer one exists.
584585
// It looks throw caches, pending headers and datastore
585586
func (s *Store[H]) advanceHead(ctx context.Context) {
587+
if log.Level() == zapcore.DebugLevel {
588+
now := time.Now()
589+
log.Debug("advancing head")
590+
defer func() {
591+
log.Debugw("finished advancing head", "took(s)", time.Since(now))
592+
}()
593+
}
594+
586595
newHead, changed := s.nextHead(ctx)
587596
if changed {
588597
s.contiguousHead.Store(&newHead)
@@ -617,6 +626,15 @@ func (s *Store[H]) nextHead(ctx context.Context) (head H, changed bool) {
617626
if err != nil {
618627
return head, changed
619628
}
629+
630+
if !changed && log.Level() == zapcore.DebugLevel {
631+
now := time.Now()
632+
log.Debugw("advancing head", "start_height", head.Height())
633+
defer func() {
634+
log.Debugw("finished advancing head", "end_height", head.Height(), "took(s)", time.Since(now))
635+
}()
636+
}
637+
620638
head = h
621639
changed = true
622640
}
@@ -638,6 +656,15 @@ func (s *Store[H]) nextTail(ctx context.Context) (tail H, changed bool) {
638656
if err != nil {
639657
return tail, changed
640658
}
659+
660+
if !changed && log.Level() == zapcore.DebugLevel {
661+
now := time.Now()
662+
log.Debugw("receding tail", "start_height", tail.Height())
663+
defer func() {
664+
log.Debugw("finished receding tail", "end_height", tail.Height(), "took(s)", time.Since(now))
665+
}()
666+
}
667+
641668
tail = h
642669
changed = true
643670
}

0 commit comments

Comments
 (0)