-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create helper for max size, as bounded by Limit
#20
Comments
import
std/typetraits,
../beacon_chain/spec/eth2_ssz_serialization,
../beacon_chain/spec/datatypes/[deneb]
proc maxSize(T: type): int =
when isFixedSize(T):
fixedPortionSize(T)
elif T is HashList:
maxSize(T.T)
elif T is BitList:
(T.maxLen div 8) + 1
elif T is BitArray:
(T.maxLen + 7) div 8
elif T is List:
type E = T.T
when isFixedSize(E):
T.maxLen * maxSize(E)
else:
T.maxLen * (maxSize(E) + 4)
elif T is object|tuple:
var size = fixedPortionSize(T)
for field in fields(default(T)):
when not isFixedSize(typeof(field)):
size += maxSize(typeof(field))
size
else:
0
proc printSizes(T: type, indent: string) =
when T is object:
for name, field in fieldPairs(default(T)):
type F = typeof(field)
echo indent, name, ": ", maxSize(F)
when not isFixedSize(F):
printSizes(F, indent & " ")
proc printSizes(T: type) =
echo T.name, ": ", maxSize(T)
printSizes(T, " ")
printSizes(deneb.SignedBeaconBlock)
printSizes(Attestation) a humble beginning that gets us as far as the deneb block I think |
etan-status
added a commit
that referenced
this issue
Jan 9, 2025
As requested in #20, add a helper to compute maximum theoretical length of an SSZ object. Note that there is an extra limit of 4GB due to offset size that is not considered by the function.
Merged
Merged
etan-status
added a commit
that referenced
this issue
Jan 10, 2025
Introduces `minSize` as a counterpart to `maxSize` (#20).
Merged
etan-status
added a commit
that referenced
this issue
Jan 10, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Many types like
Attestation
have a useful max serialized size that can be computed by using theLimit
of everyList
as upper bound - a helper to compute this value would be generally useful for example to harden the decompression code against overlong messages: status-im/nimbus-eth2#3230 (comment)The text was updated successfully, but these errors were encountered: