Skip to content

Commit

Permalink
Merge pull request #49 from qubic/dev
Browse files Browse the repository at this point in the history
Add flag to reset empty tick keys
  • Loading branch information
LINCKODE authored Aug 6, 2024
2 parents 9ab07c0 + 0723912 commit debf2db
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 216 deletions.
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
.idea/
.DS_Store
.DS_Store

# Exclude store files
store/*.sst
store/CURRENT
store/LOCK
store/MANIFEST-*
store/OPTIONS-*
store/*.log

go-archiver
*.swagger.json
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func run() error {
StorageFolder string `conf:"default:store"`
ProcessTickTimeout time.Duration `conf:"default:5s"`
}
Store struct {
ResetEmptyTickKeys bool `conf:"default:false"`
}
}

if err := conf.Parse(os.Args[1:], prefix, &cfg); err != nil {
Expand Down Expand Up @@ -85,6 +88,14 @@ func run() error {

ps := store.NewPebbleStore(db, nil)

if cfg.Store.ResetEmptyTickKeys {
fmt.Printf("Resetting empty ticks for all epochs...\n")
err = tick.ResetEmptyTicksForAllEpochs(ps)
if err != nil {
return errors.Wrap(err, "resetting empty ticks keys")
}
}

err = tick.CalculateEmptyTicksForAllEpochs(ps)
if err != nil {
return errors.Wrap(err, "calculating empty ticks for all epochs")
Expand Down
434 changes: 222 additions & 212 deletions protobuff/archive.pb.go

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions protobuff/archive.proto
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ message GetTransferTransactionsPerTickRequestV2 {
string identity = 1;
uint32 start_tick = 2;
uint32 end_tick = 3;
bool sc_only=4;
bool sc_only = 4;
bool desc = 5;
}


Expand Down Expand Up @@ -444,4 +445,4 @@ service ArchiveService {
get: "/v1/healthcheck"
};
};
}
}
11 changes: 11 additions & 0 deletions rpc/v2_endpoints.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package rpc

import (
"cmp"
"context"
"encoding/hex"
"slices"

"github.com/pkg/errors"
"github.com/qubic/go-archiver/protobuff"
"github.com/qubic/go-archiver/store"
Expand Down Expand Up @@ -364,6 +367,14 @@ func (s *Server) GetIdentityTransfersInTickRangeV2(ctx context.Context, req *pro
totalTransactions = append(totalTransactions, transfers)
}

if req.Desc == true {

slices.SortFunc(totalTransactions, func(a, b *protobuff.PerTickIdentityTransfers) int {
return -cmp.Compare(a.TickNumber, b.TickNumber)
})

}

return &protobuff.GetIdentityTransfersInTickRangeResponseV2{
Transactions: totalTransactions,
}, nil
Expand Down
10 changes: 10 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,3 +708,13 @@ func (s *PebbleStore) GetEmptyTicksForEpochs(epochs []uint32) (map[uint32]uint32
return emptyTickMap, nil

}

func (s *PebbleStore) DeleteEmptyTicksKeyForEpoch(epoch uint32) error {
key := emptyTicksPerEpochKey(epoch)

err := s.db.Delete(key, pebble.Sync)
if err != nil {
return errors.Wrapf(err, "deleting empty ticks key for epoch %d", epoch)
}
return nil
}
22 changes: 21 additions & 1 deletion validator/tick/empty_tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func CheckIfTickIsEmpty(tickData types.TickData) (bool, error) {

func CalculateEmptyTicksForAllEpochs(ps *store.PebbleStore) error {

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()

epochs, err := ps.GetLastProcessedTicksPerEpoch(ctx)
Expand Down Expand Up @@ -102,3 +102,23 @@ func CalculateEmptyTicksForAllEpochs(ps *store.PebbleStore) error {
}
return nil
}

func ResetEmptyTicksForAllEpochs(ps *store.PebbleStore) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
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("Reseting empty ticks for epoch: %d\n", epoch)
err := ps.DeleteEmptyTicksKeyForEpoch(epoch)
if err != nil {
return errors.Wrap(err, "deleting empty tick key")
}
}

return nil
}

0 comments on commit debf2db

Please sign in to comment.