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

Block: replace static constructors #3489

Merged
merged 23 commits into from
Jul 12, 2024
Merged

Block: replace static constructors #3489

merged 23 commits into from
Jul 12, 2024

Conversation

ScottyPoi
Copy link
Contributor

@ScottyPoi ScottyPoi commented Jul 10, 2024

Works on #3487

Replaces all static Block methods with independently defined functions

Block constructor methods:

  • Block.fromBlockData
  • Block.fromRLPSerializedBlock
  • Block.fromValuesArray
  • Block.fromRPC
  • Block.fromJsonRPCProvider
  • Block.fromExecutionPayload
  • Block.fromBeaconPayloadJson

moved to packages/block/src/blockConstructor.ts and renamed:

  • createBlock
  • createBlockFromRLPSerializedBlock
  • createBlockFromBytesArray
  • createBlockFromRPC
  • createBlockFromJsonRPCProvider
  • createBlockFromExecutionPayload
  • createBlockFromBeaconPayloadJson

Trie Root methods:

  • Block.genWithdrawalsTrieRoot
  • Block.genTransactionsTrieRoot
  • Block.genRequestsTrieRoot

moved to packages/block/src/helpers.ts and renamed:

  • genWithdrawalsTrieRoot
  • genTransactionsTrieRoot
  • genRequestsTrieRoot

@ScottyPoi
Copy link
Contributor Author

ScottyPoi commented Jul 10, 2024

Tests failing with this message:

Error: Missing "./dist/cjs/helpers.js" specifier in "@ethereumjs/block" package

update

fixed with commit bc519ad

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.

Ok, had a look, great, some things around general conventions for this kind of PRs, otherwise I guess we can also already take this in, had some closer look at the EVM changes, these are actually not that vast so I guess merging won't be as much as a problem as I anticipated.

There are 3 merge conflicts in this PR to fix though first.

@@ -0,0 +1,442 @@
import { RLP } from '@ethereumjs/rlp'
Copy link
Member

Choose a reason for hiding this comment

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

I would like to establish a general naming convention for this file name that we re-use throughout all libraries, so that it's just clear where to look for, same a bit as our types.ts files.

Can we take constructors.ts here in this case? That would be my pledge! 🙂

So without block (redundant, I would also pledge for just always having one file for this per library), and also using plural (constructors), since several constructors (let's always use this name, and not fall back to singular if for the moment there is only one constructor present for a library).

Copy link
Member

Choose a reason for hiding this comment

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

(so these comments go more or less 1:1 for the other PR for blockchain)

const executionPayload = executionPayloadFromBeaconPayload(payload)
return Block.fromExecutionPayload(executionPayload, opts)
}

/**
* This constructor takes the values, validates them, assigns them and freezes the object.
* Use the static factory methods to assist in creating a Block object from varying data types and options.
Copy link
Member

Choose a reason for hiding this comment

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

One thing which has gotten a bit worse with this extraction is discoverability, so it has gotten harder to find/auto-complete what constructors are available.

Can we make it a habit to therefore to always provide a list with all the (linked, so clickable) static constructor methods, either here or along the class (Block) code docs (can't fully decide, where does one stumble more upon this? If one imports a Block and then hovers over the class import or if one types in new Block() and then sees the code docs for the constructor? Guess maybe the class docs?).

So that would be great and pretty helpful!

Also: can you add a @deprecated note here for this constructor as well, like we have for other constructors (tx? evm?) already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. It is a nicer experience to type in Block. and have the constructors pop up.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, but really only in the code docs, not that we talk past each other! 🙂

So like:

/**
/* ...
/* The following constructors are available:
/* - createBlockFromBlockData() // <- This should then be clickable on mouseover in the IDE (VS Code)
/* - ...
**/

@holgerd77
Copy link
Member

holgerd77 commented Jul 11, 2024

Ah, and one other thing: I would also find it great if we make it a habit to always post a comparable pre- and post-PR bundle size respectively the diff, so that we get a feeling about the changes and have this "measured".

Won't be dramatically big here, but nevertheless.

Can you maybe do this along the instructions from my presentation (slide 5 😋), and so maybe do a super-small script creating a block using one of the constructors (best the simplest to use one) with the old Block.from and see how the bundle size goes (so: pointing in the - now called - vite.config.bundle.ts file in EVM to your new small script and then run npm run visualize:bundle) and then post the numbers here? 🙂

Guess this will generally be pretty motivating! 🏆 😄

@ScottyPoi ScottyPoi force-pushed the block-static-methods branch from 0320141 to e77d773 Compare July 11, 2024 21:09
Copy link

codecov bot commented Jul 12, 2024

Codecov Report

Attention: Patch coverage is 54.16667% with 11 lines in your changes missing coverage. Please review.

Project coverage is 35.07%. Comparing base (d24ca11) to head (074535b).
Report is 51 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (d24ca11) and HEAD (074535b). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (d24ca11) HEAD (074535b)
common 1 0
blockchain 1 0
util 1 0
statemanager 1 0
Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
blockchain ?
common ?
evm 68.87% <ø> (?)
genesis 0.00% <ø> (?)
statemanager ?
trie 53.29% <ø> (?)
util ?
vm 58.63% <54.16%> (?)

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

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 merged commit ea4bc06 into master Jul 12, 2024
34 of 36 checks passed
@holgerd77 holgerd77 deleted the block-static-methods branch July 12, 2024 08:37
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.

2 participants