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.

65 lines
1.1 KiB

blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
  1. package v2
  2. import (
  3. "github.com/Workiva/go-datastructures/queue"
  4. )
  5. // Event is the type that can be added to the priority queue.
  6. type Event queue.Item
  7. type priority interface {
  8. Compare(other queue.Item) int
  9. Priority() int
  10. }
  11. type priorityLow struct{}
  12. type priorityNormal struct{}
  13. type priorityHigh struct{}
  14. func (p priorityLow) Priority() int {
  15. return 1
  16. }
  17. func (p priorityNormal) Priority() int {
  18. return 2
  19. }
  20. func (p priorityHigh) Priority() int {
  21. return 3
  22. }
  23. func (p priorityLow) Compare(other queue.Item) int {
  24. op := other.(priority)
  25. if p.Priority() > op.Priority() {
  26. return 1
  27. } else if p.Priority() == op.Priority() {
  28. return 0
  29. }
  30. return -1
  31. }
  32. func (p priorityNormal) Compare(other queue.Item) int {
  33. op := other.(priority)
  34. if p.Priority() > op.Priority() {
  35. return 1
  36. } else if p.Priority() == op.Priority() {
  37. return 0
  38. }
  39. return -1
  40. }
  41. func (p priorityHigh) Compare(other queue.Item) int {
  42. op := other.(priority)
  43. if p.Priority() > op.Priority() {
  44. return 1
  45. } else if p.Priority() == op.Priority() {
  46. return 0
  47. }
  48. return -1
  49. }
  50. type noOpEvent struct {
  51. priorityLow
  52. }
  53. var noOp = noOpEvent{}