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.

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