mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-02 22:21:44 +00:00
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
This commit is contained in:
committed by
Anton Kaliaev
parent
8b7ca8fd99
commit
ab0835463f
@ -22,26 +22,83 @@ import (
|
||||
// string (escaped with single quotes), number, date or time.
|
||||
//
|
||||
// Examples:
|
||||
// tm.event = 'NewBlock' # new blocks
|
||||
// tm.event = 'CompleteProposal' # node got a complete proposal
|
||||
// tm.event = 'NewBlock' # new blocks
|
||||
// tm.event = 'CompleteProposal' # node got a complete proposal
|
||||
// tm.event = 'Tx' AND tx.hash = 'XYZ' # single transaction
|
||||
// tm.event = 'Tx' AND tx.height = 5 # all txs of the fifth block
|
||||
// tx.height = 5 # all txs of the fifth block
|
||||
// tm.event = 'Tx' AND tx.height = 5 # all txs of the fifth block
|
||||
// tx.height = 5 # all txs of the fifth block
|
||||
//
|
||||
// Tendermint provides a few predefined keys: tm.event, tx.hash and tx.height.
|
||||
// Note for transactions, you can define additional keys by providing tags with
|
||||
// Note for transactions, you can define additional keys by providing events with
|
||||
// DeliverTx response.
|
||||
//
|
||||
// DeliverTx{
|
||||
// Tags: []*KVPair{
|
||||
// "agent.name": "K",
|
||||
// }
|
||||
// }
|
||||
// import (
|
||||
// abci "github.com/tendermint/tendermint/abci/types"
|
||||
// "github.com/tendermint/tendermint/libs/pubsub/query"
|
||||
// )
|
||||
//
|
||||
// tm.event = 'Tx' AND agent.name = 'K'
|
||||
// tm.event = 'Tx' AND account.created_at >= TIME 2013-05-03T14:45:00Z
|
||||
// tm.event = 'Tx' AND contract.sign_date = DATE 2017-01-01
|
||||
// tm.event = 'Tx' AND account.owner CONTAINS 'Igor'
|
||||
// abci.ResponseDeliverTx{
|
||||
// Events: []abci.Event{
|
||||
// {
|
||||
// Type: "rewards.withdraw",
|
||||
// Attributes: cmn.KVPairs{
|
||||
// cmn.KVPair{Key: []byte("address"), Value: []byte("AddrA")},
|
||||
// cmn.KVPair{Key: []byte("source"), Value: []byte("SrcX")},
|
||||
// cmn.KVPair{Key: []byte("amount"), Value: []byte("...")},
|
||||
// cmn.KVPair{Key: []byte("balance"), Value: []byte("...")},
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "rewards.withdraw",
|
||||
// Attributes: cmn.KVPairs{
|
||||
// cmn.KVPair{Key: []byte("address"), Value: []byte("AddrB")},
|
||||
// cmn.KVPair{Key: []byte("source"), Value: []byte("SrcY")},
|
||||
// cmn.KVPair{Key: []byte("amount"), Value: []byte("...")},
|
||||
// cmn.KVPair{Key: []byte("balance"), Value: []byte("...")},
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Type: "transfer",
|
||||
// Attributes: cmn.KVPairs{
|
||||
// cmn.KVPair{Key: []byte("sender"), Value: []byte("AddrC")},
|
||||
// cmn.KVPair{Key: []byte("recipient"), Value: []byte("AddrD")},
|
||||
// cmn.KVPair{Key: []byte("amount"), Value: []byte("...")},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// All events are indexed by a composite key of the form {eventType}.{evenAttrKey}.
|
||||
// In the above examples, the following keys would be indexed:
|
||||
// - rewards.withdraw.address
|
||||
// - rewards.withdraw.source
|
||||
// - rewards.withdraw.amount
|
||||
// - rewards.withdraw.balance
|
||||
// - transfer.sender
|
||||
// - transfer.recipient
|
||||
// - transfer.amount
|
||||
//
|
||||
// Multiple event types with duplicate keys are allowed and are meant to
|
||||
// categorize unique and distinct events. In the above example, all events
|
||||
// indexed under the key `rewards.withdraw.address` will have the following
|
||||
// values stored and queryable:
|
||||
//
|
||||
// - AddrA
|
||||
// - AddrB
|
||||
//
|
||||
// To create a query for txs where address AddrA withdrew rewards:
|
||||
// query.MustParse("tm.event = 'Tx' AND rewards.withdraw.address = 'AddrA'")
|
||||
//
|
||||
// To create a query for txs where address AddrA withdrew rewards from source Y:
|
||||
// query.MustParse("tm.event = 'Tx' AND rewards.withdraw.address = 'AddrA' AND rewards.withdraw.source = 'Y'")
|
||||
//
|
||||
// To create a query for txs where AddrA transferred funds:
|
||||
// query.MustParse("tm.event = 'Tx' AND transfer.sender = 'AddrA'")
|
||||
//
|
||||
// The following queries would return no results:
|
||||
// query.MustParse("tm.event = 'Tx' AND transfer.sender = 'AddrZ'")
|
||||
// query.MustParse("tm.event = 'Tx' AND rewards.withdraw.address = 'AddrZ'")
|
||||
// query.MustParse("tm.event = 'Tx' AND rewards.withdraw.source = 'W'")
|
||||
//
|
||||
// See list of all possible events here
|
||||
// https://godoc.org/github.com/tendermint/tendermint/types#pkg-constants
|
||||
@ -106,8 +163,10 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to parse query")
|
||||
}
|
||||
|
||||
subCtx, cancel := context.WithTimeout(ctx.Context(), SubscribeTimeout)
|
||||
defer cancel()
|
||||
|
||||
sub, err := eventBus.Subscribe(subCtx, addr, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -117,7 +176,7 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er
|
||||
for {
|
||||
select {
|
||||
case msg := <-sub.Out():
|
||||
resultEvent := &ctypes.ResultEvent{Query: query, Data: msg.Data(), Tags: msg.Tags()}
|
||||
resultEvent := &ctypes.ResultEvent{Query: query, Data: msg.Data(), Events: msg.Events()}
|
||||
ctx.WSConn.TryWriteRPCResponse(
|
||||
rpctypes.NewRPCSuccessResponse(
|
||||
ctx.WSConn.Codec(),
|
||||
|
@ -205,7 +205,7 @@ type (
|
||||
|
||||
// Event data from a subscription
|
||||
type ResultEvent struct {
|
||||
Query string `json:"query"`
|
||||
Data types.TMEventData `json:"data"`
|
||||
Tags map[string]string `json:"tags"`
|
||||
Query string `json:"query"`
|
||||
Data types.TMEventData `json:"data"`
|
||||
Events map[string][]string `json:"events"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user