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.

47 lines
1.7 KiB

  1. ---
  2. order: 3
  3. ---
  4. # Implementation
  5. ## Blocksync Reactor
  6. - coordinates the pool for syncing
  7. - coordinates the store for persistence
  8. - coordinates the playing of blocks towards the app using a sm.BlockExecutor
  9. - handles switching between fastsync and consensus
  10. - it is a p2p.BaseReactor
  11. - starts the pool.Start() and its poolRoutine()
  12. - registers all the concrete types and interfaces for serialisation
  13. ### poolRoutine
  14. - listens to these channels:
  15. - pool requests blocks from a specific peer by posting to requestsCh, block reactor then sends
  16. a &bcBlockRequestMessage for a specific height
  17. - pool signals timeout of a specific peer by posting to timeoutsCh
  18. - switchToConsensusTicker to periodically try and switch to consensus
  19. - trySyncTicker to periodically check if we have fallen behind and then catch-up sync
  20. - if there aren't any new blocks available on the pool it skips syncing
  21. - tries to sync the app by taking downloaded blocks from the pool, gives them to the app and stores
  22. them on disk
  23. - implements Receive which is called by the switch/peer
  24. - calls AddBlock on the pool when it receives a new block from a peer
  25. ## Block Pool
  26. - responsible for downloading blocks from peers
  27. - makeRequestersRoutine()
  28. - removes timeout peers
  29. - starts new requesters by calling makeNextRequester()
  30. - requestRoutine():
  31. - picks a peer and sends the request, then blocks until:
  32. - pool is stopped by listening to pool.Quit
  33. - requester is stopped by listening to Quit
  34. - request is redone
  35. - we receive a block
  36. - gotBlockCh is strange
  37. ## Go Routines in Blocksync Reactor
  38. ![Go Routines Diagram](img/bc-reactor-routines.png)