From 8a0afb04f98a0f65c32ff526b41cc3555c0330a5 Mon Sep 17 00:00:00 2001 From: Scorbajio Date: Sun, 8 Sep 2024 11:00:09 -0700 Subject: [PATCH] Rename DefaultStateManager to MerkleStateManager (#3641) * Rename DefaultStateManager to MerkleStateManager * Make naming change consistent throughout monorepo * Rename DefaultSateManagerOpts to MerkleStateManagerOpts * Rename stateManager.ts to merkleStateManager.ts * Fix lint issues * Update packages/statemanager/test/statelessVerkleStateManager.spec.ts * statemanager: cleanup --------- Co-authored-by: Gabriel Rocheleau --- packages/client/src/execution/vmexecution.ts | 10 +-- .../client/src/sync/fetcher/accountfetcher.ts | 8 +-- .../src/sync/fetcher/bytecodefetcher.ts | 8 +-- .../client/src/sync/fetcher/storagefetcher.ts | 8 +-- .../src/sync/fetcher/trienodefetcher.ts | 8 +-- packages/client/src/sync/snapsync.ts | 4 +- packages/client/src/types.ts | 4 +- packages/client/src/util/debug.ts | 4 +- .../integration/fullethereumservice.spec.ts | 14 ++-- packages/client/test/miner/miner.spec.ts | 4 +- .../client/test/miner/pendingBlock.spec.ts | 4 +- .../engine/getPayloadBodiesByHashV1.spec.ts | 26 +++---- .../engine/getPayloadBodiesByRangeV1.spec.ts | 10 +-- .../test/rpc/engine/getPayloadV3.spec.ts | 14 ++-- .../test/rpc/eth/sendRawTransaction.spec.ts | 50 ++++++------- packages/client/test/sim/snapsync.spec.ts | 6 +- packages/client/test/sync/txpool.spec.ts | 10 +-- packages/evm/examples/browser.html | 4 +- packages/evm/examples/withBlockchain.ts | 4 +- packages/statemanager/examples/basicUsage.ts | 4 +- packages/statemanager/examples/browser.html | 4 +- .../examples/fromProofInstantiation.ts | 6 +- packages/statemanager/src/index.ts | 2 +- ...{stateManager.ts => merkleStateManager.ts} | 22 +++--- .../src/statelessVerkleStateManager.ts | 4 +- packages/statemanager/src/types.ts | 2 +- .../test/checkpointing.account.spec.ts | 4 +- .../test/checkpointing.code.spec.ts | 70 +++++++++---------- .../test/checkpointing.storage.spec.ts | 4 +- .../test/proofStateManager.spec.ts | 20 +++--- .../statemanager/test/rpcStateManager.spec.ts | 10 +-- .../test/stateManager.account.spec.ts | 14 ++-- .../test/stateManager.code.spec.ts | 18 ++--- .../statemanager/test/stateManager.spec.ts | 30 ++++---- .../test/stateManager.storage.spec.ts | 16 ++--- .../test/statelessVerkleStateManager.spec.ts | 2 + packages/statemanager/test/vmState.spec.ts | 10 +-- packages/vm/benchmarks/util.ts | 6 +- packages/vm/src/constructors.ts | 4 +- packages/vm/test/api/index.spec.ts | 8 +-- packages/vm/test/api/runBlock.spec.ts | 12 ++-- .../vm/test/api/state/accountExists.spec.ts | 4 +- .../tester/runners/BlockchainTestsRunner.ts | 4 +- .../tester/runners/GeneralStateTestsRunner.ts | 4 +- 44 files changed, 243 insertions(+), 241 deletions(-) rename packages/statemanager/src/{stateManager.ts => merkleStateManager.ts} (98%) diff --git a/packages/client/src/execution/vmexecution.ts b/packages/client/src/execution/vmexecution.ts index c601e98700..37c063747a 100644 --- a/packages/client/src/execution/vmexecution.ts +++ b/packages/client/src/execution/vmexecution.ts @@ -10,7 +10,7 @@ import { getGenesis } from '@ethereumjs/genesis' import { CacheType, Caches, - DefaultStateManager, + MerkleStateManager, StatelessVerkleStateManager, } from '@ethereumjs/statemanager' import { createTrie } from '@ethereumjs/trie' @@ -161,7 +161,7 @@ export class VMExecution extends Execution { this.config.logger.info(`Initializing code cache size=${this.config.codeCache}`) this.config.logger.info(`Initializing trie cache size=${this.config.trieCache}`) - const stateManager = new DefaultStateManager({ + const stateManager = new MerkleStateManager({ trie, prefixStorageTrieKeys: this.config.prefixStorageTrieKeys, caches: new Caches({ @@ -683,7 +683,7 @@ export class VMExecution extends Execution { (!this.config.execCommon.gteHardfork(Hardfork.Osaka) && typeof this.vm.stateManager.initVerkleExecutionWitness === 'function') || (this.config.execCommon.gteHardfork(Hardfork.Osaka) && - this.vm.stateManager instanceof DefaultStateManager) + this.vm.stateManager instanceof MerkleStateManager) ) { throw Error( `Invalid vm stateManager type=${typeof this.vm.stateManager} for fork=${ @@ -1028,8 +1028,8 @@ export class VMExecution extends Execution { } stats() { - if (this._statsVM instanceof DefaultStateManager) { - const sm = this._statsVM.stateManager as DefaultStateManager + if (this._statsVM instanceof MerkleStateManager) { + const sm = this._statsVM.stateManager as MerkleStateManager const deactivatedStats = { size: 0, reads: 0, hits: 0, writes: 0 } let stats stats = sm['_caches']?.account?.stats() ?? deactivatedStats diff --git a/packages/client/src/sync/fetcher/accountfetcher.ts b/packages/client/src/sync/fetcher/accountfetcher.ts index 197aae3659..49cea99859 100644 --- a/packages/client/src/sync/fetcher/accountfetcher.ts +++ b/packages/client/src/sync/fetcher/accountfetcher.ts @@ -1,4 +1,4 @@ -import { DefaultStateManager } from '@ethereumjs/statemanager' +import { MerkleStateManager } from '@ethereumjs/statemanager' import { verifyTrieRangeProof } from '@ethereumjs/trie' import { BIGINT_0, @@ -54,7 +54,7 @@ export interface AccountFetcherOptions extends FetcherOptions { /** Destroy fetcher once all tasks are done */ destroyWhenDone?: boolean - stateManager?: DefaultStateManager + stateManager?: MerkleStateManager fetcherDoneFlags?: SnapFetcherDoneFlags } @@ -69,7 +69,7 @@ export type JobTask = { export class AccountFetcher extends Fetcher { protected debug: Debugger - stateManager: DefaultStateManager + stateManager: MerkleStateManager accountTrie: Trie root: Uint8Array @@ -96,7 +96,7 @@ export class AccountFetcher extends Fetcher this.first = options.first this.count = options.count ?? BIGINT_2EXP256 - this.first - this.stateManager = options.stateManager ?? new DefaultStateManager() + this.stateManager = options.stateManager ?? new MerkleStateManager() this.accountTrie = this.stateManager['_getAccountTrie']() this.debug = debugDefault('client:AccountFetcher') diff --git a/packages/client/src/sync/fetcher/bytecodefetcher.ts b/packages/client/src/sync/fetcher/bytecodefetcher.ts index a5868d92e9..06507f70cb 100644 --- a/packages/client/src/sync/fetcher/bytecodefetcher.ts +++ b/packages/client/src/sync/fetcher/bytecodefetcher.ts @@ -1,4 +1,4 @@ -import { CODEHASH_PREFIX, DefaultStateManager } from '@ethereumjs/statemanager' +import { CODEHASH_PREFIX, MerkleStateManager } from '@ethereumjs/statemanager' import { BIGINT_0, bytesToHex, @@ -26,7 +26,7 @@ type ByteCodeDataResponse = Uint8Array[] & { completed?: boolean } */ export interface ByteCodeFetcherOptions extends FetcherOptions { hashes: Uint8Array[] - stateManager?: DefaultStateManager + stateManager?: MerkleStateManager fetcherDoneFlags?: SnapFetcherDoneFlags /** Destroy fetcher once all tasks are done */ @@ -40,7 +40,7 @@ export type JobTask = { export class ByteCodeFetcher extends Fetcher { protected debug: Debugger - stateManager: DefaultStateManager + stateManager: MerkleStateManager fetcherDoneFlags: SnapFetcherDoneFlags codeDB: DB @@ -54,7 +54,7 @@ export class ByteCodeFetcher extends Fetcher constructor(options: ByteCodeFetcherOptions) { super(options) this.hashes = options.hashes ?? [] - this.stateManager = options.stateManager ?? new DefaultStateManager() + this.stateManager = options.stateManager ?? new MerkleStateManager() this.fetcherDoneFlags = options.fetcherDoneFlags ?? getInitFetcherDoneFlags() this.fetcherDoneFlags.byteCodeFetcher.count = BigInt(this.hashes.length) this.codeDB = this.stateManager['_getCodeDB']() diff --git a/packages/client/src/sync/fetcher/storagefetcher.ts b/packages/client/src/sync/fetcher/storagefetcher.ts index 2dfb3fda22..ccee112da2 100644 --- a/packages/client/src/sync/fetcher/storagefetcher.ts +++ b/packages/client/src/sync/fetcher/storagefetcher.ts @@ -1,4 +1,4 @@ -import { DefaultStateManager } from '@ethereumjs/statemanager' +import { MerkleStateManager } from '@ethereumjs/statemanager' import { verifyTrieRangeProof } from '@ethereumjs/trie' import { BIGINT_0, @@ -56,7 +56,7 @@ export interface StorageFetcherOptions extends FetcherOptions { /** Destroy fetcher once all tasks are done */ destroyWhenDone?: boolean - stateManager: DefaultStateManager + stateManager: MerkleStateManager fetcherDoneFlags: SnapFetcherDoneFlags } @@ -69,7 +69,7 @@ export type JobTask = { export class StorageFetcher extends Fetcher { protected debug: Debugger root: Uint8Array - stateManager: DefaultStateManager + stateManager: MerkleStateManager fetcherDoneFlags: SnapFetcherDoneFlags /** The accounts to fetch storage data for */ @@ -88,7 +88,7 @@ export class StorageFetcher extends Fetcher - stateManager?: DefaultStateManager + stateManager?: MerkleStateManager /** Destroy fetcher once all tasks are done */ destroyWhenDone?: boolean @@ -69,7 +69,7 @@ export class TrieNodeFetcher extends Fetcher protected debug: Debugger root: Uint8Array - stateManager: DefaultStateManager + stateManager: MerkleStateManager fetcherDoneFlags: SnapFetcherDoneFlags accountTrie: Trie codeDB: DB @@ -105,7 +105,7 @@ export class TrieNodeFetcher extends Fetcher this.requestedNodeToPath = new Map() this.fetchedAccountNodes = new Map() - this.stateManager = options.stateManager ?? new DefaultStateManager() + this.stateManager = options.stateManager ?? new MerkleStateManager() this.accountTrie = this.stateManager['_getAccountTrie']() this.codeDB = this.stateManager['_getCodeDB']() diff --git a/packages/client/src/sync/snapsync.ts b/packages/client/src/sync/snapsync.ts index 529bd59a0a..17ec45aecd 100644 --- a/packages/client/src/sync/snapsync.ts +++ b/packages/client/src/sync/snapsync.ts @@ -12,7 +12,7 @@ import type { Peer } from '../net/peer/peer.js' import type { Skeleton } from '../service/skeleton.js' import type { SnapFetcherDoneFlags } from './fetcher/types.js' import type { SynchronizerOptions } from './sync.js' -import type { DefaultStateManager } from '@ethereumjs/statemanager' +import type { MerkleStateManager } from '@ethereumjs/statemanager' interface SnapSynchronizerOptions extends SynchronizerOptions { /** Skeleton chain */ @@ -228,7 +228,7 @@ export class SnapSynchronizer extends Synchronizer { this.fetcher = new AccountFetcher({ config: this.config, pool: this.pool, - stateManager: this.execution.vm.stateManager as DefaultStateManager, + stateManager: this.execution.vm.stateManager as MerkleStateManager, root: stateRoot, // This needs to be determined from the current state of the MPT dump first: BigInt(0), diff --git a/packages/client/src/types.ts b/packages/client/src/types.ts index 88f57fc494..aa5faab06c 100644 --- a/packages/client/src/types.ts +++ b/packages/client/src/types.ts @@ -4,7 +4,7 @@ import type { SyncMode } from './index.js' import type { Peer } from './net/peer/index.js' import type { Server } from './net/server/index.js' import type { Block, BlockHeader } from '@ethereumjs/block' -import type { DefaultStateManager } from '@ethereumjs/statemanager' +import type { MerkleStateManager } from '@ethereumjs/statemanager' import type { Address } from '@ethereumjs/util' import type { Multiaddr } from '@multiformats/multiaddr' import type * as promClient from 'prom-client' @@ -41,7 +41,7 @@ export interface EventParams { [Event.SYNC_FETCHED_BLOCKS]: [blocks: Block[]] [Event.SYNC_FETCHED_HEADERS]: [headers: BlockHeader[]] [Event.SYNC_SYNCHRONIZED]: [chainHeight: bigint] - [Event.SYNC_SNAPSYNC_COMPLETE]: [stateRoot: Uint8Array, stateManager: DefaultStateManager] + [Event.SYNC_SNAPSYNC_COMPLETE]: [stateRoot: Uint8Array, stateManager: MerkleStateManager] [Event.SYNC_ERROR]: [syncError: Error] [Event.SYNC_FETCHER_ERROR]: [fetchError: Error, task: any, peer: Peer | null | undefined] [Event.PEER_CONNECTED]: [connectedPeer: Peer] diff --git a/packages/client/src/util/debug.ts b/packages/client/src/util/debug.ts index 43d540c3bc..7c819871a4 100644 --- a/packages/client/src/util/debug.ts +++ b/packages/client/src/util/debug.ts @@ -30,7 +30,7 @@ import { Common } from '@ethereumjs/common' import { Block } from '@ethereumjs/block' import { VM, runBlock, createVM } from './src' import { Trie } from '@ethereumjs/trie' -import { DefaultStateManager } from './src/state' +import { MerkleStateManager } from './src/state' import { Blockchain } from '@ethereumjs/blockchain' const main = async () => { @@ -41,7 +41,7 @@ const main = async () => { const stateDB = new Level('${execution.config.getDataDirectory(DataDirectory.State)}') const trie = new Trie({ db: stateDB, useKeyHashing: true }) - const stateManager = new DefaultStateManager({ trie, common }) + const stateManager = new MerkleStateManager({ trie, common }) // Ensure we run on the right root stateManager.setStateRoot(hexToBytes('${bytesToHex( await execution.vm.stateManager.getStateRoot(), diff --git a/packages/client/test/integration/fullethereumservice.spec.ts b/packages/client/test/integration/fullethereumservice.spec.ts index d72de32016..064a4ef010 100644 --- a/packages/client/test/integration/fullethereumservice.spec.ts +++ b/packages/client/test/integration/fullethereumservice.spec.ts @@ -1,7 +1,7 @@ import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Hardfork } from '@ethereumjs/common' -import { DefaultStateManager } from '@ethereumjs/statemanager' +import { MerkleStateManager } from '@ethereumjs/statemanager' import { createFeeMarket1559TxFromRLP } from '@ethereumjs/tx' import { Account, bytesToHex, equalsBytes, hexToBytes, toBytes } from '@ethereumjs/util' import * as td from 'testdouble' @@ -18,10 +18,10 @@ import { destroy } from './util.js' const config = new Config({ accountCache: 10000, storageCache: 1000 }) // Stub out setStateRoot since correct state root doesn't exist in mock state. -const ogSetStateRoot = DefaultStateManager.prototype.setStateRoot -DefaultStateManager.prototype.setStateRoot = (): any => {} -const originalStateManagerCopy = DefaultStateManager.prototype.shallowCopy -DefaultStateManager.prototype.shallowCopy = function () { +const ogSetStateRoot = MerkleStateManager.prototype.setStateRoot +MerkleStateManager.prototype.setStateRoot = (): any => {} +const originalStateManagerCopy = MerkleStateManager.prototype.shallowCopy +MerkleStateManager.prototype.shallowCopy = function () { return this } async function setup(): Promise<[MockServer, FullEthereumService]> { @@ -128,6 +128,6 @@ describe('should handle LES requests', async () => { await destroy(server, service) // unstub setStateRoot - DefaultStateManager.prototype.setStateRoot = ogSetStateRoot - DefaultStateManager.prototype.shallowCopy = originalStateManagerCopy + MerkleStateManager.prototype.setStateRoot = ogSetStateRoot + MerkleStateManager.prototype.shallowCopy = originalStateManagerCopy }, 30000) diff --git a/packages/client/test/miner/miner.spec.ts b/packages/client/test/miner/miner.spec.ts index e1f2dcf256..d4fd649b16 100644 --- a/packages/client/test/miner/miner.spec.ts +++ b/packages/client/test/miner/miner.spec.ts @@ -6,7 +6,7 @@ import { createCommonFromGethGenesis, createCustomCommon, } from '@ethereumjs/common' -import { DefaultStateManager } from '@ethereumjs/statemanager' +import { MerkleStateManager } from '@ethereumjs/statemanager' import { createFeeMarket1559Tx, createLegacyTx } from '@ethereumjs/tx' import { Address, equalsBytes, hexToBytes } from '@ethereumjs/util' import { AbstractLevel } from 'abstract-level' @@ -45,7 +45,7 @@ BlockHeader.prototype['_consensusFormatValidation'] = vi.fn() // Stub out setStateRoot so txPool.validate checks will pass since correct state root // doesn't exist in fakeChain state anyway -DefaultStateManager.prototype.setStateRoot = vi.fn() +MerkleStateManager.prototype.setStateRoot = vi.fn() class FakeChain { open() {} diff --git a/packages/client/test/miner/pendingBlock.spec.ts b/packages/client/test/miner/pendingBlock.spec.ts index ff23f8dd3b..da6ef97e8e 100644 --- a/packages/client/test/miner/pendingBlock.spec.ts +++ b/packages/client/test/miner/pendingBlock.spec.ts @@ -1,7 +1,7 @@ import { BlockHeader, createBlockHeader } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Common, Goerli, Hardfork, Mainnet, createCommonFromGethGenesis } from '@ethereumjs/common' -import { DefaultStateManager } from '@ethereumjs/statemanager' +import { MerkleStateManager } from '@ethereumjs/statemanager' import { createBlob4844Tx, createFeeMarket1559Tx, createLegacyTx } from '@ethereumjs/tx' import { Account, @@ -97,7 +97,7 @@ describe('[PendingBlock]', async () => { } }) - DefaultStateManager.prototype.setStateRoot = vi.fn() + MerkleStateManager.prototype.setStateRoot = vi.fn() const createTx = ( from = A, diff --git a/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts b/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts index a851b99500..94382757db 100644 --- a/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts +++ b/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts @@ -1,6 +1,6 @@ import { createBlock, createBlockHeader } from '@ethereumjs/block' import { Hardfork } from '@ethereumjs/common' -import { DefaultStateManager } from '@ethereumjs/statemanager' +import { MerkleStateManager } from '@ethereumjs/statemanager' import { createTxFromTxData } from '@ethereumjs/tx' import { Account, @@ -32,10 +32,10 @@ describe(method, () => { it('call with valid parameters', async () => { // Disable stateroot validation in TxPool since valid state root isn't available - const originalSetStateRoot = DefaultStateManager.prototype.setStateRoot - const originalStateManagerCopy = DefaultStateManager.prototype.shallowCopy - DefaultStateManager.prototype.setStateRoot = function (): any {} - DefaultStateManager.prototype.shallowCopy = function () { + const originalSetStateRoot = MerkleStateManager.prototype.setStateRoot + const originalStateManagerCopy = MerkleStateManager.prototype.shallowCopy + MerkleStateManager.prototype.setStateRoot = function (): any {} + MerkleStateManager.prototype.shallowCopy = function () { return this } const { chain, service, server, common } = await setupChain(genesisJSON, 'post-merge', { @@ -108,16 +108,16 @@ describe(method, () => { assert.equal(res.result.length, 3, 'length of response matches number of block hashes sent') // Restore setStateRoot - DefaultStateManager.prototype.setStateRoot = originalSetStateRoot - DefaultStateManager.prototype.shallowCopy = originalStateManagerCopy + MerkleStateManager.prototype.setStateRoot = originalSetStateRoot + MerkleStateManager.prototype.shallowCopy = originalStateManagerCopy }) it('call with valid parameters on pre-Shanghai block', async () => { // Disable stateroot validation in TxPool since valid state root isn't available - const originalSetStateRoot = DefaultStateManager.prototype.setStateRoot - const originalStateManagerCopy = DefaultStateManager.prototype.shallowCopy - DefaultStateManager.prototype.setStateRoot = function (): any {} - DefaultStateManager.prototype.shallowCopy = function () { + const originalSetStateRoot = MerkleStateManager.prototype.setStateRoot + const originalStateManagerCopy = MerkleStateManager.prototype.shallowCopy + MerkleStateManager.prototype.setStateRoot = function (): any {} + MerkleStateManager.prototype.shallowCopy = function () { return this } const { chain, service, server, common } = await setupChain( @@ -192,7 +192,7 @@ describe(method, () => { ) // Restore setStateRoot - DefaultStateManager.prototype.setStateRoot = originalSetStateRoot - DefaultStateManager.prototype.shallowCopy = originalStateManagerCopy + MerkleStateManager.prototype.setStateRoot = originalSetStateRoot + MerkleStateManager.prototype.shallowCopy = originalStateManagerCopy }) }) diff --git a/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts b/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts index 75e11fbf2e..67b30b6ba0 100644 --- a/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts +++ b/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts @@ -1,6 +1,6 @@ import { createBlock, createBlockHeader } from '@ethereumjs/block' import { Hardfork } from '@ethereumjs/common' -import { DefaultStateManager } from '@ethereumjs/statemanager' +import { MerkleStateManager } from '@ethereumjs/statemanager' import { createTxFromTxData } from '@ethereumjs/tx' import { Account, bytesToHex, createAddressFromPrivateKey, hexToBytes } from '@ethereumjs/util' import { assert, describe, it, vi } from 'vitest' @@ -30,8 +30,8 @@ describe(method, () => { }) it('call with valid parameters', async () => { - DefaultStateManager.prototype.setStateRoot = vi.fn() - DefaultStateManager.prototype.shallowCopy = function () { + MerkleStateManager.prototype.setStateRoot = vi.fn() + MerkleStateManager.prototype.shallowCopy = function () { return this } const { chain, service, server, common } = await setupChain(genesisJSON, 'post-merge', { @@ -112,8 +112,8 @@ describe(method, () => { }) it('call with valid parameters on pre-Shanghai hardfork', async () => { - DefaultStateManager.prototype.setStateRoot = vi.fn() - DefaultStateManager.prototype.shallowCopy = function () { + MerkleStateManager.prototype.setStateRoot = vi.fn() + MerkleStateManager.prototype.shallowCopy = function () { return this } const { chain, service, server, common } = await setupChain(preShanghaiGenesisJSON, 'london', { diff --git a/packages/client/test/rpc/engine/getPayloadV3.spec.ts b/packages/client/test/rpc/engine/getPayloadV3.spec.ts index 28b4b69747..b7b2b1b0d4 100644 --- a/packages/client/test/rpc/engine/getPayloadV3.spec.ts +++ b/packages/client/test/rpc/engine/getPayloadV3.spec.ts @@ -1,5 +1,5 @@ import { Hardfork } from '@ethereumjs/common' -import { DefaultStateManager } from '@ethereumjs/statemanager' +import { MerkleStateManager } from '@ethereumjs/statemanager' import { createTxFromTxData } from '@ethereumjs/tx' import { Account, @@ -61,10 +61,10 @@ describe(method, () => { it('call with known payload', async () => { // Disable stateroot validation in TxPool since valid state root isn't available - const originalSetStateRoot = DefaultStateManager.prototype.setStateRoot - const originalStateManagerCopy = DefaultStateManager.prototype.shallowCopy - DefaultStateManager.prototype.setStateRoot = function (): any {} - DefaultStateManager.prototype.shallowCopy = function () { + const originalSetStateRoot = MerkleStateManager.prototype.setStateRoot + const originalStateManagerCopy = MerkleStateManager.prototype.shallowCopy + MerkleStateManager.prototype.setStateRoot = function (): any {} + MerkleStateManager.prototype.shallowCopy = function () { return this } @@ -131,7 +131,7 @@ describe(method, () => { assert.equal(commitments[0], bytesToHex(txCommitments[0]), 'commitment should match') assert.equal(blobs[0], bytesToHex(txBlobs[0]), 'blob should match') - DefaultStateManager.prototype.setStateRoot = originalSetStateRoot - DefaultStateManager.prototype.shallowCopy = originalStateManagerCopy + MerkleStateManager.prototype.setStateRoot = originalSetStateRoot + MerkleStateManager.prototype.shallowCopy = originalStateManagerCopy }) }) diff --git a/packages/client/test/rpc/eth/sendRawTransaction.spec.ts b/packages/client/test/rpc/eth/sendRawTransaction.spec.ts index 9a9247b199..4869d58313 100644 --- a/packages/client/test/rpc/eth/sendRawTransaction.spec.ts +++ b/packages/client/test/rpc/eth/sendRawTransaction.spec.ts @@ -1,6 +1,6 @@ import { BlockHeader } from '@ethereumjs/block' import { Common, Hardfork, Mainnet, createCommonFromGethGenesis } from '@ethereumjs/common' -import { DefaultStateManager } from '@ethereumjs/statemanager' +import { MerkleStateManager } from '@ethereumjs/statemanager' import { createBlob4844Tx, createFeeMarket1559TxFromRLP, createLegacyTx } from '@ethereumjs/tx' import { Account, @@ -24,10 +24,10 @@ const method = 'eth_sendRawTransaction' describe(method, () => { it('call with valid arguments', async () => { // Disable stateroot validation in TxPool since valid state root isn't available - const originalSetStateRoot = DefaultStateManager.prototype.setStateRoot - const originalStateManagerCopy = DefaultStateManager.prototype.shallowCopy - DefaultStateManager.prototype.setStateRoot = function (): any {} - DefaultStateManager.prototype.shallowCopy = function () { + const originalSetStateRoot = MerkleStateManager.prototype.setStateRoot + const originalStateManagerCopy = MerkleStateManager.prototype.shallowCopy + MerkleStateManager.prototype.setStateRoot = function (): any {} + MerkleStateManager.prototype.shallowCopy = function () { return this } // Unschedule any timestamp since tests are not configured for timestamps @@ -66,14 +66,14 @@ describe(method, () => { ) // Restore setStateRoot - DefaultStateManager.prototype.setStateRoot = originalSetStateRoot - DefaultStateManager.prototype.shallowCopy = originalStateManagerCopy + MerkleStateManager.prototype.setStateRoot = originalSetStateRoot + MerkleStateManager.prototype.shallowCopy = originalStateManagerCopy }) it('send local tx with gasprice lower than minimum', async () => { // Disable stateroot validation in TxPool since valid state root isn't available - const originalSetStateRoot = DefaultStateManager.prototype.setStateRoot - DefaultStateManager.prototype.setStateRoot = (): any => {} + const originalSetStateRoot = MerkleStateManager.prototype.setStateRoot + MerkleStateManager.prototype.setStateRoot = (): any => {} const syncTargetHeight = new Common({ chain: Mainnet }).hardforkBlock(Hardfork.London) const { rpc } = await baseSetup({ syncTargetHeight, includeVM: true }) @@ -94,13 +94,13 @@ describe(method, () => { ) // Restore setStateRoot - DefaultStateManager.prototype.setStateRoot = originalSetStateRoot + MerkleStateManager.prototype.setStateRoot = originalSetStateRoot }) it('call with invalid arguments: not enough balance', async () => { // Disable stateroot validation in TxPool since valid state root isn't available - const originalSetStateRoot = DefaultStateManager.prototype.setStateRoot - DefaultStateManager.prototype.setStateRoot = (): any => {} + const originalSetStateRoot = MerkleStateManager.prototype.setStateRoot + MerkleStateManager.prototype.setStateRoot = (): any => {} const syncTargetHeight = new Common({ chain: Mainnet }).hardforkBlock(Hardfork.London) const { rpc } = await baseSetup({ syncTargetHeight, includeVM: true }) @@ -113,7 +113,7 @@ describe(method, () => { assert.ok(res.error.message.includes('insufficient balance')) // Restore setStateRoot - DefaultStateManager.prototype.setStateRoot = originalSetStateRoot + MerkleStateManager.prototype.setStateRoot = originalSetStateRoot }) it('call with sync target height not set yet', async () => { @@ -170,10 +170,10 @@ describe(method, () => { it('call with no peers', async () => { // Disable stateroot validation in TxPool since valid state root isn't available - const originalSetStateRoot = DefaultStateManager.prototype.setStateRoot - DefaultStateManager.prototype.setStateRoot = (): any => {} - const originalStateManagerCopy = DefaultStateManager.prototype.shallowCopy - DefaultStateManager.prototype.shallowCopy = function () { + const originalSetStateRoot = MerkleStateManager.prototype.setStateRoot + MerkleStateManager.prototype.setStateRoot = (): any => {} + const originalStateManagerCopy = MerkleStateManager.prototype.shallowCopy + MerkleStateManager.prototype.shallowCopy = function () { return this } const common = new Common({ chain: Mainnet, hardfork: Hardfork.London }) @@ -204,16 +204,16 @@ describe(method, () => { assert.ok(res.error.message.includes('no peer connection available')) // Restore setStateRoot - DefaultStateManager.prototype.setStateRoot = originalSetStateRoot - DefaultStateManager.prototype.shallowCopy = originalStateManagerCopy + MerkleStateManager.prototype.setStateRoot = originalSetStateRoot + MerkleStateManager.prototype.shallowCopy = originalStateManagerCopy }) it('blob EIP 4844 transaction', async () => { // Disable stateroot validation in TxPool since valid state root isn't available - const originalSetStateRoot = DefaultStateManager.prototype.setStateRoot - DefaultStateManager.prototype.setStateRoot = (): any => {} - const originalStateManagerCopy = DefaultStateManager.prototype.shallowCopy - DefaultStateManager.prototype.shallowCopy = function () { + const originalSetStateRoot = MerkleStateManager.prototype.setStateRoot + MerkleStateManager.prototype.setStateRoot = (): any => {} + const originalStateManagerCopy = MerkleStateManager.prototype.shallowCopy + MerkleStateManager.prototype.shallowCopy = function () { return this } // Disable block header consensus format validation @@ -283,8 +283,8 @@ describe(method, () => { assert.ok(res2.error.message.includes('replacement blob gas too low')) // Restore stubbed out functionality - DefaultStateManager.prototype.setStateRoot = originalSetStateRoot - DefaultStateManager.prototype.shallowCopy = originalStateManagerCopy + MerkleStateManager.prototype.setStateRoot = originalSetStateRoot + MerkleStateManager.prototype.shallowCopy = originalStateManagerCopy BlockHeader.prototype['_consensusFormatValidation'] = consensusFormatValidation }) }) diff --git a/packages/client/test/sim/snapsync.spec.ts b/packages/client/test/sim/snapsync.spec.ts index 8b4a24a300..33d7c0e2f0 100644 --- a/packages/client/test/sim/snapsync.spec.ts +++ b/packages/client/test/sim/snapsync.spec.ts @@ -25,7 +25,7 @@ import { } from './simutils.js' import type { EthereumClient } from '../../src/client.js' -import type { DefaultStateManager } from '@ethereumjs/statemanager' +import type { MerkleStateManager } from '@ethereumjs/statemanager' import type { PrefixedHexString } from '@ethereumjs/util' const client = Client.http({ port: 8545 }) @@ -43,7 +43,7 @@ let senderBalance = BigInt(customGenesisState[sender][0]) let ejsClient: EthereumClient | null = null let beaconSyncRelayer: any = null let snapCompleted: Promise | undefined = undefined -let stateManager: DefaultStateManager | undefined = undefined +let stateManager: MerkleStateManager | undefined = undefined // This account doesn't exist in the genesis so starting balance is zero const EOATransferToAccount = '0x3dA33B9A0894b908DdBb00d96399e506515A1009' @@ -271,7 +271,7 @@ async function createSnapClient( const snapSyncCompletedPromise = new Promise((resolve) => { config.events.once( Event.SYNC_SNAPSYNC_COMPLETE, - (stateRoot: Uint8Array, stateManager: DefaultStateManager) => + (stateRoot: Uint8Array, stateManager: MerkleStateManager) => resolve([stateRoot, stateManager]), ) }) diff --git a/packages/client/test/sync/txpool.spec.ts b/packages/client/test/sync/txpool.spec.ts index b93d5e2f25..812dfe12fd 100644 --- a/packages/client/test/sync/txpool.spec.ts +++ b/packages/client/test/sync/txpool.spec.ts @@ -1,6 +1,6 @@ import { createBlock } from '@ethereumjs/block' import { Common, Hardfork, Mainnet } from '@ethereumjs/common' -import { DefaultStateManager } from '@ethereumjs/statemanager' +import { MerkleStateManager } from '@ethereumjs/statemanager' import { createAccessList2930Tx, createFeeMarket1559Tx } from '@ethereumjs/tx' import { Account, @@ -106,7 +106,7 @@ const config = new Config({ accountCache: 10000, storageCache: 1000 }) const handleTxs = async ( txs: any[], failMessage: string, - stateManager?: DefaultStateManager, + stateManager?: MerkleStateManager, pool?: TxPool, ) => { if (pool === undefined) { @@ -152,8 +152,8 @@ const handleTxs = async ( } describe('[TxPool]', async () => { - const ogStateManagerSetStateRoot = DefaultStateManager.prototype.setStateRoot - DefaultStateManager.prototype.setStateRoot = (): any => {} + const ogStateManagerSetStateRoot = MerkleStateManager.prototype.setStateRoot + MerkleStateManager.prototype.setStateRoot = (): any => {} const A = { address: hexToBytes('0x0b90087d864e82a284dca15923f3776de6bb016f'), @@ -884,5 +884,5 @@ describe('[TxPool]', async () => { pool.stop() pool.close() }) - DefaultStateManager.prototype.setStateRoot = ogStateManagerSetStateRoot + MerkleStateManager.prototype.setStateRoot = ogStateManagerSetStateRoot }) diff --git a/packages/evm/examples/browser.html b/packages/evm/examples/browser.html index 586f5f4561..7d60c4b90c 100644 --- a/packages/evm/examples/browser.html +++ b/packages/evm/examples/browser.html @@ -7,12 +7,12 @@ import { Blockchain } from '@ethereumjs/blockchain' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { EVM } from '@ethereumjs/evm' - import { DefaultStateManager } from '@ethereumjs/statemanager' + import { MerkleStateManager } from '@ethereumjs/statemanager' import { bytesToHex, hexToBytes } from '@ethereumjs/util' const main = async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const stateManager = new DefaultStateManager() + const stateManager = new MerkleStateManager() const blockchain = await Blockchain.create() const evm = await EVM.create({ diff --git a/packages/evm/examples/withBlockchain.ts b/packages/evm/examples/withBlockchain.ts index 4bdda1dc48..89c0c45c6c 100644 --- a/packages/evm/examples/withBlockchain.ts +++ b/packages/evm/examples/withBlockchain.ts @@ -1,14 +1,14 @@ import { createBlockchain } from '@ethereumjs/blockchain' import { Common, Hardfork, Mainnet } from '@ethereumjs/common' import { createEVM } from '@ethereumjs/evm' -import { DefaultStateManager } from '@ethereumjs/statemanager' +import { MerkleStateManager } from '@ethereumjs/statemanager' import { bytesToHex, hexToBytes } from '@ethereumjs/util' import type { PrefixedHexString } from '@ethereumjs/util' const main = async () => { const common = new Common({ chain: Mainnet, hardfork: Hardfork.Shanghai }) - const stateManager = new DefaultStateManager() + const stateManager = new MerkleStateManager() const blockchain = await createBlockchain() const evm = await createEVM({ diff --git a/packages/statemanager/examples/basicUsage.ts b/packages/statemanager/examples/basicUsage.ts index 462e28b8cd..8dc4f38d63 100644 --- a/packages/statemanager/examples/basicUsage.ts +++ b/packages/statemanager/examples/basicUsage.ts @@ -1,8 +1,8 @@ -import { DefaultStateManager } from '@ethereumjs/statemanager' +import { MerkleStateManager } from '@ethereumjs/statemanager' import { Account, Address, hexToBytes } from '@ethereumjs/util' const main = async () => { - const stateManager = new DefaultStateManager() + const stateManager = new MerkleStateManager() const address = new Address(hexToBytes('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b')) const account = new Account(BigInt(0), BigInt(1000)) await stateManager.checkpoint() diff --git a/packages/statemanager/examples/browser.html b/packages/statemanager/examples/browser.html index 0d0d377ce2..2fa2183759 100644 --- a/packages/statemanager/examples/browser.html +++ b/packages/statemanager/examples/browser.html @@ -5,11 +5,11 @@ EthereumJS Browser Examples