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.

44 lines
1.6 KiB

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