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.

84 lines
3.2 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. ReapMaxBytes(max int) types.Txs
  21. Update(height int64, txs types.Txs, filter func(types.Tx) bool) 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. func (MockMempool) Lock() {}
  30. func (MockMempool) Unlock() {}
  31. func (MockMempool) Size() int { return 0 }
  32. func (MockMempool) CheckTx(tx types.Tx, cb func(*abci.Response)) error { return nil }
  33. func (MockMempool) ReapMaxBytes(max int) types.Txs { return types.Txs{} }
  34. func (MockMempool) Update(height int64, txs types.Txs, filter func(types.Tx) bool) error { return nil }
  35. func (MockMempool) Flush() {}
  36. func (MockMempool) FlushAppConn() error { return nil }
  37. func (MockMempool) TxsAvailable() <-chan struct{} { return make(chan struct{}) }
  38. func (MockMempool) EnableTxsAvailable() {}
  39. //------------------------------------------------------
  40. // blockstore
  41. // BlockStoreRPC is the block store interface used by the RPC.
  42. type BlockStoreRPC interface {
  43. Height() int64
  44. LoadBlockMeta(height int64) *types.BlockMeta
  45. LoadBlock(height int64) *types.Block
  46. LoadBlockPart(height int64, index int) *types.Part
  47. LoadBlockCommit(height int64) *types.Commit
  48. LoadSeenCommit(height int64) *types.Commit
  49. }
  50. // BlockStore defines the BlockStore interface used by the ConsensusState.
  51. type BlockStore interface {
  52. BlockStoreRPC
  53. SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)
  54. }
  55. //-----------------------------------------------------------------------------------------------------
  56. // evidence pool
  57. // EvidencePool defines the EvidencePool interface used by the ConsensusState.
  58. type EvidencePool interface {
  59. PendingEvidence(int) []types.Evidence
  60. AddEvidence(types.Evidence) error
  61. Update(*types.Block, State)
  62. }
  63. // MockMempool is an empty implementation of a Mempool, useful for testing.
  64. type MockEvidencePool struct{}
  65. func (m MockEvidencePool) PendingEvidence(int) []types.Evidence { return nil }
  66. func (m MockEvidencePool) AddEvidence(types.Evidence) error { return nil }
  67. func (m MockEvidencePool) Update(*types.Block, State) {}