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.

146 lines
4.4 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 mempool
  2. import (
  3. "context"
  4. "fmt"
  5. "math"
  6. abci "github.com/tendermint/tendermint/abci/types"
  7. "github.com/tendermint/tendermint/internal/p2p"
  8. "github.com/tendermint/tendermint/types"
  9. )
  10. const (
  11. MempoolChannel = p2p.ChannelID(0x30)
  12. // PeerCatchupSleepIntervalMS defines how much time to sleep if a peer is behind
  13. PeerCatchupSleepIntervalMS = 100
  14. // UnknownPeerID is the peer ID to use when running CheckTx when there is
  15. // no peer (e.g. RPC)
  16. UnknownPeerID uint16 = 0
  17. MaxActiveIDs = math.MaxUint16
  18. )
  19. //go:generate ../../scripts/mockery_generate.sh Mempool
  20. // Mempool defines the mempool interface.
  21. //
  22. // Updates to the mempool need to be synchronized with committing a block so
  23. // applications can reset their transient state on Commit.
  24. type Mempool interface {
  25. // CheckTx executes a new transaction against the application to determine
  26. // its validity and whether it should be added to the mempool.
  27. CheckTx(ctx context.Context, tx types.Tx, callback func(*abci.ResponseCheckTx), txInfo TxInfo) error
  28. // RemoveTxByKey removes a transaction, identified by its key,
  29. // from the mempool.
  30. RemoveTxByKey(txKey types.TxKey) error
  31. // ReapMaxBytesMaxGas reaps transactions from the mempool up to maxBytes
  32. // bytes total with the condition that the total gasWanted must be less than
  33. // maxGas.
  34. //
  35. // If both maxes are negative, there is no cap on the size of all returned
  36. // transactions (~ all available transactions).
  37. ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs
  38. // ReapMaxTxs reaps up to max transactions from the mempool. If max is
  39. // negative, there is no cap on the size of all returned transactions
  40. // (~ all available transactions).
  41. ReapMaxTxs(max int) types.Txs
  42. // Lock locks the mempool. The consensus must be able to hold lock to safely
  43. // update.
  44. Lock()
  45. // Unlock unlocks the mempool.
  46. Unlock()
  47. // Update informs the mempool that the given txs were committed and can be
  48. // discarded.
  49. //
  50. // NOTE:
  51. // 1. This should be called *after* block is committed by consensus.
  52. // 2. Lock/Unlock must be managed by the caller.
  53. Update(
  54. ctx context.Context,
  55. blockHeight int64,
  56. blockTxs types.Txs,
  57. txResults []*abci.ExecTxResult,
  58. newPreFn PreCheckFunc,
  59. newPostFn PostCheckFunc,
  60. ) error
  61. // FlushAppConn flushes the mempool connection to ensure async callback calls
  62. // are done, e.g. from CheckTx.
  63. //
  64. // NOTE:
  65. // 1. Lock/Unlock must be managed by caller.
  66. FlushAppConn(context.Context) error
  67. // Flush removes all transactions from the mempool and caches.
  68. Flush()
  69. // TxsAvailable returns a channel which fires once for every height, and only
  70. // when transactions are available in the mempool.
  71. //
  72. // NOTE:
  73. // 1. The returned channel may be nil if EnableTxsAvailable was not called.
  74. TxsAvailable() <-chan struct{}
  75. // EnableTxsAvailable initializes the TxsAvailable channel, ensuring it will
  76. // trigger once every height when transactions are available.
  77. EnableTxsAvailable()
  78. // Size returns the number of transactions in the mempool.
  79. Size() int
  80. // SizeBytes returns the total size of all txs in the mempool.
  81. SizeBytes() int64
  82. }
  83. // PreCheckFunc is an optional filter executed before CheckTx and rejects
  84. // transaction if false is returned. An example would be to ensure that a
  85. // transaction doesn't exceeded the block size.
  86. type PreCheckFunc func(types.Tx) error
  87. // PostCheckFunc is an optional filter executed after CheckTx and rejects
  88. // transaction if false is returned. An example would be to ensure a
  89. // transaction doesn't require more gas than available for the block.
  90. type PostCheckFunc func(types.Tx, *abci.ResponseCheckTx) error
  91. // PreCheckMaxBytes checks that the size of the transaction is smaller or equal
  92. // to the expected maxBytes.
  93. func PreCheckMaxBytes(maxBytes int64) PreCheckFunc {
  94. return func(tx types.Tx) error {
  95. txSize := types.ComputeProtoSizeForTxs([]types.Tx{tx})
  96. if txSize > maxBytes {
  97. return fmt.Errorf("tx size is too big: %d, max: %d", txSize, maxBytes)
  98. }
  99. return nil
  100. }
  101. }
  102. // PostCheckMaxGas checks that the wanted gas is smaller or equal to the passed
  103. // maxGas. Returns nil if maxGas is -1.
  104. func PostCheckMaxGas(maxGas int64) PostCheckFunc {
  105. return func(tx types.Tx, res *abci.ResponseCheckTx) error {
  106. if maxGas == -1 {
  107. return nil
  108. }
  109. if res.GasWanted < 0 {
  110. return fmt.Errorf("gas wanted %d is negative",
  111. res.GasWanted)
  112. }
  113. if res.GasWanted > maxGas {
  114. return fmt.Errorf("gas wanted %d is greater than max gas %d",
  115. res.GasWanted, maxGas)
  116. }
  117. return nil
  118. }
  119. }