All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog (modification: no type change headlines) and this project adheres to Semantic Versioning.
- Integration of EIP2718 (Typed Transactions) and EIP2930 (Access List Transaction), PR #1048. It is now possible to create blocks with access list transactions.
This release introduces Clique/PoA support for the Block
library, see the main PR #1032 as well as the follow-up PRs #1074 and PR #1088. The BlockHeader.validate()
function now properly validates the various Clique/PoA-specific properties (extraData
checks and others, see API documentation) and BlockHeader.validateConsensus()
can be used to properly validate that a Clique/PoA block has the correct signature.
For sealing a block on instantiation there is a new cliqueSigner
constructor option:
const cliqueSigner = Buffer.from('PRIVATE_KEY_HEX_STRING', 'hex')
const block = Block.fromHeaderData(headerData, { cliqueSigner })
Additionally there are the following new utility methods for Clique/PoA related functionality in the BlockHeader
class:
BlockHeader.validateCliqueDifficulty(blockchain: Blockchain): boolean
BlockHeader.cliqueSigHash()
BlockHeader.cliqueIsEpochTransition(): boolean
BlockHeader.cliqueExtraVanity(): Buffer
BlockHeader.cliqueExtraSeal(): Buffer
BlockHeader.cliqueEpochTransitionSigners(): Address[]
BlockHeader.cliqueVerifySignature(signerList: Address[]): boolean
BlockHeader.cliqueSigner(): Address
See the API docs for a detailed documentation. Note that these methods will throw if called in a non-Clique/PoA context.
- The
Common
instance passed is now copied to avoid side-effects towards the outer common instance on HF updates, PR #1089 - Fixed a bug where txs have been created with the wrong HF when
hardforkByBlockNumber
is used along with the static constructors, PR #1089 - Fixed a bug where
Common
has not been passed to the returned block in theblockFromRpc()
method, PR #1032
Attention! This new version is part of a series of EthereumJS releases all moving to a new scoped package name format. In this case the library is renamed as follows:
ethereumjs-block
->@ethereumjs/block
Please update your library references accordingly or install with:
npm i @ethereumjs/block
This is the first TypeScript based release of the library, see PR #72. The import structure has slightly changed along:
TypeScript
import { BlockHeader } from 'ethereumjs-block'
import { Block } from 'ethereumjs-block'
JavaScript/Node.js
const BlockHeader = require('ethereumjs-block').BlockHeader
const Block = require('ethereumjs-block').Block
The library now also comes with a type declaration file distributed along with the package published.
This release is a major refactoring of the block library to simplify and strengthen its code base. Refactoring work has been done along PR #72 (Promises) and PR #883 (refactoring of API and internal code structure).
The way to instantiate a new BlockHeader
or Block
object has been completely reworked and is now more explicit, less error prone and produces more TypeScript
friendly and readable code.
The old direct constructor usage is now discouraged in favor of different dedicated static factory methods to create new objects.
Breaking: While the main constructors can still be called, signatures changed significantly and your old new Block(...)
, new BlockHeader(...)
instantiations won't work any more and needs to be updated.
BlockHeader Class
There are three new factory methods to create a new BlockHeader
:
- Pass in a Header-attribute named dictionary to
BlockHeader.fromHeaderData(headerData: HeaderData = {}, opts?: BlockOptions)
:
const headerData = {
number: 15,
parentHash: '0x6bfee7294bf44572b7266358e627f3c35105e1c3851f3de09e6d646f955725a7',
difficulty: 131072,
gasLimit: 8000000,
timestamp: 1562422144,
}
const header = BlockHeader.fromHeaderData(headerData)
- Create a
BlockHeader
from an RLP-serialized headerBuffer
withBlockHeader.fromRLPSerializedHeader(serialized: Buffer, opts: BlockOptions)
.
const serialized = Buffer.from(
'f901f7a06bfee7294bf44572b7266358e627f3c35105e1c3851f3de09e6d646f955725a7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000f837a120080845d20ab8080a00000000000000000000000000000000000000000000000000000000000000000880000000000000000',
'hex'
)
const header = BlockHeader.fromRLPSerializedHeader(serialized)
- Create a
BlockHeader
from an array ofBuffer
values, you can do a first short roundtrip test with:
const valuesArray = header.raw()
BlockHeader.fromValuesArray(valuesArray)
Generally internal types representing block header values are now closer to their domain representation (number, difficulty, gasLimit) instead of having everthing represented as a Buffer
.
Block Class
There are analogue new static factories for the Block
class:
Block.fromBlockData(blockData: BlockData = {}, opts?: BlockOptions)
Block.fromRLPSerializedBlock(serialized: Buffer, opts?: BlockOptions)
Block.fromValuesArray(values: BlockBuffer, opts?: BlockOptions)
Learn more about the full API in the docs.
The returned block is now frozen and immutable. To work with a maliable block, copy it with const fakeBlock = Object.create(block)
.
If you need Block
mutability - e.g. because you want to subclass Block
and modifiy its behavior - there is a freeze
option to prevent the Object.freeze()
call on initialization, see PR #941.
The API of this library is now completely promise-based and the old callback-style interface has been dropped.
This affects the following methods of the API now being defined as async
and returning a Promise
:
Header Class
BlockHeader.validate(blockchain: Blockchain, height?: BN): Promise<void>
Block Class
Block.genTxTrie(): Promise<void>
Block.validate(blockChain: Blockchain): Promise<void>
Block.validateUncles(blockchain: Blockchain): Promise<void>
Usage example:
try {
await block.validate(blockchain)
// Block validation has passed
} catch (err) {
// handle errors appropriately
}
Breaking: The signatures of the following header validation methods have been updated to take a parentBlockHeader
instead of a parentBlock
input parameter for consistency and removing a circling dependency with Block
:
BlockHeader.canonicalDifficulty(parentBlockHeader: BlockHeader): BN
BlockHeader.validateDifficulty(parentBlockHeader: BlockHeader): boolean
BlockHeader.validateGasLimit(parentBlockHeader: BlockHeader): boolean
On the Block
library new corresponding methods have been added which both operate on a block instance and expect a parentBlock
as an input parameter.
Breaking: Note that canonicalDifficulty()
and validateDifficulty()
in block and header now throw on non-PoW chains, see PR #937.
Breaking: Non-blockchain dependent validation checks have been extracted from validate()
to its own Block.validateData()
function. For the validate()
method in block and header blockchain
is now a mandatory parameter, see PR #942
Breaking: The default HF on the library has been updated from petersburg
to istanbul
, see PR #906.
The HF setting is now automatically taken from the HF set for Common.DEAULT_HARDFORK
, see PR #863.
We significantly updated our internal tool and CI setup along the work on PR #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 a separate ES5
build distributed along using the browser
directive as an entrypoint, see PR #921. This will result in performance benefits for Node.js consumers, see here for a releated discussion.
Features
- Added
Block.genesis()
andBlockHeader.genesis()
aliases to create a genesis block or header, PR #883 - Added
DAO
hardfork support (check forextraData
attribute ifDAO
HF is active), PR #843 - Added the
calcDifficultyFromHeader
constructor option. If thisBlockHeader
is supplied, then thedifficulty
of the constructedBlockHeader
will be set to the canonical difficulty (also ifdifficulty
is set as parameter in the constructor). See #929 - Added full uncle validation, which verifies if the uncles'
parentHash
points to the canonical chain, is not yet included and also is an uncle and not a canonical block. See PR #935 - Additional consistency and validation checks in
Block.validateUncles()
for included uncle headers, PR #935
Changes and Refactoring
- Added Node
10
,12
support, dropped Node7
support, PR #72 - Passing in a blockchain is now optional on
Block.validate()
, PR #883 - Breaking:
Block.validateTransactions(stringError: true)
now returns astring[]
, PR #883 - Breaking: Decoupling of the
Block.serialize()
andBlock.raw()
methods,Block.serialize()
now always returns the RLP-encoded block (signature change!),Block.raw()
always returns the pureBuffer
array, PR #883 - Breaking:
Block.toJSON()
now always returns the labeledJSON
representation, removal of thelabeled
function parameter, PR #883 - Updated
merkle-patricia-tree
dependency tov4
, PR #787 - Updated
ethereumjs-util
dependency tov7
, PR #748 - Removal of the
async
dependency, PR #72
CI and Testing
- Browser test run on CI, PR #72
- Karma browser test run config modernization and simplification, PR #72
- Updated test source files to
TypeScript
, PR #72
Bug Fixes
- Signature fix for pre-homestead blocks, PR #67
- Fixed bug where block options have not been passed on to the main constructor from the static factory methods, see PR #941
This is the first release candidate towards a final library release, see beta.2 and especially beta.1 release notes for an overview on the full changes since the last publicly released version.
- Additional consistency and validation checks in
Block.validateUncles()
for included uncle headers, PR #935
This is the second beta release towards a final library release, see beta.1 release notes for an overview on the full changes since the last publicly released version.
- Added
freeze
option to allow for block freeze deactivation (e.g. to allow for subclassing block and adding additional parameters), see PR #941 - Breaking: Difficulty-depending methods
canonicalDifficulty()
andvalidateDifficulty()
in block and header now throw on non-PoW chains, see PR #937 - Breaking: Non-blockchain dependent validation checks have been extracted from
validate()
to its ownBlock.validateData()
function. For thevalidate()
method in block and headerblockchain
is now a mandatory parameter, see PR #942 - Fixed bug where block options have not been passed on to the main constructor from the static factory methods, see PR #941
- Added full uncle validation, which verifies if the uncles'
parentHash
points to the canonical chain, is not yet included and also is an uncle and not a canonical block. See PR #935.
Attention! This new version is part of a series of EthereumJS releases all moving to a new scoped package name format. In this case the library is renamed as follows:
ethereumjs-block
->@ethereumjs/block
Please update your library references accordingly or install with:
npm i @ethereumjs/block
This is the first TypeScript based release of the library, see PR #72. The import structure has slightly changed along:
TypeScript
import { BlockHeader } from 'ethereumjs-block'
import { Block } from 'ethereumjs-block'
JavaScript/Node.js
const BlockHeader = require('ethereumjs-block').BlockHeader
const Block = require('ethereumjs-block').Block
The library now also comes with a type declaration file distributed along with the package published.
This release is a major refactoring of the block library to simplify and strengthen its code base. Refactoring work has been done along PR #72 (Promises) and PR #883 (refactoring of API and internal code structure).
The way to instantiate a new BlockHeader
or Block
object has been completely reworked and is
now more explicit, less error prone and produces more TypeScript
friendly and readable code.
The old direct constructor usage is now discouraged in favor of different dedicated static factory methods to create new objects.
Breaking: While the main constructors can still be called, signatures changed significantly and
your old new Block(...)
, new BlockHeader(...)
instantiations won't work any more and needs to be
updated.
BlockHeader Class
There are three new factory methods to create a new BlockHeader
:
- Pass in a Header-attribute named dictionary to
BlockHeader.fromHeaderData(headerData: HeaderData = {}, opts?: BlockOptions)
:
const headerData = {
number: 15,
parentHash: '0x6bfee7294bf44572b7266358e627f3c35105e1c3851f3de09e6d646f955725a7',
difficulty: 131072,
gasLimit: 8000000,
timestamp: 1562422144,
}
const header = BlockHeader.fromHeaderData(headerData)
- Create a
BlockHeader
from an RLP-serialized headerBuffer
withBlockHeader.fromRLPSerializedHeader(serialized: Buffer, opts: BlockOptions)
.
const serialized = Buffer.from(
'f901f7a06bfee7294bf44572b7266358e627f3c35105e1c3851f3de09e6d646f955725a7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000f837a120080845d20ab8080a00000000000000000000000000000000000000000000000000000000000000000880000000000000000',
'hex'
)
const header = BlockHeader.fromRLPSerializedHeader(serialized)
- Create a
BlockHeader
from an array ofBuffer
values, you can do a first short roundtrip test with:
const valuesArray = header.raw()
BlockHeader.fromValuesArray(valuesArray)
Generally internal types representing block header values are now closer to their domain representation
(number, difficulty, gasLimit) instead of having everthing represented as a Buffer
.
Block Class
There are analogue new static factories for the Block
class:
Block.fromBlockData(blockData: BlockData = {}, opts?: BlockOptions)
Block.fromRLPSerializedBlock(serialized: Buffer, opts?: BlockOptions)
Block.fromValuesArray(values: BlockBuffer, opts?: BlockOptions)
Learn more about the full API in the docs.
The returned block is now frozen and immutable. To work with a maliable block, copy it with const fakeBlock = Object.create(block)
.
The API of this library is now completely promise-based and the old callback-style interface has been dropped.
This affects the following methods of the API now being defined as async
and
returning a Promise
:
Header Class
BlockHeader.validate(blockchain: Blockchain, height?: BN): Promise<void>
Block Class
Block.genTxTrie(): Promise<void>
Block.validate(blockChain: Blockchain): Promise<void>
Block.validateUncles(blockchain: Blockchain): Promise<void>
Usage example:
try {
await block.validate(blockchain)
// Block validation has passed
} catch (err) {
// handle errors appropriately
}
Breaking: The signatures of the following header validation methods have been updated to take a parentBlockHeader
instead of a
parentBlock
input parameter for consistency and removing a circling dependency with Block
:
BlockHeader.canonicalDifficulty(parentBlockHeader: BlockHeader): BN
BlockHeader.validateDifficulty(parentBlockHeader: BlockHeader): boolean
BlockHeader.validateGasLimit(parentBlockHeader: BlockHeader): boolean
On the Block
library new corresponding methods have been added which both operate on a block instance and expect a parentBlock
as an input parameter.
Breaking: The default HF on the library has been updated from petersburg
to istanbul
, see PR #906.
The HF setting is now automatically taken from the HF set for Common.DEAULT_HARDFORK
,
see PR #863.
We significantly updated our internal tool and CI setup along the work on
PR #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
a separate ES5
build distributed along using the browser
directive as an entrypoint, see
PR #921. This will result
in performance benefits for Node.js consumers, see here for a releated discussion.
Features
- Added
Block.genesis()
andBlockHeader.genesis()
aliases to create a genesis block or header, PR #883 - Added
DAO
hardfork support (check forextraData
attribute ifDAO
HF is active), PR #843 - Added the
calcDifficultyFromHeader
constructor option. If thisBlockHeader
is supplied, then thedifficulty
of the constructedBlockHeader
will be set to the canonical difficulty (also ifdifficulty
is set as parameter in the constructor). See #929
Changes and Refactoring
- Added Node
10
,12
support, dropped Node7
support, PR #72 - Passing in a blockchain is now optional on
Block.validate()
, PR #883 - Breaking:
Block.validateTransactions(stringError: true)
now returns astring[]
, PR #883 - Breaking: Decoupling of the
Block.serialize()
andBlock.raw()
methods,Block.serialize()
now always returns the RLP-encoded block (signature change!),Block.raw()
always returns the pureBuffer
array, PR #883 - Breaking:
Block.toJSON()
now always returns the labeledJSON
representation, removal of thelabeled
function parameter, PR #883 - Updated
merkle-patricia-tree
dependency tov4
, PR #787 - Updated
ethereumjs-util
dependency tov7
, PR #748 - Removal of the
async
dependency, PR #72
CI and Testing
- Browser test run on CI, PR #72
- Karma browser test run config modernization and simplification PR #72
- Updated test source files to
TypeScript
, PR #72
Bug Fixes
- Signature fix for pre-homestead blocks, PR #67
2.2.2 - 2019-12-17
MuirGlacier support by updating to the new difficulty formula as stated in EIP-2384.
Please note that this release does not contain all the changes merged into
master since the v2.2.0
release and only backports the difficulty formula
adjustments to support MuirGlacier without having to go through migration to
the v3.0.0
which contains breaking changes.
2.2.1 - 2019-11-14
Istanbul support by updating to the most recent ethereumjs-tx
version
v2.1.1.
Please note that this release does not contain all the changes merged into
master since the v2.2.0
release and only backports the most recent
ethereumjs-tx
version to allow users to support Istanbul without having
to go through migration to the v3.0.0
which contains breaking changes.
2.2.0 - 2019-02-06
Petersburg (aka constantinopleFix
) as well as Goerli
support/readiness by updating to a supporting ethereumjs-common
version
v1.1.0,
PR #64
Other Changes:
- Fixed package size issue by excluding tests and docs from being included in the package, PR #66
- Error message fixes in
index.js
, PR #62 - Replace uses of deprecated
new Buffer
withBuffer.from
, PR #60 - Remove
ethereumjs-testing
dependency (much smaller dev dependencies), PR #61
2.1.0 - 2018-10-19
- Constantinople support, added difficulty bomb delay (EIP-1234), PR #54
- Updated test data, added Constantinople tests, PR #56, #57
- Added
timestamp
field tosetGenesisParams()
, PR #52
2.0.1 - 2018-08-08
- Fixes
BlockHeader.prototype.validate()
bug, see PR #49
2.0.0 - 2018-06-25
This release introduces both support for different chains
(mainnet
, ropsten
, ...)
and hardforks
up to the latest applied HF (byzantium
). Parameters and genesis values
are provided by the new ethereumjs-common
library which also defines the set of supported chains and forks.
Changes in detail:
- New initialization parameters
opts.chain
(default:mainnet
) andopts.hardfork
(default:null
, block number-based behaviour), PR #44 - Alternatively a
Common
class object can be provided directly with theopts.common
parameter, see API docs - Correct block validation for all know hardforks, PR
#47, if no hardfork is set validation logic
is determined by block number in combination with the
chain
set - Genesis block initialization depending on the
chain
set (seeethereumjs-common
for supported chains) - Extensive test additions to cover the newly introduced capabilities and changes
- Fix default value for
nonce
(empty buffer -><Buffer 00 00 00 00 00 00 00 00>
), PR #42
1.7.1 - 2018-02-15
- Fix
browserify
issue blocking updates for packages depending onethereumjs-block
library, PR #40 - Updated
ethereumjs/common
dependency, PR #38
1.7.0 - 2017-10-11
Metro-Byzantium
compatible- New difficulty formula (EIP 100)
- Difficulty bomb delay (EIP 649)
- Removed
isHomestead
,isHomesteadReprice
from API methods
1.6.0 - 2017-07-12
- Breakout header-from-rpc as separate module
1.5.1 - 2017-06-04
- Dev dependency updates
- BN for gas limit