-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
statemanager: cache and other refactors (#3569)
* Revert "statemanager: refactor logic into capabilities (#3554)" This reverts commit d7d1dab. * statemanager: refactor modifyAccountFields * statemanager: adjust return statements * statemanager: refactor separate caches into caches class * statemanager: fix shallow copy logic * client: fix vmexecution statemanager cache opts * statemanager: refactor some capabilities to caches methods * statemanager: fix tests * statemanager: refactor caches into optional opt passed in directly to the sm * statemanager: adjust tests with refactored caches * client: adjust vm execution with update cache * vm: fix vm tests * vm: adjust test runners with non-default caches * statemanager: simplify handling of deactivate * statemanager: remove redundant checks * statemanager: remove non null asesertion * statemanager: remove cache opt from key naming * statemanager: refactor rpc state manager to use caches * statemanager: fix rpc state manager tests * client: vmexecution cache stats refactor * statemanageR: updategetproof json-rpc call format * statemanager: remove deactivate from caches * client: remove deactivate from vm execution instantiation --------- Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com>
- Loading branch information
1 parent
837a83f
commit 45e0a6d
Showing
30 changed files
with
635 additions
and
585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { AccountCache } from './account.js' | ||
import { CodeCache } from './code.js' | ||
import { StorageCache } from './storage.js' | ||
import { CacheType, type CachesStateManagerOpts } from './types.js' | ||
|
||
import type { CacheOpts } from './types.js' | ||
import type { Address } from '@ethereumjs/util' | ||
|
||
export class Caches { | ||
account?: AccountCache | ||
code?: CodeCache | ||
storage?: StorageCache | ||
|
||
settings: Record<'account' | 'code' | 'storage', CacheOpts> | ||
|
||
constructor(opts: CachesStateManagerOpts = {}) { | ||
const accountSettings = { | ||
type: opts.account?.type ?? CacheType.ORDERED_MAP, | ||
size: opts.account?.size ?? 100000, | ||
} | ||
|
||
const codeSettings = { | ||
type: opts.code?.type ?? CacheType.ORDERED_MAP, | ||
size: opts.code?.size ?? 20000, | ||
} | ||
|
||
const storageSettings = { | ||
type: opts.storage?.type ?? CacheType.ORDERED_MAP, | ||
size: opts.storage?.size ?? 20000, | ||
} | ||
|
||
this.settings = { | ||
account: accountSettings, | ||
code: codeSettings, | ||
storage: storageSettings, | ||
} | ||
|
||
if (this.settings.account.size !== 0) { | ||
this.account = new AccountCache({ | ||
size: this.settings.account.size, | ||
type: this.settings.account.type, | ||
}) | ||
} | ||
|
||
if (this.settings.code.size !== 0) { | ||
this.code = new CodeCache({ | ||
size: this.settings.code.size, | ||
type: this.settings.code.type, | ||
}) | ||
} | ||
|
||
if (this.settings.storage.size !== 0) { | ||
this.storage = new StorageCache({ | ||
size: this.settings.storage.size, | ||
type: this.settings.storage.type, | ||
}) | ||
} | ||
} | ||
|
||
checkpoint() { | ||
this.account?.checkpoint() | ||
this.storage?.checkpoint() | ||
this.code?.checkpoint() | ||
} | ||
|
||
clear() { | ||
this.account?.clear() | ||
this.storage?.clear() | ||
this.code?.clear() | ||
} | ||
|
||
commit() { | ||
this.account?.commit() | ||
this.storage?.commit() | ||
this.code?.commit() | ||
} | ||
|
||
deleteAccount(address: Address) { | ||
this.code?.del(address) | ||
this.account?.del(address) | ||
this.storage?.clearStorage(address) | ||
} | ||
|
||
revert() { | ||
this.account?.revert() | ||
this.storage?.revert() | ||
this.code?.revert() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,36 @@ | ||
import type { CacheType } from '@ethereumjs/common' | ||
export enum CacheType { | ||
LRU = 'lru', | ||
ORDERED_MAP = 'ordered_map', | ||
} | ||
|
||
export interface CacheOpts { | ||
/** | ||
* Size of the cache (only for LRU cache) | ||
* | ||
* Default: 100000 (account cache) / 20000 (storage cache) / 20000 (code cache) | ||
* | ||
* Note: the cache/trie interplay mechanism is designed in a way that | ||
* the theoretical number of max modified accounts between two flush operations | ||
* should be smaller than the cache size, otherwise the cache will "forget" the | ||
* old modifications resulting in an incomplete set of trie-flushed accounts. | ||
*/ | ||
size: number | ||
/** | ||
* Cache type to use. | ||
* | ||
* Available options: | ||
* | ||
* ORDERED_MAP: Cache with no fixed upper bound and dynamic allocation, | ||
* use for dynamic setups like testing or similar. | ||
* | ||
* LRU: LRU cache with pre-allocation of memory and a fixed size. | ||
* Use for larger and more persistent caches. | ||
*/ | ||
type: CacheType | ||
} | ||
|
||
export interface CachesStateManagerOpts { | ||
account?: Partial<CacheOpts> | ||
code?: Partial<CacheOpts> | ||
storage?: Partial<CacheOpts> | ||
} |
Oops, something went wrong.