Skip to content

Commit

Permalink
Configurable timeout for calculating historical empty ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
LINCKODE committed Jul 29, 2024
1 parent 84e0dba commit 1f2fbda
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func run() error {
ProcessTickTimeout time.Duration `conf:"default:5s"`
}
EmptyTicks struct {
CalculateAll bool `conf:"default:false"`
CalculateAll bool `conf:"default:false"`
Timeout time.Duration `conf:"default:30m"`
}
}

Expand Down Expand Up @@ -91,14 +92,15 @@ func run() error {

if cfg.EmptyTicks.CalculateAll == true {

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), cfg.EmptyTicks.Timeout)
defer cancel()
epochs, err := ps.GetLastProcessedTicksPerEpoch(ctx)
if err != nil {
return errors.Wrap(err, "getting epoch list from db")
}

for epoch, _ := range epochs {
fmt.Printf("Calculating empty ticks for epoch %d\n", epoch)
emptyTicksPerEpoch, err := tick.CalculateEmptyTicksForEpoch(ctx, ps, epoch)
if err != nil {
return errors.Wrapf(err, "calculating empty ticks for epoch %d", epoch)
Expand Down
2 changes: 2 additions & 0 deletions validator/tick/empty_tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tick

import (
"context"
"fmt"
"github.com/pkg/errors"
"github.com/qubic/go-archiver/protobuff"
"github.com/qubic/go-archiver/store"
Expand Down Expand Up @@ -32,6 +33,7 @@ func CalculateEmptyTicksForEpoch(ctx context.Context, ps *store.PebbleStore, epo
}

if CheckIfTickIsEmptyProto(tickData) {
fmt.Printf("Found empty tick.\n")
emptyTicks += 1
continue
}
Expand Down

0 comments on commit 1f2fbda

Please sign in to comment.