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.

37 lines
1.3 KiB

  1. The blockchain is stored as follows, assuming genesis block is stored
  2. each block has a single child to store main chain
  3. each block can have multiple children to store numerous blocks as alternative
  4. each block stores the following extra info
  5. 1) height
  6. 2) single parent
  7. 3) cumulative difficulty
  8. 4) size of block ( size of all transactions included within block + size of block )
  9. 5) timestamp
  10. 6) cumulative coins
  11. 7) block blob itself
  12. 8) child
  13. 9) multiple children ( alternative or orphan blocks )
  14. storing block mean storing all attributes except child/children
  15. connecting a block means setting child/children attributes properly
  16. imagine the chain as a doubly linked list, with traversal possible using blockids as ptrs
  17. the psedo code is as follows
  18. 1) verify incoming blockor semantic errors
  19. 2) verify block pow
  20. 3) verify each and every transaction for correctnes
  21. 4) store the transactions
  22. 5) store the block, height, cumulative difficulty, coins emission etc
  23. 6) check whether block is the new top,
  24. 7) if yes,update main chain
  25. 8) if not we have to do chain reorganisation at the top
  26. 9) choose the block with higher poW as new top
  27. 10) push alt chain txs to mem pool
  28. 11) if block is being added somewhere in the middle, find the chain with higher Pow as main chain
  29. 12) push the orphan block txs to mempool