Skip to content

@ethereumjs/statemanager v1.0.0-beta.1

Pre-release
Pre-release
Compare
Choose a tag to compare
@holgerd77 holgerd77 released this 30 Jun 10:27
· 1405 commits to master since this release
c5260ba

This release is part of a larger breaking release round where all EthereumJS monorepo libraries (VM, Tx, Trie, other) get major version upgrades. This round of releases has been prepared for a long time and we are really pleased with and proud of the result, thanks to all team members and contributors who worked so hard and made this possible! 🙂 ❤️

We have gotten rid of a lot of technical debt and inconsistencies and removed unused functionality, renamed methods, improved on the API and on TypeScript typing, to name a few of the more local type of refactoring changes. There are also broader structural changes like a full transition to native JavaScript BigInt values as well as various somewhat deep-reaching refactorings, both within a single package as well as some reaching beyond the scope of a single package. Also two completely new packages - @ethereumjs/evm (in addition to the existing @ethereumjs/vm package) and @ethereumjs/statemanager - have been created, leading to a more modular Ethereum JavaScript VM.

We are very much confident that users of the libraries will greatly benefit from the changes being introduced. However - along the upgrade process - these releases require some extra attention and care since the changeset is both so big and deep reaching. We highly recommend to closely read the release notes, we have done our best to create a full picture on the changes with some special emphasis on delicate code and API parts and give some explicit guidance on how to upgrade and where problems might arise!

So, enjoy the releases (this is a first round of Beta releases, with final releases following a couple of weeks after if things go well)! 🎉

The EthereumJS Team

New Package

The StateManager has been extracted from the VM and is now a separate package, see PR #1817. The new package can be installed separately with:

npm i @ethereumjs/statemanager

The @ethereumjs/vm package still has this package added as a dependency and it is automatically integrated. The StateManager provides a high-level interface to an underlying state storage solution. This is classically a Trie (in our case: an @ethereumjs/trie) instance, but can also be something else, e.g. a plain database, an underlying RPC connection or a Verkle Tree in the future.

The extraction of this module allows to easier customize a StateManager and provide or use your own implementations in the future. It is now also possible to use the StateManager standalone for high-level state access in a non-VM context.

A StateManager must adhere to a predefined interface StateManager and implement a certain set of state access methods like getAccount(), putContractCode(),... Such an implementation is then guaranteed to work e.g. in the @ethereumjs/vm implementation.

StateManager Refactoring

Along with the package extraction parts of the old StateManager has also been reworked. So if you are building on the old StateManager class/interface it is likely not enough to just change on the import statement but do some adjustments to get things working. Here is a summary of the changes.

Methods added:

  • flush()

Methods removed:

  • touchAccount() (EVM-specific, remained in EVMStateAccess interface in EVM)
  • All methods from EIP2929StateManager (removed as separate interface) (EVM-specific, remained in EVMStateAccess interface in EVM)
  • getOriginalContractStorage() (EVM-specific, remained in EVMStateAccess interface in EVM)
  • hasGenesisState() (removed)
  • generateGenesis() (removed)
  • generateCanonicalGenesis() (EVM-specific, remained in EVMStateAccess interface in EVM)
  • cleanupTouchedAccounts() (EVM-specific, remained in EVMStateAccess interface in EVM)
  • clearOriginalStorageCache() (EVM-specific, remained in EVMStateAccess interface in EVM)

Other Changes:

  • New partial parent interface StateAccess with just the access focused functionality

So overall the StateManager interface got a lot leaner requiring fewer methods to be implemented which should make an implementation and/or adoption a lot easier.

The StateManager package ships with a Trie-based StateManager implementation extending from a BaseStateManager which might be a suitable starting point for your own implementations. This will very much depend on the specific needs though.

BigInt Introduction / ES2020 Build Target

With this round of breaking releases the whole EthereumJS library stack removes the BN.js library and switches to use native JavaScript BigInt values for large-number operations and interactions.

This makes the libraries more secure and robust (no more BN.js v4 vs v5 incompatibilities) and generally comes with substantial performance gains for the large-number-arithmetic-intense parts of the libraries (particularly the VM).

To allow for BigInt support our build target has been updated to ES2020. We feel that some still remaining browser compatibility issues on the edges (old Safari versions e.g.) are justified by the substantial gains this step brings along.

See #1671 and #1771 for the core BigInt transition PRs.

Disabled esModuleInterop and allowSyntheticDefaultImports TypeScript Compiler Options

The above TypeScript options provide some semantic sugar like allowing to write an import like import React from "react" instead of import * as React from "react", see esModuleInterop and allowSyntheticDefaultImports docs for some details.

While this is convenient, it deviates from the ESM specification and forces downstream users into using these options, which might not be desirable, see this TypeScript Semver docs section for some more detailed argumentation.

Along with the breaking releases we have therefore deactivated both of these options and you might therefore need to adapt some import statements accordingly. Note that you still can activate these options in your bundle and/or transpilation pipeline (but now you also have the option not to, which you didn't have before).