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.

568 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
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
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
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
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
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
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
  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.WriteSync()
  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.WriteSync()
  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. switch {
  150. case err != nil:
  151. return []*types.TxResult{}, errors.Wrap(err, "error while retrieving the result")
  152. case res == nil:
  153. return []*types.TxResult{}, nil
  154. default:
  155. return []*types.TxResult{res}, nil
  156. }
  157. }
  158. // conditions to skip because they're handled before "everything else"
  159. skipIndexes := make([]int, 0)
  160. // extract ranges
  161. // if both upper and lower bounds exist, it's better to get them in order not
  162. // no iterate over kvs that are not within range.
  163. ranges, rangeIndexes := lookForRanges(conditions)
  164. if len(ranges) > 0 {
  165. skipIndexes = append(skipIndexes, rangeIndexes...)
  166. for _, r := range ranges {
  167. if !hashesInitialized {
  168. filteredHashes = txi.matchRange(r, startKey(r.key), filteredHashes, true)
  169. hashesInitialized = true
  170. // Ignore any remaining conditions if the first condition resulted
  171. // in no matches (assuming implicit AND operand).
  172. if len(filteredHashes) == 0 {
  173. break
  174. }
  175. } else {
  176. filteredHashes = txi.matchRange(r, startKey(r.key), filteredHashes, false)
  177. }
  178. }
  179. }
  180. // if there is a height condition ("tx.height=3"), extract it
  181. height := lookForHeight(conditions)
  182. // for all other conditions
  183. for i, c := range conditions {
  184. if cmn.IntInSlice(i, skipIndexes) {
  185. continue
  186. }
  187. if !hashesInitialized {
  188. filteredHashes = txi.match(c, startKeyForCondition(c, height), filteredHashes, true)
  189. hashesInitialized = true
  190. // Ignore any remaining conditions if the first condition resulted
  191. // in no matches (assuming implicit AND operand).
  192. if len(filteredHashes) == 0 {
  193. break
  194. }
  195. } else {
  196. filteredHashes = txi.match(c, startKeyForCondition(c, height), filteredHashes, false)
  197. }
  198. }
  199. results := make([]*types.TxResult, 0, len(filteredHashes))
  200. for _, h := range filteredHashes {
  201. res, err := txi.Get(h)
  202. if err != nil {
  203. return nil, errors.Wrapf(err, "failed to get Tx{%X}", h)
  204. }
  205. results = append(results, res)
  206. }
  207. // sort by height & index by default
  208. sort.Slice(results, func(i, j int) bool {
  209. if results[i].Height == results[j].Height {
  210. return results[i].Index < results[j].Index
  211. }
  212. return results[i].Height < results[j].Height
  213. })
  214. return results, nil
  215. }
  216. func lookForHash(conditions []query.Condition) (hash []byte, err error, ok bool) {
  217. for _, c := range conditions {
  218. if c.Tag == types.TxHashKey {
  219. decoded, err := hex.DecodeString(c.Operand.(string))
  220. return decoded, err, true
  221. }
  222. }
  223. return
  224. }
  225. // lookForHeight returns a height if there is an "height=X" condition.
  226. func lookForHeight(conditions []query.Condition) (height int64) {
  227. for _, c := range conditions {
  228. if c.Tag == types.TxHeightKey && c.Op == query.OpEqual {
  229. return c.Operand.(int64)
  230. }
  231. }
  232. return 0
  233. }
  234. // special map to hold range conditions
  235. // Example: account.number => queryRange{lowerBound: 1, upperBound: 5}
  236. type queryRanges map[string]queryRange
  237. type queryRange struct {
  238. lowerBound interface{} // int || time.Time
  239. upperBound interface{} // int || time.Time
  240. key string
  241. includeLowerBound bool
  242. includeUpperBound bool
  243. }
  244. func (r queryRange) lowerBoundValue() interface{} {
  245. if r.lowerBound == nil {
  246. return nil
  247. }
  248. if r.includeLowerBound {
  249. return r.lowerBound
  250. } else {
  251. switch t := r.lowerBound.(type) {
  252. case int64:
  253. return t + 1
  254. case time.Time:
  255. return t.Unix() + 1
  256. default:
  257. panic("not implemented")
  258. }
  259. }
  260. }
  261. func (r queryRange) AnyBound() interface{} {
  262. if r.lowerBound != nil {
  263. return r.lowerBound
  264. } else {
  265. return r.upperBound
  266. }
  267. }
  268. func (r queryRange) upperBoundValue() interface{} {
  269. if r.upperBound == nil {
  270. return nil
  271. }
  272. if r.includeUpperBound {
  273. return r.upperBound
  274. } else {
  275. switch t := r.upperBound.(type) {
  276. case int64:
  277. return t - 1
  278. case time.Time:
  279. return t.Unix() - 1
  280. default:
  281. panic("not implemented")
  282. }
  283. }
  284. }
  285. func lookForRanges(conditions []query.Condition) (ranges queryRanges, indexes []int) {
  286. ranges = make(queryRanges)
  287. for i, c := range conditions {
  288. if isRangeOperation(c.Op) {
  289. r, ok := ranges[c.Tag]
  290. if !ok {
  291. r = queryRange{key: c.Tag}
  292. }
  293. switch c.Op {
  294. case query.OpGreater:
  295. r.lowerBound = c.Operand
  296. case query.OpGreaterEqual:
  297. r.includeLowerBound = true
  298. r.lowerBound = c.Operand
  299. case query.OpLess:
  300. r.upperBound = c.Operand
  301. case query.OpLessEqual:
  302. r.includeUpperBound = true
  303. r.upperBound = c.Operand
  304. }
  305. ranges[c.Tag] = r
  306. indexes = append(indexes, i)
  307. }
  308. }
  309. return ranges, indexes
  310. }
  311. func isRangeOperation(op query.Operator) bool {
  312. switch op {
  313. case query.OpGreater, query.OpGreaterEqual, query.OpLess, query.OpLessEqual:
  314. return true
  315. default:
  316. return false
  317. }
  318. }
  319. // match returns all matching txs by hash that meet a given condition and start
  320. // key. An already filtered result (filteredHashes) is provided such that any
  321. // non-intersecting matches are removed.
  322. //
  323. // NOTE: filteredHashes may be empty if no previous condition has matched.
  324. func (txi *TxIndex) match(
  325. c query.Condition,
  326. startKeyBz []byte,
  327. filteredHashes map[string][]byte,
  328. firstRun bool,
  329. ) map[string][]byte {
  330. // A previous match was attempted but resulted in no matches, so we return
  331. // no matches (assuming AND operand).
  332. if !firstRun && len(filteredHashes) == 0 {
  333. return filteredHashes
  334. }
  335. tmpHashes := make(map[string][]byte)
  336. switch {
  337. case c.Op == query.OpEqual:
  338. it := dbm.IteratePrefix(txi.store, startKeyBz)
  339. defer it.Close()
  340. for ; it.Valid(); it.Next() {
  341. tmpHashes[string(it.Value())] = it.Value()
  342. }
  343. case c.Op == query.OpContains:
  344. // XXX: startKey does not apply here.
  345. // For example, if startKey = "account.owner/an/" and search query = "account.owner CONTAINS an"
  346. // we can't iterate with prefix "account.owner/an/" because we might miss keys like "account.owner/Ulan/"
  347. it := dbm.IteratePrefix(txi.store, startKey(c.Tag))
  348. defer it.Close()
  349. for ; it.Valid(); it.Next() {
  350. if !isTagKey(it.Key()) {
  351. continue
  352. }
  353. if strings.Contains(extractValueFromKey(it.Key()), c.Operand.(string)) {
  354. tmpHashes[string(it.Value())] = it.Value()
  355. }
  356. }
  357. default:
  358. panic("other operators should be handled already")
  359. }
  360. if len(tmpHashes) == 0 || firstRun {
  361. // Either:
  362. //
  363. // 1. Regardless if a previous match was attempted, which may have had
  364. // results, but no match was found for the current condition, then we
  365. // return no matches (assuming AND operand).
  366. //
  367. // 2. A previous match was not attempted, so we return all results.
  368. return tmpHashes
  369. }
  370. // Remove/reduce matches in filteredHashes that were not found in this
  371. // match (tmpHashes).
  372. for k := range filteredHashes {
  373. if tmpHashes[k] == nil {
  374. delete(filteredHashes, k)
  375. }
  376. }
  377. return filteredHashes
  378. }
  379. // matchRange returns all matching txs by hash that meet a given queryRange and
  380. // start key. An already filtered result (filteredHashes) is provided such that
  381. // any non-intersecting matches are removed.
  382. //
  383. // NOTE: filteredHashes may be empty if no previous condition has matched.
  384. func (txi *TxIndex) matchRange(
  385. r queryRange,
  386. startKey []byte,
  387. filteredHashes map[string][]byte,
  388. firstRun bool,
  389. ) map[string][]byte {
  390. // A previous match was attempted but resulted in no matches, so we return
  391. // no matches (assuming AND operand).
  392. if !firstRun && len(filteredHashes) == 0 {
  393. return filteredHashes
  394. }
  395. tmpHashes := make(map[string][]byte)
  396. lowerBound := r.lowerBoundValue()
  397. upperBound := r.upperBoundValue()
  398. it := dbm.IteratePrefix(txi.store, startKey)
  399. defer it.Close()
  400. LOOP:
  401. for ; it.Valid(); it.Next() {
  402. if !isTagKey(it.Key()) {
  403. continue
  404. }
  405. if _, ok := r.AnyBound().(int64); ok {
  406. v, err := strconv.ParseInt(extractValueFromKey(it.Key()), 10, 64)
  407. if err != nil {
  408. continue LOOP
  409. }
  410. include := true
  411. if lowerBound != nil && v < lowerBound.(int64) {
  412. include = false
  413. }
  414. if upperBound != nil && v > upperBound.(int64) {
  415. include = false
  416. }
  417. if include {
  418. tmpHashes[string(it.Value())] = it.Value()
  419. }
  420. // XXX: passing time in a ABCI Tags is not yet implemented
  421. // case time.Time:
  422. // v := strconv.ParseInt(extractValueFromKey(it.Key()), 10, 64)
  423. // if v == r.upperBound {
  424. // break
  425. // }
  426. }
  427. }
  428. if len(tmpHashes) == 0 || firstRun {
  429. // Either:
  430. //
  431. // 1. Regardless if a previous match was attempted, which may have had
  432. // results, but no match was found for the current condition, then we
  433. // return no matches (assuming AND operand).
  434. //
  435. // 2. A previous match was not attempted, so we return all results.
  436. return tmpHashes
  437. }
  438. // Remove/reduce matches in filteredHashes that were not found in this
  439. // match (tmpHashes).
  440. for k := range filteredHashes {
  441. if tmpHashes[k] == nil {
  442. delete(filteredHashes, k)
  443. }
  444. }
  445. return filteredHashes
  446. }
  447. ///////////////////////////////////////////////////////////////////////////////
  448. // Keys
  449. func isTagKey(key []byte) bool {
  450. return strings.Count(string(key), tagKeySeparator) == 3
  451. }
  452. func extractValueFromKey(key []byte) string {
  453. parts := strings.SplitN(string(key), tagKeySeparator, 3)
  454. return parts[1]
  455. }
  456. func keyForEvent(key string, value []byte, result *types.TxResult) []byte {
  457. return []byte(fmt.Sprintf("%s/%s/%d/%d",
  458. key,
  459. value,
  460. result.Height,
  461. result.Index,
  462. ))
  463. }
  464. func keyForHeight(result *types.TxResult) []byte {
  465. return []byte(fmt.Sprintf("%s/%d/%d/%d",
  466. types.TxHeightKey,
  467. result.Height,
  468. result.Height,
  469. result.Index,
  470. ))
  471. }
  472. func startKeyForCondition(c query.Condition, height int64) []byte {
  473. if height > 0 {
  474. return startKey(c.Tag, c.Operand, height)
  475. }
  476. return startKey(c.Tag, c.Operand)
  477. }
  478. func startKey(fields ...interface{}) []byte {
  479. var b bytes.Buffer
  480. for _, f := range fields {
  481. b.Write([]byte(fmt.Sprintf("%v", f) + tagKeySeparator))
  482. }
  483. return b.Bytes()
  484. }