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.

197 lines
5.1 KiB

abci: Synchronize FinalizeBlock with the updated specification (#7983) This change set implements the most recent version of `FinalizeBlock`. # What does this change actually contain? * This change set is rather large but fear not! The majority of the files touched and changes are renaming `ResponseDeliverTx` to `ExecTxResult`. This should be a pretty inoffensive change since they're effectively the same type but with a different name. * The `execBlockOnProxyApp` was totally removed since it served as just a wrapper around the logic that is now mostly encapsulated within `FinalizeBlock` * The `updateState` helper function has been made a public method on `State`. It was being exposed as a shim through the testing infrastructure, so this seemed innocuous. * Tests already existed to ensure that the application received the `ByzantineValidators` and the `ValidatorUpdates`, but one was fixed up to ensure that `LastCommitInfo` was being sent across. * Tests were removed from the `psql` indexer that seemed to search for an event in the indexer that was not being created. # Questions for reviewers * We store this [ABCIResponses](https://github.com/tendermint/tendermint/blob/5721a13ab1f4479f9807f449f0bf5c536b9a05f2/proto/tendermint/state/types.pb.go#L37) type in the data base as the block results. This type has changed since v0.35 to contain the `FinalizeBlock` response. I'm wondering if we need to do any shimming to keep the old data retrieveable? * Similarly, this change is exposed via the RPC through [ResultBlockResults](https://github.com/tendermint/tendermint/blob/5721a13ab1f4479f9807f449f0bf5c536b9a05f2/rpc/coretypes/responses.go#L69) changing. Should we somehow shim or notify for this change? closes: #7658
3 years ago
  1. package types
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "github.com/gogo/protobuf/jsonpb"
  6. types "github.com/tendermint/tendermint/proto/tendermint/types"
  7. )
  8. const (
  9. CodeTypeOK uint32 = 0
  10. )
  11. // IsOK returns true if Code is OK.
  12. func (r ResponseCheckTx) IsOK() bool {
  13. return r.Code == CodeTypeOK
  14. }
  15. // IsErr returns true if Code is something other than OK.
  16. func (r ResponseCheckTx) IsErr() bool {
  17. return r.Code != CodeTypeOK
  18. }
  19. // IsOK returns true if Code is OK.
  20. func (r ResponseDeliverTx) IsOK() bool {
  21. return r.Code == CodeTypeOK
  22. }
  23. // IsErr returns true if Code is something other than OK.
  24. func (r ResponseDeliverTx) IsErr() bool {
  25. return r.Code != CodeTypeOK
  26. }
  27. // IsOK returns true if Code is OK.
  28. func (r ExecTxResult) IsOK() bool {
  29. return r.Code == CodeTypeOK
  30. }
  31. // IsErr returns true if Code is something other than OK.
  32. func (r ExecTxResult) IsErr() bool {
  33. return r.Code != CodeTypeOK
  34. }
  35. // IsOK returns true if Code is OK.
  36. func (r ResponseQuery) IsOK() bool {
  37. return r.Code == CodeTypeOK
  38. }
  39. // IsErr returns true if Code is something other than OK.
  40. func (r ResponseQuery) IsErr() bool {
  41. return r.Code != CodeTypeOK
  42. }
  43. // IsUnknown returns true if Code is Unknown
  44. func (r ResponseVerifyVoteExtension) IsUnknown() bool {
  45. return r.Result == ResponseVerifyVoteExtension_UNKNOWN
  46. }
  47. // IsOK returns true if Code is OK
  48. func (r ResponseVerifyVoteExtension) IsOK() bool {
  49. return r.Result == ResponseVerifyVoteExtension_ACCEPT
  50. }
  51. // IsErr returns true if Code is something other than OK.
  52. func (r ResponseVerifyVoteExtension) IsErr() bool {
  53. return r.Result != ResponseVerifyVoteExtension_ACCEPT
  54. }
  55. //---------------------------------------------------------------------------
  56. // override JSON marshaling so we emit defaults (ie. disable omitempty)
  57. var (
  58. jsonpbMarshaller = jsonpb.Marshaler{
  59. EnumsAsInts: true,
  60. EmitDefaults: true,
  61. }
  62. jsonpbUnmarshaller = jsonpb.Unmarshaler{}
  63. )
  64. func (r *ResponseCheckTx) MarshalJSON() ([]byte, error) {
  65. s, err := jsonpbMarshaller.MarshalToString(r)
  66. return []byte(s), err
  67. }
  68. func (r *ResponseCheckTx) UnmarshalJSON(b []byte) error {
  69. reader := bytes.NewBuffer(b)
  70. return jsonpbUnmarshaller.Unmarshal(reader, r)
  71. }
  72. func (r *ResponseDeliverTx) MarshalJSON() ([]byte, error) {
  73. s, err := jsonpbMarshaller.MarshalToString(r)
  74. return []byte(s), err
  75. }
  76. func (r *ResponseDeliverTx) UnmarshalJSON(b []byte) error {
  77. reader := bytes.NewBuffer(b)
  78. return jsonpbUnmarshaller.Unmarshal(reader, r)
  79. }
  80. func (r *ResponseQuery) MarshalJSON() ([]byte, error) {
  81. s, err := jsonpbMarshaller.MarshalToString(r)
  82. return []byte(s), err
  83. }
  84. func (r *ResponseQuery) UnmarshalJSON(b []byte) error {
  85. reader := bytes.NewBuffer(b)
  86. return jsonpbUnmarshaller.Unmarshal(reader, r)
  87. }
  88. func (r *ResponseCommit) MarshalJSON() ([]byte, error) {
  89. s, err := jsonpbMarshaller.MarshalToString(r)
  90. return []byte(s), err
  91. }
  92. func (r *ResponseCommit) UnmarshalJSON(b []byte) error {
  93. reader := bytes.NewBuffer(b)
  94. return jsonpbUnmarshaller.Unmarshal(reader, r)
  95. }
  96. func (r *EventAttribute) MarshalJSON() ([]byte, error) {
  97. s, err := jsonpbMarshaller.MarshalToString(r)
  98. return []byte(s), err
  99. }
  100. func (r *EventAttribute) UnmarshalJSON(b []byte) error {
  101. reader := bytes.NewBuffer(b)
  102. return jsonpbUnmarshaller.Unmarshal(reader, r)
  103. }
  104. // Some compile time assertions to ensure we don't
  105. // have accidental runtime surprises later on.
  106. // jsonEncodingRoundTripper ensures that asserted
  107. // interfaces implement both MarshalJSON and UnmarshalJSON
  108. type jsonRoundTripper interface {
  109. json.Marshaler
  110. json.Unmarshaler
  111. }
  112. var _ jsonRoundTripper = (*ResponseCommit)(nil)
  113. var _ jsonRoundTripper = (*ResponseQuery)(nil)
  114. var _ jsonRoundTripper = (*ResponseDeliverTx)(nil)
  115. var _ jsonRoundTripper = (*ResponseCheckTx)(nil)
  116. var _ jsonRoundTripper = (*EventAttribute)(nil)
  117. // -----------------------------------------------
  118. // construct Result data
  119. func RespondExtendVote(appDataToSign, appDataSelfAuthenticating []byte) ResponseExtendVote {
  120. return ResponseExtendVote{
  121. VoteExtension: &types.VoteExtension{
  122. AppDataToSign: appDataToSign,
  123. AppDataSelfAuthenticating: appDataSelfAuthenticating,
  124. },
  125. }
  126. }
  127. func RespondVerifyVoteExtension(ok bool) ResponseVerifyVoteExtension {
  128. result := ResponseVerifyVoteExtension_REJECT
  129. if ok {
  130. result = ResponseVerifyVoteExtension_ACCEPT
  131. }
  132. return ResponseVerifyVoteExtension{
  133. Result: result,
  134. }
  135. }
  136. // deterministicExecTxResult constructs a copy of response that omits
  137. // non-deterministic fields. The input response is not modified.
  138. func deterministicExecTxResult(response *ExecTxResult) *ExecTxResult {
  139. return &ExecTxResult{
  140. Code: response.Code,
  141. Data: response.Data,
  142. GasWanted: response.GasWanted,
  143. GasUsed: response.GasUsed,
  144. }
  145. }
  146. // MarshalTxResults encodes the the TxResults as a list of byte
  147. // slices. It strips off the non-deterministic pieces of the TxResults
  148. // so that the resulting data can be used for hash comparisons and used
  149. // in Merkle proofs.
  150. func MarshalTxResults(r []*ExecTxResult) ([][]byte, error) {
  151. s := make([][]byte, len(r))
  152. for i, e := range r {
  153. d := deterministicExecTxResult(e)
  154. b, err := d.Marshal()
  155. if err != nil {
  156. return nil, err
  157. }
  158. s[i] = b
  159. }
  160. return s, nil
  161. }