Skip to content

Commit

Permalink
The light at the end of the SSZ typed tunnel
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Dec 23, 2020
1 parent 6df6931 commit ce0f7af
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 2 additions & 1 deletion beacon_chain/ssz/bytes_reader.nim
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ func readSszValue*[T](input: openArray[byte],
raise newException(MalformedSszError, "SSZ input of insufficient size")

enumInstanceSerializedFields(val, fieldName, field):
const boundingOffsets = getFieldBoundingOffsets(T, fieldName)
type RecordType = T # Upstream: Workaround type resolution
const boundingOffsets = getFieldBoundingOffsets(RecordType, fieldName)

# type FieldType = type field # buggy
# For some reason, Nim gets confused about the alias here. This could be a
Expand Down
13 changes: 6 additions & 7 deletions beacon_chain/ssz/ssz_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,15 @@ template writeField*(w: var SszWriter,
mixin toSszType
when ctx is FixedSizedWriterCtx:
writeFixedSized(w.stream, toSszType(field))
else:
type FieldType = type toSszType(field)

when isFixedSize(FieldType):
else: # Upstream: type RecordType = type toSszType(field) will crash
when isFixedSize(type toSszType(field)):
writeFixedSized(ctx.fixedParts, toSszType(field))
else:
trs "WRITING OFFSET ", ctx.offset, " FOR ", fieldName
writeOffset(ctx.fixedParts, ctx.offset)
let initPos = w.stream.pos
trs "WRITING VAR SIZE VALUE OF TYPE ", name(FieldType)
when FieldType is BitList:
trs "WRITING VAR SIZE VALUE OF TYPE ", name(type toSszType(field))
when (type toSszType(field)) is BitList:
trs "BIT SEQ ", bytes(field)
writeVarSizeType(w, toSszType(field))
ctx.offset += w.stream.pos - initPos
Expand Down Expand Up @@ -164,7 +162,8 @@ proc writeVarSizeType(w: var SszWriter, value: auto) {.raises: [Defect, IOError]
writeSeq(w, bytes value)
elif value is object|tuple|array:
trs "WRITING OBJECT OR ARRAY"
var ctx = beginRecord(w, type value)
type RecordType = type value # Upstream, alias needed or crash
var ctx = beginRecord(w, RecordType)
enumerateSubFields(value, field):
writeField w, ctx, astToStr(field), field
endRecord w, ctx
Expand Down
2 changes: 1 addition & 1 deletion docs/block_validation_flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The related base types are:
- metadata (slot, blockchain state before/after, proposer)
- merkle hash of the BeaconBlockBody
- SignedBeaconBlock
- BeaconBLock
- BeaconBlock
- + BLS signature

The base types are defined in the Eth2 specs.
Expand Down

0 comments on commit ce0f7af

Please sign in to comment.