Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add TxStatus rpc endpoint 2 #1196

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 27 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 All @@ -60,6 +69,7 @@ func (txi *TxIndex) Get(hash []byte) (*abci.TxResult, error) {
return nil, fmt.Errorf("error reading TxResult: %v", err)
}

fmt.Println("txResult is nil", txResult.Tx == nil)
return txResult, nil
}

Expand Down Expand Up @@ -121,6 +131,12 @@ func (txi *TxIndex) Index(result *abci.TxResult) error {
return err
}

if txi.config != nil && 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 @@ -168,6 +184,13 @@ func (txi *TxIndex) indexEvents(result *abci.TxResult, hash []byte, store dbm.Ba
func (txi *TxIndex) indexResult(batch dbm.Batch, result *abci.TxResult) error {
hash := types.Tx(result.Tx).Hash()

if txi.config != nil && 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 +305,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 +404,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 +687,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 +713,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
Loading
Loading