Skip to content

implement initial sync from latest block to genesis block #97

Closed
@thepiwo

Description

@thepiwo

#88 has to be finished first
only do this in pair programming

  • blocks sync:
    1. ask random peers about top and get top block of random peer(s) if we don't have it
    2. for every block that we don't know the parent ask random peers for parent. Optional: mark block as "bad" if no-one can provide it's parent
    • for every block we get in i., ii.:
      a. "single" validate transactions without chainstate, coinbase sum, version and root_hash(discard if invalid)
      b. get parent if we don't have parent
    1. for every "single" validated block that has not been "fully" validated:
      a. if parent is not validate. Validate parent.
      b. If parent does not exist skip.
      c. validate the block
    2. compare height of topmost block with chainstate height. If it's higher advance chainstate:
      a. generate list of block between chainstate and highest block by traversing from top. If you find an marked as "invalid" block, mark all of it's children as invalid. (all blocks from top block to that block including top)
      b. if you get to genesis while looking for chainstate block: regenerate chainstate from genesis. (We have to have some chainstate snapshots in future to avoid that)
      c. validate blocks in order beginning with child of chainstate block. Update chainstate while doing that.
      d. if validation fails at one point mark the block as "invalid" and mark all it's children as "invalid".
      e. if validation failed at one point try again to get the topmost block and if it's not chainstate block try to advance chainstate as above described.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions