You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

563 lines
14 KiB

abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
7 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
7 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
libs/pubsub: relax tx querying (#4070) Some linting/cleanup missed from the initial events refactor Don't panic; instead, return false, error when matching breaks unexpectedly Strip non-numeric chars from values when attempting to match against query values Have the server log during send upon error * cleanup/lint Query#Conditions and do not panic * cleanup/lint Query#Matches and do not panic * cleanup/lint matchValue and do not panic * rever to panic in Query#Conditions * linting * strip alpha chars when attempting to match * add pending log entries * Update libs/pubsub/query/query.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * build: update variable names * update matchValue to return an error * update Query#Matches to return an error * update TestMatches * log error in send * Fix tests * Fix TestEmptyQueryMatchesAnything * fix linting * Update libs/pubsub/query/query.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update libs/pubsub/query/query.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update libs/pubsub/query/query.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update libs/pubsub/query/query.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update libs/pubsub/query/query.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update libs/pubsub/pubsub.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * add missing errors pkg import * update Query#Conditions to return an error * update query pkg unit tests * update TxIndex#Search * update pending changelog
5 years ago
libs/pubsub: relax tx querying (#4070) Some linting/cleanup missed from the initial events refactor Don't panic; instead, return false, error when matching breaks unexpectedly Strip non-numeric chars from values when attempting to match against query values Have the server log during send upon error * cleanup/lint Query#Conditions and do not panic * cleanup/lint Query#Matches and do not panic * cleanup/lint matchValue and do not panic * rever to panic in Query#Conditions * linting * strip alpha chars when attempting to match * add pending log entries * Update libs/pubsub/query/query.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * build: update variable names * update matchValue to return an error * update Query#Matches to return an error * update TestMatches * log error in send * Fix tests * Fix TestEmptyQueryMatchesAnything * fix linting * Update libs/pubsub/query/query.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update libs/pubsub/query/query.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update libs/pubsub/query/query.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update libs/pubsub/query/query.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update libs/pubsub/query/query.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * Update libs/pubsub/pubsub.go Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * add missing errors pkg import * update Query#Conditions to return an error * update query pkg unit tests * update TxIndex#Search * update pending changelog
5 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
abci: Refactor tagging events using list of lists (#3643) ## PR This PR introduces a fundamental breaking change to the structure of ABCI response and tx tags and the way they're processed. Namely, the SDK can support more complex and aggregated events for distribution and slashing. In addition, block responses can include duplicate keys in events. Implement new Event type. An event has a type and a list of KV pairs (ie. list-of-lists). Typical events may look like: "rewards": [{"amount": "5000uatom", "validator": "...", "recipient": "..."}] "sender": [{"address": "...", "balance": "100uatom"}] The events are indexed by {even.type}.{even.attribute[i].key}/.... In this case a client would subscribe or query for rewards.recipient='...' ABCI response types and related types now include Events []Event instead of Tags []cmn.KVPair. PubSub logic now publishes/matches against map[string][]string instead of map[string]string to support duplicate keys in response events (from #1385). A match is successful if the value is found in the slice of strings. closes: #1859 closes: #2905 ## Commits: * Implement Event ABCI type and updates responses to use events * Update messages_test.go * Update kvstore.go * Update event_bus.go * Update subscription.go * Update pubsub.go * Update kvstore.go * Update query logic to handle slice of strings in events * Update Empty#Matches and unit tests * Update pubsub logic * Update EventBus#Publish * Update kv tx indexer * Update godocs * Update ResultEvent to use slice of strings; update RPC * Update more tests * Update abci.md * Check for key in validateAndStringifyEvents * Fix KV indexer to skip empty keys * Fix linting errors * Update CHANGELOG_PENDING.md * Update docs/spec/abci/abci.md Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update abci/types/types.proto Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update docs/spec/abci/abci.md Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update libs/pubsub/query/query.go Co-Authored-By: Ethan Buchman <ethan@coinculture.info> * Update match function to match if ANY value matches * Implement TestSubscribeDuplicateKeys * Update TestMatches to include multi-key test cases * Update events.go * Update Query interface godoc * Update match godoc * Add godoc for matchValue * DRY-up tx indexing * Return error from PublishWithEvents in EventBus#Publish * Update PublishEventNewBlockHeader to return an error * Fix build * Update events doc in ABCI * Update ABCI events godoc * Implement TestEventBusPublishEventTxDuplicateKeys * Update TestSubscribeDuplicateKeys to be table-driven * Remove mod file * Remove markdown from events godoc * Implement TestTxSearchDeprecatedIndexing test
6 years ago
  1. package kv
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/hex"
  6. "fmt"
  7. "strconv"
  8. "strings"
  9. "github.com/gogo/protobuf/proto"
  10. dbm "github.com/tendermint/tm-db"
  11. abci "github.com/tendermint/tendermint/abci/types"
  12. "github.com/tendermint/tendermint/libs/pubsub/query"
  13. "github.com/tendermint/tendermint/state/indexer"
  14. "github.com/tendermint/tendermint/state/txindex"
  15. "github.com/tendermint/tendermint/types"
  16. )
  17. const (
  18. tagKeySeparator = "/"
  19. )
  20. var _ txindex.TxIndexer = (*TxIndex)(nil)
  21. // TxIndex is the simplest possible indexer, backed by key-value storage (levelDB).
  22. type TxIndex struct {
  23. store dbm.DB
  24. }
  25. // NewTxIndex creates new KV indexer.
  26. func NewTxIndex(store dbm.DB) *TxIndex {
  27. return &TxIndex{
  28. store: store,
  29. }
  30. }
  31. // Get gets transaction from the TxIndex storage and returns it or nil if the
  32. // transaction is not found.
  33. func (txi *TxIndex) Get(hash []byte) (*abci.TxResult, error) {
  34. if len(hash) == 0 {
  35. return nil, txindex.ErrorEmptyHash
  36. }
  37. rawBytes, err := txi.store.Get(hash)
  38. if err != nil {
  39. panic(err)
  40. }
  41. if rawBytes == nil {
  42. return nil, nil
  43. }
  44. txResult := new(abci.TxResult)
  45. err = proto.Unmarshal(rawBytes, txResult)
  46. if err != nil {
  47. return nil, fmt.Errorf("error reading TxResult: %v", err)
  48. }
  49. return txResult, nil
  50. }
  51. // AddBatch indexes a batch of transactions using the given list of events. Each
  52. // key that indexed from the tx's events is a composite of the event type and
  53. // the respective attribute's key delimited by a "." (eg. "account.number").
  54. // Any event with an empty type is not indexed.
  55. func (txi *TxIndex) AddBatch(b *txindex.Batch) error {
  56. storeBatch := txi.store.NewBatch()
  57. defer storeBatch.Close()
  58. for _, result := range b.Ops {
  59. hash := types.Tx(result.Tx).Hash()
  60. // index tx by events
  61. err := txi.indexEvents(result, hash, storeBatch)
  62. if err != nil {
  63. return err
  64. }
  65. // index by height (always)
  66. err = storeBatch.Set(keyForHeight(result), hash)
  67. if err != nil {
  68. return err
  69. }
  70. rawBytes, err := proto.Marshal(result)
  71. if err != nil {
  72. return err
  73. }
  74. // index by hash (always)
  75. err = storeBatch.Set(hash, rawBytes)
  76. if err != nil {
  77. return err
  78. }
  79. }
  80. return storeBatch.WriteSync()
  81. }
  82. // Index indexes a single transaction using the given list of events. Each key
  83. // that indexed from the tx's events is a composite of the event type and the
  84. // respective attribute's key delimited by a "." (eg. "account.number").
  85. // Any event with an empty type is not indexed.
  86. func (txi *TxIndex) Index(result *abci.TxResult) error {
  87. b := txi.store.NewBatch()
  88. defer b.Close()
  89. hash := types.Tx(result.Tx).Hash()
  90. // index tx by events
  91. err := txi.indexEvents(result, hash, b)
  92. if err != nil {
  93. return err
  94. }
  95. // index by height (always)
  96. err = b.Set(keyForHeight(result), hash)
  97. if err != nil {
  98. return err
  99. }
  100. rawBytes, err := proto.Marshal(result)
  101. if err != nil {
  102. return err
  103. }
  104. // index by hash (always)
  105. err = b.Set(hash, rawBytes)
  106. if err != nil {
  107. return err
  108. }
  109. return b.WriteSync()
  110. }
  111. func (txi *TxIndex) indexEvents(result *abci.TxResult, hash []byte, store dbm.Batch) error {
  112. for _, event := range result.Result.Events {
  113. // only index events with a non-empty type
  114. if len(event.Type) == 0 {
  115. continue
  116. }
  117. for _, attr := range event.Attributes {
  118. if len(attr.Key) == 0 {
  119. continue
  120. }
  121. // index if `index: true` is set
  122. compositeTag := fmt.Sprintf("%s.%s", event.Type, string(attr.Key))
  123. if attr.GetIndex() {
  124. err := store.Set(keyForEvent(compositeTag, attr.Value, result), hash)
  125. if err != nil {
  126. return err
  127. }
  128. }
  129. }
  130. }
  131. return nil
  132. }
  133. // Search performs a search using the given query.
  134. //
  135. // It breaks the query into conditions (like "tx.height > 5"). For each
  136. // condition, it queries the DB index. One special use cases here: (1) if
  137. // "tx.hash" is found, it returns tx result for it (2) for range queries it is
  138. // better for the client to provide both lower and upper bounds, so we are not
  139. // performing a full scan. Results from querying indexes are then intersected
  140. // and returned to the caller, in no particular order.
  141. //
  142. // Search will exit early and return any result fetched so far,
  143. // when a message is received on the context chan.
  144. func (txi *TxIndex) Search(ctx context.Context, q *query.Query) ([]*abci.TxResult, error) {
  145. select {
  146. case <-ctx.Done():
  147. return make([]*abci.TxResult, 0), nil
  148. default:
  149. }
  150. var hashesInitialized bool
  151. filteredHashes := make(map[string][]byte)
  152. // get a list of conditions (like "tx.height > 5")
  153. conditions, err := q.Conditions()
  154. if err != nil {
  155. return nil, fmt.Errorf("error during parsing conditions from query: %w", err)
  156. }
  157. // if there is a hash condition, return the result immediately
  158. hash, ok, err := lookForHash(conditions)
  159. if err != nil {
  160. return nil, fmt.Errorf("error during searching for a hash in the query: %w", err)
  161. } else if ok {
  162. res, err := txi.Get(hash)
  163. switch {
  164. case err != nil:
  165. return []*abci.TxResult{}, fmt.Errorf("error while retrieving the result: %w", err)
  166. case res == nil:
  167. return []*abci.TxResult{}, nil
  168. default:
  169. return []*abci.TxResult{res}, nil
  170. }
  171. }
  172. // conditions to skip because they're handled before "everything else"
  173. skipIndexes := make([]int, 0)
  174. // extract ranges
  175. // if both upper and lower bounds exist, it's better to get them in order not
  176. // no iterate over kvs that are not within range.
  177. ranges, rangeIndexes := indexer.LookForRanges(conditions)
  178. if len(ranges) > 0 {
  179. skipIndexes = append(skipIndexes, rangeIndexes...)
  180. for _, qr := range ranges {
  181. if !hashesInitialized {
  182. filteredHashes = txi.matchRange(ctx, qr, startKey(qr.Key), filteredHashes, true)
  183. hashesInitialized = true
  184. // Ignore any remaining conditions if the first condition resulted
  185. // in no matches (assuming implicit AND operand).
  186. if len(filteredHashes) == 0 {
  187. break
  188. }
  189. } else {
  190. filteredHashes = txi.matchRange(ctx, qr, startKey(qr.Key), filteredHashes, false)
  191. }
  192. }
  193. }
  194. // if there is a height condition ("tx.height=3"), extract it
  195. height := lookForHeight(conditions)
  196. // for all other conditions
  197. for i, c := range conditions {
  198. if intInSlice(i, skipIndexes) {
  199. continue
  200. }
  201. if !hashesInitialized {
  202. filteredHashes = txi.match(ctx, c, startKeyForCondition(c, height), filteredHashes, true)
  203. hashesInitialized = true
  204. // Ignore any remaining conditions if the first condition resulted
  205. // in no matches (assuming implicit AND operand).
  206. if len(filteredHashes) == 0 {
  207. break
  208. }
  209. } else {
  210. filteredHashes = txi.match(ctx, c, startKeyForCondition(c, height), filteredHashes, false)
  211. }
  212. }
  213. results := make([]*abci.TxResult, 0, len(filteredHashes))
  214. for _, h := range filteredHashes {
  215. res, err := txi.Get(h)
  216. if err != nil {
  217. return nil, fmt.Errorf("failed to get Tx{%X}: %w", h, err)
  218. }
  219. results = append(results, res)
  220. // Potentially exit early.
  221. select {
  222. case <-ctx.Done():
  223. break
  224. default:
  225. }
  226. }
  227. return results, nil
  228. }
  229. func lookForHash(conditions []query.Condition) (hash []byte, ok bool, err error) {
  230. for _, c := range conditions {
  231. if c.CompositeKey == types.TxHashKey {
  232. decoded, err := hex.DecodeString(c.Operand.(string))
  233. return decoded, true, err
  234. }
  235. }
  236. return
  237. }
  238. // lookForHeight returns a height if there is an "height=X" condition.
  239. func lookForHeight(conditions []query.Condition) (height int64) {
  240. for _, c := range conditions {
  241. if c.CompositeKey == types.TxHeightKey && c.Op == query.OpEqual {
  242. return c.Operand.(int64)
  243. }
  244. }
  245. return 0
  246. }
  247. // match returns all matching txs by hash that meet a given condition and start
  248. // key. An already filtered result (filteredHashes) is provided such that any
  249. // non-intersecting matches are removed.
  250. //
  251. // NOTE: filteredHashes may be empty if no previous condition has matched.
  252. func (txi *TxIndex) match(
  253. ctx context.Context,
  254. c query.Condition,
  255. startKeyBz []byte,
  256. filteredHashes map[string][]byte,
  257. firstRun bool,
  258. ) map[string][]byte {
  259. // A previous match was attempted but resulted in no matches, so we return
  260. // no matches (assuming AND operand).
  261. if !firstRun && len(filteredHashes) == 0 {
  262. return filteredHashes
  263. }
  264. tmpHashes := make(map[string][]byte)
  265. switch {
  266. case c.Op == query.OpEqual:
  267. it, err := dbm.IteratePrefix(txi.store, startKeyBz)
  268. if err != nil {
  269. panic(err)
  270. }
  271. defer it.Close()
  272. for ; it.Valid(); it.Next() {
  273. tmpHashes[string(it.Value())] = it.Value()
  274. // Potentially exit early.
  275. select {
  276. case <-ctx.Done():
  277. break
  278. default:
  279. }
  280. }
  281. if err := it.Error(); err != nil {
  282. panic(err)
  283. }
  284. case c.Op == query.OpExists:
  285. // XXX: can't use startKeyBz here because c.Operand is nil
  286. // (e.g. "account.owner/<nil>/" won't match w/ a single row)
  287. it, err := dbm.IteratePrefix(txi.store, startKey(c.CompositeKey))
  288. if err != nil {
  289. panic(err)
  290. }
  291. defer it.Close()
  292. for ; it.Valid(); it.Next() {
  293. tmpHashes[string(it.Value())] = it.Value()
  294. // Potentially exit early.
  295. select {
  296. case <-ctx.Done():
  297. break
  298. default:
  299. }
  300. }
  301. if err := it.Error(); err != nil {
  302. panic(err)
  303. }
  304. case c.Op == query.OpContains:
  305. // XXX: startKey does not apply here.
  306. // For example, if startKey = "account.owner/an/" and search query = "account.owner CONTAINS an"
  307. // we can't iterate with prefix "account.owner/an/" because we might miss keys like "account.owner/Ulan/"
  308. it, err := dbm.IteratePrefix(txi.store, startKey(c.CompositeKey))
  309. if err != nil {
  310. panic(err)
  311. }
  312. defer it.Close()
  313. for ; it.Valid(); it.Next() {
  314. if !isTagKey(it.Key()) {
  315. continue
  316. }
  317. if strings.Contains(extractValueFromKey(it.Key()), c.Operand.(string)) {
  318. tmpHashes[string(it.Value())] = it.Value()
  319. }
  320. // Potentially exit early.
  321. select {
  322. case <-ctx.Done():
  323. break
  324. default:
  325. }
  326. }
  327. if err := it.Error(); err != nil {
  328. panic(err)
  329. }
  330. default:
  331. panic("other operators should be handled already")
  332. }
  333. if len(tmpHashes) == 0 || firstRun {
  334. // Either:
  335. //
  336. // 1. Regardless if a previous match was attempted, which may have had
  337. // results, but no match was found for the current condition, then we
  338. // return no matches (assuming AND operand).
  339. //
  340. // 2. A previous match was not attempted, so we return all results.
  341. return tmpHashes
  342. }
  343. // Remove/reduce matches in filteredHashes that were not found in this
  344. // match (tmpHashes).
  345. for k := range filteredHashes {
  346. if tmpHashes[k] == nil {
  347. delete(filteredHashes, k)
  348. // Potentially exit early.
  349. select {
  350. case <-ctx.Done():
  351. break
  352. default:
  353. }
  354. }
  355. }
  356. return filteredHashes
  357. }
  358. // matchRange returns all matching txs by hash that meet a given queryRange and
  359. // start key. An already filtered result (filteredHashes) is provided such that
  360. // any non-intersecting matches are removed.
  361. //
  362. // NOTE: filteredHashes may be empty if no previous condition has matched.
  363. func (txi *TxIndex) matchRange(
  364. ctx context.Context,
  365. qr indexer.QueryRange,
  366. startKey []byte,
  367. filteredHashes map[string][]byte,
  368. firstRun bool,
  369. ) map[string][]byte {
  370. // A previous match was attempted but resulted in no matches, so we return
  371. // no matches (assuming AND operand).
  372. if !firstRun && len(filteredHashes) == 0 {
  373. return filteredHashes
  374. }
  375. tmpHashes := make(map[string][]byte)
  376. lowerBound := qr.LowerBoundValue()
  377. upperBound := qr.UpperBoundValue()
  378. it, err := dbm.IteratePrefix(txi.store, startKey)
  379. if err != nil {
  380. panic(err)
  381. }
  382. defer it.Close()
  383. LOOP:
  384. for ; it.Valid(); it.Next() {
  385. if !isTagKey(it.Key()) {
  386. continue
  387. }
  388. if _, ok := qr.AnyBound().(int64); ok {
  389. v, err := strconv.ParseInt(extractValueFromKey(it.Key()), 10, 64)
  390. if err != nil {
  391. continue LOOP
  392. }
  393. include := true
  394. if lowerBound != nil && v < lowerBound.(int64) {
  395. include = false
  396. }
  397. if upperBound != nil && v > upperBound.(int64) {
  398. include = false
  399. }
  400. if include {
  401. tmpHashes[string(it.Value())] = it.Value()
  402. }
  403. // XXX: passing time in a ABCI Events is not yet implemented
  404. // case time.Time:
  405. // v := strconv.ParseInt(extractValueFromKey(it.Key()), 10, 64)
  406. // if v == r.upperBound {
  407. // break
  408. // }
  409. }
  410. // Potentially exit early.
  411. select {
  412. case <-ctx.Done():
  413. break
  414. default:
  415. }
  416. }
  417. if err := it.Error(); err != nil {
  418. panic(err)
  419. }
  420. if len(tmpHashes) == 0 || firstRun {
  421. // Either:
  422. //
  423. // 1. Regardless if a previous match was attempted, which may have had
  424. // results, but no match was found for the current condition, then we
  425. // return no matches (assuming AND operand).
  426. //
  427. // 2. A previous match was not attempted, so we return all results.
  428. return tmpHashes
  429. }
  430. // Remove/reduce matches in filteredHashes that were not found in this
  431. // match (tmpHashes).
  432. for k := range filteredHashes {
  433. if tmpHashes[k] == nil {
  434. delete(filteredHashes, k)
  435. // Potentially exit early.
  436. select {
  437. case <-ctx.Done():
  438. break
  439. default:
  440. }
  441. }
  442. }
  443. return filteredHashes
  444. }
  445. // Keys
  446. func isTagKey(key []byte) bool {
  447. return strings.Count(string(key), tagKeySeparator) == 3
  448. }
  449. func extractValueFromKey(key []byte) string {
  450. parts := strings.SplitN(string(key), tagKeySeparator, 3)
  451. return parts[1]
  452. }
  453. func keyForEvent(key string, value []byte, result *abci.TxResult) []byte {
  454. return []byte(fmt.Sprintf("%s/%s/%d/%d",
  455. key,
  456. value,
  457. result.Height,
  458. result.Index,
  459. ))
  460. }
  461. func keyForHeight(result *abci.TxResult) []byte {
  462. return []byte(fmt.Sprintf("%s/%d/%d/%d",
  463. types.TxHeightKey,
  464. result.Height,
  465. result.Height,
  466. result.Index,
  467. ))
  468. }
  469. func startKeyForCondition(c query.Condition, height int64) []byte {
  470. if height > 0 {
  471. return startKey(c.CompositeKey, c.Operand, height)
  472. }
  473. return startKey(c.CompositeKey, c.Operand)
  474. }
  475. func startKey(fields ...interface{}) []byte {
  476. var b bytes.Buffer
  477. for _, f := range fields {
  478. b.Write([]byte(fmt.Sprintf("%v", f) + tagKeySeparator))
  479. }
  480. return b.Bytes()
  481. }