Skip to content

Commit 3d332ae

Browse files
committed
debug logs for advancing/receding
1 parent 20200cc commit 3d332ae

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
)
@@ -580,6 +581,14 @@ func (s *Store[H]) get(ctx context.Context, hash header.Hash) ([]byte, error) {
580581
// advanceHead moves contiguous Head forward if a newer one exists.
581582
// It looks throw caches, pending headers and datastore
582583
func (s *Store[H]) advanceHead(ctx context.Context) {
584+
if log.Level() == zapcore.DebugLevel {
585+
now := time.Now()
586+
log.Debug("advancing head")
587+
defer func() {
588+
log.Debugw("finished advancing head", "took(s)", time.Since(now))
589+
}()
590+
}
591+
583592
newHead, changed := s.nextHead(ctx)
584593
if changed {
585594
s.contiguousHead.Store(&newHead)
@@ -614,6 +623,15 @@ func (s *Store[H]) nextHead(ctx context.Context) (head H, changed bool) {
614623
if err != nil {
615624
return head, changed
616625
}
626+
627+
if !changed && log.Level() == zapcore.DebugLevel {
628+
now := time.Now()
629+
log.Debugw("advancing head", "start_height", head.Height())
630+
defer func() {
631+
log.Debugw("finished advancing head", "end_height", head.Height(), "took(s)", time.Since(now))
632+
}()
633+
}
634+
617635
head = h
618636
changed = true
619637
}
@@ -635,6 +653,15 @@ func (s *Store[H]) nextTail(ctx context.Context) (tail H, changed bool) {
635653
if err != nil {
636654
return tail, changed
637655
}
656+
657+
if !changed && log.Level() == zapcore.DebugLevel {
658+
now := time.Now()
659+
log.Debugw("receding tail", "start_height", tail.Height())
660+
defer func() {
661+
log.Debugw("finished receding tail", "end_height", tail.Height(), "took(s)", time.Since(now))
662+
}()
663+
}
664+
638665
tail = h
639666
changed = true
640667
}

0 commit comments

Comments
 (0)