Skip to content

Commit

Permalink
rename fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Jul 28, 2023
1 parent eaa7f3c commit a15df5d
Show file tree
Hide file tree
Showing 23 changed files with 95 additions and 96 deletions.
4 changes: 2 additions & 2 deletions packages/block/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,9 @@ export class Block {
}

const expectedExcessBlobGas = parentHeader.calcNextExcessBlobGas()
if (this.header.excessBlobGas !== expectedExcessblobGas) {
if (this.header.excessBlobGas !== expectedExcessBlobGas) {
throw new Error(
`block excessblobGas mismatch: have ${this.header.excessblobGas}, want ${expectedExcessblobGas}`
`block excessBlobGas mismatch: have ${this.header.excessBlobGas}, want ${expectedExcessBlobGas}`
)
}
}
Expand Down
12 changes: 6 additions & 6 deletions packages/block/src/from-beacon-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export type BeaconPayloadJson = {
block_hash: string
transactions: string[]
withdrawals?: BeaconWithdrawal[]
data_gas_used?: string
excess_data_gas?: string
blob_gas_used?: string
excess_blob_gas?: string
parent_beacon_block_root?: string
}

Expand Down Expand Up @@ -63,11 +63,11 @@ export function executionPayloadFromBeaconPayload(payload: BeaconPayloadJson): E
}))
}

if (payload.data_gas_used !== undefined && payload.data_gas_used !== null) {
executionPayload.blobGasUsed = bigIntToHex(BigInt(payload.data_gas_used))
if (payload.blob_gas_used !== undefined && payload.blob_gas_used !== null) {
executionPayload.blobGasUsed = bigIntToHex(BigInt(payload.blob_gas_used))
}
if (payload.excess_data_gas !== undefined && payload.excess_data_gas !== null) {
executionPayload.excessblobGas = bigIntToHex(BigInt(payload.excess_data_gas))
if (payload.excess_blob_gas !== undefined && payload.excess_blob_gas !== null) {
executionPayload.excessBlobGas = bigIntToHex(BigInt(payload.excess_blob_gas))
}
if (payload.parent_beacon_block_root !== undefined && payload.parent_beacon_block_root !== null) {
executionPayload.parentBeaconBlockRoot = payload.parent_beacon_block_root
Expand Down
4 changes: 2 additions & 2 deletions packages/block/src/header-from-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function blockHeaderFromRpc(blockParams: JsonRpcBlock, options?: BlockOpt
baseFeePerGas,
withdrawalsRoot,
blobGasUsed,
excessblobGas,
excessBlobGas,
} = blockParams

const blockHeader = BlockHeader.fromHeaderData(
Expand All @@ -52,7 +52,7 @@ export function blockHeaderFromRpc(blockParams: JsonRpcBlock, options?: BlockOpt
baseFeePerGas,
withdrawalsRoot,
blobGasUsed,
excessblobGas,
excessBlobGas,
},
options
)
Expand Down
38 changes: 19 additions & 19 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class BlockHeader {
public readonly baseFeePerGas?: bigint
public readonly withdrawalsRoot?: Uint8Array
public readonly blobGasUsed?: bigint
public readonly excessblobGas?: bigint
public readonly excessBlobGas?: bigint
public readonly parentBeaconBlockRoot?: Uint8Array

public readonly common: Common
Expand Down Expand Up @@ -109,7 +109,7 @@ export class BlockHeader {
*/
public static fromValuesArray(values: BlockHeaderBytes, opts: BlockOptions = {}) {
const headerData = valuesArrayToHeaderData(values)
const { number, baseFeePerGas, excessblobGas, blobGasUsed, parentBeaconBlockRoot } = headerData
const { number, baseFeePerGas, excessBlobGas, blobGasUsed, parentBeaconBlockRoot } = headerData
const header = BlockHeader.fromHeaderData(headerData, opts)
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (header.common.isActivatedEIP(1559) && baseFeePerGas === undefined) {
Expand All @@ -121,8 +121,8 @@ export class BlockHeader {
}
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (header.common.isActivatedEIP(4844)) {
if (excessblobGas === undefined) {
throw new Error('invalid header. excessblobGas should be provided')
if (excessBlobGas === undefined) {
throw new Error('invalid header. excessBlobGas should be provided')
} else if (blobGasUsed === undefined) {
throw new Error('invalid header. blobGasUsed should be provided')
}
Expand Down Expand Up @@ -211,7 +211,7 @@ export class BlockHeader {
: undefined,
withdrawalsRoot: this.common.isActivatedEIP(4895) ? KECCAK256_RLP : undefined,
blobGasUsed: this.common.isActivatedEIP(4844) ? BigInt(0) : undefined,
excessblobGas: this.common.isActivatedEIP(4844) ? BigInt(0) : undefined,
excessBlobGas: this.common.isActivatedEIP(4844) ? BigInt(0) : undefined,
parentBeaconBlockRoot: this.common.isActivatedEIP(4788) ? zeros(32) : undefined,
}

Expand All @@ -221,8 +221,8 @@ export class BlockHeader {
toType(headerData.withdrawalsRoot, TypeOutput.Uint8Array) ?? hardforkDefaults.withdrawalsRoot
const blobGasUsed =
toType(headerData.blobGasUsed, TypeOutput.BigInt) ?? hardforkDefaults.blobGasUsed
const excessblobGas =
toType(headerData.excessblobGas, TypeOutput.BigInt) ?? hardforkDefaults.excessblobGas
const excessBlobGas =
toType(headerData.excessBlobGas, TypeOutput.BigInt) ?? hardforkDefaults.excessBlobGas
const parentBeaconBlockRoot =
toType(headerData.parentBeaconBlockRoot, TypeOutput.Uint8Array) ??
hardforkDefaults.parentBeaconBlockRoot
Expand All @@ -242,7 +242,7 @@ export class BlockHeader {
throw new Error('blob gas used can only be provided with EIP4844 activated')
}

if (headerData.excessblobGas !== undefined) {
if (headerData.excessBlobGas !== undefined) {
throw new Error('excess blob gas can only be provided with EIP4844 activated')
}
}
Expand Down Expand Up @@ -271,7 +271,7 @@ export class BlockHeader {
this.baseFeePerGas = baseFeePerGas
this.withdrawalsRoot = withdrawalsRoot
this.blobGasUsed = blobGasUsed
this.excessblobGas = excessblobGas
this.excessBlobGas = excessBlobGas
this.parentBeaconBlockRoot = parentBeaconBlockRoot
this._genericFormatValidation()
this._validateDAOExtraData()
Expand Down Expand Up @@ -580,12 +580,12 @@ export class BlockHeader {
* @returns the price in gwei per unit of blob gas spent
*/
getblobGasPrice(): bigint {
if (this.excessblobGas === undefined) {
throw new Error('header must have excessblobGas field populated')
if (this.excessBlobGas === undefined) {
throw new Error('header must have excessBlobGas field populated')
}
return fakeExponential(
this.common.param('gasPrices', 'minblobGasPrice'),
this.excessblobGas,
this.excessBlobGas,
this.common.param('gasConfig', 'blobGasPriceUpdateFraction')
)
}
Expand All @@ -607,15 +607,15 @@ export class BlockHeader {
/**
* Calculates the excess blob gas for next (hopefully) post EIP 4844 block.
*/
public calcNextExcessblobGas(): bigint {
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 targetGasConsumed = (this.excessBlobGas ?? BigInt(0)) + (this.blobGasUsed ?? BigInt(0))
const targetBlobGasPerBlock = this.common.param('gasConfig', 'targetBlobGasPerBlock')

if (targetGasConsumed <= targetblobGasPerBlock) {
if (targetGasConsumed <= targetBlobGasPerBlock) {
return BigInt(0)
} else {
return targetGasConsumed - targetblobGasPerBlock
return targetGasConsumed - targetBlobGasPerBlock
}
}

Expand Down Expand Up @@ -650,7 +650,7 @@ export class BlockHeader {
}
if (this.common.isActivatedEIP(4844) === true) {
rawItems.push(bigIntToUnpaddedBytes(this.blobGasUsed!))
rawItems.push(bigIntToUnpaddedBytes(this.excessblobGas!))
rawItems.push(bigIntToUnpaddedBytes(this.excessBlobGas!))
}
if (this.common.isActivatedEIP(4788) === true) {
rawItems.push(this.parentBeaconBlockRoot!)
Expand Down Expand Up @@ -923,7 +923,7 @@ export class BlockHeader {
}
if (this.common.isActivatedEIP(4844) === true) {
jsonDict.blobGasUsed = bigIntToHex(this.blobGasUsed!)
jsonDict.excessblobGas = bigIntToHex(this.excessblobGas!)
jsonDict.excessBlobGas = bigIntToHex(this.excessBlobGas!)
}
if (this.common.isActivatedEIP(4788) === true) {
jsonDict.parentBeaconBlockRoot = bytesToHex(this.parentBeaconBlockRoot!)
Expand Down
4 changes: 2 additions & 2 deletions packages/block/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function valuesArrayToHeaderData(values: BlockHeaderBytes): HeaderData {
baseFeePerGas,
withdrawalsRoot,
blobGasUsed,
excessblobGas,
excessBlobGas,
parentBeaconBlockRoot,
] = values

Expand Down Expand Up @@ -71,7 +71,7 @@ export function valuesArrayToHeaderData(values: BlockHeaderBytes): HeaderData {
baseFeePerGas,
withdrawalsRoot,
blobGasUsed,
excessblobGas,
excessBlobGas,
parentBeaconBlockRoot,
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/block/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export interface HeaderData {
baseFeePerGas?: BigIntLike
withdrawalsRoot?: BytesLike
blobGasUsed?: BigIntLike
excessblobGas?: BigIntLike
excessBlobGas?: BigIntLike
parentBeaconBlockRoot?: BytesLike
}

Expand Down Expand Up @@ -158,7 +158,7 @@ export interface JsonHeader {
baseFeePerGas?: string
withdrawalsRoot?: string
blobGasUsed?: string
excessblobGas?: string
excessBlobGas?: string
parentBeaconBlockRoot?: string
}

Expand Down Expand Up @@ -190,7 +190,7 @@ export interface JsonRpcBlock {
withdrawals?: Array<JsonRpcWithdrawal> // If EIP-4895 is enabled for this block, array of withdrawals
withdrawalsRoot?: string // If EIP-4895 is enabled for this block, the root of the withdrawal trie of the block.
blobGasUsed?: string // If EIP-4844 is enabled for this block, returns the blob gas used for the block
excessblobGas?: string // If EIP-4844 is enabled for this block, returns the excess blob gas for the block
excessBlobGas?: string // If EIP-4844 is enabled for this block, returns the excess blob gas for the block
parentBeaconBlockRoot?: string // If EIP-4788 is enabled for this block, returns parent beacon block root
}

Expand Down Expand Up @@ -220,6 +220,6 @@ export type ExecutionPayload = {
transactions: PrefixedHexString[] // Array of DATA - Array of transaction rlp strings,
withdrawals?: WithdrawalV1[] // Array of withdrawal objects
blobGasUsed?: PrefixedHexString // QUANTITY, 64 Bits
excessblobGas?: PrefixedHexString // QUANTITY, 64 Bits
excessBlobGas?: PrefixedHexString // QUANTITY, 64 Bits
parentBeaconBlockRoot?: PrefixedHexString // QUANTITY, 64 Bits
}
4 changes: 2 additions & 2 deletions packages/block/test/eip4788block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('EIP4788 header tests', () => {
assert.doesNotThrow(() => {
BlockHeader.fromHeaderData(
{
excessblobGas: 0n,
excessBlobGas: 0n,
blobGasUsed: 0n,
parentBeaconBlockRoot: zeros(32),
},
Expand All @@ -64,7 +64,7 @@ describe('EIP4788 header tests', () => {
assert.equal(
block.toJSON().header?.parentBeaconBlockRoot,
bytesToHex(zeros(32)),
'JSON output includes excessblobGas'
'JSON output includes excessBlobGas'
)
})
})
44 changes: 22 additions & 22 deletions packages/block/test/eip4844block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('EIP4844 header tests', () => {
() => {
BlockHeader.fromHeaderData(
{
excessblobGas: 1n,
excessBlobGas: 1n,
},
{
common: earlyCommon,
Expand All @@ -50,7 +50,7 @@ describe('EIP4844 header tests', () => {
},
'excess blob gas can only be provided with EIP4844 activated',
undefined,
'should throw when setting excessblobGas with EIP4844 not being activated'
'should throw when setting excessBlobGas with EIP4844 not being activated'
)

assert.throws(
Expand All @@ -69,19 +69,19 @@ describe('EIP4844 header tests', () => {
'should throw when setting blobGasUsed with EIP4844 not being activated'
)

const excessblobGas = BlockHeader.fromHeaderData(
const excessBlobGas = BlockHeader.fromHeaderData(
{},
{ common, skipConsensusFormatValidation: true }
).excessblobGas
).excessBlobGas
assert.equal(
excessblobGas,
excessBlobGas,
0n,
'instantiates block with reasonable default excess blob gas value when not provided'
)
assert.doesNotThrow(() => {
BlockHeader.fromHeaderData(
{
excessblobGas: 0n,
excessBlobGas: 0n,
},
{
common,
Expand All @@ -97,9 +97,9 @@ describe('EIP4844 header tests', () => {
{ common, skipConsensusFormatValidation: true }
)
assert.equal(
block.toJSON().header?.excessblobGas,
block.toJSON().header?.excessBlobGas,
'0x0',
'JSON output includes excessblobGas'
'JSON output includes excessBlobGas'
)
}
})
Expand All @@ -110,40 +110,40 @@ describe('blob gas tests', () => {
if (isBrowser() === false) {
const preShardingHeader = BlockHeader.fromHeaderData({})

let excessblobGas = preShardingHeader.calcNextExcessblobGas()
let excessBlobGas = preShardingHeader.calcNextExcessBlobGas()
assert.equal(
excessblobGas,
excessBlobGas,
0n,
'excess blob gas where 4844 is not active on header should be 0'
)

assert.throws(
() => preShardingHeader.calcDataFee(1),
'header must have excessblobGas field',
'header must have excessBlobGas field',
undefined,
'calcDataFee throws when header has no excessblobGas field'
'calcDataFee throws when header has no excessBlobGas field'
)

const lowGasHeader = BlockHeader.fromHeaderData(
{ number: 1, excessblobGas: 5000 },
{ number: 1, excessBlobGas: 5000 },
{ common, skipConsensusFormatValidation: true }
)

excessblobGas = lowGasHeader.calcNextExcessblobGas()
let blobGasPrice = lowGasHeader.getblobGasPrice()
excessBlobGas = lowGasHeader.calcNextExcessBlobGas()
let blobGasPrice = lowGasHeader.getBlobGasPrice()
assert.equal(
excessblobGas,
excessBlobGas,
0n,
'excess blob gas should be 0 for small parent header blob gas'
)
assert.equal(blobGasPrice, 1n, 'blob gas price should be 1n when low or no excess blob gas')
const highGasHeader = BlockHeader.fromHeaderData(
{ number: 1, excessblobGas: 6291456, blobGasUsed: BigInt(6) * blobGasPerBlob },
{ number: 1, excessBlobGas: 6291456, blobGasUsed: BigInt(6) * blobGasPerBlob },
{ common, skipConsensusFormatValidation: true }
)
excessblobGas = highGasHeader.calcNextExcessblobGas()
excessBlobGas = highGasHeader.calcNextExcessBlobGas()
blobGasPrice = highGasHeader.getblobGasPrice()
assert.equal(excessblobGas, 6684672n)
assert.equal(excessBlobGas, 6684672n)
assert.equal(blobGasPrice, 6n, 'computed correct blob gas price')

assert.equal(lowGasHeader.calcDataFee(1), 131072n, 'compute data fee correctly')
Expand Down Expand Up @@ -184,10 +184,10 @@ describe('transaction validation tests', () => {
).sign(randomBytes(32))

const parentHeader = BlockHeader.fromHeaderData(
{ number: 1n, excessblobGas: 4194304, blobGasUsed: 0 },
{ number: 1n, excessBlobGas: 4194304, blobGasUsed: 0 },
{ common, skipConsensusFormatValidation: true }
)
const excessblobGas = parentHeader.calcNextExcessblobGas()
const excessBlobGas = parentHeader.calcNextExcessBlobGas()

// eslint-disable-next-line no-inner-declarations
function getBlock(transactions: TypedTransaction[]) {
Expand All @@ -197,7 +197,7 @@ describe('transaction validation tests', () => {
{
number: 2n,
parentHash: parentHeader.hash(),
excessblobGas,
excessBlobGas,
blobGasUsed: BigInt(blobs) * blobGasPerBlob,
},
{ common, skipConsensusFormatValidation: true }
Expand Down
Loading

0 comments on commit a15df5d

Please sign in to comment.