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.

122 lines
4.4 KiB

  1. # ADR 058: Event hashing
  2. ## Changelog
  3. - 2020-07-17: initial version
  4. - 2020-07-27: fixes after Ismail and Ethan's comments
  5. - 2020-07-27: declined
  6. ## Context
  7. Before [PR#4845](https://github.com/tendermint/tendermint/pull/4845),
  8. `Header#LastResultsHash` was a root of the Merkle tree built from `DeliverTx`
  9. results. Only `Code`, `Data` fields were included because `Info` and `Log`
  10. fields are non-deterministic.
  11. At some point, we've added events to `ResponseBeginBlock`, `ResponseEndBlock`,
  12. and `ResponseDeliverTx` to give applications a way to attach some additional
  13. information to blocks / transactions.
  14. Many applications seem to have started using them since.
  15. However, before [PR#4845](https://github.com/tendermint/tendermint/pull/4845)
  16. there was no way to prove that certain events were a part of the result
  17. (_unless the application developer includes them into the state tree_).
  18. Hence, [PR#4845](https://github.com/tendermint/tendermint/pull/4845) was
  19. opened. In it, `GasWanted` along with `GasUsed` are included when hashing
  20. `DeliverTx` results. Also, events from `BeginBlock`, `EndBlock` and `DeliverTx`
  21. results are hashed into the `LastResultsHash` as follows:
  22. - Since we do not expect `BeginBlock` and `EndBlock` to contain many events,
  23. these will be Protobuf encoded and included in the Merkle tree as leaves.
  24. - `LastResultsHash` therefore is the root hash of a Merkle tree w/ 3 leafs:
  25. proto-encoded `ResponseBeginBlock#Events`, root hash of a Merkle tree build
  26. from `ResponseDeliverTx` responses (Log, Info and Codespace fields are
  27. ignored), and proto-encoded `ResponseEndBlock#Events`.
  28. - Order of events is unchanged - same as received from the ABCI application.
  29. [Spec PR](https://github.com/tendermint/spec/pull/97/files)
  30. While it's certainly good to be able to prove something, introducing new events
  31. or removing such becomes difficult because it breaks the `LastResultsHash`. It
  32. means that every time you add, remove or update an event, you'll need a
  33. hard-fork. And that is undoubtedly bad for applications, which are evolving and
  34. don't have a stable events set.
  35. ## Decision
  36. As a middle ground approach, the proposal is to add the
  37. `Block#LastResultsEvents` consensus parameter that is a list of all events that
  38. are to be hashed in the header.
  39. ```
  40. @ proto/tendermint/abci/types.proto:295 @ message BlockParams {
  41. int64 max_bytes = 1;
  42. // Note: must be greater or equal to -1
  43. int64 max_gas = 2;
  44. // List of events, which will be hashed into the LastResultsHash
  45. repeated string last_results_events = 3;
  46. }
  47. ```
  48. Initially the list is empty. The ABCI application can change it via `InitChain`
  49. or `EndBlock`.
  50. Example:
  51. ```go
  52. func (app *MyApp) DeliverTx(req types.RequestDeliverTx) types.ResponseDeliverTx {
  53. //...
  54. events := []abci.Event{
  55. {
  56. Type: "transfer",
  57. Attributes: []abci.EventAttribute{
  58. {Key: []byte("sender"), Value: []byte("Bob"), Index: true},
  59. },
  60. },
  61. }
  62. return types.ResponseDeliverTx{Code: code.CodeTypeOK, Events: events}
  63. }
  64. ```
  65. For "transfer" event to be hashed, the `LastResultsEvents` must contain a
  66. string "transfer".
  67. ## Status
  68. Declined
  69. **Until there's more stability/motivation/use-cases/demand, the decision is to
  70. push this entirely application side and just have apps which want events to be
  71. provable to insert them into their application-side merkle trees. Of course
  72. this puts more pressure on their application state and makes event proving
  73. application specific, but it might help built up a better sense of use-cases
  74. and how this ought to ultimately be done by Tendermint.**
  75. ## Consequences
  76. ### Positive
  77. 1. networks can perform parameter change proposals to update this list as new events are added
  78. 2. allows networks to avoid having to do hard-forks
  79. 3. events can still be added at-will to the application w/o breaking anything
  80. ### Negative
  81. 1. yet another consensus parameter
  82. 2. more things to track in the tendermint state
  83. ## References
  84. - [ADR 021](./adr-021-abci-events.md)
  85. - [Indexing transactions](../app-dev/indexing-transactions.md)
  86. ## Appendix A. Alternative proposals
  87. The other proposal was to add `Hash bool` flag to the `Event`, similarly to
  88. `Index bool` EventAttribute's field. When `true`, Tendermint would hash it into
  89. the `LastResultsEvents`. The downside is that the logic is implicit and depends
  90. largely on the node's operator, who decides what application code to run. The
  91. above proposal makes it (the logic) explicit and easy to upgrade via
  92. governance.