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.

103 lines
3.4 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(uint32) []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. func (emptyEvidencePool) AddPOLC(types.ProofOfLockChange) error { return nil }
  48. //-----------------------------------------------------------------------------
  49. // mockProxyApp uses ABCIResponses to give the right results.
  50. //
  51. // Useful because we don't want to call Commit() twice for the same block on
  52. // the real app.
  53. func newMockProxyApp(appHash []byte, abciResponses *sm.ABCIResponses) proxy.AppConnConsensus {
  54. clientCreator := proxy.NewLocalClientCreator(&mockProxyApp{
  55. appHash: appHash,
  56. abciResponses: abciResponses,
  57. })
  58. cli, _ := clientCreator.NewABCIClient()
  59. err := cli.Start()
  60. if err != nil {
  61. panic(err)
  62. }
  63. return proxy.NewAppConnConsensus(cli)
  64. }
  65. type mockProxyApp struct {
  66. abci.BaseApplication
  67. appHash []byte
  68. txCount int
  69. abciResponses *sm.ABCIResponses
  70. }
  71. func (mock *mockProxyApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
  72. r := mock.abciResponses.DeliverTxs[mock.txCount]
  73. mock.txCount++
  74. if r == nil { //it could be nil because of amino unMarshall, it will cause an empty ResponseDeliverTx to become nil
  75. return abci.ResponseDeliverTx{}
  76. }
  77. return *r
  78. }
  79. func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock {
  80. mock.txCount = 0
  81. return *mock.abciResponses.EndBlock
  82. }
  83. func (mock *mockProxyApp) Commit() abci.ResponseCommit {
  84. return abci.ResponseCommit{Data: mock.appHash}
  85. }