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.

90 lines
2.7 KiB

7 years ago
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 testsuite
  2. import (
  3. "bytes"
  4. "context"
  5. "errors"
  6. "fmt"
  7. mrand "math/rand"
  8. abciclient "github.com/tendermint/tendermint/abci/client"
  9. "github.com/tendermint/tendermint/abci/types"
  10. tmrand "github.com/tendermint/tendermint/libs/rand"
  11. )
  12. func InitChain(ctx context.Context, client abciclient.Client) error {
  13. total := 10
  14. vals := make([]types.ValidatorUpdate, total)
  15. for i := 0; i < total; i++ {
  16. pubkey := tmrand.Bytes(33)
  17. // nolint:gosec // G404: Use of weak random number generator
  18. power := mrand.Int()
  19. vals[i] = types.UpdateValidator(pubkey, int64(power), "")
  20. }
  21. _, err := client.InitChain(ctx, types.RequestInitChain{
  22. Validators: vals,
  23. })
  24. if err != nil {
  25. fmt.Printf("Failed test: InitChain - %v\n", err)
  26. return err
  27. }
  28. fmt.Println("Passed test: InitChain")
  29. return nil
  30. }
  31. func Commit(ctx context.Context, client abciclient.Client, hashExp []byte) error {
  32. res, err := client.Commit(ctx)
  33. data := res.Data
  34. if err != nil {
  35. fmt.Println("Failed test: Commit")
  36. fmt.Printf("error while committing: %v\n", err)
  37. return err
  38. }
  39. if !bytes.Equal(data, hashExp) {
  40. fmt.Println("Failed test: Commit")
  41. fmt.Printf("Commit hash was unexpected. Got %X expected %X\n", data, hashExp)
  42. return errors.New("commitTx failed")
  43. }
  44. fmt.Println("Passed test: Commit")
  45. return nil
  46. }
  47. func FinalizeBlock(ctx context.Context, client abciclient.Client, txBytes [][]byte, codeExp []uint32, dataExp []byte) error {
  48. res, _ := client.FinalizeBlock(ctx, types.RequestFinalizeBlock{Txs: txBytes})
  49. for i, tx := range res.TxResults {
  50. code, data, log := tx.Code, tx.Data, tx.Log
  51. if code != codeExp[i] {
  52. fmt.Println("Failed test: FinalizeBlock")
  53. fmt.Printf("FinalizeBlock response code was unexpected. Got %v expected %v. Log: %v\n",
  54. code, codeExp, log)
  55. return errors.New("FinalizeBlock error")
  56. }
  57. if !bytes.Equal(data, dataExp) {
  58. fmt.Println("Failed test: FinalizeBlock")
  59. fmt.Printf("FinalizeBlock response data was unexpected. Got %X expected %X\n",
  60. data, dataExp)
  61. return errors.New("FinalizeBlock error")
  62. }
  63. }
  64. fmt.Println("Passed test: FinalizeBlock")
  65. return nil
  66. }
  67. func CheckTx(ctx context.Context, client abciclient.Client, txBytes []byte, codeExp uint32, dataExp []byte) error {
  68. res, _ := client.CheckTx(ctx, types.RequestCheckTx{Tx: txBytes})
  69. code, data, log := res.Code, res.Data, res.Log
  70. if code != codeExp {
  71. fmt.Println("Failed test: CheckTx")
  72. fmt.Printf("CheckTx response code was unexpected. Got %v expected %v. Log: %v\n",
  73. code, codeExp, log)
  74. return errors.New("checkTx")
  75. }
  76. if !bytes.Equal(data, dataExp) {
  77. fmt.Println("Failed test: CheckTx")
  78. fmt.Printf("CheckTx response data was unexpected. Got %X expected %X\n",
  79. data, dataExp)
  80. return errors.New("checkTx")
  81. }
  82. fmt.Println("Passed test: CheckTx")
  83. return nil
  84. }