Skip to content

Commit

Permalink
Fix block pool at genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim authored and arnetheduck committed Mar 12, 2019
1 parent 1cb0a4f commit da44c89
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion beacon_chain/beacon_chain_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import

type
BeaconChainDB* = ref object
## DB of finalized blocks
backend: TrieDatabaseRef

DbKeyKind = enum
kHashToState
kHashToBlock
kHeadBlock # Pointer to the most recent block seen
kHeadBlock # Pointer to the most recent finalized block seen
kTailBlock # Pointer to the earliest finalized block

func subkey(kind: DbKeyKind): array[1, byte] =
Expand Down
8 changes: 7 additions & 1 deletion beacon_chain/block_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ proc init*(T: type BlockPool, db: BeaconChainDB): BlockPool =

let
tail = db.getTailBlock()
head = db.getHeadBlock()
head = db.getHeadBlock() # Note: we assume only finalized blocks are in DB

doAssert tail.isSome(), "Missing tail block, database corrupt?"
doAssert head.isSome(), "Missing head block, database corrupt?"

let
headRoot = head.get()
headBlock = db.getBlock(headRoot)
headRef = BlockRef.init(headRoot, headBlock.get())
tailRoot = tail.get()
tailBlock = db.getBlock(tailRoot)
tailRef = BlockRef.init(tailRoot, tailBlock.get())
Expand Down Expand Up @@ -76,6 +78,10 @@ proc init*(T: type BlockPool, db: BeaconChainDB): BlockPool =
data: db.getBlock(tailRef.root).get(),
refs: tailRef,
),
finalizedHead: BlockData(
data: db.getBlock(headRef.root).get(),
refs: headRef,
),
db: db
)

Expand Down

0 comments on commit da44c89

Please sign in to comment.