-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into block-consensus-met…
…hods-refactoring
- Loading branch information
Showing
37 changed files
with
726 additions
and
804 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
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.