Skip to content

Commit

Permalink
statemanager: fix shallow copy logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau committed Aug 9, 2024
1 parent 31c94af commit bba928b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/client/src/execution/vmexecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
DBSetHashToNumber,
DBSetTD,
} from '@ethereumjs/blockchain'
import { CacheType, ConsensusType, Hardfork } from '@ethereumjs/common'
import { ConsensusType, Hardfork } from '@ethereumjs/common'
import { MCLBLS, RustBN254 } from '@ethereumjs/evm'
import { getGenesis } from '@ethereumjs/genesis'
import {
Expand Down
4 changes: 1 addition & 3 deletions packages/statemanager/src/stateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,7 @@ export class DefaultStateManager implements StateManagerInterface {
trie,
prefixStorageTrieKeys,
prefixCodeHashes,
accountCacheOpts,
storageCacheOpts,
codeCacheOpts,
cachesOpts: { accountCacheOpts, storageCacheOpts, codeCacheOpts },
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/statemanager/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface RPCStateManagerOpts extends BaseStateManagerOpts {
/**
* Options for constructing a {@link StateManager}.
*/
export interface DefaultStateManagerOpts extends BaseStateManagerOpts, CachesStateManagerOpts {
export interface DefaultStateManagerOpts extends BaseStateManagerOpts {
/**
* A {@link Trie} instance
*/
Expand Down
20 changes: 11 additions & 9 deletions packages/statemanager/test/stateManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,37 @@ describe('StateManager -> General', () => {

sm = new DefaultStateManager({
trie,
accountCacheOpts: {
type: CacheType.LRU,
},
storageCacheOpts: {
type: CacheType.LRU,
cachesOpts: {
accountCacheOpts: {
type: CacheType.LRU,
},
storageCacheOpts: {
type: CacheType.LRU,
},
},
})

smCopy = sm.shallowCopy()
assert.equal(
smCopy['_accountCacheSettings'].type,
smCopy['_caches'].settings.account.type,
CacheType.ORDERED_MAP,
'should switch to ORDERED_MAP account cache on copy()',
)
assert.equal(
smCopy['_storageCacheSettings'].type,
smCopy['_caches'].settings.storage.type,
CacheType.ORDERED_MAP,
'should switch to ORDERED_MAP storage cache on copy()',
)
assert.equal(smCopy['_trie']['_opts'].cacheSize, 0, 'should set trie cache size to 0')

smCopy = sm.shallowCopy(false)
assert.equal(
smCopy['_accountCacheSettings'].type,
smCopy['_caches'].settings.account.type,
CacheType.LRU,
'should retain account cache type when deactivate cache downleveling',
)
assert.equal(
smCopy['_storageCacheSettings'].type,
smCopy['_caches'].settings.storage.type,
CacheType.LRU,
'should retain storage cache type when deactivate cache downleveling',
)
Expand Down
16 changes: 9 additions & 7 deletions packages/statemanager/test/statelessVerkleStateManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => {

it(`copy()`, async () => {
const stateManager = new StatelessVerkleStateManager({
accountCacheOpts: {
type: CacheType.ORDERED_MAP,
},
storageCacheOpts: {
type: CacheType.ORDERED_MAP,
cachesOpts: {
accountCacheOpts: {
type: CacheType.ORDERED_MAP,
},
storageCacheOpts: {
type: CacheType.ORDERED_MAP,
},
},
common,
verkleCrypto,
Expand All @@ -158,12 +160,12 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => {
const stateManagerCopy = stateManager.shallowCopy() as StatelessVerkleStateManager

assert.equal(
(stateManagerCopy as any)['_accountCacheSettings'].type,
stateManagerCopy['_caches'].settings.account.type,
CacheType.ORDERED_MAP,
'should switch to ORDERED_MAP account cache on copy()',
)
assert.equal(
(stateManagerCopy as any)['_storageCacheSettings'].type,
stateManagerCopy['_caches'].settings.storage.type,
CacheType.ORDERED_MAP,
'should switch to ORDERED_MAP storage cache on copy()',
)
Expand Down

0 comments on commit bba928b

Please sign in to comment.