abci: Port EventAttribute field type change to main (#9335)

* types: Refactor EventAttribute (#6408)

Cherry-pick of 09a6ad7b1e

* Ensure context is honored

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Replace with tagged switch

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Ensure contexts are honored

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add UPGRADING note about type change

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove unnecessary conversion

Signed-off-by: Thane Thomson <connect@thanethomson.com>

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
Thane Thomson
2022-08-30 10:13:55 -04:00
committed by GitHub
parent 2313f35800
commit 7b40167f58
17 changed files with 156 additions and 143 deletions

View File

@@ -20,6 +20,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
- Rename `AppVersion` to `App` so as to not stutter.
- [abci] \#9301 New ABCI methods `PrepareProposal` and `ProcessProposal` which give the app control over transactions proposed and allows for verification of proposed blocks.
- [abci] \#8656, \#8901 Added cli commands for `PrepareProposal` and `ProcessProposal`. (@jmalicevic, @hvanz)
- [abci] \#6403 Change the `key` and `value` fields from `[]byte` to `string` in the `EventAttribute` type. (@alexanderbez)
- P2P Protocol

View File

@@ -26,6 +26,11 @@ Tendermint Core.
in order to ensure compatibility.
* The `SetOption` method has been removed from the ABCI `Client` interface.
The corresponding Protobuf types have been deprecated.
* The `key` and `value` fields in the `EventAttribute` type have been changed
from type `bytes` to `string`. As per the [Protocol Buffers updating
guidelines](https://developers.google.com/protocol-buffers/docs/proto3#updating),
this should have no effect on the wire-level encoding for UTF8-encoded
strings.
## v0.34.20

View File

@@ -91,15 +91,16 @@ func (app *Application) DeliverTx(req types.RequestDeliverTx) types.ResponseDeli
if isReplacedTx(req.Tx) {
app.txToRemove[string(req.Tx)] = struct{}{}
}
var key, value []byte
var key, value string
parts := bytes.Split(req.Tx, []byte("="))
if len(parts) == 2 {
key, value = parts[0], parts[1]
key, value = string(parts[0]), string(parts[1])
} else {
key, value = req.Tx, req.Tx
key, value = string(req.Tx), string(req.Tx)
}
err := app.state.db.Set(prefixKey(key), value)
err := app.state.db.Set(prefixKey([]byte(key)), []byte(value))
if err != nil {
panic(err)
}
@@ -109,10 +110,10 @@ func (app *Application) DeliverTx(req types.RequestDeliverTx) types.ResponseDeli
{
Type: "app",
Attributes: []types.EventAttribute{
{Key: []byte("creator"), Value: []byte("Cosmoshi Netowoko"), Index: true},
{Key: []byte("key"), Value: key, Index: true},
{Key: []byte("index_key"), Value: []byte("index is working"), Index: true},
{Key: []byte("noindex_key"), Value: []byte("index is working"), Index: false},
{Key: "creator", Value: "Cosmoshi Netowoko", Index: true},
{Key: "key", Value: key, Index: true},
{Key: "index_key", Value: "index is working", Index: true},
{Key: "noindex_key", Value: "index is working", Index: false},
},
},
}

View File

@@ -25,7 +25,7 @@ func TestMarshalJSON(t *testing.T) {
{
Type: "testEvent",
Attributes: []EventAttribute{
{Key: []byte("pho"), Value: []byte("bo")},
{Key: "pho", Value: "bo"},
},
},
},
@@ -92,7 +92,7 @@ func TestWriteReadMessage2(t *testing.T) {
{
Type: "testEvent",
Attributes: []EventAttribute{
{Key: []byte("abc"), Value: []byte("def")},
{Key: "abc", Value: "def"},
},
},
},

View File

@@ -2894,8 +2894,8 @@ func (m *Event) GetAttributes() []EventAttribute {
// EventAttribute is a single key-value pair, associated with an event.
type EventAttribute struct {
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
Index bool `protobuf:"varint,3,opt,name=index,proto3" json:"index,omitempty"`
}
@@ -2932,18 +2932,18 @@ func (m *EventAttribute) XXX_DiscardUnknown() {
var xxx_messageInfo_EventAttribute proto.InternalMessageInfo
func (m *EventAttribute) GetKey() []byte {
func (m *EventAttribute) GetKey() string {
if m != nil {
return m.Key
}
return nil
return ""
}
func (m *EventAttribute) GetValue() []byte {
func (m *EventAttribute) GetValue() string {
if m != nil {
return m.Value
}
return nil
return ""
}
func (m *EventAttribute) GetIndex() bool {
@@ -3459,7 +3459,7 @@ func init() {
func init() { proto.RegisterFile("tendermint/abci/types.proto", fileDescriptor_252557cfdd89a31a) }
var fileDescriptor_252557cfdd89a31a = []byte{
// 3004 bytes of a gzipped FileDescriptorProto
// 3006 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x5a, 0x3b, 0x73, 0x23, 0xc7,
0xf1, 0xc7, 0xfb, 0xd1, 0x78, 0x2d, 0xe7, 0xa8, 0x13, 0x0e, 0x3a, 0x91, 0xa7, 0xbd, 0x92, 0x74,
0x77, 0x92, 0x48, 0xfd, 0xa9, 0xff, 0xe9, 0x51, 0xb2, 0x6c, 0x11, 0x38, 0x9c, 0x41, 0x91, 0x22,
@@ -3607,47 +3607,47 @@ var fileDescriptor_252557cfdd89a31a = []byte{
0x9e, 0x8a, 0xad, 0x2e, 0xcd, 0x1f, 0xea, 0x23, 0xc8, 0x32, 0x6f, 0x43, 0x3d, 0x07, 0xab, 0x6b,
0x8a, 0x64, 0x94, 0xb6, 0xd1, 0xcf, 0x00, 0x34, 0x42, 0x1c, 0xa3, 0x37, 0x0e, 0x06, 0x58, 0x9f,
0xef, 0xad, 0xb6, 0x3d, 0xbe, 0xe6, 0x75, 0xe1, 0xb6, 0x56, 0x03, 0xd1, 0x90, 0xeb, 0x0a, 0x29,
0x94, 0xf7, 0xa1, 0x1a, 0x95, 0xf5, 0xd2, 0xa7, 0xe4, 0x9c, 0xf4, 0x29, 0x15, 0x4e, 0x9f, 0xfc,
0xe4, 0x2b, 0xcd, 0x4b, 0xd8, 0xac, 0x23, 0x7f, 0x92, 0x84, 0x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to suppress errors if they are not otherwise used.
@@ -14566,7 +14566,7 @@ func (m *EventAttribute) Unmarshal(dAtA []byte) error {
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType)
}
var byteLen int
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTypes
@@ -14576,31 +14576,29 @@ func (m *EventAttribute) Unmarshal(dAtA []byte) error {
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthTypes
}
postIndex := iNdEx + byteLen
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthTypes
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...)
if m.Key == nil {
m.Key = []byte{}
}
m.Key = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType)
}
var byteLen int
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTypes
@@ -14610,25 +14608,23 @@ func (m *EventAttribute) Unmarshal(dAtA []byte) error {
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthTypes
}
postIndex := iNdEx + byteLen
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthTypes
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...)
if m.Value == nil {
m.Value = []byte{}
}
m.Value = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 0 {

View File

@@ -344,9 +344,9 @@ message Event {
// EventAttribute is a single key-value pair, associated with an event.
message EventAttribute {
bytes key = 1;
bytes value = 2;
bool index = 3; // nondeterministic
string key = 1;
string value = 2;
bool index = 3; // nondeterministic
}
// TxResult contains results of executing the transaction.

View File

@@ -468,13 +468,13 @@ func (idx *BlockerIndexer) indexEvents(batch dbm.Batch, events []abci.Event, typ
}
// index iff the event specified index:true and it's not a reserved event
compositeKey := fmt.Sprintf("%s.%s", event.Type, string(attr.Key))
compositeKey := fmt.Sprintf("%s.%s", event.Type, attr.Key)
if compositeKey == types.BlockHeightKey {
return fmt.Errorf("event type and attribute key \"%s\" is reserved; please use a different key", compositeKey)
}
if attr.GetIndex() {
key, err := eventKey(compositeKey, typ, string(attr.Value), height)
key, err := eventKey(compositeKey, typ, attr.Value, height)
if err != nil {
return fmt.Errorf("failed to create block index key: %w", err)
}

View File

@@ -26,8 +26,8 @@ func TestBlockIndexer(t *testing.T) {
Type: "begin_event",
Attributes: []abci.EventAttribute{
{
Key: []byte("proposer"),
Value: []byte("FCAA001"),
Key: "proposer",
Value: "FCAA001",
Index: true,
},
},
@@ -40,8 +40,8 @@ func TestBlockIndexer(t *testing.T) {
Type: "end_event",
Attributes: []abci.EventAttribute{
{
Key: []byte("foo"),
Value: []byte("100"),
Key: "foo",
Value: "100",
Index: true,
},
},
@@ -64,8 +64,8 @@ func TestBlockIndexer(t *testing.T) {
Type: "begin_event",
Attributes: []abci.EventAttribute{
{
Key: []byte("proposer"),
Value: []byte("FCAA001"),
Key: "proposer",
Value: "FCAA001",
Index: true,
},
},
@@ -78,8 +78,8 @@ func TestBlockIndexer(t *testing.T) {
Type: "end_event",
Attributes: []abci.EventAttribute{
{
Key: []byte("foo"),
Value: []byte(fmt.Sprintf("%d", i)),
Key: "foo",
Value: fmt.Sprintf("%d", i),
Index: index,
},
},

View File

@@ -111,7 +111,7 @@ INSERT INTO `+tableEvents+` (block_id, tx_id, type) VALUES ($1, $2, $3)
if !attr.Index {
continue
}
compositeKey := evt.Type + "." + string(attr.Key)
compositeKey := evt.Type + "." + attr.Key
if _, err := dbtx.Exec(`
INSERT INTO `+tableAttributes+` (event_id, key, composite_key, value)
VALUES ($1, $2, $3, $4);
@@ -133,7 +133,7 @@ func makeIndexedEvent(compositeKey, value string) abci.Event {
return abci.Event{Type: compositeKey}
}
return abci.Event{Type: compositeKey[:i], Attributes: []abci.EventAttribute{
{Key: []byte(compositeKey[i+1:]), Value: []byte(value), Index: true},
{Key: compositeKey[i+1:], Value: value, Index: true},
}}
}

View File

@@ -168,8 +168,8 @@ func TestIndexing(t *testing.T) {
{Type: "", Attributes: []abci.EventAttribute{
{
Key: []byte("not_allowed"),
Value: []byte("Vlad"),
Key: "not_allowed",
Value: "Vlad",
Index: true,
},
}},

View File

@@ -160,16 +160,16 @@ func TestABCIResponsesSaveLoad2(t *testing.T) {
{
Data: []byte("Gotcha!"),
Events: []abci.Event{
{Type: "type1", Attributes: []abci.EventAttribute{{Key: []byte("a"), Value: []byte("1")}}},
{Type: "type2", Attributes: []abci.EventAttribute{{Key: []byte("build"), Value: []byte("stuff")}}},
{Type: "type1", Attributes: []abci.EventAttribute{{Key: "a", Value: "1"}}},
{Type: "type2", Attributes: []abci.EventAttribute{{Key: "build", Value: "stuff"}}},
},
},
},
[]*abci.ResponseDeliverTx{
{Code: 383, Data: nil},
{Code: 0, Data: []byte("Gotcha!"), Events: []abci.Event{
{Type: "type1", Attributes: []abci.EventAttribute{{Key: []byte("a"), Value: []byte("1")}}},
{Type: "type2", Attributes: []abci.EventAttribute{{Key: []byte("build"), Value: []byte("stuff")}}},
{Type: "type1", Attributes: []abci.EventAttribute{{Key: "a", Value: "1"}}},
{Type: "type2", Attributes: []abci.EventAttribute{{Key: "build", Value: "stuff"}}},
}},
}},
3: {

View File

@@ -145,7 +145,11 @@ func (txi *TxIndex) indexEvents(result *abci.TxResult, hash []byte, store dbm.Ba
}
// index if `index: true` is set
compositeTag := fmt.Sprintf("%s.%s", event.Type, string(attr.Key))
compositeTag := fmt.Sprintf("%s.%s", event.Type, attr.Key)
// ensure event does not conflict with a reserved prefix key
if compositeTag == types.TxHashKey || compositeTag == types.TxHeightKey {
return fmt.Errorf("event type and attribute key \"%s\" is reserved; please use a different key", compositeTag)
}
if attr.GetIndex() {
err := store.Set(keyForEvent(compositeTag, attr.Value, result), hash)
if err != nil {
@@ -252,6 +256,7 @@ func (txi *TxIndex) Search(ctx context.Context, q *query.Query) ([]*abci.TxResul
}
results := make([]*abci.TxResult, 0, len(filteredHashes))
RESULTS_LOOP:
for _, h := range filteredHashes {
res, err := txi.Get(h)
if err != nil {
@@ -262,7 +267,7 @@ func (txi *TxIndex) Search(ctx context.Context, q *query.Query) ([]*abci.TxResul
// Potentially exit early.
select {
case <-ctx.Done():
break
break RESULTS_LOOP
default:
}
}
@@ -310,21 +315,22 @@ func (txi *TxIndex) match(
tmpHashes := make(map[string][]byte)
switch {
case c.Op == query.OpEqual:
switch c.Op {
case query.OpEqual:
it, err := dbm.IteratePrefix(txi.store, startKeyBz)
if err != nil {
panic(err)
}
defer it.Close()
EQ_LOOP:
for ; it.Valid(); it.Next() {
tmpHashes[string(it.Value())] = it.Value()
// Potentially exit early.
select {
case <-ctx.Done():
break
break EQ_LOOP
default:
}
}
@@ -332,7 +338,7 @@ func (txi *TxIndex) match(
panic(err)
}
case c.Op == query.OpExists:
case query.OpExists:
// XXX: can't use startKeyBz here because c.Operand is nil
// (e.g. "account.owner/<nil>/" won't match w/ a single row)
it, err := dbm.IteratePrefix(txi.store, startKey(c.CompositeKey))
@@ -341,13 +347,14 @@ func (txi *TxIndex) match(
}
defer it.Close()
EXISTS_LOOP:
for ; it.Valid(); it.Next() {
tmpHashes[string(it.Value())] = it.Value()
// Potentially exit early.
select {
case <-ctx.Done():
break
break EXISTS_LOOP
default:
}
}
@@ -355,7 +362,7 @@ func (txi *TxIndex) match(
panic(err)
}
case c.Op == query.OpContains:
case query.OpContains:
// XXX: startKey does not apply here.
// For example, if startKey = "account.owner/an/" and search query = "account.owner CONTAINS an"
// we can't iterate with prefix "account.owner/an/" because we might miss keys like "account.owner/Ulan/"
@@ -365,6 +372,7 @@ func (txi *TxIndex) match(
}
defer it.Close()
CONTAINS_LOOP:
for ; it.Valid(); it.Next() {
if !isTagKey(it.Key()) {
continue
@@ -377,7 +385,7 @@ func (txi *TxIndex) match(
// Potentially exit early.
select {
case <-ctx.Done():
break
break CONTAINS_LOOP
default:
}
}
@@ -401,6 +409,7 @@ func (txi *TxIndex) match(
// Remove/reduce matches in filteredHashes that were not found in this
// match (tmpHashes).
REMOVE_LOOP:
for k := range filteredHashes {
if tmpHashes[k] == nil {
delete(filteredHashes, k)
@@ -408,7 +417,7 @@ func (txi *TxIndex) match(
// Potentially exit early.
select {
case <-ctx.Done():
break
break REMOVE_LOOP
default:
}
}
@@ -481,7 +490,7 @@ LOOP:
// Potentially exit early.
select {
case <-ctx.Done():
break
break LOOP
default:
}
}
@@ -502,6 +511,7 @@ LOOP:
// Remove/reduce matches in filteredHashes that were not found in this
// match (tmpHashes).
REMOVE_LOOP:
for k := range filteredHashes {
if tmpHashes[k] == nil {
delete(filteredHashes, k)
@@ -509,7 +519,7 @@ LOOP:
// Potentially exit early.
select {
case <-ctx.Done():
break
break REMOVE_LOOP
default:
}
}
@@ -529,7 +539,7 @@ func extractValueFromKey(key []byte) string {
return parts[1]
}
func keyForEvent(key string, value []byte, result *abci.TxResult) []byte {
func keyForEvent(key string, value string, result *abci.TxResult) []byte {
return []byte(fmt.Sprintf("%s/%s/%d/%d",
key,
value,

View File

@@ -32,8 +32,8 @@ func BenchmarkTxSearch(b *testing.B) {
{
Type: "transfer",
Attributes: []abci.EventAttribute{
{Key: []byte("address"), Value: []byte(fmt.Sprintf("address_%d", i%100)), Index: true},
{Key: []byte("amount"), Value: []byte("50"), Index: true},
{Key: "address", Value: fmt.Sprintf("address_%d", i%100), Index: true},
{Key: "amount", Value: "50", Index: true},
},
},
}

View File

@@ -69,9 +69,9 @@ func TestTxSearch(t *testing.T) {
indexer := NewTxIndex(db.NewMemDB())
txResult := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("1"), Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("owner"), Value: []byte("Ivan"), Index: true}}},
{Type: "", Attributes: []abci.EventAttribute{{Key: []byte("not_allowed"), Value: []byte("Vlad"), Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: "owner", Value: "Ivan", Index: true}}},
{Type: "", Attributes: []abci.EventAttribute{{Key: "not_allowed", Value: "Vlad", Index: true}}},
})
hash := types.Tx(txResult.Tx).Hash()
@@ -143,9 +143,9 @@ func TestTxSearchWithCancelation(t *testing.T) {
indexer := NewTxIndex(db.NewMemDB())
txResult := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("1"), Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("owner"), Value: []byte("Ivan"), Index: true}}},
{Type: "", Attributes: []abci.EventAttribute{{Key: []byte("not_allowed"), Value: []byte("Vlad"), Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: "owner", Value: "Ivan", Index: true}}},
{Type: "", Attributes: []abci.EventAttribute{{Key: "not_allowed", Value: "Vlad", Index: true}}},
})
err := indexer.Index(txResult)
require.NoError(t, err)
@@ -162,7 +162,7 @@ func TestTxSearchDeprecatedIndexing(t *testing.T) {
// index tx using events indexing (composite key)
txResult1 := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("1"), Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}},
})
hash1 := types.Tx(txResult1.Tx).Hash()
@@ -240,8 +240,8 @@ func TestTxSearchOneTxWithMultipleSameTagsButDifferentValues(t *testing.T) {
indexer := NewTxIndex(db.NewMemDB())
txResult := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("1"), Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("2"), Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "2", Index: true}}},
})
err := indexer.Index(txResult)
@@ -263,7 +263,7 @@ func TestTxSearchMultipleTxs(t *testing.T) {
// indexed first, but bigger height (to test the order of transactions)
txResult := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("1"), Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}},
})
txResult.Tx = types.Tx("Bob's account")
@@ -274,7 +274,7 @@ func TestTxSearchMultipleTxs(t *testing.T) {
// indexed second, but smaller height (to test the order of transactions)
txResult2 := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("2"), Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "2", Index: true}}},
})
txResult2.Tx = types.Tx("Alice's account")
txResult2.Height = 1
@@ -285,7 +285,7 @@ func TestTxSearchMultipleTxs(t *testing.T) {
// indexed third (to test the order of transactions)
txResult3 := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number"), Value: []byte("3"), Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "3", Index: true}}},
})
txResult3.Tx = types.Tx("Jack's account")
txResult3.Height = 1
@@ -296,7 +296,7 @@ func TestTxSearchMultipleTxs(t *testing.T) {
// indexed fourth (to test we don't include txs with similar events)
// https://github.com/tendermint/tendermint/issues/2908
txResult4 := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: []byte("number.id"), Value: []byte("1"), Index: true}}},
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number.id", Value: "1", Index: true}}},
})
txResult4.Tx = types.Tx("Mike's account")
txResult4.Height = 2

View File

@@ -176,12 +176,12 @@ func (app *Application) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock
Type: "val_updates",
Attributes: []abci.EventAttribute{
{
Key: []byte("size"),
Value: []byte(strconv.Itoa(valUpdates.Len())),
Key: "size",
Value: strconv.Itoa(valUpdates.Len()),
},
{
Key: []byte("height"),
Value: []byte(strconv.Itoa(int(req.Height))),
Key: "height",
Value: strconv.Itoa(int(req.Height)),
},
},
},

View File

@@ -123,8 +123,8 @@ func (b *EventBus) validateAndStringifyEvents(events []types.Event, logger log.L
continue
}
compositeTag := fmt.Sprintf("%s.%s", event.Type, string(attr.Key))
result[compositeTag] = append(result[compositeTag], string(attr.Value))
compositeTag := fmt.Sprintf("%s.%s", event.Type, attr.Key)
result[compositeTag] = append(result[compositeTag], attr.Value)
}
}

View File

@@ -30,7 +30,7 @@ func TestEventBusPublishEventTx(t *testing.T) {
result := abci.ResponseDeliverTx{
Data: []byte("bar"),
Events: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{{Key: []byte("baz"), Value: []byte("1")}}},
{Type: "testType", Attributes: []abci.EventAttribute{{Key: "baz", Value: "1"}}},
},
}
@@ -78,12 +78,12 @@ func TestEventBusPublishEventNewBlock(t *testing.T) {
block := MakeBlock(0, []Tx{}, nil, []Evidence{})
resultBeginBlock := abci.ResponseBeginBlock{
Events: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{{Key: []byte("baz"), Value: []byte("1")}}},
{Type: "testType", Attributes: []abci.EventAttribute{{Key: "baz", Value: "1"}}},
},
}
resultEndBlock := abci.ResponseEndBlock{
Events: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{{Key: []byte("foz"), Value: []byte("2")}}},
{Type: "testType", Attributes: []abci.EventAttribute{{Key: "foz", Value: "2"}}},
},
}
@@ -133,25 +133,25 @@ func TestEventBusPublishEventTxDuplicateKeys(t *testing.T) {
{
Type: "transfer",
Attributes: []abci.EventAttribute{
{Key: []byte("sender"), Value: []byte("foo")},
{Key: []byte("recipient"), Value: []byte("bar")},
{Key: []byte("amount"), Value: []byte("5")},
{Key: "sender", Value: "foo"},
{Key: "recipient", Value: "bar"},
{Key: "amount", Value: "5"},
},
},
{
Type: "transfer",
Attributes: []abci.EventAttribute{
{Key: []byte("sender"), Value: []byte("baz")},
{Key: []byte("recipient"), Value: []byte("cat")},
{Key: []byte("amount"), Value: []byte("13")},
{Key: "sender", Value: "baz"},
{Key: "recipient", Value: "cat"},
{Key: "amount", Value: "13"},
},
},
{
Type: "withdraw.rewards",
Attributes: []abci.EventAttribute{
{Key: []byte("address"), Value: []byte("bar")},
{Key: []byte("source"), Value: []byte("iceman")},
{Key: []byte("amount"), Value: []byte("33")},
{Key: "address", Value: "bar"},
{Key: "source", Value: "iceman"},
{Key: "amount", Value: "33"},
},
},
},
@@ -237,12 +237,12 @@ func TestEventBusPublishEventNewBlockHeader(t *testing.T) {
block := MakeBlock(0, []Tx{}, nil, []Evidence{})
resultBeginBlock := abci.ResponseBeginBlock{
Events: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{{Key: []byte("baz"), Value: []byte("1")}}},
{Type: "testType", Attributes: []abci.EventAttribute{{Key: "baz", Value: "1"}}},
},
}
resultEndBlock := abci.ResponseEndBlock{
Events: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{{Key: []byte("foz"), Value: []byte("2")}}},
{Type: "testType", Attributes: []abci.EventAttribute{{Key: "foz", Value: "2"}}},
},
}