Skip to content

Commit

Permalink
deprecate the max blob gas checks as per 7742
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Dec 8, 2024
1 parent 3bd746f commit 7e2d406
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
20 changes: 13 additions & 7 deletions packages/block/src/block/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,19 @@ export class Block {
}
}
if (this.common.isActivatedEIP(4844)) {
const blobGasLimit = this.common.param('maxblobGasPerBlock')
const blobGasPerBlob = this.common.param('blobGasPerBlob')
if (tx instanceof Blob4844Tx) {
blobGasUsed += BigInt(tx.numBlobs()) * blobGasPerBlob
if (blobGasUsed > blobGasLimit) {
// max blob gas check is deprecated with 7742
if(!this.common.isActivatedEIP(7742)){
const blobGasLimit = this.common.param('maxblobGasPerBlock')
if (blobGasUsed > blobGasLimit) {
errs.push(
`tx causes total blob gas of ${blobGasUsed} to exceed maximum blob gas per block of ${blobGasLimit}`,
)
}
}
}
}
if (errs.length > 0) {
errors.push(`errors at tx ${i}: ${errs.join(', ')}`)
Expand Down Expand Up @@ -354,7 +357,6 @@ export class Block {
*/
validateBlobTransactions(parentHeader: BlockHeader) {
if (this.common.isActivatedEIP(4844)) {
const blobGasLimit = this.common.param('maxblobGasPerBlock')
const blobGasPerBlob = this.common.param('blobGasPerBlob')
let blobGasUsed = BIGINT_0

Expand All @@ -380,10 +382,14 @@ export class Block {

blobGasUsed += BigInt(tx.blobVersionedHashes.length) * blobGasPerBlob

if (blobGasUsed > blobGasLimit) {
throw new Error(
`tx causes total blob gas of ${blobGasUsed} to exceed maximum blob gas per block of ${blobGasLimit}`,
)
// max blob gas check is deprecated with 7742
if(!this.common.isActivatedEIP(7742)){
const blobGasLimit = this.common.param('maxblobGasPerBlock')
if (blobGasUsed > blobGasLimit) {
throw new Error(
`tx causes total blob gas of ${blobGasUsed} to exceed maximum blob gas per block of ${blobGasLimit}`,
)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/miner/pendingBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ export class PendingBlock {
try {
await builder.addTransaction(tx, {
skipHardForkValidation: this.skipHardForkValidation,
maxBlobsPerBlock: this.maxBlobsPerBlock,
})
addTxResult = AddTxResult.Success
} catch (error: any) {
Expand Down
8 changes: 7 additions & 1 deletion packages/client/src/rpc/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,8 @@ export class Eth {
// Blob Transactions sent over RPC are expected to be in Network Wrapper format
tx = createBlob4844TxFromSerializedNetworkWrapper(txBuf, { common })

// max blob gas check is deprecated with 7742
if(!tx.common.isActivatedEIP(7742)){
const blobGasLimit = tx.common.param('maxblobGasPerBlock')
const blobGasPerBlob = tx.common.param('blobGasPerBlob')

Expand All @@ -1185,6 +1187,7 @@ export class Eth {
}`,
)
}
}
} else {
tx = createTxFromRLP(txBuf, { common })
}
Expand Down Expand Up @@ -1416,7 +1419,10 @@ export class Eth {

let baseFeePerBlobGas = BIGINT_0
let blobGasUsedRatio = 0
if (b.header.excessBlobGas !== undefined) {

// max blob gas checks is deprecated with 7742
// TODO: figure out what max to use for ratio
if (b.header.excessBlobGas !== undefined && !b.common.isActivatedEIP(7742)) {
baseFeePerBlobGas = b.header.getBlobGasPrice()
const max = b.common.param('maxblobGasPerBlock')
blobGasUsedRatio = Number(blobGasUsed) / Number(max)
Expand Down
2 changes: 2 additions & 0 deletions packages/client/src/service/txpool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ export class TxPool {
}

pruneBlobsAndProofsCache() {
// TODO figure out how to get this param for purning may be should be done by slot or just take
// a high target of 128 blobs that ethereum eventually intends to achieve
const blobGasLimit = this.config.chainCommon.param('maxblobGasPerBlock')
const blobGasPerBlob = this.config.chainCommon.param('blobGasPerBlob')
const allowedBlobsPerBlock = Number(blobGasLimit / blobGasPerBlob)
Expand Down
6 changes: 3 additions & 3 deletions packages/vm/src/buildBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ export class BlockBuilder {
{
skipHardForkValidation,

Check failure on line 220 in packages/vm/src/buildBlock.ts

View workflow job for this annotation

GitHub Actions / vm-pr / vm-api

test/api/buildBlock.spec.ts > BlockBuilder > should build a valid block

TypeError: Cannot destructure property 'skipHardForkValidation' of 'undefined' as it is undefined. ❯ BlockBuilder.addTransaction src/buildBlock.ts:220:7 ❯ test/api/buildBlock.spec.ts:59:24

Check failure on line 220 in packages/vm/src/buildBlock.ts

View workflow job for this annotation

GitHub Actions / vm-pr / vm-api

test/api/buildBlock.spec.ts > BlockBuilder > should correctly seal a PoW block

TypeError: Cannot destructure property 'skipHardForkValidation' of 'undefined' as it is undefined. ❯ BlockBuilder.addTransaction src/buildBlock.ts:220:7 ❯ test/api/buildBlock.spec.ts:129:24

Check failure on line 220 in packages/vm/src/buildBlock.ts

View workflow job for this annotation

GitHub Actions / vm-pr / vm-api

test/api/buildBlock.spec.ts > BlockBuilder > should correctly seal a PoA block

TypeError: Cannot destructure property 'skipHardForkValidation' of 'undefined' as it is undefined. ❯ BlockBuilder.addTransaction src/buildBlock.ts:220:7 ❯ test/api/buildBlock.spec.ts:231:24

Check failure on line 220 in packages/vm/src/buildBlock.ts

View workflow job for this annotation

GitHub Actions / vm-pr / vm-api

test/api/buildBlock.spec.ts > BlockBuilder > should throw if block already built or reverted

TypeError: Cannot destructure property 'skipHardForkValidation' of 'undefined' as it is undefined. ❯ BlockBuilder.addTransaction src/buildBlock.ts:220:7 ❯ test/api/buildBlock.spec.ts:261:24

Check failure on line 220 in packages/vm/src/buildBlock.ts

View workflow job for this annotation

GitHub Actions / vm-pr / vm-api

test/api/EIPs/eip-4844-blobs.spec.ts > EIP4844 tests > should build a block correctly with blobs

TypeError: Cannot destructure property 'skipHardForkValidation' of 'undefined' as it is undefined. ❯ BlockBuilder.addTransaction src/buildBlock.ts:220:7 ❯ test/api/EIPs/eip-4844-blobs.spec.ts:83:24

Check failure on line 220 in packages/vm/src/buildBlock.ts

View workflow job for this annotation

GitHub Actions / vm-pr / vm-api

test/api/EIPs/eip-6110.spec.ts > EIP-7685 buildBlock tests > should include deposit request when a deposit transaction is included in a block

TypeError: Cannot destructure property 'skipHardForkValidation' of 'undefined' as it is undefined. ❯ BlockBuilder.addTransaction src/buildBlock.ts:220:7 ❯ test/api/EIPs/eip-6110.spec.ts:114:24
allowNoBlobs,
}: { skipHardForkValidation?: boolean; allowNoBlobs?: boolean } = {},
maxBlobsPerBlock,
}: { skipHardForkValidation?: boolean; allowNoBlobs?: boolean,maxBlobsPerBlock?: number },
) {
this.checkStatus()

Expand All @@ -231,8 +232,6 @@ export class BlockBuilder {
// According to the Yellow Paper, a transaction's gas limit
// cannot be greater than the remaining gas in the block
const blockGasLimit = toType(this.headerData.gasLimit, TypeOutput.BigInt)

const blobGasLimit = this.vm.common.param('maxblobGasPerBlock')
const blobGasPerBlob = this.vm.common.param('blobGasPerBlob')

const blockGasRemaining = blockGasLimit - this.gasUsed
Expand All @@ -255,6 +254,7 @@ export class BlockBuilder {
}
}

const blobGasLimit = maxBlobsPerBlock!==undefined ? BigInt(maxBlobsPerBlock)*blobGasPerBlob:this.vm.common.param('maxblobGasPerBlock')
if (this.blobGasUsed + BigInt(blobTx.numBlobs()) * blobGasPerBlob > blobGasLimit) {
throw new Error('block blob gas limit reached')
}
Expand Down

0 comments on commit 7e2d406

Please sign in to comment.