Skip to content

Commit

Permalink
Monorepo: adjust removal of default exports in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau committed Jul 5, 2022
1 parent b77beb3 commit 33db4c5
Show file tree
Hide file tree
Showing 18 changed files with 433 additions and 409 deletions.
64 changes: 37 additions & 27 deletions packages/block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ This means that a Block object instantiated without providing an explicit `Commo
If you want to prevent these kind of implicit HF switches in the future it is likely a good practice to just always do your upper-level library instantiations with a `Common` instance setting an explicit HF, e.g.:

```typescript
import Common, { Chain, Hardfork } from '@ethereumjs/common'
import { Chain, Common, Hardfork } from '@ethereumjs/common'

const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Merge })
const block = Block.fromBlockData({
// Provide your block data here or use default values
}, { common })
const block = Block.fromBlockData(
{
// Provide your block data here or use default values
},
{ common }
)
```

### BigInt Introduction / ES2020 Build Target
Expand All @@ -51,19 +54,19 @@ The above TypeScript options provide some semantic sugar like allowing to write

While this is convenient, it deviates from the ESM specification and forces downstream users into using these options, which might not be desirable, see [this TypeScript Semver docs section](https://www.semver-ts.org/#module-interop) for some more detailed argumentation.

Along with the breaking releases we have therefore deactivated both of these options and you might therefore need to adapt some import statements accordingly. Note that you still can activate these options in your bundle and/or transpilation pipeline (but now you also have the option *not* to, which you didn't have before).
Along with the breaking releases we have therefore deactivated both of these options and you might therefore need to adapt some import statements accordingly. Note that you still can activate these options in your bundle and/or transpilation pipeline (but now you also have the option _not_ to, which you didn't have before).

### BigInt-Related API Changes

The `Block` option `hardforkByTD` (merge-related) is now taking in `BigIntLike` data types instead of `BNLike`. Header data fields internally represented as a number - like `number` or `gasLimit` - now have `BigInt` as their internal data type and are also passed in as `BigIntLike` instead of `BNLike`.
The `Block` option `hardforkByTD` (merge-related) is now taking in `BigIntLike` data types instead of `BNLike`. Header data fields internally represented as a number - like `number` or `gasLimit` - now have `BigInt` as their internal data type and are also passed in as `BigIntLike` instead of `BNLike`.

The following method signatures have been changed along the update and need some attention:

- `BlockHeader.calcNextBaseFee(): bigint`
- `BlockHeader.ethashCanonicalDifficulty(parentBlock: Block): bigint` (method also renamed, see validation-refactor section)
- `Block.ethashCanonicalDifficulty(parentBlock: Block): bigint` (method also renamed, see validation-refactor section)

Also worth to note that both the `raw()` and `toJSON()` methods are actually *not* affected, respectively delivering values as `Buffer` and `string`.
Also worth to note that both the `raw()` and `toJSON()` methods are actually _not_ affected, respectively delivering values as `Buffer` and `string`.

### API Method/Getter Removals

Expand All @@ -74,7 +77,6 @@ Additionally the following deprecated methods/getters have been removed from the
- `toJSON()` method: `baseFee` property (use `baseFeePerGas` instead)
- `toJSON()` method: `bloom` property (use `logsBloom` instead)


### Reworked BlockHeader Constructor API

While the `BlockHeader` library main constructor usage is discouraged in favor of the various static constructor methods (e.g. `BlockHeader.fromHeaderData()`), it will realistically still be directly used and this change is therefore mentioned here in the release notes.
Expand Down Expand Up @@ -147,12 +149,15 @@ An ArrowGlacier block can be instantiated with:

```typescript
import { Block } from '@ethereumjs/block'
import Common, { Chain, Hardfork } from '@ethereumjs/common'
import { Chain, Common, Hardfork } from '@ethereumjs/common'

const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.ArrowGlacier })
const block = Block.fromBlockData({
// Provide your block data here or use default values
}, { common })
const block = Block.fromBlockData(
{
// Provide your block data here or use default values
},
{ common }
)
```

### Additional Error Context for Error Messages
Expand Down Expand Up @@ -200,11 +205,14 @@ You can instantiate a Merge/PoS block like this:

```typescript
import { Block } from '@ethereumjs/block'
import Common, { Chain, Hardfork } from '@ethereumjs/common'
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Merge, })
const block = Block.fromBlockData({
// Provide your block data here or use default values
}, { common })
import { Chain, Common, Hardfork } from '@ethereumjs/common'
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Merge })
const block = Block.fromBlockData(
{
// Provide your block data here or use default values
},
{ common }
)
```

See: PR [#1393](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1393) and PR [#1408](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1393)
Expand All @@ -219,7 +227,6 @@ See. PR [#1473](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1473)

- The hash from the `block.hash()` method now gets cached for blocks created with the `freeze` option (activated by default), PR [#1445](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1445)


## 3.4.0 - 2021-07-08

### Finalized London HF Support
Expand All @@ -244,16 +251,19 @@ This `Block` release comes with full functional support for the `london` hardfor
```typescript
import { BN } from 'ethereumjs-util'
import { Block } from '@ethereumjs/block'
import Common from '@ethereumjs/common'
import { Common } from '@ethereumjs/common'
const common = new Common({ chain: 'mainnet', hardfork: 'london' })

const block = Block.fromBlockData({
header: {
baseFeePerGas: new BN(10),
gasLimit: new BN(100),
gasUsed: new BN(60)
}
}, { common })
const block = Block.fromBlockData(
{
header: {
baseFeePerGas: new BN(10),
gasLimit: new BN(100),
gasUsed: new BN(60),
},
},
{ common }
)

// Base fee will increase for next block since the
// gas used is greater than half the gas limit
Expand Down Expand Up @@ -288,7 +298,7 @@ Please note that the default HF is still set to `istanbul`. You therefore need t

```typescript
import { Block } from 'ethereumjs-block'
import Common from '@ethereumjs/common'
import { Common } from '@ethereumjs/common'
const common = new Common({ chain: 'mainnet', hardfork: 'berlin' })
const block = Block.fromBlockData({}, { common })
```
Expand Down
62 changes: 35 additions & 27 deletions packages/block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Discord][discord-badge]][discord-link]

| Implements schema and functions related to Ethereum's block. |
| --- |
| ------------------------------------------------------------ |

Note: this `README` reflects the state of the library from `v3.0.0` onwards. See `README` from the [standalone repository](https://github.com/ethereumjs/ethereumjs-block) for an introduction on the last preceding release.

Expand Down Expand Up @@ -63,16 +63,19 @@ To instantiate an EIP-1559 block, the hardfork parameter on the `Common` instanc

```typescript
import { Block } from '@ethereumjs/block'
import Common, { Chain, Hardfork } from '@ethereumjs/common'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })

const block = Block.fromBlockData({
header: {
baseFeePerGas: BigInt(10),
gasLimit: BigInt(100),
gasUsed: BigInt(60)
}
}, { common })
const block = Block.fromBlockData(
{
header: {
baseFeePerGas: BigInt(10),
gasLimit: BigInt(100),
gasUsed: BigInt(60),
},
},
{ common }
)

// Base fee will increase for next block since the
// gas used is greater than half the gas limit
Expand All @@ -81,17 +84,19 @@ block.header.calcNextBaseFee().toNumber() // 11
// So for creating a block with a matching base fee in a certain
// chain context you can do:

const blockWithMatchingBaseFee = Block.fromBlockData({
header: {
baseFeePerGas: parentHeader.calcNextBaseFee(),
gasLimit: BigInt(100),
gasUsed: BigInt(60)
}
}, { common })

const blockWithMatchingBaseFee = Block.fromBlockData(
{
header: {
baseFeePerGas: parentHeader.calcNextBaseFee(),
gasLimit: BigInt(100),
gasUsed: BigInt(60),
},
},
{ common }
)
```

EIP-1559 blocks have an extra `baseFeePerGas` field (default: `BigInt(7)`) and can encompass `FeeMarketEIP1559Transaction` txs (type `2`) (supported by `@ethereumjs/tx` `v3.2.0` or higher) as well as `Transaction` legacy txs (internal type `0`) and `AccessListEIP2930Transaction` txs (type `1`).
EIP-1559 blocks have an extra `baseFeePerGas` field (default: `BigInt(7)`) and can encompass `FeeMarketEIP1559Transaction` txs (type `2`) (supported by `@ethereumjs/tx` `v3.2.0` or higher) as well as `Transaction` legacy txs (internal type `0`) and `AccessListEIP2930Transaction` txs (type `1`).

## Consensus Types

Expand All @@ -103,8 +108,8 @@ An Ethash/PoW block can be instantiated as follows:

```typescript
import { Block } from '@ethereumjs/block'
import Common, { Chain } from '@ethereumjs/common'
const common = new Common({ chain: Chain.Mainnet })
import { Chain, Common } from '@ethereumjs/common'
const common = new Common({ chain: Chain.Mainnet })
console.log(common.consensusType()) // 'pow'
console.log(common.consensusAlgorithm()) // 'ethash'
const block = Block.fromBlockData({}, { common })
Expand All @@ -120,8 +125,8 @@ A clique block can be instantiated as follows:

```typescript
import { Block } from '@ethereumjs/block'
import Common, { Chain } from '@ethereumjs/common'
const common = new Common({ chain: Chain.Goerli })
import { Chain, Common } from '@ethereumjs/common'
const common = new Common({ chain: Chain.Goerli })
console.log(common.consensusType()) // 'poa'
console.log(common.consensusAlgorithm()) // 'clique'
const block = Block.fromBlockData({}, { common })
Expand Down Expand Up @@ -157,11 +162,14 @@ You can instantiate a Merge/PoS block like this:

```typescript
import { Block } from '@ethereumjs/block'
import Common, { Chain, Hardfork } from '@ethereumjs/common'
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Merge, })
const block = Block.fromBlockData({
// Provide your block data here or use default values
}, { common })
import { Chain, Common, Hardfork } from '@ethereumjs/common'
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Merge })
const block = Block.fromBlockData(
{
// Provide your block data here or use default values
},
{ common }
)
```

Note that all `Merge` respectively `Casper/PoS` related functionality is still considered `experimental`.
Expand Down
26 changes: 13 additions & 13 deletions packages/blockchain/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The above TypeScript options provide some semantic sugar like allowing to write

While this is convenient, it deviates from the ESM specification and forces downstream users into using these options, which might not be desirable, see [this TypeScript Semver docs section](https://www.semver-ts.org/#module-interop) for some more detailed argumentation.

Along with the breaking releases we have therefore deactivated both of these options and you might therefore need to adapt some import statements accordingly. Note that you still can activate these options in your bundle and/or transpilation pipeline (but now you also have the option *not* to, which you didn't have before).
Along with the breaking releases we have therefore deactivated both of these options and you might therefore need to adapt some import statements accordingly. Note that you still can activate these options in your bundle and/or transpilation pipeline (but now you also have the option _not_ to, which you didn't have before).

### BigInt-Related and other API Changes

Expand Down Expand Up @@ -115,8 +115,8 @@ Please note that for backwards-compatibility reasons the associated Common is st
An ArrowGlacier blockchain object can be instantiated with:

```typescript
import Blockchain from '@ethereumjs/blockchain'
import Common, { Chain, Hardfork } from '@ethereumjs/common'
import { Blockchain } from '@ethereumjs/blockchain'
import { Chain, Common, Hardfork } from '@ethereumjs/common'

const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.ArrowGlacier })
const blockchain = await Blockchain.create({ common })
Expand Down Expand Up @@ -170,8 +170,8 @@ This release comes with full functional `london` HF support (all EIPs are finali
Please note that the default HF is still set to `istanbul`. You therefore need to explicitly set the `hardfork` parameter for instantiating a `Blockchain` instance with a `london` HF activated:

```typescript
import Blockchain from '@ethereumjs/blockchain'
import Common from '@ethereumjs/common'
import { Blockchain } from '@ethereumjs/blockchain'
import { Common } from '@ethereumjs/common'
const common = new Common({ chain: 'mainnet', hardfork: 'london' })
const blockchain = await Blockchain.create({ common })
```
Expand All @@ -193,8 +193,8 @@ This release comes with full `berlin` HF support by setting the `Block`, `Tx` an
Please note that the default HF is still set to `istanbul`. You therefore need to explicitly set the `hardfork` parameter for instantiating a `Blockchain` instance with a `berlin` HF activated:

```typescript
import Blockchain from '@ethereumjs/blockchain'
import Common from '@ethereumjs/common'
import { Blockchain } from '@ethereumjs/blockchain'
import { Common } from '@ethereumjs/common'
const common = new Common({ chain: 'mainnet', hardfork: 'berlin' })
const blockchain = await Blockchain.create({ common })
```
Expand Down Expand Up @@ -266,7 +266,7 @@ See `Blockchain` [README](https://github.com/ethereumjs/ethereumjs-monorepo/tree
The library now has an additional safe static constructor `Blockchain.create()` which awaits the init method and throws if the init method throws:

```typescript
import Blockchain from '@ethereumjs/blockchain'
import { Blockchain } from '@ethereumjs/blockchain'
const common = new Common({ chain: 'ropsten' })
const blockchain = await Blockchain.create({ common })
```
Expand All @@ -279,7 +279,7 @@ Constructor options (both for the static and the main constructor) for chain set

Genesis handling has been reworked to now be safer and reduce the risk of wiping a blockchain by setting a new genesis, see PR [#930](https://github.com/ethereumjs/ethereumjs-monorepo/pull/930).

**Breaking**: The dedicated `setGenesisBlock()` methods and the optional `isGenesis` option on `Blockchain.putBlock()` have been removed. Instead the genesis block is created on initialization either from the `Common` library instance passed or a custom genesis block passed along with the `genesisBlock` option. If a custom genesis block is used, this custom block now always has to be passed along on `Blockchain` initialization, also when operating on an already existing DB.
**Breaking**: The dedicated `setGenesisBlock()` methods and the optional `isGenesis` option on `Blockchain.putBlock()` have been removed. Instead the genesis block is created on initialization either from the `Common` library instance passed or a custom genesis block passed along with the `genesisBlock` option. If a custom genesis block is used, this custom block now always has to be passed along on `Blockchain` initialization, also when operating on an already existing DB.

### Removed deprecated `validate` option

Expand Down Expand Up @@ -342,7 +342,7 @@ This is the new recommended way to instantiate a `Blockchain` object, see PR [#9

Genesis handling has been reworked to now be safer and reduce the risk of wiping a blockchain by setting a new genesis, see PR [#930](https://github.com/ethereumjs/ethereumjs-monorepo/pull/930).

**Breaking**: The dedicated `setGenesisBlock()` methods and the optional `isGenesis` option on `Blockchain.putBlock()` have been removed. Instead the genesis block is created on initialization either from the `Common` library instance passed or a custom genesis block passed along with the `genesisBlock` option. If a custom genesis block is used, this custom block now always has to be passed along on `Blockchain` initialization, also when operating on an already existing DB.
**Breaking**: The dedicated `setGenesisBlock()` methods and the optional `isGenesis` option on `Blockchain.putBlock()` have been removed. Instead the genesis block is created on initialization either from the `Common` library instance passed or a custom genesis block passed along with the `genesisBlock` option. If a custom genesis block is used, this custom block now always has to be passed along on `Blockchain` initialization, also when operating on an already existing DB.

**Changes and Refactoring**

Expand Down Expand Up @@ -401,7 +401,7 @@ Constructor options for chain setup on all VM monorepo libraries have been simpl
Example:

```typescript
import Blockchain from '@ethereumjs/blockchain'
import { Blockchain } from '@ethereumjs/blockchain'
const common = new Common({ chain: 'ropsten', hardfork: 'byzantium' })
const blockchain = new Blockchain({ common })
```
Expand All @@ -412,8 +412,8 @@ The deprecated `validate` option has been removed, please use `valdiateBlock` an

### Dual ES5 and ES2017 Builds

We significantly updated our internal tool and CI setup along the work on
PR [#913](https://github.com/ethereumjs/ethereumjs-monorepo/pull/913) with an update to `ESLint` from `TSLint`
We significantly updated our internal tool and CI setup along the work on
PR [#913](https://github.com/ethereumjs/ethereumjs-monorepo/pull/913) with an update to `ESLint` from `TSLint`
for code linting and formatting and the introduction of a new build setup.

Packages now target `ES2017` for Node.js builds (the `main` entrypoint from `package.json`) and introduce
Expand Down
12 changes: 6 additions & 6 deletions packages/blockchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Discord][discord-badge]][discord-link]

| A module to store and interact with blocks. |
| --- |
| ------------------------------------------- |

Note: this `README` reflects the state of the library from `v5.0.0` onwards. See `README` from the [standalone repository](https://github.com/ethereumjs/ethereumjs-blockchain) for an introduction on the last preceding release.

Expand All @@ -24,8 +24,8 @@ The following is an example to iterate through an existing Geth DB (needs `level
This module performs write operations. Making a backup of your data before trying it is recommended. Otherwise, you can end up with a compromised DB state.

```typescript
import Blockchain from '@ethereumjs/blockchain'
import Common, { Chain } from '@ethereumjs/common'
import { Blockchain } from '@ethereumjs/blockchain'
import { Chain, Common } from '@ethereumjs/common'

const { Level } = require('level')

Expand Down Expand Up @@ -59,9 +59,9 @@ For debugging blockchain control flows the [debug](https://github.com/visionmedi

The following initial logger is currently available:

| Logger | Description |
| - | - |
| `blockchain:clique` | Clique operations like updating the vote and/or signer list |
| Logger | Description |
| ------------------- | ----------------------------------------------------------- |
| `blockchain:clique` | Clique operations like updating the vote and/or signer list |

The following is an example for a logger run:

Expand Down
Loading

0 comments on commit 33db4c5

Please sign in to comment.