Skip to content

Commit d852cf1

Browse files
committed
Initialize SyncDag with genesis root/slot to avoid downloading.
1 parent 05a0ba4 commit d852cf1

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

beacon_chain/sync/sync_dag.nim

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ func init*[T](
8888
columnsMap: Opt.some(columns)
8989
)
9090

91-
proc init*(
92-
t: typedesc[SyncDag],
93-
A: typedesc,
94-
B: typedesc
95-
): SyncDag[A, B] =
96-
SyncDag[A, B]()
97-
9891
iterator parents*(entry: SyncDagEntryRef): SyncDagEntryRef =
9992
doAssert(not(isNil(entry)), "Entry should not be nil")
10093
var currentEntry = entry
@@ -283,3 +276,21 @@ proc prune*[A, B](
283276
if sdag.roots.pop(item, entry):
284277
entry.parent = nil
285278
entry = nil
279+
280+
proc init*(
281+
t: typedesc[SyncDag],
282+
A: typedesc,
283+
B: typedesc
284+
): SyncDag[A, B] =
285+
var res = SyncDag[A, B]()
286+
let
287+
genesisRoot =
288+
Eth2Digest()
289+
genesisBid =
290+
BlockId(root: genesisRoot, slot: GENESIS_SLOT)
291+
genesisEntry =
292+
SyncDagEntryRef(blockId: genesisBid, flags: {DagEntryFlag.Finalized})
293+
res.roots[genesisRoot] = genesisEntry
294+
res.slots[GENESIS_SLOT] = toHashSet(@[genesisRoot])
295+
res.lastSlot = GENESIS_SLOT
296+
res

0 commit comments

Comments
 (0)