-
-
Notifications
You must be signed in to change notification settings - Fork 289
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
fix: use toRootHex where applicable #7021
Conversation
Performance Report✔️ no performance regression detected Full benchmark results
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #7021 +/- ##
=========================================
Coverage 49.24% 49.24%
=========================================
Files 578 578
Lines 37438 37443 +5
Branches 2162 2168 +6
=========================================
+ Hits 18435 18440 +5
Misses 18963 18963
Partials 40 40 |
packages/utils/src/bytes.ts
Outdated
|
||
// this is to compliant to toHex() or toHexString() behavior | ||
// in case unit tests, or consumers pass in a Uint8Array that is not 32 bytes accidentally | ||
return toHex(root); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wemeetagain @nflaig I want to make it compliant to the old apis so we don't have to worry about the wrong usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we calling this in any unit tests? since performance is not relevant there we might be fine with just throwing an error if byte length is invalid. So either the test values have to be adapted or can use toHex
there instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree to throw error here if it's not 32
my other thought is should we append "0x"
here? we mostly use it for internal track and log
the down side with appending "0x"
is almost 40% more memory allocation
// Bytes32 Buffer.toString(hex) + 0x - 121.7 bytes / instance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we have toMemoryEfficientHexStr
for that?
function toMemoryEfficientHexStr(hex: Uint8Array | string): string { |
I would like to have hex values prefixed with 0x in logs and we also use this on the api which needs 0x-prefix on all hex strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok then let's just keep 0x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aren't most / all of these hex strings transient anyways?
not ready until unit test is fixed see #7025 |
should be fixed |
* fix: use toRootHex where applicable * fix: toRootHex() to handle different lengths * fix: throw error if root is not 32 bytes * Fix eth1MergeBlockTracker unit test --------- Co-authored-by: Nico Flaig <nflaig@protonmail.com>
🎉 This PR is included in v1.22.0 🎉 |
Motivation
Description
toHex()
and replace bytoRootHex()
(previously I missed them because I only searched fortoHexString()
)lodestar/packages/types/src/bellatrix/sszTypes.ts
Line 54 in 44b2156
toRootHex()
compliant to the old apis