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.

102 lines
3.3 KiB

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