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.

86 lines
3.0 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/types"
  5. )
  6. //------------------------------------------------------
  7. // blockchain services types
  8. // NOTE: Interfaces used by RPC must be thread safe!
  9. //------------------------------------------------------
  10. //------------------------------------------------------
  11. // mempool
  12. // Mempool defines the mempool interface as used by the ConsensusState.
  13. // Updates to the mempool need to be synchronized with committing a block
  14. // so apps can reset their transient state on Commit
  15. type Mempool interface {
  16. Lock()
  17. Unlock()
  18. Size() int
  19. CheckTx(types.Tx, func(*abci.Response)) error
  20. Reap(int) types.Txs
  21. Update(height int64, txs types.Txs) error
  22. Flush()
  23. FlushAppConn() error
  24. TxsAvailable() <-chan struct{}
  25. EnableTxsAvailable()
  26. }
  27. // MockMempool is an empty implementation of a Mempool, useful for testing.
  28. type MockMempool struct {
  29. }
  30. func (m MockMempool) Lock() {}
  31. func (m MockMempool) Unlock() {}
  32. func (m MockMempool) Size() int { return 0 }
  33. func (m MockMempool) CheckTx(tx types.Tx, cb func(*abci.Response)) error { return nil }
  34. func (m MockMempool) Reap(n int) types.Txs { return types.Txs{} }
  35. func (m MockMempool) Update(height int64, txs types.Txs) error { return nil }
  36. func (m MockMempool) Flush() {}
  37. func (m MockMempool) FlushAppConn() error { return nil }
  38. func (m MockMempool) TxsAvailable() <-chan struct{} { return make(chan struct{}) }
  39. func (m MockMempool) EnableTxsAvailable() {}
  40. //------------------------------------------------------
  41. // blockstore
  42. // BlockStoreRPC is the block store interface used by the RPC.
  43. type BlockStoreRPC interface {
  44. Height() int64
  45. LoadBlockMeta(height int64) *types.BlockMeta
  46. LoadBlock(height int64) *types.Block
  47. LoadBlockPart(height int64, index int) *types.Part
  48. LoadBlockCommit(height int64) *types.Commit
  49. LoadSeenCommit(height int64) *types.Commit
  50. }
  51. // BlockStore defines the BlockStore interface used by the ConsensusState.
  52. type BlockStore interface {
  53. BlockStoreRPC
  54. SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)
  55. }
  56. //-----------------------------------------------------------------------------------------------------
  57. // evidence pool
  58. // EvidencePool defines the EvidencePool interface used by the ConsensusState.
  59. type EvidencePool interface {
  60. PendingEvidence() []types.Evidence
  61. AddEvidence(types.Evidence) error
  62. Update(*types.Block, State)
  63. }
  64. // MockMempool is an empty implementation of a Mempool, useful for testing.
  65. type MockEvidencePool struct {
  66. }
  67. func (m MockEvidencePool) PendingEvidence() []types.Evidence { return nil }
  68. func (m MockEvidencePool) AddEvidence(types.Evidence) error { return nil }
  69. func (m MockEvidencePool) Update(*types.Block, State) {}