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.

564 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
5 years ago
7 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
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
5 years ago
7 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
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
5 years ago
7 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
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
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
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
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
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
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
5 years ago
  1. package kv
  2. import (
  3. "bytes"
  4. "encoding/hex"
  5. "fmt"
  6. "sort"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "github.com/pkg/errors"
  11. dbm "github.com/tendermint/tm-db"
  12. cmn "github.com/tendermint/tendermint/libs/common"
  13. "github.com/tendermint/tendermint/libs/pubsub/query"
  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. tagsToIndex []string
  25. indexAllTags bool
  26. }
  27. // NewTxIndex creates new KV indexer.
  28. func NewTxIndex(store dbm.DB, options ...func(*TxIndex)) *TxIndex {
  29. txi := &TxIndex{store: store, tagsToIndex: make([]string, 0), indexAllTags: false}
  30. for _, o := range options {
  31. o(txi)
  32. }
  33. return txi
  34. }
  35. // IndexTags is an option for setting which tags to index.
  36. func IndexTags(tags []string) func(*TxIndex) {
  37. return func(txi *TxIndex) {
  38. txi.tagsToIndex = tags
  39. }
  40. }
  41. // IndexAllTags is an option for indexing all tags.
  42. func IndexAllTags() func(*TxIndex) {
  43. return func(txi *TxIndex) {
  44. txi.indexAllTags = true
  45. }
  46. }
  47. // Get gets transaction from the TxIndex storage and returns it or nil if the
  48. // transaction is not found.
  49. func (txi *TxIndex) Get(hash []byte) (*types.TxResult, error) {
  50. if len(hash) == 0 {
  51. return nil, txindex.ErrorEmptyHash
  52. }
  53. rawBytes := txi.store.Get(hash)
  54. if rawBytes == nil {
  55. return nil, nil
  56. }
  57. txResult := new(types.TxResult)
  58. err := cdc.UnmarshalBinaryBare(rawBytes, &txResult)
  59. if err != nil {
  60. return nil, fmt.Errorf("Error reading TxResult: %v", err)
  61. }
  62. return txResult, nil
  63. }
  64. // AddBatch indexes a batch of transactions using the given list of events. Each
  65. // key that indexed from the tx's events is a composite of the event type and
  66. // the respective attribute's key delimited by a "." (eg. "account.number").
  67. // Any event with an empty type is not indexed.
  68. func (txi *TxIndex) AddBatch(b *txindex.Batch) error {
  69. storeBatch := txi.store.NewBatch()
  70. defer storeBatch.Close()
  71. for _, result := range b.Ops {
  72. hash := result.Tx.Hash()
  73. // index tx by events
  74. txi.indexEvents(result, hash, storeBatch)
  75. // index tx by height
  76. if txi.indexAllTags || cmn.StringInSlice(types.TxHeightKey, txi.tagsToIndex) {
  77. storeBatch.Set(keyForHeight(result), hash)
  78. }
  79. // index tx by hash
  80. rawBytes, err := cdc.MarshalBinaryBare(result)
  81. if err != nil {
  82. return err
  83. }
  84. storeBatch.Set(hash, rawBytes)
  85. }
  86. storeBatch.Write()
  87. return nil
  88. }
  89. // Index indexes a single transaction using the given list of events. Each key
  90. // that indexed from the tx's events is a composite of the event type and the
  91. // respective attribute's key delimited by a "." (eg. "account.number").
  92. // Any event with an empty type is not indexed.
  93. func (txi *TxIndex) Index(result *types.TxResult) error {
  94. b := txi.store.NewBatch()
  95. defer b.Close()
  96. hash := result.Tx.Hash()
  97. // index tx by events
  98. txi.indexEvents(result, hash, b)
  99. // index tx by height
  100. if txi.indexAllTags || cmn.StringInSlice(types.TxHeightKey, txi.tagsToIndex) {
  101. b.Set(keyForHeight(result), hash)
  102. }
  103. // index tx by hash
  104. rawBytes, err := cdc.MarshalBinaryBare(result)
  105. if err != nil {
  106. return err
  107. }
  108. b.Set(hash, rawBytes)
  109. b.Write()
  110. return nil
  111. }
  112. func (txi *TxIndex) indexEvents(result *types.TxResult, hash []byte, store dbm.SetDeleter) {
  113. for _, event := range result.Result.Events {
  114. // only index events with a non-empty type
  115. if len(event.Type) == 0 {
  116. continue
  117. }
  118. for _, attr := range event.Attributes {
  119. if len(attr.Key) == 0 {
  120. continue
  121. }
  122. compositeTag := fmt.Sprintf("%s.%s", event.Type, string(attr.Key))
  123. if txi.indexAllTags || cmn.StringInSlice(compositeTag, txi.tagsToIndex) {
  124. store.Set(keyForEvent(compositeTag, attr.Value, result), hash)
  125. }
  126. }
  127. }
  128. }
  129. // Search performs a search using the given query. It breaks the query into
  130. // conditions (like "tx.height > 5"). For each condition, it queries the DB
  131. // index. One special use cases here: (1) if "tx.hash" is found, it returns tx
  132. // result for it (2) for range queries it is better for the client to provide
  133. // both lower and upper bounds, so we are not performing a full scan. Results
  134. // from querying indexes are then intersected and returned to the caller.
  135. func (txi *TxIndex) Search(q *query.Query) ([]*types.TxResult, error) {
  136. var hashesInitialized bool
  137. filteredHashes := make(map[string][]byte)
  138. // get a list of conditions (like "tx.height > 5")
  139. conditions, err := q.Conditions()
  140. if err != nil {
  141. return nil, errors.Wrap(err, "error during parsing conditions from query")
  142. }
  143. // if there is a hash condition, return the result immediately
  144. hash, err, ok := lookForHash(conditions)
  145. if err != nil {
  146. return nil, errors.Wrap(err, "error during searching for a hash in the query")
  147. } else if ok {
  148. res, err := txi.Get(hash)
  149. if res == nil {
  150. return []*types.TxResult{}, nil
  151. }
  152. return []*types.TxResult{res}, errors.Wrap(err, "error while retrieving the result")
  153. }
  154. // conditions to skip because they're handled before "everything else"
  155. skipIndexes := make([]int, 0)
  156. // extract ranges
  157. // if both upper and lower bounds exist, it's better to get them in order not
  158. // no iterate over kvs that are not within range.
  159. ranges, rangeIndexes := lookForRanges(conditions)
  160. if len(ranges) > 0 {
  161. skipIndexes = append(skipIndexes, rangeIndexes...)
  162. for _, r := range ranges {
  163. if !hashesInitialized {
  164. filteredHashes = txi.matchRange(r, startKey(r.key), filteredHashes, true)
  165. hashesInitialized = true
  166. // Ignore any remaining conditions if the first condition resulted
  167. // in no matches (assuming implicit AND operand).
  168. if len(filteredHashes) == 0 {
  169. break
  170. }
  171. } else {
  172. filteredHashes = txi.matchRange(r, startKey(r.key), filteredHashes, false)
  173. }
  174. }
  175. }
  176. // if there is a height condition ("tx.height=3"), extract it
  177. height := lookForHeight(conditions)
  178. // for all other conditions
  179. for i, c := range conditions {
  180. if cmn.IntInSlice(i, skipIndexes) {
  181. continue
  182. }
  183. if !hashesInitialized {
  184. filteredHashes = txi.match(c, startKeyForCondition(c, height), filteredHashes, true)
  185. hashesInitialized = true
  186. // Ignore any remaining conditions if the first condition resulted
  187. // in no matches (assuming implicit AND operand).
  188. if len(filteredHashes) == 0 {
  189. break
  190. }
  191. } else {
  192. filteredHashes = txi.match(c, startKeyForCondition(c, height), filteredHashes, false)
  193. }
  194. }
  195. results := make([]*types.TxResult, 0, len(filteredHashes))
  196. for _, h := range filteredHashes {
  197. res, err := txi.Get(h)
  198. if err != nil {
  199. return nil, errors.Wrapf(err, "failed to get Tx{%X}", h)
  200. }
  201. results = append(results, res)
  202. }
  203. // sort by height & index by default
  204. sort.Slice(results, func(i, j int) bool {
  205. if results[i].Height == results[j].Height {
  206. return results[i].Index < results[j].Index
  207. }
  208. return results[i].Height < results[j].Height
  209. })
  210. return results, nil
  211. }
  212. func lookForHash(conditions []query.Condition) (hash []byte, err error, ok bool) {
  213. for _, c := range conditions {
  214. if c.Tag == types.TxHashKey {
  215. decoded, err := hex.DecodeString(c.Operand.(string))
  216. return decoded, err, true
  217. }
  218. }
  219. return
  220. }
  221. // lookForHeight returns a height if there is an "height=X" condition.
  222. func lookForHeight(conditions []query.Condition) (height int64) {
  223. for _, c := range conditions {
  224. if c.Tag == types.TxHeightKey && c.Op == query.OpEqual {
  225. return c.Operand.(int64)
  226. }
  227. }
  228. return 0
  229. }
  230. // special map to hold range conditions
  231. // Example: account.number => queryRange{lowerBound: 1, upperBound: 5}
  232. type queryRanges map[string]queryRange
  233. type queryRange struct {
  234. lowerBound interface{} // int || time.Time
  235. upperBound interface{} // int || time.Time
  236. key string
  237. includeLowerBound bool
  238. includeUpperBound bool
  239. }
  240. func (r queryRange) lowerBoundValue() interface{} {
  241. if r.lowerBound == nil {
  242. return nil
  243. }
  244. if r.includeLowerBound {
  245. return r.lowerBound
  246. } else {
  247. switch t := r.lowerBound.(type) {
  248. case int64:
  249. return t + 1
  250. case time.Time:
  251. return t.Unix() + 1
  252. default:
  253. panic("not implemented")
  254. }
  255. }
  256. }
  257. func (r queryRange) AnyBound() interface{} {
  258. if r.lowerBound != nil {
  259. return r.lowerBound
  260. } else {
  261. return r.upperBound
  262. }
  263. }
  264. func (r queryRange) upperBoundValue() interface{} {
  265. if r.upperBound == nil {
  266. return nil
  267. }
  268. if r.includeUpperBound {
  269. return r.upperBound
  270. } else {
  271. switch t := r.upperBound.(type) {
  272. case int64:
  273. return t - 1
  274. case time.Time:
  275. return t.Unix() - 1
  276. default:
  277. panic("not implemented")
  278. }
  279. }
  280. }
  281. func lookForRanges(conditions []query.Condition) (ranges queryRanges, indexes []int) {
  282. ranges = make(queryRanges)
  283. for i, c := range conditions {
  284. if isRangeOperation(c.Op) {
  285. r, ok := ranges[c.Tag]
  286. if !ok {
  287. r = queryRange{key: c.Tag}
  288. }
  289. switch c.Op {
  290. case query.OpGreater:
  291. r.lowerBound = c.Operand
  292. case query.OpGreaterEqual:
  293. r.includeLowerBound = true
  294. r.lowerBound = c.Operand
  295. case query.OpLess:
  296. r.upperBound = c.Operand
  297. case query.OpLessEqual:
  298. r.includeUpperBound = true
  299. r.upperBound = c.Operand
  300. }
  301. ranges[c.Tag] = r
  302. indexes = append(indexes, i)
  303. }
  304. }
  305. return ranges, indexes
  306. }
  307. func isRangeOperation(op query.Operator) bool {
  308. switch op {
  309. case query.OpGreater, query.OpGreaterEqual, query.OpLess, query.OpLessEqual:
  310. return true
  311. default:
  312. return false
  313. }
  314. }
  315. // match returns all matching txs by hash that meet a given condition and start
  316. // key. An already filtered result (filteredHashes) is provided such that any
  317. // non-intersecting matches are removed.
  318. //
  319. // NOTE: filteredHashes may be empty if no previous condition has matched.
  320. func (txi *TxIndex) match(
  321. c query.Condition,
  322. startKeyBz []byte,
  323. filteredHashes map[string][]byte,
  324. firstRun bool,
  325. ) map[string][]byte {
  326. // A previous match was attempted but resulted in no matches, so we return
  327. // no matches (assuming AND operand).
  328. if !firstRun && len(filteredHashes) == 0 {
  329. return filteredHashes
  330. }
  331. tmpHashes := make(map[string][]byte)
  332. switch {
  333. case c.Op == query.OpEqual:
  334. it := dbm.IteratePrefix(txi.store, startKeyBz)
  335. defer it.Close()
  336. for ; it.Valid(); it.Next() {
  337. tmpHashes[string(it.Value())] = it.Value()
  338. }
  339. case c.Op == query.OpContains:
  340. // XXX: startKey does not apply here.
  341. // For example, if startKey = "account.owner/an/" and search query = "account.owner CONTAINS an"
  342. // we can't iterate with prefix "account.owner/an/" because we might miss keys like "account.owner/Ulan/"
  343. it := dbm.IteratePrefix(txi.store, startKey(c.Tag))
  344. defer it.Close()
  345. for ; it.Valid(); it.Next() {
  346. if !isTagKey(it.Key()) {
  347. continue
  348. }
  349. if strings.Contains(extractValueFromKey(it.Key()), c.Operand.(string)) {
  350. tmpHashes[string(it.Value())] = it.Value()
  351. }
  352. }
  353. default:
  354. panic("other operators should be handled already")
  355. }
  356. if len(tmpHashes) == 0 || firstRun {
  357. // Either:
  358. //
  359. // 1. Regardless if a previous match was attempted, which may have had
  360. // results, but no match was found for the current condition, then we
  361. // return no matches (assuming AND operand).
  362. //
  363. // 2. A previous match was not attempted, so we return all results.
  364. return tmpHashes
  365. }
  366. // Remove/reduce matches in filteredHashes that were not found in this
  367. // match (tmpHashes).
  368. for k := range filteredHashes {
  369. if tmpHashes[k] == nil {
  370. delete(filteredHashes, k)
  371. }
  372. }
  373. return filteredHashes
  374. }
  375. // matchRange returns all matching txs by hash that meet a given queryRange and
  376. // start key. An already filtered result (filteredHashes) is provided such that
  377. // any non-intersecting matches are removed.
  378. //
  379. // NOTE: filteredHashes may be empty if no previous condition has matched.
  380. func (txi *TxIndex) matchRange(
  381. r queryRange,
  382. startKey []byte,
  383. filteredHashes map[string][]byte,
  384. firstRun bool,
  385. ) map[string][]byte {
  386. // A previous match was attempted but resulted in no matches, so we return
  387. // no matches (assuming AND operand).
  388. if !firstRun && len(filteredHashes) == 0 {
  389. return filteredHashes
  390. }
  391. tmpHashes := make(map[string][]byte)
  392. lowerBound := r.lowerBoundValue()
  393. upperBound := r.upperBoundValue()
  394. it := dbm.IteratePrefix(txi.store, startKey)
  395. defer it.Close()
  396. LOOP:
  397. for ; it.Valid(); it.Next() {
  398. if !isTagKey(it.Key()) {
  399. continue
  400. }
  401. if _, ok := r.AnyBound().(int64); ok {
  402. v, err := strconv.ParseInt(extractValueFromKey(it.Key()), 10, 64)
  403. if err != nil {
  404. continue LOOP
  405. }
  406. include := true
  407. if lowerBound != nil && v < lowerBound.(int64) {
  408. include = false
  409. }
  410. if upperBound != nil && v > upperBound.(int64) {
  411. include = false
  412. }
  413. if include {
  414. tmpHashes[string(it.Value())] = it.Value()
  415. }
  416. // XXX: passing time in a ABCI Tags is not yet implemented
  417. // case time.Time:
  418. // v := strconv.ParseInt(extractValueFromKey(it.Key()), 10, 64)
  419. // if v == r.upperBound {
  420. // break
  421. // }
  422. }
  423. }
  424. if len(tmpHashes) == 0 || firstRun {
  425. // Either:
  426. //
  427. // 1. Regardless if a previous match was attempted, which may have had
  428. // results, but no match was found for the current condition, then we
  429. // return no matches (assuming AND operand).
  430. //
  431. // 2. A previous match was not attempted, so we return all results.
  432. return tmpHashes
  433. }
  434. // Remove/reduce matches in filteredHashes that were not found in this
  435. // match (tmpHashes).
  436. for k := range filteredHashes {
  437. if tmpHashes[k] == nil {
  438. delete(filteredHashes, k)
  439. }
  440. }
  441. return filteredHashes
  442. }
  443. ///////////////////////////////////////////////////////////////////////////////
  444. // Keys
  445. func isTagKey(key []byte) bool {
  446. return strings.Count(string(key), tagKeySeparator) == 3
  447. }
  448. func extractValueFromKey(key []byte) string {
  449. parts := strings.SplitN(string(key), tagKeySeparator, 3)
  450. return parts[1]
  451. }
  452. func keyForEvent(key string, value []byte, result *types.TxResult) []byte {
  453. return []byte(fmt.Sprintf("%s/%s/%d/%d",
  454. key,
  455. value,
  456. result.Height,
  457. result.Index,
  458. ))
  459. }
  460. func keyForHeight(result *types.TxResult) []byte {
  461. return []byte(fmt.Sprintf("%s/%d/%d/%d",
  462. types.TxHeightKey,
  463. result.Height,
  464. result.Height,
  465. result.Index,
  466. ))
  467. }
  468. func startKeyForCondition(c query.Condition, height int64) []byte {
  469. if height > 0 {
  470. return startKey(c.Tag, c.Operand, height)
  471. }
  472. return startKey(c.Tag, c.Operand)
  473. }
  474. func startKey(fields ...interface{}) []byte {
  475. var b bytes.Buffer
  476. for _, f := range fields {
  477. b.Write([]byte(fmt.Sprintf("%v", f) + tagKeySeparator))
  478. }
  479. return b.Bytes()
  480. }