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.

213 lines
5.5 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. func (r ResponsePrepareProposal) IsTxStatusUnknown() bool {
  44. return r.ModifiedTxStatus == ResponsePrepareProposal_UNKNOWN
  45. }
  46. func (r ResponsePrepareProposal) IsTxStatusModified() bool {
  47. return r.ModifiedTxStatus == ResponsePrepareProposal_MODIFIED
  48. }
  49. func (r ResponseProcessProposal) IsAccepted() bool {
  50. return r.Status == ResponseProcessProposal_ACCEPT
  51. }
  52. func (r ResponseProcessProposal) IsStatusUnknown() bool {
  53. return r.Status == ResponseProcessProposal_UNKNOWN
  54. }
  55. // IsStatusUnknown returns true if Code is Unknown
  56. func (r ResponseVerifyVoteExtension) IsStatusUnknown() bool {
  57. return r.Status == ResponseVerifyVoteExtension_UNKNOWN
  58. }
  59. // IsOK returns true if Code is OK
  60. func (r ResponseVerifyVoteExtension) IsOK() bool {
  61. return r.Status == ResponseVerifyVoteExtension_ACCEPT
  62. }
  63. // IsErr returns true if Code is something other than OK.
  64. func (r ResponseVerifyVoteExtension) IsErr() bool {
  65. return r.Status != ResponseVerifyVoteExtension_ACCEPT
  66. }
  67. //---------------------------------------------------------------------------
  68. // override JSON marshaling so we emit defaults (ie. disable omitempty)
  69. var (
  70. jsonpbMarshaller = jsonpb.Marshaler{
  71. EnumsAsInts: true,
  72. EmitDefaults: true,
  73. }
  74. jsonpbUnmarshaller = jsonpb.Unmarshaler{}
  75. )
  76. func (r *ResponseCheckTx) MarshalJSON() ([]byte, error) {
  77. s, err := jsonpbMarshaller.MarshalToString(r)
  78. return []byte(s), err
  79. }
  80. func (r *ResponseCheckTx) UnmarshalJSON(b []byte) error {
  81. reader := bytes.NewBuffer(b)
  82. return jsonpbUnmarshaller.Unmarshal(reader, r)
  83. }
  84. func (r *ResponseDeliverTx) MarshalJSON() ([]byte, error) {
  85. s, err := jsonpbMarshaller.MarshalToString(r)
  86. return []byte(s), err
  87. }
  88. func (r *ResponseDeliverTx) UnmarshalJSON(b []byte) error {
  89. reader := bytes.NewBuffer(b)
  90. return jsonpbUnmarshaller.Unmarshal(reader, r)
  91. }
  92. func (r *ResponseQuery) MarshalJSON() ([]byte, error) {
  93. s, err := jsonpbMarshaller.MarshalToString(r)
  94. return []byte(s), err
  95. }
  96. func (r *ResponseQuery) UnmarshalJSON(b []byte) error {
  97. reader := bytes.NewBuffer(b)
  98. return jsonpbUnmarshaller.Unmarshal(reader, r)
  99. }
  100. func (r *ResponseCommit) MarshalJSON() ([]byte, error) {
  101. s, err := jsonpbMarshaller.MarshalToString(r)
  102. return []byte(s), err
  103. }
  104. func (r *ResponseCommit) UnmarshalJSON(b []byte) error {
  105. reader := bytes.NewBuffer(b)
  106. return jsonpbUnmarshaller.Unmarshal(reader, r)
  107. }
  108. func (r *EventAttribute) MarshalJSON() ([]byte, error) {
  109. s, err := jsonpbMarshaller.MarshalToString(r)
  110. return []byte(s), err
  111. }
  112. func (r *EventAttribute) UnmarshalJSON(b []byte) error {
  113. reader := bytes.NewBuffer(b)
  114. return jsonpbUnmarshaller.Unmarshal(reader, r)
  115. }
  116. // Some compile time assertions to ensure we don't
  117. // have accidental runtime surprises later on.
  118. // jsonEncodingRoundTripper ensures that asserted
  119. // interfaces implement both MarshalJSON and UnmarshalJSON
  120. type jsonRoundTripper interface {
  121. json.Marshaler
  122. json.Unmarshaler
  123. }
  124. var _ jsonRoundTripper = (*ResponseCommit)(nil)
  125. var _ jsonRoundTripper = (*ResponseQuery)(nil)
  126. var _ jsonRoundTripper = (*ResponseDeliverTx)(nil)
  127. var _ jsonRoundTripper = (*ResponseCheckTx)(nil)
  128. var _ jsonRoundTripper = (*EventAttribute)(nil)
  129. // -----------------------------------------------
  130. // construct Result data
  131. func RespondExtendVote(appDataToSign, appDataSelfAuthenticating []byte) ResponseExtendVote {
  132. return ResponseExtendVote{
  133. VoteExtension: &types.VoteExtension{
  134. AppDataToSign: appDataToSign,
  135. AppDataSelfAuthenticating: appDataSelfAuthenticating,
  136. },
  137. }
  138. }
  139. func RespondVerifyVoteExtension(ok bool) ResponseVerifyVoteExtension {
  140. status := ResponseVerifyVoteExtension_REJECT
  141. if ok {
  142. status = ResponseVerifyVoteExtension_ACCEPT
  143. }
  144. return ResponseVerifyVoteExtension{
  145. Status: status,
  146. }
  147. }
  148. // deterministicExecTxResult constructs a copy of response that omits
  149. // non-deterministic fields. The input response is not modified.
  150. func deterministicExecTxResult(response *ExecTxResult) *ExecTxResult {
  151. return &ExecTxResult{
  152. Code: response.Code,
  153. Data: response.Data,
  154. GasWanted: response.GasWanted,
  155. GasUsed: response.GasUsed,
  156. }
  157. }
  158. // MarshalTxResults encodes the the TxResults as a list of byte
  159. // slices. It strips off the non-deterministic pieces of the TxResults
  160. // so that the resulting data can be used for hash comparisons and used
  161. // in Merkle proofs.
  162. func MarshalTxResults(r []*ExecTxResult) ([][]byte, error) {
  163. s := make([][]byte, len(r))
  164. for i, e := range r {
  165. d := deterministicExecTxResult(e)
  166. b, err := d.Marshal()
  167. if err != nil {
  168. return nil, err
  169. }
  170. s[i] = b
  171. }
  172. return s, nil
  173. }