Skip to content

Commit 6b1ab81

Browse files
committed
Support both snappy-encoded and pure SSZ genesis states
1 parent 672c69b commit 6b1ab81

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

beacon_chain/networking/network_metadata_downloads.nim

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,23 @@ proc fetchBytes*(metadata: GenesisMetadata,
3737
of BakedIn:
3838
result = @(metadata.bakedBytes)
3939
of BakedInUrl:
40-
result = decodeFramed(await downloadFile(genesisStateUrlOverride.get(parseUri metadata.url)))
40+
result = await downloadFile(genesisStateUrlOverride.get(parseUri metadata.url))
41+
# Under the built-in default URL, we serve a snappy-encoded BeaconState in order
42+
# to reduce the size of the downloaded file with roughly 50% (this precise ratio
43+
# depends on the number of validator recors). The user is still free to provide
44+
# any URL which may serve an uncompressed state (e.g. a Beacon API endpoint)
45+
#
46+
# Since a SSZ-encoded BeaconState will start with a LittleEndian genesis time
47+
# (64 bits) while a snappy framed stream will always start with a fixed header
48+
# that will decoded as a timestamp with the value 5791996851603375871 (year 2153).
49+
#
50+
# TODO: A more complete solution will implement compression on the HTTP level,
51+
# by relying on the Content-Encoding header to determine the compression
52+
# algorithm. The detection method used here will not interfere with such
53+
# an implementation and it may remain useful when dealing with misconfigured
54+
# HTTP servers.
55+
if result.isSnappyFramedStream:
56+
result = decodeFramed(result)
4157
if eth2digest(result) != metadata.digest:
4258
raise (ref DigestMismatchError)(
4359
msg: "The downloaded genesis state cannot be verified (checksum mismatch)")

beacon_chain/nimbus_beacon_node.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ proc init*(T: type BeaconNode,
562562
elif metadata.hasGenesis:
563563
try:
564564
if metadata.genesis.kind == BakedInUrl:
565-
info "Obtaining genesis state", sourceUrl = metadata.genesis.url
565+
info "Obtaining genesis state",
566+
sourceUrl = $config.genesisStateUrl.get(parseUri metadata.genesis.url)
566567
await metadata.genesis.fetchBytes(config.genesisStateUrl)
567568
except CatchableError as err:
568569
error "Failed to obtain genesis state",

vendor/nim-snappy

0 commit comments

Comments
 (0)