Skip to content

Commit

Permalink
logging added
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed Sep 25, 2024
1 parent 68dcabf commit 1fd1aa7
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 16 deletions.
3 changes: 2 additions & 1 deletion indexers/blockindexer/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package indexer
import (
"context"

"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/pubsub/query"
"github.com/tendermint/tendermint/types"
)
Expand All @@ -21,5 +22,5 @@ type BlockIndexer interface {
Search(ctx context.Context, q *query.Query) ([]int64, error)

// Delete indexed block entries up to (but not including) a height. It returns number of entries pruned.
Prune(from, to uint64) (uint64, error)
Prune(from, to uint64, logger log.Logger) (uint64, error)
}
17 changes: 13 additions & 4 deletions indexers/blockindexer/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strconv"
"strings"

"github.com/tendermint/tendermint/libs/log"

"github.com/dymensionxyz/gerr-cosmos/gerrc"
"github.com/google/orderedcode"

Expand Down Expand Up @@ -525,19 +527,19 @@ func (idx *BlockerIndexer) indexEvents(batch store.KVBatch, events []abci.Event,
return keys, nil
}

func (idx *BlockerIndexer) Prune(from, to uint64) (uint64, error) {
func (idx *BlockerIndexer) Prune(from, to uint64, logger log.Logger) (uint64, error) {
if from <= 0 {
return 0, fmt.Errorf("from height must be greater than 0: %w", gerrc.ErrInvalidArgument)
}

if to <= from {
return 0, fmt.Errorf("to height must be greater than from height: to: %d: from: %d: %w", to, from, gerrc.ErrInvalidArgument)
}
blocksPruned, err := idx.pruneBlocks(from, to)
blocksPruned, err := idx.pruneBlocks(from, to, logger)
return blocksPruned, err
}

func (idx *BlockerIndexer) pruneBlocks(from, to uint64) (uint64, error) {
func (idx *BlockerIndexer) pruneBlocks(from, to uint64, logger log.Logger) (uint64, error) {
pruned := uint64(0)
batch := idx.store.NewBatch()
defer batch.Discard()
Expand All @@ -552,17 +554,24 @@ func (idx *BlockerIndexer) pruneBlocks(from, to uint64) (uint64, error) {

for h := int64(from); h < int64(to); h++ {
ok, err := idx.Has(h)
if err != nil || !ok {
if err != nil {
logger.Debug("pruning block indexer checking height", "err", err)
continue
}
if !ok {
continue
}
key, err := heightKey(h)
if err != nil {
logger.Debug("pruning block indexer getting height key", "err", err)
continue
}
if err := batch.Delete(key); err != nil {
logger.Debug("pruning block indexer deleting height key", "err", err)
continue
}
if err := idx.pruneEvents(h, batch); err != nil {
logger.Debug("pruning block indexer events", "err", err)
continue
}
pruned++
Expand Down
3 changes: 2 additions & 1 deletion indexers/blockindexer/kv/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/pubsub/query"
"github.com/tendermint/tendermint/types"
"golang.org/x/exp/rand"
Expand Down Expand Up @@ -170,7 +171,7 @@ func TestBlockIndexerPruning(t *testing.T) {
require.Equal(t, numBlocks, uint64(len(results)))

// prune indexer for all heights
pruned, err := indexer.Prune(1, numBlocks+1)
pruned, err := indexer.Prune(1, numBlocks+1, log.NewNopLogger())
require.NoError(t, err)
require.Equal(t, numBlocks, pruned)

Expand Down
4 changes: 3 additions & 1 deletion indexers/blockindexer/null/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"

"github.com/tendermint/tendermint/libs/log"

indexer "github.com/dymensionxyz/dymint/indexers/blockindexer"
"github.com/tendermint/tendermint/libs/pubsub/query"
"github.com/tendermint/tendermint/types"
Expand All @@ -26,6 +28,6 @@ func (idx *BlockerIndexer) Search(ctx context.Context, q *query.Query) ([]int64,
return []int64{}, nil
}

func (idx *BlockerIndexer) Prune(from, to uint64) (uint64, error) {
func (idx *BlockerIndexer) Prune(from, to uint64, logger log.Logger) (uint64, error) {
return 0, nil
}
4 changes: 3 additions & 1 deletion indexers/txindex/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"

"github.com/tendermint/tendermint/libs/log"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/pubsub/query"
)
Expand All @@ -24,7 +26,7 @@ type TxIndexer interface {
Search(ctx context.Context, q *query.Query) ([]*abci.TxResult, error)

// Delete index entries for the heights between from (included) and to (not included). It returns heights pruned
Prune(from, to uint64) (uint64, error)
Prune(from, to uint64, logger log.Logger) (uint64, error)
}

// Batch groups together multiple Index operations to be performed at the same time.
Expand Down
4 changes: 2 additions & 2 deletions indexers/txindex/indexer_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func (is *IndexerService) OnStop() {

// Prune removes tx and blocks indexed up to (but not including) a height.
func (is *IndexerService) Prune(from, to uint64) error {
_, err := is.blockIdxr.Prune(from, to)
_, err := is.blockIdxr.Prune(from, to, is.Logger)
if err != nil {
return err
}
_, err = is.txIdxr.Prune(from, to)
_, err = is.txIdxr.Prune(from, to, is.Logger)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions indexers/txindex/indexer_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ func TestIndexerServiceIndexesBlocks(t *testing.T) {
require.NoError(t, err)
require.Equal(t, txResult2, res)

blocksPruned, err := blockIndexer.Prune(1, 2)
blocksPruned, err := blockIndexer.Prune(1, 2, log.NewNopLogger())
require.NoError(t, err)
expectedBlocksPruned := uint64(1)
require.Equal(t, expectedBlocksPruned, blocksPruned)

txPruned, err := txIndexer.Prune(1, 2)
txPruned, err := txIndexer.Prune(1, 2, log.NewNopLogger())
require.NoError(t, err)
expectedTxPruned := uint64(2)
require.Equal(t, expectedTxPruned, txPruned)
Expand Down
3 changes: 2 additions & 1 deletion indexers/txindex/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/gogo/protobuf/proto"
"github.com/tendermint/tendermint/libs/log"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/pubsub/query"
Expand Down Expand Up @@ -568,7 +569,7 @@ LOOP:
return filteredHashes
}

func (txi *TxIndex) Prune(from, to uint64) (uint64, error) {
func (txi *TxIndex) Prune(from, to uint64, logger log.Logger) (uint64, error) {
pruned, err := txi.pruneTxs(from, to)
if err != nil {
return 0, err
Expand Down
4 changes: 2 additions & 2 deletions indexers/txindex/kv/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"golang.org/x/exp/rand"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/pubsub/query"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -339,7 +340,7 @@ func TestTxIndexerPruning(t *testing.T) {
require.Equal(t, txsWithEvents, len(results))

// prune indexer for all heights
pruned, err := indexer.Prune(1, numBlocks+1)
pruned, err := indexer.Prune(1, numBlocks+1, log.NewNopLogger())
require.NoError(t, err)
require.Equal(t, uint64(numBlocks), pruned)

Expand Down Expand Up @@ -374,7 +375,6 @@ func txResultWithEvents(events []abci.Event) *abci.TxResult {
}
func getRandomTxResult(height int64, events []abci.Event) *abci.TxResult {
tx := types.Tx(randomTxHash())
fmt.Println(tx.Hash())
return &abci.TxResult{
Height: height,
Index: 0,
Expand Down
4 changes: 3 additions & 1 deletion indexers/txindex/null/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"

"github.com/tendermint/tendermint/libs/log"

"github.com/dymensionxyz/dymint/indexers/txindex"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/pubsub/query"
Expand Down Expand Up @@ -33,6 +35,6 @@ func (txi *TxIndex) Search(ctx context.Context, q *query.Query) ([]*abci.TxResul
return []*abci.TxResult{}, nil
}

func (txi *TxIndex) Prune(from, to uint64) (uint64, error) {
func (txi *TxIndex) Prune(from, to uint64, logger log.Logger) (uint64, error) {
return 0, nil
}

0 comments on commit 1fd1aa7

Please sign in to comment.