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 deep copy refactor #3608

Closed
wants to merge 8 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/common/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,13 @@ export class Common {
* Returns a deep copy of this {@link Common} instance.
*/
copy(): Common {
const copy = Object.assign(Object.create(Object.getPrototypeOf(this)), this)
copy.events = new EventEmitter()
const copy = new Common({
chain: { ...this._chainParams },
eips: [...this._eips],
customCrypto: this.customCrypto,
})
copy.updateParams(this._params)
copy.setHardfork(this.hardfork())
Copy link
Member

Choose a reason for hiding this comment

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

This code has never been touched by any refactor, I am really not seeing why we should change this now.

Also, side note, the spread operator ... has issues with nested copying, see e.g. this example:

grafik

That's why spread is generally not so suitable.

Also to note: side adding setHardfork() can have massive side effects here, I remember similar experiments in the past.

return copy
}
}
Loading