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

Common: Remove Parameters #3537

Merged
merged 22 commits into from
Jul 26, 2024
Merged

Common: Remove Parameters #3537

merged 22 commits into from
Jul 26, 2024

Conversation

holgerd77
Copy link
Member

@holgerd77 holgerd77 commented Jul 24, 2024

THIS is actually the reason I did all this Common refactoring during the last days. 😂

This PR fully removes all parameters from Common and moves them over to the packages into dedicated params.ts file. Nevertheless the full Common hardfork/EIP switching logic is preserved with Common still providing the central binding ground for parameter selection, so there is are no API changes for the users whatsoever.

Initially this work was mainly motivated by our current tree shaking work. I now find other benefits rather prevailing.

This new structure makes it significantly easier to fully adjust and customize parameter sets for libraries in a robust way along all hardforks, which was previously extremely complicated. I added new params options for the affected libraries along (tx, block, evm, vm), see associated test case and/or code docs for usage.

There are somewhat significant tree shaking benefits too though.

So this is the londonTx.ts example before:

grafik

This is with the PR:

grafik

Benefits are mainly due to the large EVM parameter set not being unnecessarily pulled over to the tx library. This now goes for all libraries though with the new structure, so evm is free-d up from tx, block and vm parameters.

Some additional note:

I had some problems with side effects along plainly using the param dicts as a base for customization (manipulation of the imported dict directly affected the original dictionary itself). I added explicit notes to the docs. Also - to make deep cloning easier - I removed all BigInt usages from params and replaced it with strings. I think this is a general improvement, I had some problems with this already earlier, can't fully remember the context though. Here it is for easier deep cloning, which does not work for BigInts (depending what option you choose). Change has no drawbacks, since there is a BigInt(param) call in the Common.param() method anyhow and so there was no logic code change necessary and this rather eliminated this double-BigInt instantiation (which worked).

Ready for review! 🙂

@holgerd77
Copy link
Member Author

This is now ready for review, added a description in the initial post section.

packages/block/src/types.ts Outdated Show resolved Hide resolved
packages/block/src/types.ts Outdated Show resolved Hide resolved
packages/common/test/data/paramsTest.ts Outdated Show resolved Hide resolved
packages/common/test/data/paramsTest.ts Outdated Show resolved Hide resolved
packages/evm/src/types.ts Outdated Show resolved Hide resolved
packages/evm/src/types.ts Outdated Show resolved Hide resolved
packages/tx/src/types.ts Outdated Show resolved Hide resolved
packages/tx/src/types.ts Outdated Show resolved Hide resolved
packages/vm/src/types.ts Outdated Show resolved Hide resolved
packages/vm/src/types.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@ScottyPoi ScottyPoi left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

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

One question.

I love this idea in general to move out all the package-specific params into their own params file. I had never thought about this. Great!! 😄 👍

if (!(eip in this._params)) {
this._params[eip] = { ...paramsConfig } // copy
} else {
this._params[eip] = { ...this._params[eip], ...params[eip] }
Copy link
Member

Choose a reason for hiding this comment

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

Does / should this deep copy?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, yes, likely, thanks for catching. I actually thought this would (and I still think it does to some extend, but maybe not on the second level dicts? 🤔) But then I re-stumbled upon this in the test writing, where I tried the same and it actually didn’t.

I will keep this here to save CI but do in subsequent PR today (also about Common).

Copy link
Member

@jochem-brouwer jochem-brouwer Jul 26, 2024

Choose a reason for hiding this comment

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

That's fine! I have addressed three other places where the shallow copy seems to happen with comments.

@holgerd77 holgerd77 merged commit 1b881bc into master Jul 26, 2024
34 checks passed
@holgerd77 holgerd77 deleted the common-remove-params branch July 26, 2024 07:29
@holgerd77
Copy link
Member Author

One question.

I love this idea in general to move out all the package-specific params into their own params file. I had never thought about this. Great!! 😄 👍

This was a long thought process, and not a pop-up idea out of nowhere, by the way! 😂

@@ -75,6 +73,8 @@ export class Common {
(this._chainParams.customHardforks && this._chainParams.customHardforks[hf.name]),
])
this._hardfork = this.DEFAULT_HARDFORK
this._params = { ...(opts.params ?? {}) } // copy
Copy link
Member

Choose a reason for hiding this comment

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

If the shallow copy should be removed, then this one should likely also be addressed 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yes, good point! Thanks!

* @param params
*/
resetParams(params: ParamsDict) {
this._params = { ...params } // copy
Copy link
Member

Choose a reason for hiding this comment

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

Here is also a copy

this._paramsCache = {
...this._paramsCache,
...params['params'],
...params,
Copy link
Member

Choose a reason for hiding this comment

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

Here also a possible shallow copy.

Copy link
Member Author

Choose a reason for hiding this comment

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

Guess you mean "deep copy" but: yes!

Will all do in subsequent PR (not the state manager one)

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.

4 participants