-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from qubic/empty-ticks
Implement logic for calculating saving and exposing empty tick counts…
- Loading branch information
Showing
8 changed files
with
270 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package tick | ||
|
||
import ( | ||
"context" | ||
"github.com/pkg/errors" | ||
"github.com/qubic/go-archiver/protobuff" | ||
"github.com/qubic/go-archiver/store" | ||
"github.com/qubic/go-node-connector/types" | ||
) | ||
|
||
func CalculateEmptyTicksForEpoch(ctx context.Context, ps *store.PebbleStore, epoch uint32) (uint32, error) { | ||
|
||
epochs, err := ps.GetProcessedTickIntervals(ctx) | ||
if err != nil { | ||
return 0, errors.Wrap(err, "getting stored epochs") | ||
} | ||
|
||
for _, e := range epochs { | ||
if e.Epoch != epoch { | ||
continue | ||
} | ||
|
||
var emptyTicks uint32 | ||
|
||
for _, interval := range e.Intervals { | ||
for tickOffset := range interval.LastProcessedTick - interval.InitialProcessedTick + 1 { | ||
tickNumber := tickOffset + interval.InitialProcessedTick | ||
|
||
tickData, err := ps.GetTickData(ctx, tickNumber) | ||
if err != nil { | ||
return 0, errors.Wrapf(err, "getting tick data for tick %d", tickNumber) | ||
} | ||
|
||
if CheckIfTickIsEmptyProto(tickData) { | ||
emptyTicks += 1 | ||
continue | ||
} | ||
} | ||
} | ||
return emptyTicks, err | ||
} | ||
return 0, nil | ||
} | ||
|
||
func CheckIfTickIsEmptyProto(tickData *protobuff.TickData) bool { | ||
if tickData == nil { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
func CheckIfTickIsEmpty(tickData types.TickData) (bool, error) { | ||
data, err := qubicToProto(tickData) | ||
if err != nil { | ||
return false, errors.Wrap(err, "converting tick data to protobuf format") | ||
} | ||
|
||
return CheckIfTickIsEmptyProto(data), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters