Skip to content

Commit

Permalink
Update function docs to detail shallow copy behavior (#2855)
Browse files Browse the repository at this point in the history
  • Loading branch information
scorbajio authored Jul 4, 2023
1 parent 629c80f commit d7131f5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/blockchain/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface BlockchainInterface {
): Promise<number>

/**
* Returns a copy of the blockchain
* Returns a shallow copy of the blockchain that may share state with the original
*/
shallowCopy(): BlockchainInterface

Expand Down
9 changes: 9 additions & 0 deletions packages/evm/src/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,15 @@ export class EVM implements EVMInterface {
if (this._common.isActivatedEIP(1153)) this._transientStorage.clear()
}

/**
* This method copies the EVM, current HF and EIP settings
* and returns a new EVM instance.
*
* Note: this is only a shallow copy and both EVM instances
* will point to the same underlying state DB.
*
* @returns EVMInterface
*/
public shallowCopy(): EVMInterface {
const common = this._common.copy()
common.setHardfork(this._common.hardfork())
Expand Down
5 changes: 5 additions & 0 deletions packages/statemanager/src/ethersStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export class EthersStateManager implements EVMStateManagerInterface {
this.originalStorageCache = new OriginalStorageCache(this.getContractStorage.bind(this))
}

/**
* Note that the returned statemanager will share the same JsonRpcProvider as the original
*
* @returns EthersStateManager
*/
shallowCopy(): EthersStateManager {
const newState = new EthersStateManager({
provider: this.provider,
Expand Down
5 changes: 5 additions & 0 deletions packages/util/src/mapDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export class MapDB<
}
}

/**
* Note that the returned shallow copy will share the underlying database with the original
*
* @returns DB
*/
shallowCopy(): DB<TKey, TValue> {
return new MapDB<TKey, TValue>(this._database)
}
Expand Down
2 changes: 2 additions & 0 deletions packages/vm/src/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ export class VM {

/**
* Returns a copy of the {@link VM} instance.
*
* Note that the returned copy will share the same db as the original for the blockchain and the statemanager
*/
async shallowCopy(): Promise<VM> {
const common = this._common.copy()
Expand Down

0 comments on commit d7131f5

Please sign in to comment.