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.

98 lines
3.3 KiB

7 years ago
7 years ago
7 years ago
  1. package state
  2. import (
  3. abci "github.com/tendermint/tendermint/abci/types"
  4. "github.com/tendermint/tendermint/mempool"
  5. "github.com/tendermint/tendermint/types"
  6. )
  7. //------------------------------------------------------
  8. // blockchain services types
  9. // NOTE: Interfaces used by RPC must be thread safe!
  10. //------------------------------------------------------
  11. //------------------------------------------------------
  12. // mempool
  13. // Mempool defines the mempool interface as used by the ConsensusState.
  14. // Updates to the mempool need to be synchronized with committing a block
  15. // so apps can reset their transient state on Commit
  16. type Mempool interface {
  17. Lock()
  18. Unlock()
  19. Size() int
  20. CheckTx(types.Tx, func(*abci.Response)) error
  21. ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs
  22. Update(int64, types.Txs, mempool.PreCheckFunc, mempool.PostCheckFunc) error
  23. Flush()
  24. FlushAppConn() error
  25. TxsAvailable() <-chan struct{}
  26. EnableTxsAvailable()
  27. }
  28. // MockMempool is an empty implementation of a Mempool, useful for testing.
  29. type MockMempool struct{}
  30. var _ Mempool = MockMempool{}
  31. func (MockMempool) Lock() {}
  32. func (MockMempool) Unlock() {}
  33. func (MockMempool) Size() int { return 0 }
  34. func (MockMempool) CheckTx(_ types.Tx, _ func(*abci.Response)) error { return nil }
  35. func (MockMempool) ReapMaxBytesMaxGas(_, _ int64) types.Txs { return types.Txs{} }
  36. func (MockMempool) Update(
  37. _ int64,
  38. _ types.Txs,
  39. _ mempool.PreCheckFunc,
  40. _ mempool.PostCheckFunc,
  41. ) error {
  42. return nil
  43. }
  44. func (MockMempool) Flush() {}
  45. func (MockMempool) FlushAppConn() error { return nil }
  46. func (MockMempool) TxsAvailable() <-chan struct{} { return make(chan struct{}) }
  47. func (MockMempool) EnableTxsAvailable() {}
  48. //------------------------------------------------------
  49. // blockstore
  50. // BlockStoreRPC is the block store interface used by the RPC.
  51. type BlockStoreRPC interface {
  52. Height() int64
  53. LoadBlockMeta(height int64) *types.BlockMeta
  54. LoadBlock(height int64) *types.Block
  55. LoadBlockPart(height int64, index int) *types.Part
  56. LoadBlockCommit(height int64) *types.Commit
  57. LoadSeenCommit(height int64) *types.Commit
  58. }
  59. // BlockStore defines the BlockStore interface used by the ConsensusState.
  60. type BlockStore interface {
  61. BlockStoreRPC
  62. SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)
  63. }
  64. //-----------------------------------------------------------------------------------------------------
  65. // evidence pool
  66. // EvidencePool defines the EvidencePool interface used by the ConsensusState.
  67. // Get/Set/Commit
  68. type EvidencePool interface {
  69. PendingEvidence(int64) []types.Evidence
  70. AddEvidence(types.Evidence) error
  71. Update(*types.Block, State)
  72. // IsCommitted indicates if this evidence was already marked committed in another block.
  73. IsCommitted(types.Evidence) bool
  74. }
  75. // MockMempool is an empty implementation of a Mempool, useful for testing.
  76. type MockEvidencePool struct{}
  77. func (m MockEvidencePool) PendingEvidence(int64) []types.Evidence { return nil }
  78. func (m MockEvidencePool) AddEvidence(types.Evidence) error { return nil }
  79. func (m MockEvidencePool) Update(*types.Block, State) {}
  80. func (m MockEvidencePool) IsCommitted(types.Evidence) bool { return false }