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.

92 lines
2.7 KiB

  1. package consensus
  2. import (
  3. "context"
  4. abci "github.com/tendermint/tendermint/abci/types"
  5. "github.com/tendermint/tendermint/internal/libs/clist"
  6. mempl "github.com/tendermint/tendermint/internal/mempool"
  7. tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
  8. "github.com/tendermint/tendermint/proxy"
  9. "github.com/tendermint/tendermint/types"
  10. )
  11. //-----------------------------------------------------------------------------
  12. type emptyMempool struct{}
  13. var _ mempl.Mempool = emptyMempool{}
  14. func (emptyMempool) Lock() {}
  15. func (emptyMempool) Unlock() {}
  16. func (emptyMempool) Size() int { return 0 }
  17. func (emptyMempool) CheckTx(_ context.Context, _ types.Tx, _ func(*abci.Response), _ mempl.TxInfo) error {
  18. return nil
  19. }
  20. func (emptyMempool) ReapMaxBytesMaxGas(_, _ int64) types.Txs { return types.Txs{} }
  21. func (emptyMempool) ReapMaxTxs(n int) types.Txs { return types.Txs{} }
  22. func (emptyMempool) Update(
  23. _ int64,
  24. _ types.Txs,
  25. _ []*abci.ResponseDeliverTx,
  26. _ mempl.PreCheckFunc,
  27. _ mempl.PostCheckFunc,
  28. ) error {
  29. return nil
  30. }
  31. func (emptyMempool) Flush() {}
  32. func (emptyMempool) FlushAppConn() error { return nil }
  33. func (emptyMempool) TxsAvailable() <-chan struct{} { return make(chan struct{}) }
  34. func (emptyMempool) EnableTxsAvailable() {}
  35. func (emptyMempool) SizeBytes() int64 { return 0 }
  36. func (emptyMempool) TxsFront() *clist.CElement { return nil }
  37. func (emptyMempool) TxsWaitChan() <-chan struct{} { return nil }
  38. func (emptyMempool) InitWAL() error { return nil }
  39. func (emptyMempool) CloseWAL() {}
  40. //-----------------------------------------------------------------------------
  41. // mockProxyApp uses ABCIResponses to give the right results.
  42. //
  43. // Useful because we don't want to call Commit() twice for the same block on
  44. // the real app.
  45. func newMockProxyApp(appHash []byte, abciResponses *tmstate.ABCIResponses) proxy.AppConnConsensus {
  46. clientCreator := proxy.NewLocalClientCreator(&mockProxyApp{
  47. appHash: appHash,
  48. abciResponses: abciResponses,
  49. })
  50. cli, _ := clientCreator.NewABCIClient()
  51. err := cli.Start()
  52. if err != nil {
  53. panic(err)
  54. }
  55. return proxy.NewAppConnConsensus(cli)
  56. }
  57. type mockProxyApp struct {
  58. abci.BaseApplication
  59. appHash []byte
  60. txCount int
  61. abciResponses *tmstate.ABCIResponses
  62. }
  63. func (mock *mockProxyApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
  64. r := mock.abciResponses.DeliverTxs[mock.txCount]
  65. mock.txCount++
  66. if r == nil {
  67. return abci.ResponseDeliverTx{}
  68. }
  69. return *r
  70. }
  71. func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock {
  72. mock.txCount = 0
  73. return *mock.abciResponses.EndBlock
  74. }
  75. func (mock *mockProxyApp) Commit() abci.ResponseCommit {
  76. return abci.ResponseCommit{Data: mock.appHash}
  77. }