Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7b40167

Browse files
thanethomsonalexanderbez
andauthoredAug 30, 2022
abci: Port EventAttribute field type change to main (#9335)
* types: Refactor EventAttribute (#6408) Cherry-pick of 09a6ad7 * Ensure context is honored Signed-off-by: Thane Thomson <[email protected]> * Replace with tagged switch Signed-off-by: Thane Thomson <[email protected]> * Ensure contexts are honored Signed-off-by: Thane Thomson <[email protected]> * Add UPGRADING note about type change Signed-off-by: Thane Thomson <[email protected]> * Remove unnecessary conversion Signed-off-by: Thane Thomson <[email protected]> Signed-off-by: Thane Thomson <[email protected]> Co-authored-by: Aleksandr Bezobchuk <[email protected]>
1 parent 2313f35 commit 7b40167

File tree

17 files changed

+156
-143
lines changed

17 files changed

+156
-143
lines changed
 

‎CHANGELOG_PENDING.md

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

2425
- P2P Protocol
2526

‎UPGRADING.md

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

3035
## v0.34.20
3136

‎abci/example/kvstore/kvstore.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,16 @@ func (app *Application) DeliverTx(req types.RequestDeliverTx) types.ResponseDeli
9191
if isReplacedTx(req.Tx) {
9292
app.txToRemove[string(req.Tx)] = struct{}{}
9393
}
94-
var key, value []byte
94+
var key, value string
95+
9596
parts := bytes.Split(req.Tx, []byte("="))
9697
if len(parts) == 2 {
97-
key, value = parts[0], parts[1]
98+
key, value = string(parts[0]), string(parts[1])
9899
} else {
99-
key, value = req.Tx, req.Tx
100+
key, value = string(req.Tx), string(req.Tx)
100101
}
101102

102-
err := app.state.db.Set(prefixKey(key), value)
103+
err := app.state.db.Set(prefixKey([]byte(key)), []byte(value))
103104
if err != nil {
104105
panic(err)
105106
}
@@ -109,10 +110,10 @@ func (app *Application) DeliverTx(req types.RequestDeliverTx) types.ResponseDeli
109110
{
110111
Type: "app",
111112
Attributes: []types.EventAttribute{
112-
{Key: []byte("creator"), Value: []byte("Cosmoshi Netowoko"), Index: true},
113-
{Key: []byte("key"), Value: key, Index: true},
114-
{Key: []byte("index_key"), Value: []byte("index is working"), Index: true},
115-
{Key: []byte("noindex_key"), Value: []byte("index is working"), Index: false},
113+
{Key: "creator", Value: "Cosmoshi Netowoko", Index: true},
114+
{Key: "key", Value: key, Index: true},
115+
{Key: "index_key", Value: "index is working", Index: true},
116+
{Key: "noindex_key", Value: "index is working", Index: false},
116117
},
117118
},
118119
}

‎abci/types/messages_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestMarshalJSON(t *testing.T) {
2525
{
2626
Type: "testEvent",
2727
Attributes: []EventAttribute{
28-
{Key: []byte("pho"), Value: []byte("bo")},
28+
{Key: "pho", Value: "bo"},
2929
},
3030
},
3131
},
@@ -92,7 +92,7 @@ func TestWriteReadMessage2(t *testing.T) {
9292
{
9393
Type: "testEvent",
9494
Attributes: []EventAttribute{
95-
{Key: []byte("abc"), Value: []byte("def")},
95+
{Key: "abc", Value: "def"},
9696
},
9797
},
9898
},

‎abci/types/types.pb.go

+60-64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎proto/tendermint/abci/types.proto

+3-3
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ message Event {
344344

345345
// EventAttribute is a single key-value pair, associated with an event.
346346
message EventAttribute {
347-
bytes key = 1;
348-
bytes value = 2;
349-
bool index = 3; // nondeterministic
347+
string key = 1;
348+
string value = 2;
349+
bool index = 3; // nondeterministic
350350
}
351351

352352
// TxResult contains results of executing the transaction.

‎state/indexer/block/kv/kv.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,13 @@ func (idx *BlockerIndexer) indexEvents(batch dbm.Batch, events []abci.Event, typ
468468
}
469469

470470
// index iff the event specified index:true and it's not a reserved event
471-
compositeKey := fmt.Sprintf("%s.%s", event.Type, string(attr.Key))
471+
compositeKey := fmt.Sprintf("%s.%s", event.Type, attr.Key)
472472
if compositeKey == types.BlockHeightKey {
473473
return fmt.Errorf("event type and attribute key \"%s\" is reserved; please use a different key", compositeKey)
474474
}
475475

476476
if attr.GetIndex() {
477-
key, err := eventKey(compositeKey, typ, string(attr.Value), height)
477+
key, err := eventKey(compositeKey, typ, attr.Value, height)
478478
if err != nil {
479479
return fmt.Errorf("failed to create block index key: %w", err)
480480
}

‎state/indexer/block/kv/kv_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func TestBlockIndexer(t *testing.T) {
2626
Type: "begin_event",
2727
Attributes: []abci.EventAttribute{
2828
{
29-
Key: []byte("proposer"),
30-
Value: []byte("FCAA001"),
29+
Key: "proposer",
30+
Value: "FCAA001",
3131
Index: true,
3232
},
3333
},
@@ -40,8 +40,8 @@ func TestBlockIndexer(t *testing.T) {
4040
Type: "end_event",
4141
Attributes: []abci.EventAttribute{
4242
{
43-
Key: []byte("foo"),
44-
Value: []byte("100"),
43+
Key: "foo",
44+
Value: "100",
4545
Index: true,
4646
},
4747
},
@@ -64,8 +64,8 @@ func TestBlockIndexer(t *testing.T) {
6464
Type: "begin_event",
6565
Attributes: []abci.EventAttribute{
6666
{
67-
Key: []byte("proposer"),
68-
Value: []byte("FCAA001"),
67+
Key: "proposer",
68+
Value: "FCAA001",
6969
Index: true,
7070
},
7171
},
@@ -78,8 +78,8 @@ func TestBlockIndexer(t *testing.T) {
7878
Type: "end_event",
7979
Attributes: []abci.EventAttribute{
8080
{
81-
Key: []byte("foo"),
82-
Value: []byte(fmt.Sprintf("%d", i)),
81+
Key: "foo",
82+
Value: fmt.Sprintf("%d", i),
8383
Index: index,
8484
},
8585
},

‎state/indexer/sink/psql/psql.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ INSERT INTO `+tableEvents+` (block_id, tx_id, type) VALUES ($1, $2, $3)
111111
if !attr.Index {
112112
continue
113113
}
114-
compositeKey := evt.Type + "." + string(attr.Key)
114+
compositeKey := evt.Type + "." + attr.Key
115115
if _, err := dbtx.Exec(`
116116
INSERT INTO `+tableAttributes+` (event_id, key, composite_key, value)
117117
VALUES ($1, $2, $3, $4);
@@ -133,7 +133,7 @@ func makeIndexedEvent(compositeKey, value string) abci.Event {
133133
return abci.Event{Type: compositeKey}
134134
}
135135
return abci.Event{Type: compositeKey[:i], Attributes: []abci.EventAttribute{
136-
{Key: []byte(compositeKey[i+1:]), Value: []byte(value), Index: true},
136+
{Key: compositeKey[i+1:], Value: value, Index: true},
137137
}}
138138
}
139139

‎state/indexer/sink/psql/psql_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ func TestIndexing(t *testing.T) {
168168

169169
{Type: "", Attributes: []abci.EventAttribute{
170170
{
171-
Key: []byte("not_allowed"),
172-
Value: []byte("Vlad"),
171+
Key: "not_allowed",
172+
Value: "Vlad",
173173
Index: true,
174174
},
175175
}},

0 commit comments

Comments
 (0)
Please sign in to comment.