diff --git a/packages/block/src/header/header.ts b/packages/block/src/header/header.ts index 79675dafedd..826360773f7 100644 --- a/packages/block/src/header/header.ts +++ b/packages/block/src/header/header.ts @@ -98,7 +98,7 @@ export class BlockHeader { chain: Mainnet, // default }) } - this.common.updateParams(opts.params ?? paramsBlock) + this.common.updateParams(opts.params ?? paramsBlock, '@ethereumjs/block') this.keccakFunction = this.common.customCrypto.keccak256 ?? keccak256 diff --git a/packages/common/src/common.ts b/packages/common/src/common.ts index 7f040655404..05ffa58c63c 100644 --- a/packages/common/src/common.ts +++ b/packages/common/src/common.ts @@ -47,6 +47,7 @@ export class Common { protected _hardfork: string | Hardfork protected _eips: number[] = [] protected _params: ParamsDict + protected _includedParams: string[] = [] public readonly customCrypto: CustomCrypto @@ -101,8 +102,15 @@ export class Common { * ``` * * @param params + * @param name Provide a self-chosen name for a param set to not unnecessarily re-include parameters */ - updateParams(params: ParamsDict) { + updateParams(params: ParamsDict, name?: string) { + if (name !== undefined) { + if (this._includedParams.includes(name)) { + return + } + this._includedParams.push(name) + } for (const [eip, paramsConfig] of Object.entries(params)) { if (!(eip in this._params)) { this._params[eip] = JSON.parse(JSON.stringify(paramsConfig)) // copy @@ -114,26 +122,6 @@ export class Common { this._buildParamsCache() } - /** - * Fully resets the internal Common EIP params set with the values provided. - * - * Example Format: - * - * ```ts - * { - * 1559: { - * initialBaseFee: 1000000000, - * } - * } - * ``` - * - * @param params - */ - resetParams(params: ParamsDict) { - this._params = JSON.parse(JSON.stringify(params)) // copy - this._buildParamsCache() - } - /** * Sets the hardfork to get params for * @param hardfork String identifier (e.g. 'byzantium') or {@link Hardfork} enum @@ -842,6 +830,13 @@ export class Common { */ copy(): Common { const copy = Object.assign(Object.create(Object.getPrototypeOf(this)), this) + // TODO: hotfix since copy() method is still not working properly in Common, + // discovered along double association of this.common in the tx library + // (BaseTransaction + Subclass), where not all properties made it to the + // copied object. So this copy() should be replaced with a more robust/correct + // method (simple re-instantiation likely, needs various tests though to secure) + copy._buildParamsCache() + copy._buildActivatedEIPsCache() copy.events = new EventEmitter() return copy } diff --git a/packages/common/test/params.spec.ts b/packages/common/test/params.spec.ts index 626954fdb70..404c16718f1 100644 --- a/packages/common/test/params.spec.ts +++ b/packages/common/test/params.spec.ts @@ -18,16 +18,14 @@ describe('[Common]: Parameter instantiation / params option / Updates', () => { c.updateParams(params) msg = 'Should update parameter on updateParams() and properly rebuild cache' assert.equal(c.param('bn254AddGas'), BigInt(250), msg) - - c.resetParams(params) - msg = 'Should reset all parameters on resetParams() and properly rebuild cache' - assert.equal(c.param('bn254AddGas'), BigInt(250), msg) - assert.throws(() => { - c.param('bn254MulGas'), BigInt(250) - }) + assert.equal(c['_includedParams'].length, 0, msg) msg = 'Should not side-manipulate the original params file during updating internally' assert.equal(paramsTest['1679']['bn254AddGas'], 150) + + msg = 'Should add optional parameter set name to parameter set names array' + c.updateParams(params, 'myparams') + assert.equal(c['_includedParams'].length, 1, msg) }) }) diff --git a/packages/evm/src/evm.ts b/packages/evm/src/evm.ts index 869b479db77..b3f16ee51cb 100644 --- a/packages/evm/src/evm.ts +++ b/packages/evm/src/evm.ts @@ -194,7 +194,7 @@ export class EVM implements EVMInterface { ) } - this.common.updateParams(opts.params ?? paramsEVM) + this.common.updateParams(opts.params ?? paramsEVM, '@ethereumjs/evm') this.allowUnlimitedContractSize = opts.allowUnlimitedContractSize ?? false this.allowUnlimitedInitCodeSize = opts.allowUnlimitedInitCodeSize ?? false diff --git a/packages/tx/src/1559/tx.ts b/packages/tx/src/1559/tx.ts index 372f824e313..50d23b5b024 100644 --- a/packages/tx/src/1559/tx.ts +++ b/packages/tx/src/1559/tx.ts @@ -65,7 +65,7 @@ export class FeeMarket1559Tx extends BaseTransaction bytesToHex(blob)) diff --git a/packages/tx/src/4844/tx.ts b/packages/tx/src/4844/tx.ts index 909f462a557..c3fdcf31a5a 100644 --- a/packages/tx/src/4844/tx.ts +++ b/packages/tx/src/4844/tx.ts @@ -74,7 +74,7 @@ export class Blob4844Tx extends BaseTransaction { `Common chain ID ${this.common.chainId} not matching the derived chain ID ${chainId}`, ) } - this.common.updateParams(opts.params ?? paramsTx) + this.common.updateParams(opts.params ?? paramsTx, '@ethereumjs/tx') this.chainId = this.common.chainId() if (!this.common.isActivatedEIP(1559)) { diff --git a/packages/tx/src/7702/tx.ts b/packages/tx/src/7702/tx.ts index d9ccc9086c2..e884da019dc 100644 --- a/packages/tx/src/7702/tx.ts +++ b/packages/tx/src/7702/tx.ts @@ -68,7 +68,7 @@ export class EOACode7702Transaction extends BaseTransaction const createContract = this.to === undefined || this.to === null const allowUnlimitedInitCodeSize = opts.allowUnlimitedInitCodeSize ?? false - this.common.updateParams(opts.params ?? paramsTx) + this.common.updateParams(opts.params ?? paramsTx, '@ethereumjs/tx') if ( createContract && this.common.isActivatedEIP(3860) && diff --git a/packages/tx/src/legacy/tx.ts b/packages/tx/src/legacy/tx.ts index 2b02ec2e026..8a5731ee11d 100644 --- a/packages/tx/src/legacy/tx.ts +++ b/packages/tx/src/legacy/tx.ts @@ -63,7 +63,7 @@ export class LegacyTx extends BaseTransaction { ) } - this.common.updateParams(opts.params ?? paramsTx) + this.common.updateParams(opts.params ?? paramsTx, '@ethereumjs/tx') this.keccakFunction = this.common.customCrypto.keccak256 ?? keccak256 this.gasPrice = bytesToBigInt(toBytes(txData.gasPrice)) diff --git a/packages/tx/test/base.spec.ts b/packages/tx/test/base.spec.ts index a2117f10e58..6d37d07dacb 100644 --- a/packages/tx/test/base.spec.ts +++ b/packages/tx/test/base.spec.ts @@ -39,7 +39,7 @@ import type { AccessList2930TxData, FeeMarketEIP1559TxData, LegacyTxData } from describe('[BaseTransaction]', () => { // EIP-2930 is not enabled in Common by default (2021-03-06) - const common = new Common({ chain: Mainnet, hardfork: Hardfork.London }) + let common = new Common({ chain: Mainnet, hardfork: Hardfork.London }) const legacyTxs: BaseTransaction[] = [] for (const tx of txsData.slice(0, 4)) { @@ -148,6 +148,7 @@ describe('[BaseTransaction]', () => { `${txType.name}: tx should not be frozen when freeze deactivated in options`, ) + common = new Common({ chain: Mainnet, hardfork: Hardfork.London }) const params = JSON.parse(JSON.stringify(paramsTx)) params['1']['txGas'] = 30000 // 21000 tx = txType.create.txData({}, { common, params }) diff --git a/packages/vm/src/vm.ts b/packages/vm/src/vm.ts index 5d010271a43..4444483ad0d 100644 --- a/packages/vm/src/vm.ts +++ b/packages/vm/src/vm.ts @@ -68,7 +68,7 @@ export class VM { */ constructor(opts: VMOpts = {}) { this.common = opts.common! - this.common.updateParams(opts.params ?? paramsVM) + this.common.updateParams(opts.params ?? paramsVM, '@ethereumjs/vm') this.stateManager = opts.stateManager! this.blockchain = opts.blockchain! this.evm = opts.evm!