Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common: Remove Param Topics #3532

Merged
merged 12 commits into from
Jul 23, 2024
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"e2e:publish": "./scripts/e2e-publish.sh",
"e2e:resolutions": "node ./scripts/e2e-resolutions.js",
"examples": "npm run examples --workspaces --if-present",
"lint": "npm run lint --workspaces --if-present",
"lint:fix": "npm run lint:fix --workspaces --if-present",
"test": "npm run test --workspaces --if-present",
"test:node": "npm run test:node --workspaces --if-present",
acolytec3 marked this conversation as resolved.
Show resolved Hide resolved
"test:browser": "npm run test:browser --workspaces --if-present",
"preinstall": "npm run checkNpmVersion",
"postinstall": "npm run build --workspaces",
"prepare": "git config --local core.hooksPath .githooks",
Expand Down
8 changes: 4 additions & 4 deletions packages/block/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ export class Block {
getTransactionsValidationErrors(): string[] {
const errors: string[] = []
let blobGasUsed = BIGINT_0
const blobGasLimit = this.common.param('gasConfig', 'maxblobGasPerBlock')
const blobGasPerBlob = this.common.param('gasConfig', 'blobGasPerBlob')

// eslint-disable-next-line prefer-const
for (let [i, tx] of this.transactions.entries()) {
Expand All @@ -297,6 +295,8 @@ export class Block {
}
}
if (this.common.isActivatedEIP(4844)) {
const blobGasLimit = this.common.param('maxblobGasPerBlock')
const blobGasPerBlob = this.common.param('blobGasPerBlob')
if (tx instanceof BlobEIP4844Transaction) {
blobGasUsed += BigInt(tx.numBlobs()) * blobGasPerBlob
if (blobGasUsed > blobGasLimit) {
Expand Down Expand Up @@ -399,8 +399,8 @@ export class Block {
*/
validateBlobTransactions(parentHeader: BlockHeader) {
if (this.common.isActivatedEIP(4844)) {
const blobGasLimit = this.common.param('gasConfig', 'maxblobGasPerBlock')
const blobGasPerBlob = this.common.param('gasConfig', 'blobGasPerBlob')
const blobGasLimit = this.common.param('maxblobGasPerBlock')
const blobGasPerBlob = this.common.param('blobGasPerBlob')
let blobGasUsed = BIGINT_0

const expectedExcessBlobGas = parentHeader.calcNextExcessBlobGas()
Expand Down
44 changes: 17 additions & 27 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class BlockHeader {
const hardforkDefaults = {
baseFeePerGas: this.common.isActivatedEIP(1559)
? number === this.common.hardforkBlock(Hardfork.London)
? this.common.param('gasConfig', 'initialBaseFee')
? this.common.param('initialBaseFee')
: BIGINT_7
: undefined,
withdrawalsRoot: this.common.isActivatedEIP(4895) ? KECCAK256_RLP : undefined,
Expand Down Expand Up @@ -392,7 +392,7 @@ export class BlockHeader {
londonHfBlock !== BIGINT_0 &&
this.number === londonHfBlock
) {
const initialBaseFee = this.common.param('gasConfig', 'initialBaseFee')
const initialBaseFee = this.common.param('initialBaseFee')
if (this.baseFeePerGas !== initialBaseFee) {
const msg = this._errorMsg('Initial EIP1559 block does not have initial base fee')
throw new Error(msg)
Expand Down Expand Up @@ -446,10 +446,7 @@ export class BlockHeader {
// Consensus type dependent checks
if (this.common.consensusAlgorithm() === ConsensusAlgorithm.Ethash) {
// PoW/Ethash
if (
number > BIGINT_0 &&
this.extraData.length > this.common.param('vm', 'maxExtraDataSize')
) {
if (number > BIGINT_0 && this.extraData.length > this.common.param('maxExtraDataSize')) {
// Check length of data on all post-genesis blocks
const msg = this._errorMsg('invalid amount of extra data')
throw new Error(msg)
Expand Down Expand Up @@ -539,12 +536,12 @@ export class BlockHeader {
londonHardforkBlock !== BIGINT_0 &&
this.number === londonHardforkBlock
) {
const elasticity = this.common.param('gasConfig', 'elasticityMultiplier')
const elasticity = this.common.param('elasticityMultiplier')
parentGasLimit = parentGasLimit * elasticity
}
const gasLimit = this.gasLimit

const a = parentGasLimit / this.common.param('gasConfig', 'gasLimitBoundDivisor')
const a = parentGasLimit / this.common.param('gasLimitBoundDivisor')
const maxGasLimit = parentGasLimit + a
const minGasLimit = parentGasLimit - a

Expand All @@ -562,10 +559,9 @@ export class BlockHeader {
throw new Error(msg)
}

if (gasLimit < this.common.param('gasConfig', 'minGasLimit')) {
if (gasLimit < this.common.param('minGasLimit')) {
const msg = this._errorMsg(
`gas limit decreased below minimum gas limit. Gas limit: ${gasLimit}, minimum gas limit: ${this.common.param(
'gasConfig',
'minGasLimit'
)}`
)
Expand All @@ -584,27 +580,21 @@ export class BlockHeader {
throw new Error(msg)
}
let nextBaseFee: bigint
const elasticity = this.common.param('gasConfig', 'elasticityMultiplier')
const elasticity = this.common.param('elasticityMultiplier')
const parentGasTarget = this.gasLimit / elasticity

if (parentGasTarget === this.gasUsed) {
nextBaseFee = this.baseFeePerGas!
} else if (this.gasUsed > parentGasTarget) {
const gasUsedDelta = this.gasUsed - parentGasTarget
const baseFeeMaxChangeDenominator = this.common.param(
'gasConfig',
'baseFeeMaxChangeDenominator'
)
const baseFeeMaxChangeDenominator = this.common.param('baseFeeMaxChangeDenominator')

const calculatedDelta =
(this.baseFeePerGas! * gasUsedDelta) / parentGasTarget / baseFeeMaxChangeDenominator
nextBaseFee = (calculatedDelta > BIGINT_1 ? calculatedDelta : BIGINT_1) + this.baseFeePerGas!
} else {
const gasUsedDelta = parentGasTarget - this.gasUsed
const baseFeeMaxChangeDenominator = this.common.param(
'gasConfig',
'baseFeeMaxChangeDenominator'
)
const baseFeeMaxChangeDenominator = this.common.param('baseFeeMaxChangeDenominator')

const calculatedDelta =
(this.baseFeePerGas! * gasUsedDelta) / parentGasTarget / baseFeeMaxChangeDenominator
Expand Down Expand Up @@ -633,9 +623,9 @@ export class BlockHeader {
*/
private _getBlobGasPrice(excessBlobGas: bigint) {
return fakeExponential(
this.common.param('gasPrices', 'minBlobGasPrice'),
this.common.param('minBlobGas'),
excessBlobGas,
this.common.param('gasConfig', 'blobGasPriceUpdateFraction')
this.common.param('blobGasPriceUpdateFraction')
)
}

Expand All @@ -646,7 +636,7 @@ export class BlockHeader {
* @returns the total blob gas fee for numBlobs blobs
*/
calcDataFee(numBlobs: number): bigint {
const blobGasPerBlob = this.common.param('gasConfig', 'blobGasPerBlob')
const blobGasPerBlob = this.common.param('blobGasPerBlob')
const blobGasUsed = blobGasPerBlob * BigInt(numBlobs)

const blobGasPrice = this.getBlobGasPrice()
Expand All @@ -659,7 +649,7 @@ export class BlockHeader {
public calcNextExcessBlobGas(): bigint {
// The validation of the fields and 4844 activation is already taken care in BlockHeader constructor
const targetGasConsumed = (this.excessBlobGas ?? BIGINT_0) + (this.blobGasUsed ?? BIGINT_0)
const targetBlobGasPerBlock = this.common.param('gasConfig', 'targetBlobGasPerBlock')
const targetBlobGasPerBlock = this.common.param('targetBlobGasPerBlock')

if (targetGasConsumed <= targetBlobGasPerBlock) {
return BIGINT_0
Expand Down Expand Up @@ -774,8 +764,8 @@ export class BlockHeader {
}
const blockTs = this.timestamp
const { timestamp: parentTs, difficulty: parentDif } = parentBlockHeader
const minimumDifficulty = this.common.param('pow', 'minimumDifficulty')
const offset = parentDif / this.common.param('pow', 'difficultyBoundDivisor')
const minimumDifficulty = this.common.param('minimumDifficulty')
const offset = parentDif / this.common.param('difficultyBoundDivisor')
let num = this.number

// We use a ! here as TS cannot follow this hardfork-dependent logic, but it always gets assigned
Expand All @@ -795,7 +785,7 @@ export class BlockHeader {

if (this.common.gteHardfork(Hardfork.Byzantium)) {
// Get delay as parameter from common
num = num - this.common.param('pow', 'difficultyBombDelay')
num = num - this.common.param('difficultyBombDelay')
if (num < BIGINT_0) {
num = BIGINT_0
}
Expand All @@ -810,7 +800,7 @@ export class BlockHeader {
dif = parentDif + offset * a
} else {
// pre-homestead
if (parentTs + this.common.param('pow', 'durationLimit') > blockTs) {
if (parentTs + this.common.param('durationLimit') > blockTs) {
dif = offset + parentDif
} else {
dif = parentDif - offset
Expand Down
21 changes: 10 additions & 11 deletions packages/block/test/eip1559block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('EIP1559 tests', () => {
parentHash: genesis.hash(),
gasLimit: genesis.header.gasLimit * BigInt(2), // Special case on EIP-1559 transition block
timestamp: BigInt(1),
baseFeePerGas: common.param('gasConfig', 'initialBaseFee'),
baseFeePerGas: common.param('initialBaseFee'),
},
},
{
Expand Down Expand Up @@ -188,10 +188,9 @@ describe('EIP1559 tests', () => {
timestamp: BigInt(1),
gasLimit: genesis.header.gasLimit * BigInt(2), // Special case on EIP-1559 transition block
gasUsed:
genesis.header.gasLimit *
(common.param('gasConfig', 'elasticityMultiplier') ?? BigInt(0)) +
genesis.header.gasLimit * (common.param('elasticityMultiplier') ?? BigInt(0)) +
BigInt(1),
baseFeePerGas: common.param('gasConfig', 'initialBaseFee'),
baseFeePerGas: common.param('initialBaseFee'),
},
{
calcDifficultyFromHeader: genesis.header,
Expand All @@ -212,7 +211,7 @@ describe('EIP1559 tests', () => {
timestamp: BigInt(1),
gasLimit: genesis.header.gasLimit * BigInt(2), // Special case on EIP-1559 transition block
gasUsed: genesis.header.gasLimit * BigInt(2),
baseFeePerGas: common.param('gasConfig', 'initialBaseFee'),
baseFeePerGas: common.param('initialBaseFee'),
},
{
calcDifficultyFromHeader: genesis.header,
Expand All @@ -230,7 +229,7 @@ describe('EIP1559 tests', () => {
parentHash: genesis.hash(),
gasLimit: genesis.header.gasLimit * BigInt(2), // Special case on EIP-1559 transition block
timestamp: BigInt(1),
baseFeePerGas: common.param('gasConfig', 'initialBaseFee'),
baseFeePerGas: common.param('initialBaseFee'),
},
},
{
Expand All @@ -247,7 +246,7 @@ describe('EIP1559 tests', () => {
parentHash: genesis.hash(),
timestamp: BigInt(1),
gasLimit: parentGasLimit + parentGasLimit / BigInt(1024) - BigInt(1),
baseFeePerGas: common.param('gasConfig', 'initialBaseFee'),
baseFeePerGas: common.param('initialBaseFee'),
},
{
calcDifficultyFromHeader: genesis.header,
Expand All @@ -263,7 +262,7 @@ describe('EIP1559 tests', () => {
parentHash: genesis.hash(),
timestamp: BigInt(1),
gasLimit: parentGasLimit - parentGasLimit / BigInt(1024) + BigInt(1),
baseFeePerGas: common.param('gasConfig', 'initialBaseFee'),
baseFeePerGas: common.param('initialBaseFee'),
},
{
calcDifficultyFromHeader: genesis.header,
Expand Down Expand Up @@ -315,7 +314,7 @@ describe('EIP1559 tests', () => {
parentHash: genesis.hash(),
timestamp: BigInt(1),
gasLimit: parentGasLimit + parentGasLimit,
baseFeePerGas: common.param('gasConfig', 'initialBaseFee'),
baseFeePerGas: common.param('initialBaseFee'),
},
{
calcDifficultyFromHeader: genesis.header,
Expand Down Expand Up @@ -365,7 +364,7 @@ describe('EIP1559 tests', () => {
parentHash: genesis.hash(),
timestamp: BigInt(1),
gasLimit: parentGasLimit - parentGasLimit / BigInt(1024),
baseFeePerGas: common.param('gasConfig', 'initialBaseFee'),
baseFeePerGas: common.param('initialBaseFee'),
},
{
calcDifficultyFromHeader: genesis.header,
Expand Down Expand Up @@ -422,7 +421,7 @@ describe('EIP1559 tests', () => {
parentHash: genesis.hash(),
gasLimit: genesis.header.gasLimit * BigInt(2), // Special case on EIP-1559 transition block
timestamp: BigInt(1),
baseFeePerGas: common.param('gasConfig', 'initialBaseFee'),
baseFeePerGas: common.param('initialBaseFee'),
},
transactions: [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/block/test/eip4844block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('blob gas tests', () => {
hardfork: Hardfork.Cancun,
customCrypto: { kzg },
})
blobGasPerBlob = common.param('gasConfig', 'blobGasPerBlob')
blobGasPerBlob = common.param('blobGasPerBlob')
})
it('should work', () => {
const preShardingHeader = BlockHeader.fromHeaderData({})
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('transaction validation tests', () => {
hardfork: Hardfork.Cancun,
customCrypto: { kzg },
})
blobGasPerBlob = common.param('gasConfig', 'blobGasPerBlob')
blobGasPerBlob = common.param('blobGasPerBlob')
})
it('should work', () => {
const blobs = getBlobs('hello world')
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export class Blockchain implements BlockchainInterface {
const londonHfBlock = this.common.hardforkBlock(Hardfork.London)
const isInitialEIP1559Block = number === londonHfBlock
if (isInitialEIP1559Block) {
expectedBaseFee = header.common.param('gasConfig', 'initialBaseFee')
expectedBaseFee = header.common.param('initialBaseFee')
} else {
expectedBaseFee = parentHeader.calcNextBaseFee()
}
Expand Down
3 changes: 1 addition & 2 deletions packages/client/src/miner/miner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ export class Miner {
number === londonHardforkBlock
) {
// Get baseFeePerGas from `paramByEIP` since 1559 not currently active on common
baseFeePerGas =
this.config.chainCommon.paramByEIP('gasConfig', 'initialBaseFee', 1559) ?? BIGINT_0
baseFeePerGas = this.config.chainCommon.paramByEIP('initialBaseFee', 1559) ?? BIGINT_0
// Set initial EIP1559 block gas limit to 2x parent gas limit per logic in `block.validateGasLimit`
gasLimit = gasLimit * BIGINT_2
} else if (this.config.chainCommon.isActivatedEIP(1559)) {
Expand Down
8 changes: 4 additions & 4 deletions packages/client/src/miner/pendingBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ export class PendingBlock {
// Get if and how many blobs are allowed in the tx
let allowedBlobs
if (vm.common.isActivatedEIP(4844)) {
const blobGasLimit = vm.common.param('gasConfig', 'maxblobGasPerBlock')
const blobGasPerBlob = vm.common.param('gasConfig', 'blobGasPerBlob')
const blobGasLimit = vm.common.param('maxblobGasPerBlock')
const blobGasPerBlob = vm.common.param('blobGasPerBlob')
allowedBlobs = Number(blobGasLimit / blobGasPerBlob)
} else {
allowedBlobs = 0
Expand Down Expand Up @@ -267,8 +267,8 @@ export class PendingBlock {
let allowedBlobs
if (vm.common.isActivatedEIP(4844)) {
const bundle = this.blobsBundles.get(payloadId) ?? { blobs: [], commitments: [], proofs: [] }
const blobGasLimit = vm.common.param('gasConfig', 'maxblobGasPerBlock')
const blobGasPerBlob = vm.common.param('gasConfig', 'blobGasPerBlob')
const blobGasLimit = vm.common.param('maxblobGasPerBlock')
const blobGasPerBlob = vm.common.param('blobGasPerBlob')
allowedBlobs = Number(blobGasLimit / blobGasPerBlob) - bundle.blobs.length
} else {
allowedBlobs = 0
Expand Down
11 changes: 7 additions & 4 deletions packages/client/src/rpc/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1164,8 +1164,8 @@ export class Eth {
// Blob Transactions sent over RPC are expected to be in Network Wrapper format
tx = BlobEIP4844Transaction.fromSerializedBlobTxNetworkWrapper(txBuf, { common })

const blobGasLimit = common.param('gasConfig', 'maxblobGasPerBlock')
const blobGasPerBlob = common.param('gasConfig', 'blobGasPerBlob')
const blobGasLimit = common.param('maxblobGasPerBlock')
const blobGasPerBlob = common.param('blobGasPerBlob')

if (BigInt((tx.blobs ?? []).length) * blobGasPerBlob > blobGasLimit) {
throw Error(
Expand Down Expand Up @@ -1320,7 +1320,10 @@ export class Eth {
* @returns a hex code of an integer representing the suggested gas price in wei.
*/
async gasPrice() {
const minGasPrice: bigint = this._chain.config.chainCommon.param('gasConfig', 'minPrice')
// TODO: going more strict on parameter accesses in Common (PR #3532) revealed that this line had
// absolutely no effect by accessing a non-present gas parameter. Someone familiar with the RPC method
// implementation should look over it and recall what was meant to be accomplished here.
const minGasPrice = BIGINT_0 //: bigint = this._chain.config.chainCommon.param('minPrice')
let gasPrice = BIGINT_0
const latest = await this._chain.getCanonicalHeadHeader()
if (this._vm !== undefined && this._vm.common.isActivatedEIP(1559)) {
Expand Down Expand Up @@ -1399,7 +1402,7 @@ export class Eth {
let blobGasUsedRatio = 0
if (b.header.excessBlobGas !== undefined) {
baseFeePerBlobGas = b.header.getBlobGasPrice()
const max = b.common.param('gasConfig', 'maxblobGasPerBlock')
const max = b.common.param('maxblobGasPerBlock')
blobGasUsedRatio = Number(blobGasUsed) / Number(max)
}

Expand Down
9 changes: 7 additions & 2 deletions packages/client/test/miner/miner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,12 @@ describe('assembleBlocks() -> with saveReceipts', async () => {
})

describe('assembleBlocks() -> should not include tx under the baseFee', async () => {
const customChainParams = { hardforks: [{ name: 'london', block: 0 }] }
const customChainParams = {
hardforks: [
{ name: 'chainstart', block: 0 },
{ name: 'london', block: 0 },
],
}
const common = createCustomCommon(customChainParams, {
baseChain: CommonChain.Goerli,
hardfork: Hardfork.London,
Expand Down Expand Up @@ -647,7 +652,7 @@ describe.skip('should handle mining over the london hardfork block', async () =>
blockHeader3.gasLimit,
'gas limit should be double previous block'
)
const initialBaseFee = config.execCommon.paramByEIP('gasConfig', 'initialBaseFee', 1559)!
const initialBaseFee = config.execCommon.paramByEIP('initialBaseFee', 1559)!
assert.equal(blockHeader3.baseFeePerGas!, initialBaseFee, 'baseFee should be initial value')

// block 4
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/rpc/eth/getFeeHistory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ describe(method, () => {
hardfork: Hardfork.London,
})

const initialBaseFee = common.param('gasConfig', 'initialBaseFee')
const initialBaseFee = common.param('initialBaseFee')
const { server } = await setupChain(gethGenesisStartLondon(pow), 'powLondon')

const rpc = getRpcClient(server)
Expand Down
Loading
Loading