Skip to content

Commit

Permalink
client: add a cli option for backward compatibility with non prefixed…
Browse files Browse the repository at this point in the history
… storage tries (#3042)

* client: add a cli option for backward compatibility with non prefixed storage tries

* Apply suggestions from code review

Co-authored-by: Scorbajio <[email protected]>

* Fix comment

---------

Co-authored-by: Holger Drewes <[email protected]>
Co-authored-by: Scorbajio <[email protected]>
Co-authored-by: acolytec3 <[email protected]>
  • Loading branch information
4 people authored Sep 20, 2023
1 parent 2b13cca commit 9389082
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,14 @@ const args: ClientOpts = yargs(hideBin(process.argv))
describe: 'Force a snap sync run (for testing and development purposes)',
boolean: true,
})
.option('prefixStorageTrieKeys', {
describe:
'Enable/Disable storage trie prefixes (specify `false` for backward compatibility with previous states synced without prefixes)',
boolean: true,
default: true,
deprecated:
'Support for `--prefixStorageTrieKeys=false` is temporary. Please sync new instances with `prefixStorageTrieKeys` enabled',
})
.option('txLookupLimit', {
describe:
'Number of recent blocks to maintain transactions index for (default = about one year, 0 = entire chain)',
Expand Down Expand Up @@ -835,6 +843,7 @@ async function run() {
syncmode: args.sync,
disableBeaconSync: args.disableBeaconSync,
forceSnapSync: args.forceSnapSync,
prefixStorageTrieKeys: args.prefixStorageTrieKeys,
transports: args.transports,
txLookupLimit: args.txLookupLimit,
})
Expand Down
10 changes: 10 additions & 0 deletions packages/client/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ export interface ConfigOptions {
*/
forceSnapSync?: boolean

/**
* A temporary option to offer backward compatibility with already-synced databases that are
* using non-prefixed keys for storage tries
*
* Default: true
*/
prefixStorageTrieKeys?: boolean

/**
* Provide a custom VM instance to process blocks
*
Expand Down Expand Up @@ -402,6 +410,7 @@ export class Config {
public readonly forceSnapSync: boolean
// Just a development only flag, will/should be removed
public readonly disableSnapSync: boolean = false
public readonly prefixStorageTrieKeys: boolean

public synchronized: boolean
/** lastSyncDate in ms */
Expand Down Expand Up @@ -473,6 +482,7 @@ export class Config {

this.disableBeaconSync = options.disableBeaconSync ?? false
this.forceSnapSync = options.forceSnapSync ?? false
this.prefixStorageTrieKeys = options.prefixStorageTrieKeys ?? true

// Start it off as synchronized if this is configured to mine or as single node
this.synchronized = this.isSingleNode ?? this.mine
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/execution/vmexecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class VMExecution extends Execution {
this.config.logger.info(`Initializing trie cache size=${this.config.trieCache}`)
const stateManager = new DefaultStateManager({
trie,
prefixStorageTrieKeys: true,
prefixStorageTrieKeys: this.config.prefixStorageTrieKeys,
accountCacheOpts: {
deactivate: false,
type: CacheType.LRU,
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export interface ClientOpts {
saveReceipts?: boolean
disableBeaconSync?: boolean
forceSnapSync?: boolean
prefixStorageTrieKeys?: boolean
txLookupLimit?: number
startBlock?: number
isSingleNode?: boolean
Expand Down

0 comments on commit 9389082

Please sign in to comment.