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.

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