8000 feat(libs/pubsub): allow dash symbol in event type/attribute by melekes · Pull Request #3456 · cometbft/cometbft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(libs/pubsub): allow dash symbol in event type/attribute #3456

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

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension
8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `[libs/pubsub]` Allow dash (`-`) in event tags
([\#3401](https://github.com/cometbft/cometbft/issues/3401))
38 changes: 28 additions & 10 deletions docs/guides/app-dev/indexing-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,40 @@ curl "localhost:26657/block_search?query=\"block.height > 10\""
```


Storing the event sequence was introduced in CometBFT 0.34.26. Before that, up until Tendermint Core 0.34.26,
the event sequence was not stored in the kvstore and events were stored only by height. That means that queries
returned blocks and transactions whose event attributes match within the height but can match across different
events on that height.
This behavior was fixed with CometBFT 0.34.26+. However, if the data was indexed with earlier versions of
Tendermint Core and not re-indexed, that data will be queried as if all the attributes within a height
occurred within the same event.
Storing the event sequence was introduced in CometBFT 0.34.26. Before that, up
until Tendermint Core 0.34.26, the event sequence was not stored in the kvstore
and events were stored only by height. That means that queries returned blocks
and transactions whose event attributes match within the height but can match
across different events on that height.

This behavior was fixed with CometBFT 0.34.26+. However, if the data was
indexed with earlier versions of Tendermint Core and not re-indexed, that data
will be queried as if all the attributes within a height occurred within the
same event.

## Event attribute value types

Users can use anything as an event value. However, if the event attribute value is a number, the following needs to be taken into account:
Users can use anything as an event value. However, if the event attribute value
is a number, the following needs to be taken into account:

- Negative numbers will not be properly retrieved when querying the indexer.
- Event values are converted to big floats (from the `big/math` package). The precision of the floating point number is set to the bit length
of the integer it is supposed to represent, so that there is no loss of information due to insufficient precision. This was not present before CometBFT v0.38.x and all float values were ignored.
- Event values are converted to big floats (from the `big/math` package). The
precision of the floating point number is set to the bit length of the
integer it is supposed to represent, so that there is no loss of information
due to insufficient precision. This was not present before CometBFT v0.38.x
and all float values were ignored.
- As of CometBFT v0.38.x, queries can contain floating point numbers as well.
- Note that comparing to floats can be imprecise with a high number of decimals.

## Event type and attribute key format

An event type/attribute key is a string that can contain any Unicode letter or
digit, as well as the following characters: `.` (dot), `-` (dash), `_`
(underscore). The event type/attribute key must not start with `-` (dash) or
`.` (dot).

```
^[\w]+[\.-\w]?$
```

[abci-events]: https://github.com/cometbft/cometbft/blob/main/spec/abci/abci++_basic_concepts.md#events
2 changes: 1 addition & 1 deletion libs/pubsub/query/syntax/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The lexical terms are defined here using RE2 regular expression notation:
//
// // The name of an event attribute (type.value)
// tag = #'\w+(\.\w+)*'
// tag = #`^[\w]+[\.-\w]?$`
//
// // A datestamp (YYYY-MM-DD)
// date = #'DATE \d{4}-\d{2}-\d{2}'
Expand Down
8 changes: 6 additions & 2 deletions libs/pubsub/query/syntax/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *Scanner) Next() error {
}
if '0' <= ch && ch <= '9' {
return s.scanNumber(ch)
} else if isTagRune(ch) {
} else if isFirstTagRune(ch) {
return s.scanTagLike(ch)
}
switch ch {
Expand Down Expand Up @@ -303,7 +303,11 @@ func (s *Scanner) invalid(ch rune) error {
func isDigit(r rune) bool { return '0' <= r && r <= '9' }

func isTagRune(r rune) bool {
return r == '.' || r == '_' || unicode.IsLetter(r) || unicode.IsDigit(r)
return r == '.' || r == '_' || r == '-' || unicode.IsLetter(r) || unicode.IsDigit(r)
}

func isFirstTagRune(r rune) bool {
return r == '_' || unicode.IsLetter(r) || unicode.IsDigit(r)
}

func isTimeRune(r rune) bool {
Expand Down
4 changes: 4 additions & 0 deletions libs/pubsub/query/syntax/syntax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func TestScanner(t *testing.T) {

// Tags
{`foo foo.bar`, []syntax.Token{syntax.TTag, syntax.TTag}},
{`foo foo-foo.bar`, []syntax.Token{syntax.TTag, syntax.TTag}},
{`foo foo._bar_bar`, []syntax.Token{syntax.TTag, syntax.TTag}},

// Strings (values)
{` '' x 'x' 'x y'`, []syntax.Token{syntax.TString, syntax.TTag, syntax.TString, syntax.TString}},
Expand Down Expand Up @@ -167,6 +169,8 @@ func TestParseValid(t *testing.T) {

{"hash='136E18F7E4C348B780CF873A0BF43922E5BAFA63'", true},
{"hash=136E18F7E4C348B780CF873A0BF43922E5BAFA63", false},

{"cosm-wasm.transfer_amount=100", true},
}

for _, test := range tests {
Expand Down
Loading
0