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

Monorepo: make _* methods protected / _common -> common #2857

Merged
merged 17 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions packages/block/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Block {
public readonly uncleHeaders: BlockHeader[] = []
public readonly withdrawals?: Withdrawal[]
public readonly txTrie = new Trie()
public readonly _common: Common
public readonly common: Common

/**
* Returns the withdrawals trie root for array of Withdrawal.
Expand Down Expand Up @@ -97,7 +97,7 @@ export class Block {
const tx = TransactionFactory.fromTxData(txData, {
...opts,
// Use header common in case of setHardfork being activated
common: header._common,
common: header.common,
} as TxOptions)
transactions.push(tx)
}
Expand All @@ -107,7 +107,7 @@ export class Block {
const uncleOpts: BlockOptions = {
...opts,
// Use header common in case of setHardfork being activated
common: header._common,
common: header.common,
// Disable this option here (all other options carried over), since this overwrites the provided Difficulty to an incorrect value
calcDifficultyFromHeader: undefined,
}
Expand Down Expand Up @@ -158,7 +158,7 @@ export class Block {
const header = BlockHeader.fromValuesArray(headerData, opts)

if (
header._common.isActivatedEIP(4895) &&
header.common.isActivatedEIP(4895) &&
(values[3] === undefined || !Array.isArray(values[3]))
) {
throw new Error(
Expand All @@ -173,7 +173,7 @@ export class Block {
TransactionFactory.fromBlockBodyData(txData, {
...opts,
// Use header common in case of setHardfork being activated
common: header._common,
common: header.common,
})
)
}
Expand All @@ -183,7 +183,7 @@ export class Block {
const uncleOpts: BlockOptions = {
...opts,
// Use header common in case of setHardfork being activated
common: header._common,
common: header.common,
// Disable this option here (all other options carried over), since this overwrites the provided Difficulty to an incorrect value
calcDifficultyFromHeader: undefined,
}
Expand Down Expand Up @@ -365,28 +365,28 @@ export class Block {
opts: BlockOptions = {}
) {
this.header = header ?? BlockHeader.fromHeaderData({}, opts)
this._common = this.header._common
this.common = this.header.common

this.transactions = transactions
this.withdrawals = withdrawals ?? (this._common.isActivatedEIP(4895) ? [] : undefined)
this.withdrawals = withdrawals ?? (this.common.isActivatedEIP(4895) ? [] : undefined)
this.uncleHeaders = uncleHeaders
if (uncleHeaders.length > 0) {
this.validateUncles()
if (this._common.consensusType() === ConsensusType.ProofOfAuthority) {
if (this.common.consensusType() === ConsensusType.ProofOfAuthority) {
const msg = this._errorMsg(
'Block initialization with uncleHeaders on a PoA network is not allowed'
)
throw new Error(msg)
}
if (this._common.consensusType() === ConsensusType.ProofOfStake) {
if (this.common.consensusType() === ConsensusType.ProofOfStake) {
const msg = this._errorMsg(
'Block initialization with uncleHeaders on a PoS network is not allowed'
)
throw new Error(msg)
}
}

if (!this._common.isActivatedEIP(4895) && withdrawals !== undefined) {
if (!this.common.isActivatedEIP(4895) && withdrawals !== undefined) {
throw new Error('Cannot have a withdrawals field if EIP 4895 is not active')
}

Expand Down Expand Up @@ -469,13 +469,13 @@ export class Block {
getTransactionsValidationErrors(): string[] {
const errors: string[] = []
let dataGasUsed = BigInt(0)
const dataGasLimit = this._common.param('gasConfig', 'maxDataGasPerBlock')
const dataGasPerBlob = this._common.param('gasConfig', 'dataGasPerBlob')
const dataGasLimit = this.common.param('gasConfig', 'maxDataGasPerBlock')
const dataGasPerBlob = this.common.param('gasConfig', 'dataGasPerBlob')

// eslint-disable-next-line prefer-const
for (let [i, tx] of this.transactions.entries()) {
const errs = tx.getValidationErrors()
if (this._common.isActivatedEIP(1559) === true) {
if (this.common.isActivatedEIP(1559) === true) {
if (tx.supports(Capability.EIP1559FeeMarket)) {
tx = tx as FeeMarketEIP1559Transaction
if (tx.maxFeePerGas < this.header.baseFeePerGas!) {
Expand All @@ -488,7 +488,7 @@ export class Block {
}
}
}
if (this._common.isActivatedEIP(4844) === true) {
if (this.common.isActivatedEIP(4844) === true) {
if (tx instanceof BlobEIP4844Transaction) {
dataGasUsed += BigInt(tx.numBlobs()) * dataGasPerBlob
if (dataGasUsed > dataGasLimit) {
Expand All @@ -503,7 +503,7 @@ export class Block {
}
}

if (this._common.isActivatedEIP(4844) === true) {
if (this.common.isActivatedEIP(4844) === true) {
if (dataGasUsed !== this.header.dataGasUsed) {
errors.push(`invalid dataGasUsed expected=${this.header.dataGasUsed} actual=${dataGasUsed}`)
}
Expand Down Expand Up @@ -552,7 +552,7 @@ export class Block {
throw new Error(msg)
}

if (this._common.isActivatedEIP(4895) && !(await this.withdrawalsTrieIsValid())) {
if (this.common.isActivatedEIP(4895) && !(await this.withdrawalsTrieIsValid())) {
const msg = this._errorMsg('invalid withdrawals trie')
throw new Error(msg)
}
Expand All @@ -565,9 +565,9 @@ export class Block {
* @param parentHeader header of parent block
*/
validateBlobTransactions(parentHeader: BlockHeader) {
if (this._common.isActivatedEIP(4844)) {
const dataGasLimit = this._common.param('gasConfig', 'maxDataGasPerBlock')
const dataGasPerBlob = this._common.param('gasConfig', 'dataGasPerBlob')
if (this.common.isActivatedEIP(4844)) {
const dataGasLimit = this.common.param('gasConfig', 'maxDataGasPerBlock')
const dataGasPerBlob = this.common.param('gasConfig', 'dataGasPerBlob')
let dataGasUsed = BigInt(0)

for (const tx of this.transactions) {
Expand Down Expand Up @@ -621,7 +621,7 @@ export class Block {
* @returns true if the withdrawals trie root is valid, false otherwise
*/
async withdrawalsTrieIsValid(): Promise<boolean> {
if (!this._common.isActivatedEIP(4895)) {
if (!this.common.isActivatedEIP(4895)) {
throw new Error('EIP 4895 is not activated')
}
const withdrawalsRoot = await Block.genWithdrawalsTrieRoot(this.withdrawals!)
Expand Down Expand Up @@ -704,7 +704,7 @@ export class Block {
}
let hf = ''
try {
hf = this._common.hardfork()
hf = this.common.hardfork()
} catch (e: any) {
hf = 'error'
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block/src/from-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function blockFromRpc(
const header = blockHeaderFromRpc(blockParams, options)

const transactions: TypedTransaction[] = []
const opts = { common: header._common }
const opts = { common: header.common }
for (const _txParams of blockParams.transactions ?? []) {
const txParams = normalizeTxParams(_txParams)
const tx = TransactionFactory.fromTxData(txParams, opts)
Expand Down
Loading