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.

76 lines
2.2 KiB

  1. package v2
  2. import (
  3. "fmt"
  4. "github.com/tendermint/tendermint/state"
  5. "github.com/tendermint/tendermint/store"
  6. "github.com/tendermint/tendermint/types"
  7. )
  8. type processorContext interface {
  9. applyBlock(state state.State, blockID types.BlockID, block *types.Block) (state.State, error)
  10. verifyCommit(chainID string, blockID types.BlockID, height int64, commit *types.Commit) error
  11. saveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)
  12. }
  13. // nolint:unused
  14. type pContext struct {
  15. store *store.BlockStore
  16. executor *state.BlockExecutor
  17. state *state.State
  18. }
  19. // nolint:unused,deadcode
  20. func newProcessorContext(st *store.BlockStore, ex *state.BlockExecutor, s *state.State) *pContext {
  21. return &pContext{
  22. store: st,
  23. executor: ex,
  24. state: s,
  25. }
  26. }
  27. func (pc *pContext) applyBlock(state state.State, blockID types.BlockID, block *types.Block) (state.State, error) {
  28. return pc.executor.ApplyBlock(state, blockID, block)
  29. }
  30. func (pc *pContext) verifyCommit(chainID string, blockID types.BlockID, height int64, commit *types.Commit) error {
  31. return pc.state.Validators.VerifyCommit(chainID, blockID, height, commit)
  32. }
  33. func (pc *pContext) saveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) {
  34. pc.store.SaveBlock(block, blockParts, seenCommit)
  35. }
  36. type mockPContext struct {
  37. applicationBL []int64
  38. verificationBL []int64
  39. }
  40. func newMockProcessorContext(verificationBlackList []int64, applicationBlackList []int64) *mockPContext {
  41. return &mockPContext{
  42. applicationBL: applicationBlackList,
  43. verificationBL: verificationBlackList,
  44. }
  45. }
  46. func (mpc *mockPContext) applyBlock(state state.State, blockID types.BlockID, block *types.Block) (state.State, error) {
  47. for _, h := range mpc.applicationBL {
  48. if h == block.Height {
  49. return state, fmt.Errorf("generic application error")
  50. }
  51. }
  52. return state, nil
  53. }
  54. func (mpc *mockPContext) verifyCommit(chainID string, blockID types.BlockID, height int64, commit *types.Commit) error {
  55. for _, h := range mpc.verificationBL {
  56. if h == height {
  57. return fmt.Errorf("generic verification error")
  58. }
  59. }
  60. return nil
  61. }
  62. func (mpc *mockPContext) saveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) {
  63. }