Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze committed Jan 30, 2024
1 parent 07c167e commit 678f324
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
9 changes: 8 additions & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ func createAndStartIndexerService(
txIndexer = kv.NewTxIndex(store)
blockIndexer = blockidxkv.New(dbm.NewPrefixDB(store, []byte("block_events")))

case "kv_lite":
store, err := dbProvider(&DBContext{"tx_index", config})
if err != nil {
return nil, nil, nil, err
}
txIndexer = kv.NewTxIndexWithConfig(store, config)
blockIndexer = blockidxkv.New(dbm.NewPrefixDB(store, []byte("block_events")))

case "psql":
if config.TxIndex.PsqlConn == "" {
return nil, nil, nil, errors.New(`no psql-conn is set for the "psql" indexer`)
Expand Down Expand Up @@ -1162,7 +1170,6 @@ func (n *Node) OnStop() {
n.Logger.Error("Pyroscope tracer Shutdown", "err", err)
}
}

}

// ConfigureRPC makes sure RPC has all the objects it needs to operate.
Expand Down
20 changes: 19 additions & 1 deletion state/txindex/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gogo/protobuf/proto"

abci "github.com/cometbft/cometbft/abci/types"
cfg "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/libs/pubsub/query"
"github.com/cometbft/cometbft/state/indexer"
"github.com/cometbft/cometbft/state/txindex"
Expand All @@ -29,6 +30,7 @@ var _ txindex.TxIndexer = (*TxIndex)(nil)
type TxIndex struct {
store dbm.DB
// Number the events in the event list
config *cfg.Config
eventSeq int64
}

Expand All @@ -39,6 +41,13 @@ func NewTxIndex(store dbm.DB) *TxIndex {
}
}

func NewTxIndexWithConfig(store dbm.DB, config *cfg.Config) *TxIndex {
return &TxIndex{
store: store,
config: config,
}
}

// Get gets transaction from the TxIndex storage and returns it or nil if the
// transaction is not found.
func (txi *TxIndex) Get(hash []byte) (*abci.TxResult, error) {
Expand Down Expand Up @@ -121,6 +130,12 @@ func (txi *TxIndex) Index(result *abci.TxResult) error {
return err
}

if txi.config.TxIndex.Indexer == "kv-lite" {
// set the transaction bytes to empty
// this is to avoid the transaction bytes being set
// in the kv_lite indexer
result.Tx = []byte{}
}
rawBytes, err := proto.Marshal(result)
if err != nil {
return err
Expand Down Expand Up @@ -282,7 +297,7 @@ func (txi *TxIndex) Search(ctx context.Context, q *query.Query) ([]*abci.TxResul
// extract ranges
// if both upper and lower bounds exist, it's better to get them in order not
// no iterate over kvs that are not within range.
//If we have a query range over height and want to still look for
// If we have a query range over height and want to still look for
// specific event values we do not want to simply return all
// transactios in this height range. We remember the height range info
// and pass it on to match() to take into account when processing events.
Expand Down Expand Up @@ -381,6 +396,7 @@ func lookForHeight(conditions []query.Condition) (height int64, heightIdx int) {
}
return 0, -1
}

func (txi *TxIndex) setTmpHashes(tmpHeights map[string][]byte, it dbm.Iterator, matchEvents bool) {
if matchEvents {
eventSeq := extractEventSeqFromKey(it.Key())
Expand Down Expand Up @@ -663,6 +679,7 @@ func extractHeightFromKey(key []byte) (int64, error) {
parts := strings.SplitN(string(key), tagKeySeparator, -1)
return strconv.ParseInt(parts[len(parts)-2], 10, 64)
}

func extractValueFromKey(key []byte) string {
keyString := string(key)
parts := strings.SplitN(keyString, tagKeySeparator, -1)
Expand All @@ -688,6 +705,7 @@ func extractEventSeqFromKey(key []byte) string {
}
return "0"
}

func keyForEvent(key string, value string, result *abci.TxResult, eventSeq int64) []byte {
return []byte(fmt.Sprintf("%s/%s/%d/%d%s",
key,
Expand Down

0 comments on commit 678f324

Please sign in to comment.