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.

105 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. tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
  7. "github.com/tendermint/tendermint/proxy"
  8. sm "github.com/tendermint/tendermint/state"
  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(_ 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) TxsBytes() 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. type emptyEvidencePool struct{}
  42. var _ sm.EvidencePool = emptyEvidencePool{}
  43. func (emptyEvidencePool) PendingEvidence(uint32) []types.Evidence { return nil }
  44. func (emptyEvidencePool) AddEvidence(types.Evidence) error { return nil }
  45. func (emptyEvidencePool) Update(*types.Block, sm.State) {}
  46. func (emptyEvidencePool) IsCommitted(types.Evidence) bool { return false }
  47. func (emptyEvidencePool) IsPending(types.Evidence) bool { return false }
  48. func (emptyEvidencePool) AddPOLC(types.ProofOfLockChange) error { return nil }
  49. func (emptyEvidencePool) Header(int64) *types.Header { return nil }
  50. //-----------------------------------------------------------------------------
  51. // mockProxyApp uses ABCIResponses to give the right results.
  52. //
  53. // Useful because we don't want to call Commit() twice for the same block on
  54. // the real app.
  55. func newMockProxyApp(appHash []byte, abciResponses *tmstate.ABCIResponses) proxy.AppConnConsensus {
  56. clientCreator := proxy.NewLocalClientCreator(&mockProxyApp{
  57. appHash: appHash,
  58. abciResponses: abciResponses,
  59. })
  60. cli, _ := clientCreator.NewABCIClient()
  61. err := cli.Start()
  62. if err != nil {
  63. panic(err)
  64. }
  65. return proxy.NewAppConnConsensus(cli)
  66. }
  67. type mockProxyApp struct {
  68. abci.BaseApplication
  69. appHash []byte
  70. txCount int
  71. abciResponses *tmstate.ABCIResponses
  72. }
  73. func (mock *mockProxyApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
  74. r := mock.abciResponses.DeliverTxs[mock.txCount]
  75. mock.txCount++
  76. if r == nil {
  77. return abci.ResponseDeliverTx{}
  78. }
  79. return *r
  80. }
  81. func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock {
  82. mock.txCount = 0
  83. return *mock.abciResponses.EndBlock
  84. }
  85. func (mock *mockProxyApp) Commit() abci.ResponseCommit {
  86. return abci.ResponseCommit{Data: mock.appHash}
  87. }