Skip to content
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

Util, Monorepo: hexStringToBytes -> prefixedHexStringToBytes #2830

Merged
merged 14 commits into from
Jun 29, 2023

Conversation

jochem-brouwer
Copy link
Member

@jochem-brouwer jochem-brouwer commented Jun 27, 2023

Closes #2827

Note: if we have methods which return hex strings, the return type should be either PrefixedHexString or NotPrefixedHexString. Rewriting this in all libraries was fine, except for client, since I am not sure if the return values of the methods are prefixed or not, which is very error-prone.

TODO:

  • Ensure client runs (try to sync mainnet)
  • Fix tests (I ran them locally and thought they passed 😢 )

* @param hex
* @returns
*/
function _nonPrefixedHexStringToBytes(hex: string) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative: move this to util but shield it so no one uses it

@jochem-brouwer
Copy link
Member Author

Ok, have renamed all, tests should be fixed, however, I am totally not sure regarding client, since we have either hex-prefixed strings or non-hex-prefixed strings there, so we should take a thorough look there (or: alternatively, temporarily use an internal hexStringToBytes method which reflects the old version of util: check if hex prefixed then strip the 0x, otherwise immediately convert).

@codecov
Copy link

codecov bot commented Jun 27, 2023

Codecov Report

Merging #2830 (d3fc0ca) into master (9fbc8b0) will increase coverage by 0.00%.
The diff coverage is 88.42%.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 89.18% <100.00%> (ø)
blockchain 92.50% <ø> (ø)
client 87.07% <79.24%> (-0.01%) ⬇️
common 97.06% <100.00%> (+<0.01%) ⬆️
devp2p 86.58% <ø> (ø)
ethash ∅ <ø> (∅)
evm 66.99% <ø> (ø)
rlp ∅ <ø> (∅)
statemanager 86.41% <100.00%> (+0.01%) ⬆️
trie 90.01% <86.95%> (-0.05%) ⬇️
tx 95.97% <100.00%> (ø)
util 86.07% <100.00%> (+0.14%) ⬆️
vm 77.10% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@gabrocheleau
Copy link
Contributor

Minor question, but since we're making that change, would it be better to name this:
unprefixedHexString or
notPrefixedHexString?
The first (unprefixed) sounds more fluent to me. And googling unprefixed seems to indicate that it's more commonly used in a coding context.

@jochem-brouwer jochem-brouwer marked this pull request as ready for review June 28, 2023 12:51
@jochem-brouwer
Copy link
Member Author

we're making that change, would it be better to name this:
unprefixedHexString or

I'm not sure what you are referring to here?

The PR is open for review now, just tested locally that client works (you might have to use a custom datadir or wipe your datadir)

@gabrocheleau
Copy link
Contributor

we're making that change, would it be better to name this:
unprefixedHexString or

I'm not sure what you are referring to here?

The PR is open for review now, just tested locally that client works (you might have to use a custom datadir or wipe your datadir)

Oh sorry, I thought you had implemented explicit naming for prefixed and unprefixed hex strings, had only looked at the description and not the code. Will review later!

@jochem-brouwer jochem-brouwer requested a review from holgerd77 June 28, 2023 13:06
@@ -10,7 +10,7 @@ Note: All paths are relative paths to the `VM` package root.

1. If you change the port number in `transition-cluster.ts` to anything other than 3000 (or run `transition-cluster` on a separate machine or different IP address from retesteth), update `test/vm/retesteth/clients/ethereumjs/start.sh` to reflect the right IP and port.

2. From VM package root directory, run `npx ts-node test/retesteth/transition-cluster.ts`
2. From VM package root directory, run `npx ts-node test/retesteth/transition-cluster.cts`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not relevant for this PR, but added it here, since it felt silly to open another PR for this.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really prefer if we do not introduce an extra type UnprefixedHexString and so to not encourage/diffuse people to go into a wild mix again.

If we have - for whatever reason - this 1-2 occasions where it is necessary that we use ourselves we should rather keep this local.

@holgerd77
Copy link
Member

Otherwise this looks really great! 🤩 Wasn't aware that this has gotten so extensive!

@jochem-brouwer
Copy link
Member Author

Alright, I will remove this UnprefixedHexString (it has no use in VSCode since it still shows up as string (sigh)). I kept it mainly as tracker/reminder for myself but I will remove them.

And regarding the amount of changes: yes this was much more work than I anticipated 😅 I thought I could just "find-and-replace" but that was not the case 😂

@jochem-brouwer
Copy link
Member Author

Ok, removed (I thought I had put it in much more places 😂 )

holgerd77
holgerd77 previously approved these changes Jun 28, 2023
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -50,7 +52,7 @@ describe('EIP4895 tests', () => {
() => {
BlockHeader.fromHeaderData(
{
withdrawalsRoot: hexStringToBytes('00'.repeat(32)),
withdrawalsRoot: prefixedHexStringToBytes('0x' + '00'.repeat(32)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use the zeros util

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(For this and other ones in the file)

@@ -141,8 +141,8 @@ describe('simple merkle range proofs generation and verification', () => {
}

// Special case, two edge proofs for two edge key.
const startKey = hexStringToBytes('00'.repeat(32))
const endKey = hexStringToBytes('ff'.repeat(32))
const startKey = prefixedHexStringToBytes('0x' + '00'.repeat(32))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zeros util

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case it is cleaner to keep it like this, since endKey uses prefixedHexStringToBytes and startKey would now use zeros - makes it slightly harder to read (I do agree with block tests though these should+will be changed in 25f29dc)

gabrocheleau
gabrocheleau previously approved these changes Jun 28, 2023
@gabrocheleau
Copy link
Contributor

One test failing, looking into it.

@gabrocheleau
Copy link
Contributor

One test failing, looking into it.

Ah nvm, just noticed it is also failing on master.

@jochem-brouwer jochem-brouwer dismissed stale reviews from gabrocheleau and holgerd77 via 25f29dc June 29, 2023 11:30
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holgerd77 holgerd77 changed the title Monorepo: hexStringToBytes -> prefixedHexStringToBytes Util, Monorepo: hexStringToBytes -> prefixedHexStringToBytes Jun 29, 2023
@holgerd77 holgerd77 merged commit bec76a9 into master Jun 29, 2023
@holgerd77 holgerd77 deleted the hexStrToBytes-prefixedHexStrToBytes branch June 29, 2023 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Util: rename/adjust hexStringToBytes to prefixedHexStringToBytes
3 participants