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: Execute on Breaking Release Notes #1690

Closed
wants to merge 8 commits into from
10 changes: 5 additions & 5 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class BlockHeader {

if (this._common.isActivatedEIP(1559)) {
if (baseFeePerGas === undefined) {
const londonHfBlock = this._common.hardforkBlockBN(Hardfork.London)
const londonHfBlock = this._common.hardforkBlock(Hardfork.London)
const isInitialEIP1559Block = londonHfBlock && number.eq(londonHfBlock)
if (isInitialEIP1559Block) {
baseFeePerGas = new BN(this._common.param('gasConfig', 'initialBaseFee'))
Expand Down Expand Up @@ -384,7 +384,7 @@ export class BlockHeader {

if (nonce.length !== 8) {
// Hack to check for Kovan due to non-standard nonce length (65 bytes)
if (this._common.networkIdBN().eqn(42)) {
if (this._common.networkId().eqn(42)) {
if (nonce.length !== 65) {
const msg = this._errorMsg(
`nonce must be 65 bytes on kovan, received ${nonce.length} bytes`
Expand Down Expand Up @@ -566,7 +566,7 @@ export class BlockHeader {
let parentGasLimit = parentBlockHeader.gasLimit
// EIP-1559: assume double the parent gas limit on fork block
// to adopt to the new gas target centered logic
const londonHardforkBlock = this._common.hardforkBlockBN(Hardfork.London)
const londonHardforkBlock = this._common.hardforkBlock(Hardfork.London)
if (londonHardforkBlock && this.number.eq(londonHardforkBlock)) {
const elasticity = new BN(this._common.param('gasConfig', 'elasticityMultiplier'))
parentGasLimit = parentGasLimit.mul(elasticity)
Expand Down Expand Up @@ -716,7 +716,7 @@ export class BlockHeader {
const msg = this._errorMsg('EIP1559 block has no base fee field')
throw new Error(msg)
}
const londonHfBlock = this._common.hardforkBlockBN(Hardfork.London)
const londonHfBlock = this._common.hardforkBlock(Hardfork.London)
const isInitialEIP1559Block = londonHfBlock && this.number.eq(londonHfBlock)
if (isInitialEIP1559Block) {
const initialBaseFee = new BN(this._common.param('gasConfig', 'initialBaseFee'))
Expand Down Expand Up @@ -1012,7 +1012,7 @@ export class BlockHeader {
if (!this._common.hardforkIsActiveOnChain(Hardfork.Dao)) {
return
}
const DAOActivationBlock = this._common.hardforkBlockBN(Hardfork.Dao)
const DAOActivationBlock = this._common.hardforkBlock(Hardfork.Dao)
if (!DAOActivationBlock || DAOActivationBlock.isZero() || this.number.lt(DAOActivationBlock)) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ tape('[Block]: block functions', function (t) {
const common = new Common({ chain: Chain.Mainnet })
common.setHardfork(Hardfork.Berlin)

const mainnetForkBlock = common.hardforkBlockBN(Hardfork.London)
const mainnetForkBlock = common.hardforkBlock(Hardfork.London)
const rootBlock = Block.fromBlockData({
header: {
number: mainnetForkBlock!.subn(3),
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/eip1559block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const genesis = Block.fromBlockData({})

// Small hack to hack in the activation block number
// (Otherwise there would be need for a custom chain only for testing purposes)
common.hardforkBlockBN = function (hardfork: string | undefined) {
common.hardforkBlock = function (hardfork: string | undefined) {
if (hardfork === 'london') {
return new BN(1)
} else if (hardfork === 'dao') {
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function createBlock(
const number = parentBlock.header.number.addn(1)
const timestamp = parentBlock.header.timestamp.addn(1)

const londonHfBlock = common.hardforkBlockBN(Hardfork.London)
const londonHfBlock = common.hardforkBlock(Hardfork.London)
const baseFeePerGas =
londonHfBlock && number.gt(londonHfBlock) ? parentBlock.header.calcNextBaseFee() : undefined

Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ export default class Blockchain implements BlockchainInterface {
const currentTd = { header: new BN(0), block: new BN(0) }
let dbOps: DBOp[] = []

if (!block._common.chainIdBN().eq(this._common.chainIdBN())) {
if (!block._common.chainId().eq(this._common.chainId())) {
throw new Error('Chain mismatch while trying to put block or header')
}

Expand Down
46 changes: 22 additions & 24 deletions packages/blockchain/test/clique.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,20 +534,19 @@ tape('Clique: Initialization', (t) => {
t.test(
'Clique Voting: Epoch transitions reset all votes to allow chain checkpointing',
async (st) => {
const common = Common.forCustomChain(
'rinkeby',
{
consensus: {
type: ConsensusType.ProofOfAuthority,
algorithm: ConsensusAlgorithm.Clique,
clique: {
period: 15,
epoch: 3,
},
const common = Common.custom({
consensus: {
type: ConsensusType.ProofOfAuthority,
algorithm: ConsensusAlgorithm.Clique,
clique: {
period: 15,
epoch: 3,
},
},
'chainstart'
)
}, {
baseChain: Chain.Rinkeby,
Hardfork: Hardfork.Chainstart
})
const { blocks, blockchain } = await initWithSigners([A, B], common)
await addNextBlock(blockchain, blocks, A, [C, true], undefined, common)
await addNextBlock(blockchain, blocks, B, undefined, undefined, common)
Expand Down Expand Up @@ -597,20 +596,19 @@ tape('Clique: Initialization', (t) => {
t.test(
'Clique Voting: Recent signatures should not reset on checkpoint blocks imported in a batch',
async (st) => {
const common = Common.forCustomChain(
'rinkeby',
{
consensus: {
type: ConsensusType.ProofOfAuthority,
algorithm: ConsensusAlgorithm.Clique,
clique: {
period: 15,
epoch: 3,
},
const common = Common.custom({
consensus: {
type: ConsensusType.ProofOfAuthority,
algorithm: ConsensusAlgorithm.Clique,
clique: {
period: 15,
epoch: 3,
},
},
'chainstart'
)
}, {
baseChain: Chain.Rinkeby,
Hardfork: Hardfork.Chainstart
})
const { blocks, blockchain } = await initWithSigners([A, B, C], common)
await addNextBlock(blockchain, blocks, A, undefined, undefined, common)
await addNextBlock(blockchain, blocks, B, undefined, undefined, common)
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain/test/pos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import testnet from './testdata/testnet.json'

const buildChain = async (blockchain: Blockchain, common: Common, height: number) => {
const blocks: Block[] = []
const londonBlockNumber = common.hardforkBlockBN('london')!.toNumber()
const londonBlockNumber = common.hardforkBlock('london')!.toNumber()
const genesis = Block.genesis({}, { common })
blocks.push(genesis)

Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/blockchain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class Chain {
* Network ID
*/
get networkId(): BN {
return this.config.chainCommon.networkIdBN()
return this.config.chainCommon.networkId()
}

/**
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 @@ -223,8 +223,13 @@ tape('[Miner]', async (t) => {

t.test('assembleBlocks() -> should not include tx under the baseFee', async (t) => {
t.plan(1)
const customChainParams = { hardforks: [{ name: 'london', block: 0 }] }
const common = Common.forCustomChain(CommonChain.Rinkeby, customChainParams, Hardfork.London)
const customChainParams = {
hardforks: [{ name: 'london', block: 0 }],
}
const common = Common.custom(customChainParams, {
baseChain: CommonChain.Rinkeby,
hardfork: Hardfork.London,
})
const config = new Config({ transports: [], accounts, mine: true, common })
const pool = new PeerPool() as any
const chain = new FakeChain() as any
Expand Down
8 changes: 4 additions & 4 deletions packages/client/test/rpc/eth/sendRawTransaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { checkError } from '../util'
const method = 'eth_sendRawTransaction'

tape(`${method}: call with valid arguments`, async (t) => {
const syncTargetHeight = new Common({ chain: Chain.Mainnet }).hardforkBlockBN(Hardfork.London)
const syncTargetHeight = new Common({ chain: Chain.Mainnet }).hardforkBlock(Hardfork.London)
const { server } = baseSetup({ syncTargetHeight })

// Mainnet EIP-1559 tx
Expand Down Expand Up @@ -44,7 +44,7 @@ tape(`${method}: call with sync target height not set yet`, async (t) => {
})

tape(`${method}: call with invalid tx (wrong chain ID)`, async (t) => {
const syncTargetHeight = new Common({ chain: Chain.Mainnet }).hardforkBlockBN(Hardfork.London)
const syncTargetHeight = new Common({ chain: Chain.Mainnet }).hardforkBlock(Hardfork.London)
const { server } = baseSetup({ syncTargetHeight })

// Baikal EIP-1559 tx
Expand All @@ -57,7 +57,7 @@ tape(`${method}: call with invalid tx (wrong chain ID)`, async (t) => {
})

tape(`${method}: call with unsigned tx`, async (t) => {
const syncTargetHeight = new Common({ chain: Chain.Mainnet }).hardforkBlockBN(Hardfork.London)
const syncTargetHeight = new Common({ chain: Chain.Mainnet }).hardforkBlock(Hardfork.London)
const { server } = baseSetup({ syncTargetHeight })

// Mainnet EIP-1559 tx
Expand All @@ -79,7 +79,7 @@ tape(`${method}: call with unsigned tx`, async (t) => {
})

tape(`${method}: call with no peers`, async (t) => {
const syncTargetHeight = new Common({ chain: Chain.Mainnet }).hardforkBlockBN(Hardfork.London)
const syncTargetHeight = new Common({ chain: Chain.Mainnet }).hardforkBlock(Hardfork.London)
const { server } = baseSetup({ syncTargetHeight, noPeers: true })

// Mainnet EIP-1559 tx
Expand Down
114 changes: 0 additions & 114 deletions packages/common/docs/classes/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ can be created via the main constructor and the [CommonOpts.customChains](../int
- [addListener](default.md#addlistener)
- [bootstrapNodes](default.md#bootstrapnodes)
- [chainId](default.md#chainid)
- [chainIdBN](default.md#chainidbn)
- [chainName](default.md#chainname)
- [consensusAlgorithm](default.md#consensusalgorithm)
- [consensusConfig](default.md#consensusconfig)
Expand All @@ -56,7 +55,6 @@ can be created via the main constructor and the [CommonOpts.customChains](../int
- [gteHardfork](default.md#gtehardfork)
- [hardfork](default.md#hardfork)
- [hardforkBlock](default.md#hardforkblock)
- [hardforkBlockBN](default.md#hardforkblockbn)
- [hardforkForForkHash](default.md#hardforkforforkhash)
- [hardforkGteHardfork](default.md#hardforkgtehardfork)
- [hardforkIsActiveOnBlock](default.md#hardforkisactiveonblock)
Expand All @@ -69,9 +67,7 @@ can be created via the main constructor and the [CommonOpts.customChains](../int
- [listenerCount](default.md#listenercount)
- [listeners](default.md#listeners)
- [networkId](default.md#networkid)
- [networkIdBN](default.md#networkidbn)
- [nextHardforkBlock](default.md#nexthardforkblock)
- [nextHardforkBlockBN](default.md#nexthardforkblockbn)
- [off](default.md#off)
- [on](default.md#on)
- [once](default.md#once)
Expand All @@ -90,7 +86,6 @@ can be created via the main constructor and the [CommonOpts.customChains](../int
- [setHardforkByBlockNumber](default.md#sethardforkbyblocknumber)
- [setMaxListeners](default.md#setmaxlisteners)
- [custom](default.md#custom)
- [forCustomChain](default.md#forcustomchain)
- [isSupportedChainId](default.md#issupportedchainid)
- [listenerCount](default.md#listenercount)
- [once](default.md#once)
Expand Down Expand Up @@ -358,28 +353,6 @@ ___

### chainId

▸ **chainId**(): `number`

Returns the Id of current chain

**`deprecated`** Please use {@link Common.chainIdBN} for large number support

#### Returns

`number`

chain Id

#### Defined in

[packages/common/src/index.ts:1071](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/common/src/index.ts#L1071)

___

### chainIdBN

▸ **chainIdBN**(): `BN`

Returns the Id of current chain

#### Returns
Expand Down Expand Up @@ -725,33 +698,6 @@ ___

### hardforkBlock

▸ **hardforkBlock**(`hardfork?`): ``null`` \| `number`

Returns the hardfork change block for hardfork provided or set

**`deprecated`** Please use {@link Common.hardforkBlockBN} for large number support

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `hardfork?` | `string` | Hardfork name, optional if HF set |

#### Returns

``null`` \| `number`

Block number or null if unscheduled

#### Defined in

[packages/common/src/index.ts:834](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/common/src/index.ts#L834)

___

### hardforkBlockBN

▸ **hardforkBlockBN**(`hardfork?`): ``null`` \| `BN`

Returns the hardfork change block for hardfork provided or set

Expand Down Expand Up @@ -1041,27 +987,6 @@ ___

### networkId

▸ **networkId**(): `number`

Returns the Id of current network

**`deprecated`** Please use {@link Common.networkIdBN} for large number support

#### Returns

`number`

network Id

#### Defined in

[packages/common/src/index.ts:1096](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/common/src/index.ts#L1096)

___

### networkIdBN

▸ **networkIdBN**(): `BN`

Returns the Id of current network

Expand All @@ -1079,34 +1004,6 @@ ___

### nextHardforkBlock

▸ **nextHardforkBlock**(`hardfork?`): ``null`` \| `number`

Returns the change block for the next hardfork after the hardfork provided or set

**`deprecated`** Please use {@link Common.nextHardforkBlockBN} for large number support

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `hardfork?` | `string` | Hardfork name, optional if HF set |

#### Returns

``null`` \| `number`

Block number or null if not available

#### Defined in

[packages/common/src/index.ts:886](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/common/src/index.ts#L886)

___

### nextHardforkBlockBN

▸ **nextHardforkBlockBN**(`hardfork?`): ``null`` \| `BN`

Returns the change block for the next hardfork after the hardfork provided or set

#### Parameters
Expand Down Expand Up @@ -1591,17 +1488,6 @@ the `@ethereumjs/tx` library to a Layer-2 chain).

[packages/common/src/index.ts:211](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/common/src/index.ts#L211)

___

### forCustomChain

▸ `Static` **forCustomChain**(`baseChain`, `customChainParams`, `hardfork?`, `supportedHardforks?`): [`default`](default.md)

Creates a {@link Common} object for a custom chain, based on a standard one. It uses all the `Chain`
params from [baseChain](../interfaces/CustomCommonOpts.md#basechain) except the ones overridden in {@link customChainParams}.

**`deprecated`** Use {@link Common.custom} instead

#### Parameters

| Name | Type | Description |
Expand Down
Loading