diff --git a/packages/block/CHANGELOG.md b/packages/block/CHANGELOG.md index 4165f511f8..22455fba3a 100644 --- a/packages/block/CHANGELOG.md +++ b/packages/block/CHANGELOG.md @@ -6,6 +6,38 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) (modification: no type change headlines) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 3.1.0 - 2021-02-22 + +### Clique/PoA Support + +This release introduces Clique/PoA support for the `Block` library, see the main PR [#1032](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1032) as well as the follow-up PRs [#1074](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1074) and PR [#1088](https://github.com/ethereumjs/ethereumjs-monorepo/pull/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: + +```typescript +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. + +### Other Changes + +- The `Common` instance passed is now copied to avoid side-effects towards the outer common instance on HF updates, PR [#1089](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1089) +- Fixed a bug where txs have been created with the wrong HF when `hardforkByBlockNumber` is used along with the static constructors, PR [#1089](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1089) +- Fixed a bug where `Common` has not been passed to the returned block in the `blockFromRpc()` method, PR [#1032](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1032) + ## 3.0.0 - 2020-11-24 ### New Package Name diff --git a/packages/block/README.md b/packages/block/README.md index d89ee2865a..7e8fd82bed 100644 --- a/packages/block/README.md +++ b/packages/block/README.md @@ -57,6 +57,62 @@ try { [Documentation](./docs/README.md) +# CONSENSUS TYPES + +The block library supports the creation as well as format and consensus validation of PoW `ethash` and PoA `clique` blocks. + +## Ethash/PoW + +An Ethash/PoW block can be instantiated as follows: + +```typescript +import { Block } from '@ethereumjs/block' +import Common from '@ethereumjs/common' +const common = new Common({ chain: 'mainnet' }) +console.log(common.consensusType()) // 'pow' +console.log(common.consensusAlgorithm()) // 'ethash' +const block = Block.fromBlockData({}, { common }) +``` + +To validate that the difficulty of the block matches the canonical difficulty use `block.validate(blockchain)`. + +To calculate the difficulty when creating the block pass in the block option `calcDifficultyFromHeader` with the preceding (parent) `BlockHeader`. + +## Clique/PoA (since v3.1.0) + +A clique block can be instantiated as follows: + +```typescript +import { Block } from '@ethereumjs/block' +import Common from '@ethereumjs/common' +const common = new Common({ chain: 'goerli' }) +console.log(common.consensusType()) // 'poa' +console.log(common.consensusAlgorithm()) // 'clique' +const block = Block.fromBlockData({}, { common }) +``` + +For clique PoA `BlockHeader.validate()` function 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 you can use the `cliqueSigner` constructor option: + +```typescript +const cliqueSigner = Buffer.from('PRIVATE_KEY_HEX_STRING', 'hex') +const block = Block.fromHeaderData(headerData, { cliqueSigner }) +``` + +Additionally there are the following 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 detailed documentation. Note that these methods will throw if called in a non-Clique/PoA context. + # TESTING Tests in the `tests` directory are partly outdated and testing is primarily done by running the `BlockchainTests` from within the [ethereumjs-vm](https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/vm#synopsis) package. diff --git a/packages/block/docs/README.md b/packages/block/docs/README.md index c982b382b2..1ae798a1a9 100644 --- a/packages/block/docs/README.md +++ b/packages/block/docs/README.md @@ -7,6 +7,7 @@ ### Modules * ["block"](modules/_block_.md) +* ["clique"](modules/_clique_.md) * ["from-rpc"](modules/_from_rpc_.md) * ["header"](modules/_header_.md) * ["header-from-rpc"](modules/_header_from_rpc_.md) diff --git a/packages/block/docs/classes/_block_.block.md b/packages/block/docs/classes/_block_.block.md index 58a41bdd37..74c5db8394 100644 --- a/packages/block/docs/classes/_block_.block.md +++ b/packages/block/docs/classes/_block_.block.md @@ -50,7 +50,7 @@ An object that represents the block. \+ **new Block**(`header?`: [BlockHeader](_header_.blockheader.md), `transactions`: Transaction[], `uncleHeaders`: [BlockHeader](_header_.blockheader.md)[], `opts`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[Block](_block_.block.md)* -*Defined in [block.ts:92](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L92)* +*Defined in [block.ts:107](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L107)* This constructor takes the values, validates them, assigns them and freezes the object. Use the static factory methods to assist in creating a Block object from varying data types and options. @@ -112,7 +112,7 @@ ___ ▸ **canonicalDifficulty**(`parentBlock`: [Block](_block_.block.md)): *BN* -*Defined in [block.ts:286](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L286)* +*Defined in [block.ts:307](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L307)* Returns the canonical difficulty for this block. @@ -130,7 +130,7 @@ ___ ▸ **genTxTrie**(): *Promise‹void›* -*Defined in [block.ts:150](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L150)* +*Defined in [block.ts:168](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L168)* Generates transaction trie for validation. @@ -142,7 +142,7 @@ ___ ▸ **hash**(): *Buffer* -*Defined in [block.ts:129](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L129)* +*Defined in [block.ts:147](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L147)* Produces a hash the RLP of the block. @@ -154,7 +154,7 @@ ___ ▸ **isGenesis**(): *boolean* -*Defined in [block.ts:136](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L136)* +*Defined in [block.ts:154](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L154)* Determines if this block is the genesis block. @@ -166,7 +166,7 @@ ___ ▸ **raw**(): *[BlockBuffer](../modules/_index_.md#blockbuffer)* -*Defined in [block.ts:118](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L118)* +*Defined in [block.ts:136](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L136)* Returns a Buffer Array of the raw Buffers of this block, in order. @@ -178,7 +178,7 @@ ___ ▸ **serialize**(): *Buffer* -*Defined in [block.ts:143](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L143)* +*Defined in [block.ts:161](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L161)* Returns the rlp encoding of the block. @@ -190,7 +190,7 @@ ___ ▸ **toJSON**(): *[JsonBlock](../interfaces/_index_.jsonblock.md)* -*Defined in [block.ts:312](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L312)* +*Defined in [block.ts:333](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L333)* Returns the block in JSON format. @@ -202,7 +202,7 @@ ___ ▸ **validate**(`blockchain`: [Blockchain](../interfaces/_index_.blockchain.md)): *Promise‹void›* -*Defined in [block.ts:209](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L209)* +*Defined in [block.ts:229](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L229)* Performs the following consistency checks on the block: @@ -227,7 +227,7 @@ ___ ▸ **validateData**(): *Promise‹void›* -*Defined in [block.ts:222](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L222)* +*Defined in [block.ts:242](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L242)* Validates the block data, throwing if invalid. This can be checked on the Block itself without needing access to any parent block @@ -244,7 +244,7 @@ ___ ▸ **validateDifficulty**(`parentBlock`: [Block](_block_.block.md)): *boolean* -*Defined in [block.ts:295](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L295)* +*Defined in [block.ts:316](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L316)* Checks that the block's `difficulty` matches the canonical difficulty. @@ -262,7 +262,7 @@ ___ ▸ **validateGasLimit**(`parentBlock`: [Block](_block_.block.md)): *boolean* -*Defined in [block.ts:305](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L305)* +*Defined in [block.ts:326](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L326)* Validates if the block gasLimit remains in the boundaries set by the protocol. @@ -281,7 +281,7 @@ ___ ▸ **validateTransactions**(): *boolean* -*Defined in [block.ts:181](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L181)* +*Defined in [block.ts:201](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L201)* Validates transaction signatures and minimum gas requirements. @@ -289,7 +289,7 @@ Validates transaction signatures and minimum gas requirements. ▸ **validateTransactions**(`stringError`: false): *boolean* -*Defined in [block.ts:182](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L182)* +*Defined in [block.ts:202](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L202)* **Parameters:** @@ -301,7 +301,7 @@ Name | Type | ▸ **validateTransactions**(`stringError`: true): *string[]* -*Defined in [block.ts:183](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L183)* +*Defined in [block.ts:203](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L203)* **Parameters:** @@ -317,7 +317,7 @@ ___ ▸ **validateTransactionsTrie**(): *Promise‹boolean›* -*Defined in [block.ts:164](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L164)* +*Defined in [block.ts:182](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L182)* Validates the transaction trie by generating a trie and do a check on the root hash. @@ -330,7 +330,7 @@ ___ ▸ **validateUncles**(`blockchain`: [Blockchain](../interfaces/_index_.blockchain.md)): *Promise‹void›* -*Defined in [block.ts:262](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L262)* +*Defined in [block.ts:283](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L283)* Consistency checks and header validation for uncles included, in the block, if any. @@ -359,7 +359,7 @@ ___ ▸ **validateUnclesHash**(): *boolean* -*Defined in [block.ts:241](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L241)* +*Defined in [block.ts:262](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L262)* Validates the uncle's hash. @@ -388,7 +388,7 @@ ___ ▸ **fromRLPSerializedBlock**(`serialized`: Buffer, `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[Block](_block_.block.md)‹›* -*Defined in [block.ts:46](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L46)* +*Defined in [block.ts:53](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L53)* **Parameters:** @@ -405,7 +405,7 @@ ___ ▸ **fromValuesArray**(`values`: [BlockBuffer](../modules/_index_.md#blockbuffer), `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[Block](_block_.block.md)‹›* -*Defined in [block.ts:56](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L56)* +*Defined in [block.ts:63](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L63)* **Parameters:** @@ -422,7 +422,7 @@ ___ ▸ **genesis**(`blockData`: [BlockData](../interfaces/_index_.blockdata.md), `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[Block](_block_.block.md)‹›* -*Defined in [block.ts:89](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L89)* +*Defined in [block.ts:104](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L104)* Alias for Block.fromBlockData() with initWithGenesisHeader set to true. diff --git a/packages/block/docs/classes/_header_.blockheader.md b/packages/block/docs/classes/_header_.blockheader.md index 950d7f609c..b51bc7d5a8 100644 --- a/packages/block/docs/classes/_header_.blockheader.md +++ b/packages/block/docs/classes/_header_.blockheader.md @@ -17,6 +17,7 @@ An object that represents the block header. ### Properties * [_common](_header_.blockheader.md#_common) +* [_errorPostfix](_header_.blockheader.md#_errorpostfix) * [bloom](_header_.blockheader.md#bloom) * [coinbase](_header_.blockheader.md#coinbase) * [difficulty](_header_.blockheader.md#difficulty) @@ -35,14 +36,22 @@ An object that represents the block header. ### Methods -* [_validateBufferLengths](_header_.blockheader.md#_validatebufferlengths) +* [_validateHeaderFields](_header_.blockheader.md#_validateheaderfields) * [canonicalDifficulty](_header_.blockheader.md#canonicaldifficulty) +* [cliqueEpochTransitionSigners](_header_.blockheader.md#cliqueepochtransitionsigners) +* [cliqueExtraSeal](_header_.blockheader.md#cliqueextraseal) +* [cliqueExtraVanity](_header_.blockheader.md#cliqueextravanity) +* [cliqueIsEpochTransition](_header_.blockheader.md#cliqueisepochtransition) +* [cliqueSigHash](_header_.blockheader.md#cliquesighash) +* [cliqueSigner](_header_.blockheader.md#cliquesigner) +* [cliqueVerifySignature](_header_.blockheader.md#cliqueverifysignature) * [hash](_header_.blockheader.md#hash) * [isGenesis](_header_.blockheader.md#isgenesis) * [raw](_header_.blockheader.md#raw) * [serialize](_header_.blockheader.md#serialize) * [toJSON](_header_.blockheader.md#tojson) * [validate](_header_.blockheader.md#validate) +* [validateCliqueDifficulty](_header_.blockheader.md#validatecliquedifficulty) * [validateDifficulty](_header_.blockheader.md#validatedifficulty) * [validateGasLimit](_header_.blockheader.md#validategaslimit) * [fromHeaderData](_header_.blockheader.md#static-fromheaderdata) @@ -56,7 +65,7 @@ An object that represents the block header. \+ **new BlockHeader**(`parentHash`: Buffer, `uncleHash`: Buffer, `coinbase`: Address, `stateRoot`: Buffer, `transactionsTrie`: Buffer, `receiptTrie`: Buffer, `bloom`: Buffer, `difficulty`: BN, `number`: BN, `gasLimit`: BN, `gasUsed`: BN, `timestamp`: BN, `extraData`: Buffer, `mixHash`: Buffer, `nonce`: Buffer, `options`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[BlockHeader](_header_.blockheader.md)* -*Defined in [header.ts:138](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L138)* +*Defined in [header.ts:149](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L149)* This constructor takes the values, validates them, assigns them and freezes the object. Use the public static factory methods to assist in creating a Header object from @@ -92,7 +101,15 @@ Name | Type | Default | • **_common**: *Common* -*Defined in [header.ts:38](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L38)* +*Defined in [header.ts:48](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L48)* + +___ + +### _errorPostfix + +• **_errorPostfix**: *string* = "" + +*Defined in [header.ts:49](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L49)* ___ @@ -100,7 +117,7 @@ ___ • **bloom**: *Buffer* -*Defined in [header.ts:28](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L28)* +*Defined in [header.ts:38](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L38)* ___ @@ -108,7 +125,7 @@ ___ • **coinbase**: *Address* -*Defined in [header.ts:24](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L24)* +*Defined in [header.ts:34](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L34)* ___ @@ -116,7 +133,7 @@ ___ • **difficulty**: *BN* -*Defined in [header.ts:29](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L29)* +*Defined in [header.ts:39](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L39)* ___ @@ -124,7 +141,7 @@ ___ • **extraData**: *Buffer* -*Defined in [header.ts:34](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L34)* +*Defined in [header.ts:44](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L44)* ___ @@ -132,7 +149,7 @@ ___ • **gasLimit**: *BN* -*Defined in [header.ts:31](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L31)* +*Defined in [header.ts:41](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L41)* ___ @@ -140,7 +157,7 @@ ___ • **gasUsed**: *BN* -*Defined in [header.ts:32](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L32)* +*Defined in [header.ts:42](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L42)* ___ @@ -148,7 +165,7 @@ ___ • **mixHash**: *Buffer* -*Defined in [header.ts:35](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L35)* +*Defined in [header.ts:45](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L45)* ___ @@ -156,7 +173,7 @@ ___ • **nonce**: *Buffer* -*Defined in [header.ts:36](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L36)* +*Defined in [header.ts:46](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L46)* ___ @@ -164,7 +181,7 @@ ___ • **number**: *BN* -*Defined in [header.ts:30](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L30)* +*Defined in [header.ts:40](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L40)* ___ @@ -172,7 +189,7 @@ ___ • **parentHash**: *Buffer* -*Defined in [header.ts:22](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L22)* +*Defined in [header.ts:32](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L32)* ___ @@ -180,7 +197,7 @@ ___ • **receiptTrie**: *Buffer* -*Defined in [header.ts:27](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L27)* +*Defined in [header.ts:37](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L37)* ___ @@ -188,7 +205,7 @@ ___ • **stateRoot**: *Buffer* -*Defined in [header.ts:25](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L25)* +*Defined in [header.ts:35](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L35)* ___ @@ -196,7 +213,7 @@ ___ • **timestamp**: *BN* -*Defined in [header.ts:33](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L33)* +*Defined in [header.ts:43](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L43)* ___ @@ -204,7 +221,7 @@ ___ • **transactionsTrie**: *Buffer* -*Defined in [header.ts:26](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L26)* +*Defined in [header.ts:36](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L36)* ___ @@ -212,15 +229,15 @@ ___ • **uncleHash**: *Buffer* -*Defined in [header.ts:23](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L23)* +*Defined in [header.ts:33](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L33)* ## Methods -### _validateBufferLengths +### _validateHeaderFields -▸ **_validateBufferLengths**(): *void* +▸ **_validateHeaderFields**(): *void* -*Defined in [header.ts:242](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L242)* +*Defined in [header.ts:265](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L265)* Validates correct buffer lengths, throws if invalid. @@ -232,7 +249,7 @@ ___ ▸ **canonicalDifficulty**(`parentBlockHeader`: [BlockHeader](_header_.blockheader.md)): *BN* -*Defined in [header.ts:271](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L271)* +*Defined in [header.ts:295](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L295)* Returns the canonical difficulty for this block. @@ -246,11 +263,112 @@ Name | Type | Description | ___ +### cliqueEpochTransitionSigners + +▸ **cliqueEpochTransitionSigners**(): *Address[]* + +*Defined in [header.ts:656](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L656)* + +Returns a list of signers +(only clique PoA, throws otherwise) + +This function throws if not called on an epoch +transition block and should therefore be used +in conjunction with `cliqueIsEpochTransition()` + +**Returns:** *Address[]* + +___ + +### cliqueExtraSeal + +▸ **cliqueExtraSeal**(): *Buffer* + +*Defined in [header.ts:622](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L622)* + +Returns extra seal data +(only clique PoA, throws otherwise) + +**Returns:** *Buffer* + +___ + +### cliqueExtraVanity + +▸ **cliqueExtraVanity**(): *Buffer* + +*Defined in [header.ts:613](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L613)* + +Returns extra vanity data +(only clique PoA, throws otherwise) + +**Returns:** *Buffer* + +___ + +### cliqueIsEpochTransition + +▸ **cliqueIsEpochTransition**(): *boolean* + +*Defined in [header.ts:601](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L601)* + +Checks if the block header is an epoch transition +header (only clique PoA, throws otherwise) + +**Returns:** *boolean* + +___ + +### cliqueSigHash + +▸ **cliqueSigHash**(): *Buffer‹›* + +*Defined in [header.ts:590](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L590)* + +PoA clique signature hash without the seal. + +**Returns:** *Buffer‹›* + +___ + +### cliqueSigner + +▸ **cliqueSigner**(): *Address* + +*Defined in [header.ts:692](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L692)* + +Returns the signer address + +**Returns:** *Address* + +___ + +### cliqueVerifySignature + +▸ **cliqueVerifySignature**(`signerList`: Address[]): *boolean* + +*Defined in [header.ts:680](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L680)* + +Verifies the signature of the block (last 65 bytes of extraData field) +(only clique PoA, throws otherwise) + + Method throws if signature is invalid + +**Parameters:** + +Name | Type | +------ | ------ | +`signerList` | Address[] | + +**Returns:** *boolean* + +___ + ### hash ▸ **hash**(): *Buffer* -*Defined in [header.ts:469](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L469)* +*Defined in [header.ts:570](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L570)* Returns the hash of the block header. @@ -262,7 +380,7 @@ ___ ▸ **isGenesis**(): *boolean* -*Defined in [header.ts:476](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L476)* +*Defined in [header.ts:577](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L577)* Checks if the block header is a genesis header. @@ -274,7 +392,7 @@ ___ ▸ **raw**(): *[BlockHeaderBuffer](../modules/_index_.md#blockheaderbuffer)* -*Defined in [header.ts:446](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L446)* +*Defined in [header.ts:547](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L547)* Returns a Buffer Array of the raw Buffers in this header, in order. @@ -286,7 +404,7 @@ ___ ▸ **serialize**(): *Buffer* -*Defined in [header.ts:483](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L483)* +*Defined in [header.ts:709](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L709)* Returns the rlp encoding of the block header. @@ -298,7 +416,7 @@ ___ ▸ **toJSON**(): *[JsonHeader](../interfaces/_index_.jsonheader.md)* -*Defined in [header.ts:490](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L490)* +*Defined in [header.ts:716](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L716)* Returns the block header in JSON format. @@ -310,32 +428,57 @@ ___ ▸ **validate**(`blockchain`: [Blockchain](../interfaces/_index_.blockchain.md), `height?`: BN): *Promise‹void›* -*Defined in [header.ts:401](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L401)* +*Defined in [header.ts:460](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L460)* Validates the block header, throwing if invalid. It is being validated against the reported `parentHash`. It verifies the current block against the `parentHash`: - The `parentHash` is part of the blockchain (it is a valid header) - Current block number is parent block number + 1 - Current block has a strictly higher timestamp -- Current block has valid difficulty and gas limit -- In case that the header is an uncle header, it should not be too old or young in the chain. +- Additional PoW checks -> + - Current block has valid difficulty and gas limit + - In case that the header is an uncle header, it should not be too old or young in the chain. +- Additional PoA clique checks -> + - Various extraData checks + - Checks on coinbase and mixHash + - Current block has a timestamp diff greater or equal to PERIOD + - Current block has difficulty correctly marked as INTURN or NOTURN **Parameters:** Name | Type | Description | ------ | ------ | ------ | -`blockchain` | [Blockchain](../interfaces/_index_.blockchain.md) | validate against a @ethereumjs/blockchain | +`blockchain` | [Blockchain](../interfaces/_index_.blockchain.md) | validate against an @ethereumjs/blockchain | `height?` | BN | If this is an uncle header, this is the height of the block that is including it | **Returns:** *Promise‹void›* ___ +### validateCliqueDifficulty + +▸ **validateCliqueDifficulty**(`blockchain`: [Blockchain](../interfaces/_index_.blockchain.md)): *boolean* + +*Defined in [header.ts:391](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L391)* + +For poa, validates `difficulty` is correctly identified as INTURN or NOTURN. +Returns false if invalid. + +**Parameters:** + +Name | Type | +------ | ------ | +`blockchain` | [Blockchain](../interfaces/_index_.blockchain.md) | + +**Returns:** *boolean* + +___ + ### validateDifficulty ▸ **validateDifficulty**(`parentBlockHeader`: [BlockHeader](_header_.blockheader.md)): *boolean* -*Defined in [header.ts:359](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L359)* +*Defined in [header.ts:383](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L383)* Checks that the block's `difficulty` matches the canonical difficulty. @@ -353,7 +496,7 @@ ___ ▸ **validateGasLimit**(`parentBlockHeader`: [BlockHeader](_header_.blockheader.md)): *boolean* -*Defined in [header.ts:372](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L372)* +*Defined in [header.ts:425](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L425)* Validates if the block gasLimit remains in the boundaries set by the protocol. @@ -372,7 +515,7 @@ ___ ▸ **fromHeaderData**(`headerData`: [HeaderData](../interfaces/_index_.headerdata.md), `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[BlockHeader](_header_.blockheader.md)‹›* -*Defined in [header.ts:40](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L40)* +*Defined in [header.ts:51](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L51)* **Parameters:** @@ -389,7 +532,7 @@ ___ ▸ **fromRLPSerializedHeader**(`serialized`: Buffer, `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[BlockHeader](_header_.blockheader.md)‹›* -*Defined in [header.ts:79](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L79)* +*Defined in [header.ts:90](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L90)* **Parameters:** @@ -406,7 +549,7 @@ ___ ▸ **fromValuesArray**(`values`: [BlockHeaderBuffer](../modules/_index_.md#blockheaderbuffer), `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[BlockHeader](_header_.blockheader.md)‹›* -*Defined in [header.ts:89](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L89)* +*Defined in [header.ts:100](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L100)* **Parameters:** @@ -423,7 +566,7 @@ ___ ▸ **genesis**(`headerData`: [HeaderData](../interfaces/_index_.headerdata.md), `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[BlockHeader](_header_.blockheader.md)‹›* -*Defined in [header.ts:135](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L135)* +*Defined in [header.ts:146](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L146)* Alias for Header.fromHeaderData() with initWithGenesisHeader set to true. diff --git a/packages/block/docs/classes/_index_.block.md b/packages/block/docs/classes/_index_.block.md index 05dad77b8b..5d0bab786d 100644 --- a/packages/block/docs/classes/_index_.block.md +++ b/packages/block/docs/classes/_index_.block.md @@ -50,7 +50,7 @@ An object that represents the block. \+ **new Block**(`header?`: [BlockHeader](_index_.blockheader.md), `transactions`: Transaction[], `uncleHeaders`: [BlockHeader](_header_.blockheader.md)[], `opts`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[Block](_index_.block.md)* -*Defined in [block.ts:92](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L92)* +*Defined in [block.ts:107](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L107)* This constructor takes the values, validates them, assigns them and freezes the object. Use the static factory methods to assist in creating a Block object from varying data types and options. @@ -112,7 +112,7 @@ ___ ▸ **canonicalDifficulty**(`parentBlock`: [Block](_block_.block.md)): *BN* -*Defined in [block.ts:286](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L286)* +*Defined in [block.ts:307](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L307)* Returns the canonical difficulty for this block. @@ -130,7 +130,7 @@ ___ ▸ **genTxTrie**(): *Promise‹void›* -*Defined in [block.ts:150](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L150)* +*Defined in [block.ts:168](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L168)* Generates transaction trie for validation. @@ -142,7 +142,7 @@ ___ ▸ **hash**(): *Buffer* -*Defined in [block.ts:129](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L129)* +*Defined in [block.ts:147](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L147)* Produces a hash the RLP of the block. @@ -154,7 +154,7 @@ ___ ▸ **isGenesis**(): *boolean* -*Defined in [block.ts:136](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L136)* +*Defined in [block.ts:154](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L154)* Determines if this block is the genesis block. @@ -166,7 +166,7 @@ ___ ▸ **raw**(): *[BlockBuffer](../modules/_index_.md#blockbuffer)* -*Defined in [block.ts:118](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L118)* +*Defined in [block.ts:136](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L136)* Returns a Buffer Array of the raw Buffers of this block, in order. @@ -178,7 +178,7 @@ ___ ▸ **serialize**(): *Buffer* -*Defined in [block.ts:143](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L143)* +*Defined in [block.ts:161](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L161)* Returns the rlp encoding of the block. @@ -190,7 +190,7 @@ ___ ▸ **toJSON**(): *[JsonBlock](../interfaces/_index_.jsonblock.md)* -*Defined in [block.ts:312](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L312)* +*Defined in [block.ts:333](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L333)* Returns the block in JSON format. @@ -202,7 +202,7 @@ ___ ▸ **validate**(`blockchain`: [Blockchain](../interfaces/_index_.blockchain.md)): *Promise‹void›* -*Defined in [block.ts:209](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L209)* +*Defined in [block.ts:229](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L229)* Performs the following consistency checks on the block: @@ -227,7 +227,7 @@ ___ ▸ **validateData**(): *Promise‹void›* -*Defined in [block.ts:222](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L222)* +*Defined in [block.ts:242](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L242)* Validates the block data, throwing if invalid. This can be checked on the Block itself without needing access to any parent block @@ -244,7 +244,7 @@ ___ ▸ **validateDifficulty**(`parentBlock`: [Block](_block_.block.md)): *boolean* -*Defined in [block.ts:295](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L295)* +*Defined in [block.ts:316](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L316)* Checks that the block's `difficulty` matches the canonical difficulty. @@ -262,7 +262,7 @@ ___ ▸ **validateGasLimit**(`parentBlock`: [Block](_block_.block.md)): *boolean* -*Defined in [block.ts:305](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L305)* +*Defined in [block.ts:326](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L326)* Validates if the block gasLimit remains in the boundaries set by the protocol. @@ -281,7 +281,7 @@ ___ ▸ **validateTransactions**(): *boolean* -*Defined in [block.ts:181](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L181)* +*Defined in [block.ts:201](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L201)* Validates transaction signatures and minimum gas requirements. @@ -289,7 +289,7 @@ Validates transaction signatures and minimum gas requirements. ▸ **validateTransactions**(`stringError`: false): *boolean* -*Defined in [block.ts:182](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L182)* +*Defined in [block.ts:202](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L202)* **Parameters:** @@ -301,7 +301,7 @@ Name | Type | ▸ **validateTransactions**(`stringError`: true): *string[]* -*Defined in [block.ts:183](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L183)* +*Defined in [block.ts:203](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L203)* **Parameters:** @@ -317,7 +317,7 @@ ___ ▸ **validateTransactionsTrie**(): *Promise‹boolean›* -*Defined in [block.ts:164](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L164)* +*Defined in [block.ts:182](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L182)* Validates the transaction trie by generating a trie and do a check on the root hash. @@ -330,7 +330,7 @@ ___ ▸ **validateUncles**(`blockchain`: [Blockchain](../interfaces/_index_.blockchain.md)): *Promise‹void›* -*Defined in [block.ts:262](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L262)* +*Defined in [block.ts:283](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L283)* Consistency checks and header validation for uncles included, in the block, if any. @@ -359,7 +359,7 @@ ___ ▸ **validateUnclesHash**(): *boolean* -*Defined in [block.ts:241](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L241)* +*Defined in [block.ts:262](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L262)* Validates the uncle's hash. @@ -388,7 +388,7 @@ ___ ▸ **fromRLPSerializedBlock**(`serialized`: Buffer, `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[Block](_block_.block.md)‹›* -*Defined in [block.ts:46](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L46)* +*Defined in [block.ts:53](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L53)* **Parameters:** @@ -405,7 +405,7 @@ ___ ▸ **fromValuesArray**(`values`: [BlockBuffer](../modules/_index_.md#blockbuffer), `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[Block](_block_.block.md)‹›* -*Defined in [block.ts:56](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L56)* +*Defined in [block.ts:63](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L63)* **Parameters:** @@ -422,7 +422,7 @@ ___ ▸ **genesis**(`blockData`: [BlockData](../interfaces/_index_.blockdata.md), `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[Block](_block_.block.md)‹›* -*Defined in [block.ts:89](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L89)* +*Defined in [block.ts:104](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L104)* Alias for Block.fromBlockData() with initWithGenesisHeader set to true. diff --git a/packages/block/docs/classes/_index_.blockheader.md b/packages/block/docs/classes/_index_.blockheader.md index 0fdb54ea9e..80bfca9159 100644 --- a/packages/block/docs/classes/_index_.blockheader.md +++ b/packages/block/docs/classes/_index_.blockheader.md @@ -17,6 +17,7 @@ An object that represents the block header. ### Properties * [_common](_index_.blockheader.md#_common) +* [_errorPostfix](_index_.blockheader.md#_errorpostfix) * [bloom](_index_.blockheader.md#bloom) * [coinbase](_index_.blockheader.md#coinbase) * [difficulty](_index_.blockheader.md#difficulty) @@ -35,14 +36,22 @@ An object that represents the block header. ### Methods -* [_validateBufferLengths](_index_.blockheader.md#_validatebufferlengths) +* [_validateHeaderFields](_index_.blockheader.md#_validateheaderfields) * [canonicalDifficulty](_index_.blockheader.md#canonicaldifficulty) +* [cliqueEpochTransitionSigners](_index_.blockheader.md#cliqueepochtransitionsigners) +* [cliqueExtraSeal](_index_.blockheader.md#cliqueextraseal) +* [cliqueExtraVanity](_index_.blockheader.md#cliqueextravanity) +* [cliqueIsEpochTransition](_index_.blockheader.md#cliqueisepochtransition) +* [cliqueSigHash](_index_.blockheader.md#cliquesighash) +* [cliqueSigner](_index_.blockheader.md#cliquesigner) +* [cliqueVerifySignature](_index_.blockheader.md#cliqueverifysignature) * [hash](_index_.blockheader.md#hash) * [isGenesis](_index_.blockheader.md#isgenesis) * [raw](_index_.blockheader.md#raw) * [serialize](_index_.blockheader.md#serialize) * [toJSON](_index_.blockheader.md#tojson) * [validate](_index_.blockheader.md#validate) +* [validateCliqueDifficulty](_index_.blockheader.md#validatecliquedifficulty) * [validateDifficulty](_index_.blockheader.md#validatedifficulty) * [validateGasLimit](_index_.blockheader.md#validategaslimit) * [fromHeaderData](_index_.blockheader.md#static-fromheaderdata) @@ -56,7 +65,7 @@ An object that represents the block header. \+ **new BlockHeader**(`parentHash`: Buffer, `uncleHash`: Buffer, `coinbase`: Address, `stateRoot`: Buffer, `transactionsTrie`: Buffer, `receiptTrie`: Buffer, `bloom`: Buffer, `difficulty`: BN, `number`: BN, `gasLimit`: BN, `gasUsed`: BN, `timestamp`: BN, `extraData`: Buffer, `mixHash`: Buffer, `nonce`: Buffer, `options`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[BlockHeader](_index_.blockheader.md)* -*Defined in [header.ts:138](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L138)* +*Defined in [header.ts:149](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L149)* This constructor takes the values, validates them, assigns them and freezes the object. Use the public static factory methods to assist in creating a Header object from @@ -92,7 +101,15 @@ Name | Type | Default | • **_common**: *Common* -*Defined in [header.ts:38](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L38)* +*Defined in [header.ts:48](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L48)* + +___ + +### _errorPostfix + +• **_errorPostfix**: *string* = "" + +*Defined in [header.ts:49](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L49)* ___ @@ -100,7 +117,7 @@ ___ • **bloom**: *Buffer* -*Defined in [header.ts:28](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L28)* +*Defined in [header.ts:38](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L38)* ___ @@ -108,7 +125,7 @@ ___ • **coinbase**: *Address* -*Defined in [header.ts:24](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L24)* +*Defined in [header.ts:34](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L34)* ___ @@ -116,7 +133,7 @@ ___ • **difficulty**: *BN* -*Defined in [header.ts:29](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L29)* +*Defined in [header.ts:39](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L39)* ___ @@ -124,7 +141,7 @@ ___ • **extraData**: *Buffer* -*Defined in [header.ts:34](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L34)* +*Defined in [header.ts:44](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L44)* ___ @@ -132,7 +149,7 @@ ___ • **gasLimit**: *BN* -*Defined in [header.ts:31](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L31)* +*Defined in [header.ts:41](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L41)* ___ @@ -140,7 +157,7 @@ ___ • **gasUsed**: *BN* -*Defined in [header.ts:32](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L32)* +*Defined in [header.ts:42](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L42)* ___ @@ -148,7 +165,7 @@ ___ • **mixHash**: *Buffer* -*Defined in [header.ts:35](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L35)* +*Defined in [header.ts:45](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L45)* ___ @@ -156,7 +173,7 @@ ___ • **nonce**: *Buffer* -*Defined in [header.ts:36](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L36)* +*Defined in [header.ts:46](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L46)* ___ @@ -164,7 +181,7 @@ ___ • **number**: *BN* -*Defined in [header.ts:30](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L30)* +*Defined in [header.ts:40](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L40)* ___ @@ -172,7 +189,7 @@ ___ • **parentHash**: *Buffer* -*Defined in [header.ts:22](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L22)* +*Defined in [header.ts:32](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L32)* ___ @@ -180,7 +197,7 @@ ___ • **receiptTrie**: *Buffer* -*Defined in [header.ts:27](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L27)* +*Defined in [header.ts:37](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L37)* ___ @@ -188,7 +205,7 @@ ___ • **stateRoot**: *Buffer* -*Defined in [header.ts:25](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L25)* +*Defined in [header.ts:35](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L35)* ___ @@ -196,7 +213,7 @@ ___ • **timestamp**: *BN* -*Defined in [header.ts:33](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L33)* +*Defined in [header.ts:43](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L43)* ___ @@ -204,7 +221,7 @@ ___ • **transactionsTrie**: *Buffer* -*Defined in [header.ts:26](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L26)* +*Defined in [header.ts:36](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L36)* ___ @@ -212,15 +229,15 @@ ___ • **uncleHash**: *Buffer* -*Defined in [header.ts:23](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L23)* +*Defined in [header.ts:33](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L33)* ## Methods -### _validateBufferLengths +### _validateHeaderFields -▸ **_validateBufferLengths**(): *void* +▸ **_validateHeaderFields**(): *void* -*Defined in [header.ts:242](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L242)* +*Defined in [header.ts:265](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L265)* Validates correct buffer lengths, throws if invalid. @@ -232,7 +249,7 @@ ___ ▸ **canonicalDifficulty**(`parentBlockHeader`: [BlockHeader](_header_.blockheader.md)): *BN* -*Defined in [header.ts:271](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L271)* +*Defined in [header.ts:295](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L295)* Returns the canonical difficulty for this block. @@ -246,11 +263,112 @@ Name | Type | Description | ___ +### cliqueEpochTransitionSigners + +▸ **cliqueEpochTransitionSigners**(): *Address[]* + +*Defined in [header.ts:656](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L656)* + +Returns a list of signers +(only clique PoA, throws otherwise) + +This function throws if not called on an epoch +transition block and should therefore be used +in conjunction with `cliqueIsEpochTransition()` + +**Returns:** *Address[]* + +___ + +### cliqueExtraSeal + +▸ **cliqueExtraSeal**(): *Buffer* + +*Defined in [header.ts:622](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L622)* + +Returns extra seal data +(only clique PoA, throws otherwise) + +**Returns:** *Buffer* + +___ + +### cliqueExtraVanity + +▸ **cliqueExtraVanity**(): *Buffer* + +*Defined in [header.ts:613](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L613)* + +Returns extra vanity data +(only clique PoA, throws otherwise) + +**Returns:** *Buffer* + +___ + +### cliqueIsEpochTransition + +▸ **cliqueIsEpochTransition**(): *boolean* + +*Defined in [header.ts:601](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L601)* + +Checks if the block header is an epoch transition +header (only clique PoA, throws otherwise) + +**Returns:** *boolean* + +___ + +### cliqueSigHash + +▸ **cliqueSigHash**(): *Buffer‹›* + +*Defined in [header.ts:590](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L590)* + +PoA clique signature hash without the seal. + +**Returns:** *Buffer‹›* + +___ + +### cliqueSigner + +▸ **cliqueSigner**(): *Address* + +*Defined in [header.ts:692](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L692)* + +Returns the signer address + +**Returns:** *Address* + +___ + +### cliqueVerifySignature + +▸ **cliqueVerifySignature**(`signerList`: Address[]): *boolean* + +*Defined in [header.ts:680](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L680)* + +Verifies the signature of the block (last 65 bytes of extraData field) +(only clique PoA, throws otherwise) + + Method throws if signature is invalid + +**Parameters:** + +Name | Type | +------ | ------ | +`signerList` | Address[] | + +**Returns:** *boolean* + +___ + ### hash ▸ **hash**(): *Buffer* -*Defined in [header.ts:469](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L469)* +*Defined in [header.ts:570](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L570)* Returns the hash of the block header. @@ -262,7 +380,7 @@ ___ ▸ **isGenesis**(): *boolean* -*Defined in [header.ts:476](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L476)* +*Defined in [header.ts:577](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L577)* Checks if the block header is a genesis header. @@ -274,7 +392,7 @@ ___ ▸ **raw**(): *[BlockHeaderBuffer](../modules/_index_.md#blockheaderbuffer)* -*Defined in [header.ts:446](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L446)* +*Defined in [header.ts:547](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L547)* Returns a Buffer Array of the raw Buffers in this header, in order. @@ -286,7 +404,7 @@ ___ ▸ **serialize**(): *Buffer* -*Defined in [header.ts:483](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L483)* +*Defined in [header.ts:709](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L709)* Returns the rlp encoding of the block header. @@ -298,7 +416,7 @@ ___ ▸ **toJSON**(): *[JsonHeader](../interfaces/_index_.jsonheader.md)* -*Defined in [header.ts:490](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L490)* +*Defined in [header.ts:716](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L716)* Returns the block header in JSON format. @@ -310,32 +428,57 @@ ___ ▸ **validate**(`blockchain`: [Blockchain](../interfaces/_index_.blockchain.md), `height?`: BN): *Promise‹void›* -*Defined in [header.ts:401](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L401)* +*Defined in [header.ts:460](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L460)* Validates the block header, throwing if invalid. It is being validated against the reported `parentHash`. It verifies the current block against the `parentHash`: - The `parentHash` is part of the blockchain (it is a valid header) - Current block number is parent block number + 1 - Current block has a strictly higher timestamp -- Current block has valid difficulty and gas limit -- In case that the header is an uncle header, it should not be too old or young in the chain. +- Additional PoW checks -> + - Current block has valid difficulty and gas limit + - In case that the header is an uncle header, it should not be too old or young in the chain. +- Additional PoA clique checks -> + - Various extraData checks + - Checks on coinbase and mixHash + - Current block has a timestamp diff greater or equal to PERIOD + - Current block has difficulty correctly marked as INTURN or NOTURN **Parameters:** Name | Type | Description | ------ | ------ | ------ | -`blockchain` | [Blockchain](../interfaces/_index_.blockchain.md) | validate against a @ethereumjs/blockchain | +`blockchain` | [Blockchain](../interfaces/_index_.blockchain.md) | validate against an @ethereumjs/blockchain | `height?` | BN | If this is an uncle header, this is the height of the block that is including it | **Returns:** *Promise‹void›* ___ +### validateCliqueDifficulty + +▸ **validateCliqueDifficulty**(`blockchain`: [Blockchain](../interfaces/_index_.blockchain.md)): *boolean* + +*Defined in [header.ts:391](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L391)* + +For poa, validates `difficulty` is correctly identified as INTURN or NOTURN. +Returns false if invalid. + +**Parameters:** + +Name | Type | +------ | ------ | +`blockchain` | [Blockchain](../interfaces/_index_.blockchain.md) | + +**Returns:** *boolean* + +___ + ### validateDifficulty ▸ **validateDifficulty**(`parentBlockHeader`: [BlockHeader](_header_.blockheader.md)): *boolean* -*Defined in [header.ts:359](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L359)* +*Defined in [header.ts:383](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L383)* Checks that the block's `difficulty` matches the canonical difficulty. @@ -353,7 +496,7 @@ ___ ▸ **validateGasLimit**(`parentBlockHeader`: [BlockHeader](_header_.blockheader.md)): *boolean* -*Defined in [header.ts:372](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L372)* +*Defined in [header.ts:425](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L425)* Validates if the block gasLimit remains in the boundaries set by the protocol. @@ -372,7 +515,7 @@ ___ ▸ **fromHeaderData**(`headerData`: [HeaderData](../interfaces/_index_.headerdata.md), `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[BlockHeader](_header_.blockheader.md)‹›* -*Defined in [header.ts:40](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L40)* +*Defined in [header.ts:51](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L51)* **Parameters:** @@ -389,7 +532,7 @@ ___ ▸ **fromRLPSerializedHeader**(`serialized`: Buffer, `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[BlockHeader](_header_.blockheader.md)‹›* -*Defined in [header.ts:79](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L79)* +*Defined in [header.ts:90](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L90)* **Parameters:** @@ -406,7 +549,7 @@ ___ ▸ **fromValuesArray**(`values`: [BlockHeaderBuffer](../modules/_index_.md#blockheaderbuffer), `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[BlockHeader](_header_.blockheader.md)‹›* -*Defined in [header.ts:89](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L89)* +*Defined in [header.ts:100](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L100)* **Parameters:** @@ -423,7 +566,7 @@ ___ ▸ **genesis**(`headerData`: [HeaderData](../interfaces/_index_.headerdata.md), `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[BlockHeader](_header_.blockheader.md)‹›* -*Defined in [header.ts:135](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L135)* +*Defined in [header.ts:146](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/header.ts#L146)* Alias for Header.fromHeaderData() with initWithGenesisHeader set to true. diff --git a/packages/block/docs/interfaces/_index_.blockchain.md b/packages/block/docs/interfaces/_index_.blockchain.md index cac552bf6d..e89d72e849 100644 --- a/packages/block/docs/interfaces/_index_.blockchain.md +++ b/packages/block/docs/interfaces/_index_.blockchain.md @@ -18,7 +18,7 @@ ▸ **getBlock**(`hash`: Buffer): *Promise‹[Block](../classes/_block_.block.md)›* -*Defined in [types.ts:132](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L132)* +*Defined in [types.ts:140](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L140)* **Parameters:** diff --git a/packages/block/docs/interfaces/_index_.blockdata.md b/packages/block/docs/interfaces/_index_.blockdata.md index 3f0c3644b9..55ccd4444b 100644 --- a/packages/block/docs/interfaces/_index_.blockdata.md +++ b/packages/block/docs/interfaces/_index_.blockdata.md @@ -22,7 +22,7 @@ A block's data. • **header**? : *[HeaderData](_index_.headerdata.md)* -*Defined in [types.ts:87](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L87)* +*Defined in [types.ts:95](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L95)* Header data for the block @@ -32,7 +32,7 @@ ___ • **transactions**? : *Array‹TxData›* -*Defined in [types.ts:88](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L88)* +*Defined in [types.ts:96](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L96)* ___ @@ -40,4 +40,4 @@ ___ • **uncleHeaders**? : *Array‹[HeaderData](_index_.headerdata.md)›* -*Defined in [types.ts:89](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L89)* +*Defined in [types.ts:97](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L97)* diff --git a/packages/block/docs/interfaces/_index_.blockoptions.md b/packages/block/docs/interfaces/_index_.blockoptions.md index 9209cfd2fe..3ec093c7ff 100644 --- a/packages/block/docs/interfaces/_index_.blockoptions.md +++ b/packages/block/docs/interfaces/_index_.blockoptions.md @@ -15,6 +15,7 @@ hardfork. ### Properties * [calcDifficultyFromHeader](_index_.blockoptions.md#optional-calcdifficultyfromheader) +* [cliqueSigner](_index_.blockoptions.md#optional-cliquesigner) * [common](_index_.blockoptions.md#optional-common) * [freeze](_index_.blockoptions.md#optional-freeze) * [hardforkByBlockNumber](_index_.blockoptions.md#optional-hardforkbyblocknumber) @@ -26,7 +27,7 @@ hardfork. • **calcDifficultyFromHeader**? : *[BlockHeader](../classes/_index_.blockheader.md)* -*Defined in [types.ts:45](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L45)* +*Defined in [types.ts:48](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L48)* If a preceding `BlockHeader` (usually the parent header) is given the preceding header will be used to calculate the difficulty for this block and the calculated @@ -34,14 +35,28 @@ difficulty takes precedence over a provided static `difficulty` value. ___ +### `Optional` cliqueSigner + +• **cliqueSigner**? : *Buffer* + +*Defined in [types.ts:64](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L64)* + +Provide a clique signer's privateKey to seal this block. +Will throw if provided on a non-PoA chain. + +___ + ### `Optional` common • **common**? : *Common* -*Defined in [types.ts:21](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L21)* +*Defined in [types.ts:24](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L24)* A Common object defining the chain and the hardfork a block/block header belongs to. +Object will be internally copied so that tx behavior don't incidentally +change on future HF changes. + Default: `Common` object set to `mainnet` and the HF currently defined as the default hardfork in the `Common` class. @@ -53,7 +68,7 @@ ___ • **freeze**? : *undefined | false | true* -*Defined in [types.ts:56](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L56)* +*Defined in [types.ts:59](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L59)* A block object by default gets frozen along initialization. This gives you strong additional security guarantees on the consistency of the block parameters. @@ -70,7 +85,7 @@ ___ • **hardforkByBlockNumber**? : *undefined | false | true* -*Defined in [types.ts:27](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L27)* +*Defined in [types.ts:30](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L30)* Determine the HF by the block number @@ -82,7 +97,7 @@ ___ • **initWithGenesisHeader**? : *undefined | false | true* -*Defined in [types.ts:38](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L38)* +*Defined in [types.ts:41](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L41)* Turns the block header into the canonical genesis block header diff --git a/packages/block/docs/interfaces/_index_.headerdata.md b/packages/block/docs/interfaces/_index_.headerdata.md index 7e3a0b04d7..b45dc7d2f8 100644 --- a/packages/block/docs/interfaces/_index_.headerdata.md +++ b/packages/block/docs/interfaces/_index_.headerdata.md @@ -34,7 +34,7 @@ A block header's data. • **bloom**? : *BufferLike* -*Defined in [types.ts:69](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L69)* +*Defined in [types.ts:77](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L77)* ___ @@ -42,7 +42,7 @@ ___ • **coinbase**? : *AddressLike* -*Defined in [types.ts:65](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L65)* +*Defined in [types.ts:73](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L73)* ___ @@ -50,7 +50,7 @@ ___ • **difficulty**? : *BNLike* -*Defined in [types.ts:70](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L70)* +*Defined in [types.ts:78](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L78)* ___ @@ -58,7 +58,7 @@ ___ • **extraData**? : *BufferLike* -*Defined in [types.ts:75](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L75)* +*Defined in [types.ts:83](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L83)* ___ @@ -66,7 +66,7 @@ ___ • **gasLimit**? : *BNLike* -*Defined in [types.ts:72](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L72)* +*Defined in [types.ts:80](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L80)* ___ @@ -74,7 +74,7 @@ ___ • **gasUsed**? : *BNLike* -*Defined in [types.ts:73](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L73)* +*Defined in [types.ts:81](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L81)* ___ @@ -82,7 +82,7 @@ ___ • **mixHash**? : *BufferLike* -*Defined in [types.ts:76](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L76)* +*Defined in [types.ts:84](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L84)* ___ @@ -90,7 +90,7 @@ ___ • **nonce**? : *BufferLike* -*Defined in [types.ts:77](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L77)* +*Defined in [types.ts:85](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L85)* ___ @@ -98,7 +98,7 @@ ___ • **number**? : *BNLike* -*Defined in [types.ts:71](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L71)* +*Defined in [types.ts:79](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L79)* ___ @@ -106,7 +106,7 @@ ___ • **parentHash**? : *BufferLike* -*Defined in [types.ts:63](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L63)* +*Defined in [types.ts:71](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L71)* ___ @@ -114,7 +114,7 @@ ___ • **receiptTrie**? : *BufferLike* -*Defined in [types.ts:68](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L68)* +*Defined in [types.ts:76](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L76)* ___ @@ -122,7 +122,7 @@ ___ • **stateRoot**? : *BufferLike* -*Defined in [types.ts:66](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L66)* +*Defined in [types.ts:74](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L74)* ___ @@ -130,7 +130,7 @@ ___ • **timestamp**? : *BNLike* -*Defined in [types.ts:74](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L74)* +*Defined in [types.ts:82](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L82)* ___ @@ -138,7 +138,7 @@ ___ • **transactionsTrie**? : *BufferLike* -*Defined in [types.ts:67](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L67)* +*Defined in [types.ts:75](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L75)* ___ @@ -146,4 +146,4 @@ ___ • **uncleHash**? : *BufferLike* -*Defined in [types.ts:64](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L64)* +*Defined in [types.ts:72](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L72)* diff --git a/packages/block/docs/interfaces/_index_.jsonblock.md b/packages/block/docs/interfaces/_index_.jsonblock.md index c226b8bd38..63e67f8579 100644 --- a/packages/block/docs/interfaces/_index_.jsonblock.md +++ b/packages/block/docs/interfaces/_index_.jsonblock.md @@ -22,7 +22,7 @@ An object with the block's data represented as strings. • **header**? : *[JsonHeader](_index_.jsonheader.md)* -*Defined in [types.ts:105](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L105)* +*Defined in [types.ts:113](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L113)* Header data for the block @@ -32,7 +32,7 @@ ___ • **transactions**? : *JsonTx[]* -*Defined in [types.ts:106](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L106)* +*Defined in [types.ts:114](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L114)* ___ @@ -40,4 +40,4 @@ ___ • **uncleHeaders**? : *[JsonHeader](_index_.jsonheader.md)[]* -*Defined in [types.ts:107](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L107)* +*Defined in [types.ts:115](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L115)* diff --git a/packages/block/docs/interfaces/_index_.jsonheader.md b/packages/block/docs/interfaces/_index_.jsonheader.md index 0618b9b199..8900d334d1 100644 --- a/packages/block/docs/interfaces/_index_.jsonheader.md +++ b/packages/block/docs/interfaces/_index_.jsonheader.md @@ -34,7 +34,7 @@ An object with the block header's data represented as strings. • **bloom**? : *undefined | string* -*Defined in [types.ts:120](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L120)* +*Defined in [types.ts:128](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L128)* ___ @@ -42,7 +42,7 @@ ___ • **coinbase**? : *undefined | string* -*Defined in [types.ts:116](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L116)* +*Defined in [types.ts:124](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L124)* ___ @@ -50,7 +50,7 @@ ___ • **difficulty**? : *undefined | string* -*Defined in [types.ts:121](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L121)* +*Defined in [types.ts:129](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L129)* ___ @@ -58,7 +58,7 @@ ___ • **extraData**? : *undefined | string* -*Defined in [types.ts:126](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L126)* +*Defined in [types.ts:134](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L134)* ___ @@ -66,7 +66,7 @@ ___ • **gasLimit**? : *undefined | string* -*Defined in [types.ts:123](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L123)* +*Defined in [types.ts:131](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L131)* ___ @@ -74,7 +74,7 @@ ___ • **gasUsed**? : *undefined | string* -*Defined in [types.ts:124](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L124)* +*Defined in [types.ts:132](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L132)* ___ @@ -82,7 +82,7 @@ ___ • **mixHash**? : *undefined | string* -*Defined in [types.ts:127](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L127)* +*Defined in [types.ts:135](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L135)* ___ @@ -90,7 +90,7 @@ ___ • **nonce**? : *undefined | string* -*Defined in [types.ts:128](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L128)* +*Defined in [types.ts:136](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L136)* ___ @@ -98,7 +98,7 @@ ___ • **number**? : *undefined | string* -*Defined in [types.ts:122](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L122)* +*Defined in [types.ts:130](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L130)* ___ @@ -106,7 +106,7 @@ ___ • **parentHash**? : *undefined | string* -*Defined in [types.ts:114](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L114)* +*Defined in [types.ts:122](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L122)* ___ @@ -114,7 +114,7 @@ ___ • **receiptTrie**? : *undefined | string* -*Defined in [types.ts:119](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L119)* +*Defined in [types.ts:127](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L127)* ___ @@ -122,7 +122,7 @@ ___ • **stateRoot**? : *undefined | string* -*Defined in [types.ts:117](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L117)* +*Defined in [types.ts:125](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L125)* ___ @@ -130,7 +130,7 @@ ___ • **timestamp**? : *undefined | string* -*Defined in [types.ts:125](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L125)* +*Defined in [types.ts:133](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L133)* ___ @@ -138,7 +138,7 @@ ___ • **transactionsTrie**? : *undefined | string* -*Defined in [types.ts:118](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L118)* +*Defined in [types.ts:126](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L126)* ___ @@ -146,4 +146,4 @@ ___ • **uncleHash**? : *undefined | string* -*Defined in [types.ts:115](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L115)* +*Defined in [types.ts:123](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L123)* diff --git a/packages/block/docs/interfaces/_types_.blockchain.md b/packages/block/docs/interfaces/_types_.blockchain.md index 28b9ceca4f..60c75a19f2 100644 --- a/packages/block/docs/interfaces/_types_.blockchain.md +++ b/packages/block/docs/interfaces/_types_.blockchain.md @@ -18,7 +18,7 @@ ▸ **getBlock**(`hash`: Buffer): *Promise‹[Block](../classes/_block_.block.md)›* -*Defined in [types.ts:132](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L132)* +*Defined in [types.ts:140](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L140)* **Parameters:** diff --git a/packages/block/docs/interfaces/_types_.blockdata.md b/packages/block/docs/interfaces/_types_.blockdata.md index 380dd8f9c4..669b582d04 100644 --- a/packages/block/docs/interfaces/_types_.blockdata.md +++ b/packages/block/docs/interfaces/_types_.blockdata.md @@ -22,7 +22,7 @@ A block's data. • **header**? : *[HeaderData](_types_.headerdata.md)* -*Defined in [types.ts:87](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L87)* +*Defined in [types.ts:95](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L95)* Header data for the block @@ -32,7 +32,7 @@ ___ • **transactions**? : *Array‹TxData›* -*Defined in [types.ts:88](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L88)* +*Defined in [types.ts:96](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L96)* ___ @@ -40,4 +40,4 @@ ___ • **uncleHeaders**? : *Array‹[HeaderData](_index_.headerdata.md)›* -*Defined in [types.ts:89](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L89)* +*Defined in [types.ts:97](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L97)* diff --git a/packages/block/docs/interfaces/_types_.blockoptions.md b/packages/block/docs/interfaces/_types_.blockoptions.md index 5b8970d74f..3f821c5846 100644 --- a/packages/block/docs/interfaces/_types_.blockoptions.md +++ b/packages/block/docs/interfaces/_types_.blockoptions.md @@ -15,6 +15,7 @@ hardfork. ### Properties * [calcDifficultyFromHeader](_types_.blockoptions.md#optional-calcdifficultyfromheader) +* [cliqueSigner](_types_.blockoptions.md#optional-cliquesigner) * [common](_types_.blockoptions.md#optional-common) * [freeze](_types_.blockoptions.md#optional-freeze) * [hardforkByBlockNumber](_types_.blockoptions.md#optional-hardforkbyblocknumber) @@ -26,7 +27,7 @@ hardfork. • **calcDifficultyFromHeader**? : *[BlockHeader](../classes/_header_.blockheader.md)* -*Defined in [types.ts:45](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L45)* +*Defined in [types.ts:48](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L48)* If a preceding `BlockHeader` (usually the parent header) is given the preceding header will be used to calculate the difficulty for this block and the calculated @@ -34,14 +35,28 @@ difficulty takes precedence over a provided static `difficulty` value. ___ +### `Optional` cliqueSigner + +• **cliqueSigner**? : *Buffer* + +*Defined in [types.ts:64](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L64)* + +Provide a clique signer's privateKey to seal this block. +Will throw if provided on a non-PoA chain. + +___ + ### `Optional` common • **common**? : *Common* -*Defined in [types.ts:21](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L21)* +*Defined in [types.ts:24](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L24)* A Common object defining the chain and the hardfork a block/block header belongs to. +Object will be internally copied so that tx behavior don't incidentally +change on future HF changes. + Default: `Common` object set to `mainnet` and the HF currently defined as the default hardfork in the `Common` class. @@ -53,7 +68,7 @@ ___ • **freeze**? : *undefined | false | true* -*Defined in [types.ts:56](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L56)* +*Defined in [types.ts:59](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L59)* A block object by default gets frozen along initialization. This gives you strong additional security guarantees on the consistency of the block parameters. @@ -70,7 +85,7 @@ ___ • **hardforkByBlockNumber**? : *undefined | false | true* -*Defined in [types.ts:27](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L27)* +*Defined in [types.ts:30](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L30)* Determine the HF by the block number @@ -82,7 +97,7 @@ ___ • **initWithGenesisHeader**? : *undefined | false | true* -*Defined in [types.ts:38](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L38)* +*Defined in [types.ts:41](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L41)* Turns the block header into the canonical genesis block header diff --git a/packages/block/docs/interfaces/_types_.headerdata.md b/packages/block/docs/interfaces/_types_.headerdata.md index 0cafbed300..03b06e2d4a 100644 --- a/packages/block/docs/interfaces/_types_.headerdata.md +++ b/packages/block/docs/interfaces/_types_.headerdata.md @@ -34,7 +34,7 @@ A block header's data. • **bloom**? : *BufferLike* -*Defined in [types.ts:69](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L69)* +*Defined in [types.ts:77](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L77)* ___ @@ -42,7 +42,7 @@ ___ • **coinbase**? : *AddressLike* -*Defined in [types.ts:65](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L65)* +*Defined in [types.ts:73](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L73)* ___ @@ -50,7 +50,7 @@ ___ • **difficulty**? : *BNLike* -*Defined in [types.ts:70](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L70)* +*Defined in [types.ts:78](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L78)* ___ @@ -58,7 +58,7 @@ ___ • **extraData**? : *BufferLike* -*Defined in [types.ts:75](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L75)* +*Defined in [types.ts:83](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L83)* ___ @@ -66,7 +66,7 @@ ___ • **gasLimit**? : *BNLike* -*Defined in [types.ts:72](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L72)* +*Defined in [types.ts:80](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L80)* ___ @@ -74,7 +74,7 @@ ___ • **gasUsed**? : *BNLike* -*Defined in [types.ts:73](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L73)* +*Defined in [types.ts:81](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L81)* ___ @@ -82,7 +82,7 @@ ___ • **mixHash**? : *BufferLike* -*Defined in [types.ts:76](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L76)* +*Defined in [types.ts:84](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L84)* ___ @@ -90,7 +90,7 @@ ___ • **nonce**? : *BufferLike* -*Defined in [types.ts:77](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L77)* +*Defined in [types.ts:85](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L85)* ___ @@ -98,7 +98,7 @@ ___ • **number**? : *BNLike* -*Defined in [types.ts:71](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L71)* +*Defined in [types.ts:79](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L79)* ___ @@ -106,7 +106,7 @@ ___ • **parentHash**? : *BufferLike* -*Defined in [types.ts:63](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L63)* +*Defined in [types.ts:71](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L71)* ___ @@ -114,7 +114,7 @@ ___ • **receiptTrie**? : *BufferLike* -*Defined in [types.ts:68](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L68)* +*Defined in [types.ts:76](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L76)* ___ @@ -122,7 +122,7 @@ ___ • **stateRoot**? : *BufferLike* -*Defined in [types.ts:66](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L66)* +*Defined in [types.ts:74](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L74)* ___ @@ -130,7 +130,7 @@ ___ • **timestamp**? : *BNLike* -*Defined in [types.ts:74](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L74)* +*Defined in [types.ts:82](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L82)* ___ @@ -138,7 +138,7 @@ ___ • **transactionsTrie**? : *BufferLike* -*Defined in [types.ts:67](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L67)* +*Defined in [types.ts:75](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L75)* ___ @@ -146,4 +146,4 @@ ___ • **uncleHash**? : *BufferLike* -*Defined in [types.ts:64](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L64)* +*Defined in [types.ts:72](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L72)* diff --git a/packages/block/docs/interfaces/_types_.jsonblock.md b/packages/block/docs/interfaces/_types_.jsonblock.md index f8477dca37..7bfc5e40e1 100644 --- a/packages/block/docs/interfaces/_types_.jsonblock.md +++ b/packages/block/docs/interfaces/_types_.jsonblock.md @@ -22,7 +22,7 @@ An object with the block's data represented as strings. • **header**? : *[JsonHeader](_types_.jsonheader.md)* -*Defined in [types.ts:105](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L105)* +*Defined in [types.ts:113](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L113)* Header data for the block @@ -32,7 +32,7 @@ ___ • **transactions**? : *JsonTx[]* -*Defined in [types.ts:106](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L106)* +*Defined in [types.ts:114](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L114)* ___ @@ -40,4 +40,4 @@ ___ • **uncleHeaders**? : *[JsonHeader](_index_.jsonheader.md)[]* -*Defined in [types.ts:107](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L107)* +*Defined in [types.ts:115](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L115)* diff --git a/packages/block/docs/interfaces/_types_.jsonheader.md b/packages/block/docs/interfaces/_types_.jsonheader.md index e892bca679..e2b81caf5e 100644 --- a/packages/block/docs/interfaces/_types_.jsonheader.md +++ b/packages/block/docs/interfaces/_types_.jsonheader.md @@ -34,7 +34,7 @@ An object with the block header's data represented as strings. • **bloom**? : *undefined | string* -*Defined in [types.ts:120](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L120)* +*Defined in [types.ts:128](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L128)* ___ @@ -42,7 +42,7 @@ ___ • **coinbase**? : *undefined | string* -*Defined in [types.ts:116](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L116)* +*Defined in [types.ts:124](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L124)* ___ @@ -50,7 +50,7 @@ ___ • **difficulty**? : *undefined | string* -*Defined in [types.ts:121](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L121)* +*Defined in [types.ts:129](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L129)* ___ @@ -58,7 +58,7 @@ ___ • **extraData**? : *undefined | string* -*Defined in [types.ts:126](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L126)* +*Defined in [types.ts:134](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L134)* ___ @@ -66,7 +66,7 @@ ___ • **gasLimit**? : *undefined | string* -*Defined in [types.ts:123](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L123)* +*Defined in [types.ts:131](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L131)* ___ @@ -74,7 +74,7 @@ ___ • **gasUsed**? : *undefined | string* -*Defined in [types.ts:124](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L124)* +*Defined in [types.ts:132](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L132)* ___ @@ -82,7 +82,7 @@ ___ • **mixHash**? : *undefined | string* -*Defined in [types.ts:127](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L127)* +*Defined in [types.ts:135](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L135)* ___ @@ -90,7 +90,7 @@ ___ • **nonce**? : *undefined | string* -*Defined in [types.ts:128](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L128)* +*Defined in [types.ts:136](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L136)* ___ @@ -98,7 +98,7 @@ ___ • **number**? : *undefined | string* -*Defined in [types.ts:122](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L122)* +*Defined in [types.ts:130](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L130)* ___ @@ -106,7 +106,7 @@ ___ • **parentHash**? : *undefined | string* -*Defined in [types.ts:114](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L114)* +*Defined in [types.ts:122](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L122)* ___ @@ -114,7 +114,7 @@ ___ • **receiptTrie**? : *undefined | string* -*Defined in [types.ts:119](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L119)* +*Defined in [types.ts:127](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L127)* ___ @@ -122,7 +122,7 @@ ___ • **stateRoot**? : *undefined | string* -*Defined in [types.ts:117](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L117)* +*Defined in [types.ts:125](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L125)* ___ @@ -130,7 +130,7 @@ ___ • **timestamp**? : *undefined | string* -*Defined in [types.ts:125](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L125)* +*Defined in [types.ts:133](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L133)* ___ @@ -138,7 +138,7 @@ ___ • **transactionsTrie**? : *undefined | string* -*Defined in [types.ts:118](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L118)* +*Defined in [types.ts:126](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L126)* ___ @@ -146,4 +146,4 @@ ___ • **uncleHash**? : *undefined | string* -*Defined in [types.ts:115](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L115)* +*Defined in [types.ts:123](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L123)* diff --git a/packages/block/docs/modules/_clique_.md b/packages/block/docs/modules/_clique_.md new file mode 100644 index 0000000000..7ce7b24a81 --- /dev/null +++ b/packages/block/docs/modules/_clique_.md @@ -0,0 +1,44 @@ +[@ethereumjs/block](../README.md) › ["clique"](_clique_.md) + +# Module: "clique" + +## Index + +### Variables + +* [CLIQUE_DIFF_INTURN](_clique_.md#const-clique_diff_inturn) +* [CLIQUE_DIFF_NOTURN](_clique_.md#const-clique_diff_noturn) +* [CLIQUE_EXTRA_SEAL](_clique_.md#const-clique_extra_seal) +* [CLIQUE_EXTRA_VANITY](_clique_.md#const-clique_extra_vanity) + +## Variables + +### `Const` CLIQUE_DIFF_INTURN + +• **CLIQUE_DIFF_INTURN**: *BN‹›* = new BN(2) + +*Defined in [clique.ts:9](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/clique.ts#L9)* + +___ + +### `Const` CLIQUE_DIFF_NOTURN + +• **CLIQUE_DIFF_NOTURN**: *BN‹›* = new BN(1) + +*Defined in [clique.ts:11](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/clique.ts#L11)* + +___ + +### `Const` CLIQUE_EXTRA_SEAL + +• **CLIQUE_EXTRA_SEAL**: *65* = 65 + +*Defined in [clique.ts:6](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/clique.ts#L6)* + +___ + +### `Const` CLIQUE_EXTRA_VANITY + +• **CLIQUE_EXTRA_VANITY**: *32* = 32 + +*Defined in [clique.ts:4](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/clique.ts#L4)* diff --git a/packages/block/docs/modules/_index_.md b/packages/block/docs/modules/_index_.md index 0de5701bd4..3161886979 100644 --- a/packages/block/docs/modules/_index_.md +++ b/packages/block/docs/modules/_index_.md @@ -32,7 +32,7 @@ Ƭ **BlockBodyBuffer**: *[[TransactionsBuffer](_index_.md#transactionsbuffer), [UncleHeadersBuffer](_index_.md#uncleheadersbuffer)]* -*Defined in [types.ts:94](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L94)* +*Defined in [types.ts:102](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L102)* ___ @@ -40,7 +40,7 @@ ___ Ƭ **BlockBuffer**: *[[BlockHeaderBuffer](_index_.md#blockheaderbuffer), [TransactionsBuffer](_index_.md#transactionsbuffer), [UncleHeadersBuffer](_index_.md#uncleheadersbuffer)]* -*Defined in [types.ts:92](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L92)* +*Defined in [types.ts:100](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L100)* ___ @@ -48,7 +48,7 @@ ___ Ƭ **BlockHeaderBuffer**: *Buffer[]* -*Defined in [types.ts:93](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L93)* +*Defined in [types.ts:101](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L101)* ___ @@ -56,7 +56,7 @@ ___ Ƭ **TransactionsBuffer**: *Buffer[][]* -*Defined in [types.ts:95](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L95)* +*Defined in [types.ts:103](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L103)* ___ @@ -64,4 +64,4 @@ ___ Ƭ **UncleHeadersBuffer**: *Buffer[][]* -*Defined in [types.ts:96](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L96)* +*Defined in [types.ts:104](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L104)* diff --git a/packages/block/docs/modules/_types_.md b/packages/block/docs/modules/_types_.md index 0eb81b9300..d9ab7acb91 100644 --- a/packages/block/docs/modules/_types_.md +++ b/packages/block/docs/modules/_types_.md @@ -27,7 +27,7 @@ Ƭ **BlockBodyBuffer**: *[[TransactionsBuffer](_types_.md#transactionsbuffer), [UncleHeadersBuffer](_types_.md#uncleheadersbuffer)]* -*Defined in [types.ts:94](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L94)* +*Defined in [types.ts:102](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L102)* ___ @@ -35,7 +35,7 @@ ___ Ƭ **BlockBuffer**: *[[BlockHeaderBuffer](_types_.md#blockheaderbuffer), [TransactionsBuffer](_types_.md#transactionsbuffer), [UncleHeadersBuffer](_types_.md#uncleheadersbuffer)]* -*Defined in [types.ts:92](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L92)* +*Defined in [types.ts:100](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L100)* ___ @@ -43,7 +43,7 @@ ___ Ƭ **BlockHeaderBuffer**: *Buffer[]* -*Defined in [types.ts:93](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L93)* +*Defined in [types.ts:101](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L101)* ___ @@ -51,7 +51,7 @@ ___ Ƭ **TransactionsBuffer**: *Buffer[][]* -*Defined in [types.ts:95](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L95)* +*Defined in [types.ts:103](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L103)* ___ @@ -59,4 +59,4 @@ ___ Ƭ **UncleHeadersBuffer**: *Buffer[][]* -*Defined in [types.ts:96](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L96)* +*Defined in [types.ts:104](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/types.ts#L104)* diff --git a/packages/block/package.json b/packages/block/package.json index f2cc485551..4dd37a54a6 100644 --- a/packages/block/package.json +++ b/packages/block/package.json @@ -1,6 +1,6 @@ { "name": "@ethereumjs/block", - "version": "3.0.0", + "version": "3.1.0", "description": "Provides Block serialization and help functions", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -39,7 +39,7 @@ }, "homepage": "https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/block#readme", "dependencies": { - "@ethereumjs/common": "^2.0.0", + "@ethereumjs/common": "^2.1.0", "merkle-patricia-tree": "^4.1.0", "@ethereumjs/tx": "^3.0.2", "@types/bn.js": "^4.11.6", diff --git a/packages/block/src/block.ts b/packages/block/src/block.ts index 53683b5cc8..912e0e8e78 100644 --- a/packages/block/src/block.ts +++ b/packages/block/src/block.ts @@ -1,7 +1,7 @@ /* eslint-disable no-dupe-class-members */ import { BaseTrie as Trie } from 'merkle-patricia-tree' -import { Address, BN, rlp, keccak256, KECCAK256_RLP } from 'ethereumjs-util' +import { BN, rlp, keccak256, KECCAK256_RLP } from 'ethereumjs-util' import Common from '@ethereumjs/common' import { Transaction, TxOptions } from '@ethereumjs/tx' import { BlockHeader } from './header' @@ -17,6 +17,12 @@ export class Block { public readonly txTrie = new Trie() public readonly _common: Common + /** + * Static constructor to create a block from a block data dictionary + * + * @param blockData + * @param opts + */ public static fromBlockData(blockData: BlockData = {}, opts?: BlockOptions) { const { header: headerData, transactions: txsData, uncleHeaders: uhsData } = blockData @@ -50,6 +56,12 @@ export class Block { return new Block(header, transactions, uncleHeaders, opts) } + /** + * Static constructor to create a block from a RLP-serialized block + * + * @param serialized + * @param opts + */ public static fromRLPSerializedBlock(serialized: Buffer, opts?: BlockOptions) { const values = (rlp.decode(serialized) as any) as BlockBuffer @@ -60,6 +72,12 @@ export class Block { return Block.fromValuesArray(values, opts) } + /** + * Static constructor to create a block from an array of Buffer values + * + * @param values + * @param opts + */ public static fromValuesArray(values: BlockBuffer, opts?: BlockOptions) { if (values.length > 3) { throw new Error('invalid block. More values than expected were received') @@ -155,42 +173,6 @@ export class Block { return this.header.isGenesis() } - /** - * Checks if the block is an epoch transition - * block (only clique PoA, throws otherwise) - */ - cliqueIsEpochTransition(): boolean { - return this.header.cliqueIsEpochTransition() - } - - /** - * Returns extra vanity data - * (only clique PoA, throws otherwise) - */ - cliqueExtraVanity(): Buffer { - return this.header.cliqueExtraVanity() - } - - /** - * Returns extra seal data - * (only clique PoA, throws otherwise) - */ - cliqueExtraSeal(): Buffer { - return this.header.cliqueExtraSeal() - } - - /** - * Returns a list of signers - * (only clique PoA, throws otherwise) - * - * This function throws if not called on an epoch - * transition block and should therefore be used - * in conjunction with `cliqueIsEpochTransition()` - */ - cliqueEpochTransitionSigners(): Address[] { - return this.header.cliqueEpochTransitionSigners() - } - /** * Returns the rlp encoding of the block. */ diff --git a/packages/block/src/header.ts b/packages/block/src/header.ts index 1e3a182167..73d8a8d124 100644 --- a/packages/block/src/header.ts +++ b/packages/block/src/header.ts @@ -48,6 +48,12 @@ export class BlockHeader { public readonly _common: Common public _errorPostfix = '' + /** + * Static constructor to create a block header from a header data dictionary + * + * @param headerData + * @param opts + */ public static fromHeaderData(headerData: HeaderData = {}, opts?: BlockOptions) { const { parentHash, @@ -87,6 +93,12 @@ export class BlockHeader { ) } + /** + * Static constructor to create a block header from a RLP-serialized header + * + * @param headerData + * @param opts + */ public static fromRLPSerializedHeader(serialized: Buffer, opts?: BlockOptions) { const values = rlp.decode(serialized) @@ -97,6 +109,12 @@ export class BlockHeader { return BlockHeader.fromValuesArray(values, opts) } + /** + * Static constructor to create a block header from an array of Buffer values + * + * @param headerData + * @param opts + */ public static fromValuesArray(values: BlockHeaderBuffer, opts?: BlockOptions) { if (values.length > 15) { throw new Error('invalid header. More values than expected were received') @@ -389,6 +407,7 @@ export class BlockHeader { * Returns false if invalid. */ validateCliqueDifficulty(blockchain: Blockchain): boolean { + this._requireClique('validateCliqueDifficulty') if (!this.difficulty.eq(CLIQUE_DIFF_INTURN) && !this.difficulty.eq(CLIQUE_DIFF_NOTURN)) { throw new Error( `difficulty for clique block must be INTURN (2) or NOTURN (1), received: ${this.difficulty.toString()}` @@ -449,6 +468,8 @@ export class BlockHeader { * - Current block has valid difficulty and gas limit * - In case that the header is an uncle header, it should not be too old or young in the chain. * - Additional PoA clique checks -> + * - Various extraData checks + * - Checks on coinbase and mixHash * - Current block has a timestamp diff greater or equal to PERIOD * - Current block has difficulty correctly marked as INTURN or NOTURN * @param blockchain - validate against an @ethereumjs/blockchain @@ -585,6 +606,7 @@ export class BlockHeader { * PoA clique signature hash without the seal. */ cliqueSigHash() { + this._requireClique('cliqueSigHash') const raw = this.raw() raw[12] = this.extraData.slice(0, this.extraData.length - CLIQUE_EXTRA_SEAL) return rlphash(raw) diff --git a/packages/block/test/block.spec.ts b/packages/block/test/block.spec.ts index 22736b09eb..816eb64938 100644 --- a/packages/block/test/block.spec.ts +++ b/packages/block/test/block.spec.ts @@ -1,5 +1,5 @@ import tape from 'tape' -import { Address, BN, rlp, zeros } from 'ethereumjs-util' +import { BN, rlp, zeros } from 'ethereumjs-util' import Common from '@ethereumjs/common' import { Block, BlockBuffer } from '../src' import blockFromRpc from '../src/from-rpc' @@ -430,32 +430,6 @@ tape('[Block]: block functions', function (t) { st.end() }) - t.test('should correctly call into header clique functions', function (st) { - const common = new Common({ chain: 'rinkeby', hardfork: 'chainstart' }) - const block = Block.fromBlockData( - { header: { number: 60000, extraData: Buffer.alloc(137) } }, - { common } - ) - st.ok( - block.cliqueIsEpochTransition(), - 'header.cliqueIsEpochTransition() -> should get the header function results' - ) - st.deepEqual( - block.cliqueExtraVanity(), - Buffer.alloc(32), - 'header.cliqueExtraVanity() -> should get the header function results' - ) - st.deepEqual( - block.cliqueExtraSeal(), - Buffer.alloc(65), - 'header.cliqueExtraSeal() -> should get the header function results' - ) - const msg = 'header.cliqueEpochTransitionSigners() -> should get the header function results' - st.deepEqual(block.cliqueEpochTransitionSigners(), [Address.zero(), Address.zero()], msg) - - st.end() - }) - const testDataGenesis = require('./testdata/genesishashestest.json').test t.test('should test genesis hashes (mainnet default)', function (st) { const genesis = Block.genesis() diff --git a/packages/blockchain/CHANGELOG.md b/packages/blockchain/CHANGELOG.md index f4f06e12fb..837d2ce10a 100644 --- a/packages/blockchain/CHANGELOG.md +++ b/packages/blockchain/CHANGELOG.md @@ -6,6 +6,23 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) (modification: no type change headlines) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 5.1.0 2021-02-22 + +### Clique/PoA Support + +This release introduces Clique/PoA support for the `Blockchain` library, see the main PR [#1032](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1032) as well as the follow-up PRs [#1074](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1074) and PR [#1088](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1088). + +The blockchain package now keeps track of the latest signers and votes on new Clique/PoA signers and saves them to DB. Block format validation is now also taking all the Clique/PoA specifics into account (`extraData` format and other formal requirements from the EIP) and consensus validation is now also working for Clique/PoA chains (this verifies the respective block signatures from the corresponding authorized signers) and can be activated with the `validateConsensus` constructor flag. There is a new public method `Blockchain.cliqueActiveSigners()` to get the currently active signer list. + +### Other Features/Changes + +- Added optional `maxBlocks` parameter to `Blockchain.iterator()` method, PR [#965](https://github.com/ethereumjs/ethereumjs-monorepo/pull/965) +- `Blockchain.iterator()` now returns a `number` (instead of `void`) with the blocks actually iterated (the `Blockchain` interface allows for both for backwards-compatibility reasons for now, `void` is considered deprecated though), PR [#1065](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1065) +- Blocks in the blockchain package are now always created with the `hardforkByBlockNumber` option set to `true` to avoid inconsistencies in block behavior, PR [#1089](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1089) +- New `Blockchain.setHead(tag: string, headHash: Buffer)` method to set a specific iterator head to a certain block, PR [#965](https://github.com/ethereumjs/ethereumjs-monorepo/pull/965) +- Added `debug` logger integration, first `blockchain:clique` debug logger (see README), PR [#1103](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1103) +- Fixed a bug in the validation logic to only validate the block header if a header is passed to the internal `Blockchain._putBlockOrHeader()` function, PR [#1105](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1105) + ## 5.0.0 - 2020-11-24 ### New Package Name diff --git a/packages/blockchain/docs/README.md b/packages/blockchain/docs/README.md index 15738db617..1c00c1a4f6 100644 --- a/packages/blockchain/docs/README.md +++ b/packages/blockchain/docs/README.md @@ -6,9 +6,4 @@ ### Modules -* ["db/cache"](modules/_db_cache_.md) -* ["db/constants"](modules/_db_constants_.md) -* ["db/helpers"](modules/_db_helpers_.md) -* ["db/manager"](modules/_db_manager_.md) -* ["db/operation"](modules/_db_operation_.md) * ["index"](modules/_index_.md) diff --git a/packages/blockchain/docs/classes/_db_helpers_.dbop.md b/packages/blockchain/docs/classes/_db_helpers_.dbop.md deleted file mode 100644 index 6d38e6aecb..0000000000 --- a/packages/blockchain/docs/classes/_db_helpers_.dbop.md +++ /dev/null @@ -1,116 +0,0 @@ -[@ethereumjs/blockchain](../README.md) › ["db/helpers"](../modules/_db_helpers_.md) › [DBOp](_db_helpers_.dbop.md) - -# Class: DBOp - -The DBOp class aids creating database operations which is used by `level` using a more high-level interface - -## Hierarchy - -* **DBOp** - -## Index - -### Properties - -* [baseDBOp](_db_helpers_.dbop.md#basedbop) -* [cacheString](_db_helpers_.dbop.md#cachestring) -* [operationTarget](_db_helpers_.dbop.md#operationtarget) - -### Methods - -* [updateCache](_db_helpers_.dbop.md#updatecache) -* [del](_db_helpers_.dbop.md#static-del) -* [get](_db_helpers_.dbop.md#static-get) -* [set](_db_helpers_.dbop.md#static-set) - -## Properties - -### baseDBOp - -• **baseDBOp**: *DBOpData* - -*Defined in [db/operation.ts:49](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L49)* - -___ - -### cacheString - -• **cacheString**: *string | undefined* - -*Defined in [db/operation.ts:50](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L50)* - -___ - -### operationTarget - -• **operationTarget**: *[DBTarget](../enums/_db_operation_.dbtarget.md)* - -*Defined in [db/operation.ts:48](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L48)* - -## Methods - -### updateCache - -▸ **updateCache**(`cacheMap`: [CacheMap](../modules/_db_manager_.md#cachemap)): *void* - -*Defined in [db/operation.ts:128](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L128)* - -**Parameters:** - -Name | Type | ------- | ------ | -`cacheMap` | [CacheMap](../modules/_db_manager_.md#cachemap) | - -**Returns:** *void* - -___ - -### `Static` del - -▸ **del**(`operationTarget`: [DBTarget](../enums/_db_operation_.dbtarget.md), `key?`: [DatabaseKey](../modules/_db_operation_.md#databasekey)): *[DBOp](_db_helpers_.dbop.md)* - -*Defined in [db/operation.ts:122](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L122)* - -**Parameters:** - -Name | Type | ------- | ------ | -`operationTarget` | [DBTarget](../enums/_db_operation_.dbtarget.md) | -`key?` | [DatabaseKey](../modules/_db_operation_.md#databasekey) | - -**Returns:** *[DBOp](_db_helpers_.dbop.md)* - -___ - -### `Static` get - -▸ **get**(`operationTarget`: [DBTarget](../enums/_db_operation_.dbtarget.md), `key?`: [DatabaseKey](../modules/_db_operation_.md#databasekey)): *[DBOp](_db_helpers_.dbop.md)* - -*Defined in [db/operation.ts:103](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L103)* - -**Parameters:** - -Name | Type | ------- | ------ | -`operationTarget` | [DBTarget](../enums/_db_operation_.dbtarget.md) | -`key?` | [DatabaseKey](../modules/_db_operation_.md#databasekey) | - -**Returns:** *[DBOp](_db_helpers_.dbop.md)* - -___ - -### `Static` set - -▸ **set**(`operationTarget`: [DBTarget](../enums/_db_operation_.dbtarget.md), `value`: Buffer | object, `key?`: [DatabaseKey](../modules/_db_operation_.md#databasekey)): *[DBOp](_db_helpers_.dbop.md)* - -*Defined in [db/operation.ts:108](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L108)* - -**Parameters:** - -Name | Type | ------- | ------ | -`operationTarget` | [DBTarget](../enums/_db_operation_.dbtarget.md) | -`value` | Buffer | object | -`key?` | [DatabaseKey](../modules/_db_operation_.md#databasekey) | - -**Returns:** *[DBOp](_db_helpers_.dbop.md)* diff --git a/packages/blockchain/docs/classes/_db_operation_.dbop.md b/packages/blockchain/docs/classes/_db_operation_.dbop.md deleted file mode 100644 index 0e247c3bd0..0000000000 --- a/packages/blockchain/docs/classes/_db_operation_.dbop.md +++ /dev/null @@ -1,116 +0,0 @@ -[@ethereumjs/blockchain](../README.md) › ["db/operation"](../modules/_db_operation_.md) › [DBOp](_db_operation_.dbop.md) - -# Class: DBOp - -The DBOp class aids creating database operations which is used by `level` using a more high-level interface - -## Hierarchy - -* **DBOp** - -## Index - -### Properties - -* [baseDBOp](_db_operation_.dbop.md#basedbop) -* [cacheString](_db_operation_.dbop.md#cachestring) -* [operationTarget](_db_operation_.dbop.md#operationtarget) - -### Methods - -* [updateCache](_db_operation_.dbop.md#updatecache) -* [del](_db_operation_.dbop.md#static-del) -* [get](_db_operation_.dbop.md#static-get) -* [set](_db_operation_.dbop.md#static-set) - -## Properties - -### baseDBOp - -• **baseDBOp**: *DBOpData* - -*Defined in [db/operation.ts:49](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L49)* - -___ - -### cacheString - -• **cacheString**: *string | undefined* - -*Defined in [db/operation.ts:50](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L50)* - -___ - -### operationTarget - -• **operationTarget**: *[DBTarget](../enums/_db_operation_.dbtarget.md)* - -*Defined in [db/operation.ts:48](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L48)* - -## Methods - -### updateCache - -▸ **updateCache**(`cacheMap`: [CacheMap](../modules/_db_manager_.md#cachemap)): *void* - -*Defined in [db/operation.ts:128](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L128)* - -**Parameters:** - -Name | Type | ------- | ------ | -`cacheMap` | [CacheMap](../modules/_db_manager_.md#cachemap) | - -**Returns:** *void* - -___ - -### `Static` del - -▸ **del**(`operationTarget`: [DBTarget](../enums/_db_operation_.dbtarget.md), `key?`: [DatabaseKey](../modules/_db_operation_.md#databasekey)): *[DBOp](_db_helpers_.dbop.md)* - -*Defined in [db/operation.ts:122](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L122)* - -**Parameters:** - -Name | Type | ------- | ------ | -`operationTarget` | [DBTarget](../enums/_db_operation_.dbtarget.md) | -`key?` | [DatabaseKey](../modules/_db_operation_.md#databasekey) | - -**Returns:** *[DBOp](_db_helpers_.dbop.md)* - -___ - -### `Static` get - -▸ **get**(`operationTarget`: [DBTarget](../enums/_db_operation_.dbtarget.md), `key?`: [DatabaseKey](../modules/_db_operation_.md#databasekey)): *[DBOp](_db_helpers_.dbop.md)* - -*Defined in [db/operation.ts:103](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L103)* - -**Parameters:** - -Name | Type | ------- | ------ | -`operationTarget` | [DBTarget](../enums/_db_operation_.dbtarget.md) | -`key?` | [DatabaseKey](../modules/_db_operation_.md#databasekey) | - -**Returns:** *[DBOp](_db_helpers_.dbop.md)* - -___ - -### `Static` set - -▸ **set**(`operationTarget`: [DBTarget](../enums/_db_operation_.dbtarget.md), `value`: Buffer | object, `key?`: [DatabaseKey](../modules/_db_operation_.md#databasekey)): *[DBOp](_db_helpers_.dbop.md)* - -*Defined in [db/operation.ts:108](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L108)* - -**Parameters:** - -Name | Type | ------- | ------ | -`operationTarget` | [DBTarget](../enums/_db_operation_.dbtarget.md) | -`value` | Buffer | object | -`key?` | [DatabaseKey](../modules/_db_operation_.md#databasekey) | - -**Returns:** *[DBOp](_db_helpers_.dbop.md)* diff --git a/packages/blockchain/docs/classes/_index_.blockchain.md b/packages/blockchain/docs/classes/_index_.blockchain.md index c8a5dd4099..74904a52e6 100644 --- a/packages/blockchain/docs/classes/_index_.blockchain.md +++ b/packages/blockchain/docs/classes/_index_.blockchain.md @@ -31,10 +31,12 @@ This class stores and interacts with blocks. ### Methods +* [cliqueActiveSigners](_index_.blockchain.md#cliqueactivesigners) * [delBlock](_index_.blockchain.md#delblock) * [getBlock](_index_.blockchain.md#getblock) * [getBlocks](_index_.blockchain.md#getblocks) * [getHead](_index_.blockchain.md#gethead) +* [getIteratorHead](_index_.blockchain.md#getiteratorhead) * [getLatestBlock](_index_.blockchain.md#getlatestblock) * [getLatestHeader](_index_.blockchain.md#getlatestheader) * [getTotalDifficulty](_index_.blockchain.md#gettotaldifficulty) @@ -45,7 +47,10 @@ This class stores and interacts with blocks. * [putHeaders](_index_.blockchain.md#putheaders) * [safeNumberToHash](_index_.blockchain.md#safenumbertohash) * [selectNeededHashes](_index_.blockchain.md#selectneededhashes) +* [setHead](_index_.blockchain.md#sethead) +* [setIteratorHead](_index_.blockchain.md#setiteratorhead) * [create](_index_.blockchain.md#static-create) +* [fromBlocksData](_index_.blockchain.md#static-fromblocksdata) ## Constructors @@ -53,7 +58,7 @@ This class stores and interacts with blocks. \+ **new Blockchain**(`opts`: [BlockchainOptions](../interfaces/_index_.blockchainoptions.md)): *[Blockchain](_index_.blockchain.md)* -*Defined in [index.ts:119](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L119)* +*Defined in [index.ts:215](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L215)* Creates new Blockchain object @@ -71,7 +76,7 @@ Name | Type | Default | Description | • **_ethash**? : *Ethash* -*Defined in [index.ts:99](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L99)* +*Defined in [index.ts:134](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L134)* ___ @@ -79,7 +84,7 @@ ___ • **db**: *LevelUp* -*Defined in [index.ts:96](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L96)* +*Defined in [index.ts:111](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L111)* ___ @@ -87,7 +92,7 @@ ___ • **dbManager**: *DBManager* -*Defined in [index.ts:97](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L97)* +*Defined in [index.ts:112](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L112)* ___ @@ -95,7 +100,7 @@ ___ • **initPromise**: *Promise‹void›* -*Defined in [index.ts:114](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L114)* +*Defined in [index.ts:127](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L127)* ## Accessors @@ -103,7 +108,7 @@ ___ • **get meta**(): *object* -*Defined in [index.ts:194](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L194)* +*Defined in [index.ts:280](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L280)* Returns an object with metadata about the Blockchain. It's defined for backwards compatibility. @@ -118,13 +123,26 @@ backwards compatibility. ## Methods +### cliqueActiveSigners + +▸ **cliqueActiveSigners**(): *Address[]* + +*Defined in [index.ts:688](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L688)* + +Returns a list with the current block signers +(only clique PoA, throws otherwise) + +**Returns:** *Address[]* + +___ + ### delBlock ▸ **delBlock**(`blockHash`: Buffer): *Promise‹void›* *Implementation of [BlockchainInterface](../interfaces/_index_.blockchaininterface.md)* -*Defined in [index.ts:644](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L644)* +*Defined in [index.ts:1112](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L1112)* Completely deletes a block from the blockchain including any references to this block. If this block was in the canonical chain, then also each child @@ -151,7 +169,7 @@ ___ *Implementation of [BlockchainInterface](../interfaces/_index_.blockchaininterface.md)* -*Defined in [index.ts:527](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L527)* +*Defined in [index.ts:995](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L995)* Gets a block by its hash. @@ -169,7 +187,7 @@ ___ ▸ **getBlocks**(`blockId`: Buffer | BN | number, `maxBlocks`: number, `skip`: number, `reverse`: boolean): *Promise‹Block[]›* -*Defined in [index.ts:562](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L562)* +*Defined in [index.ts:1030](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L1030)* Looks up many blocks relative to blockId Note: due to `GetBlockHeaders (0x03)` (ETH wire protocol) we have to support skip/reverse as well. @@ -191,15 +209,44 @@ ___ ▸ **getHead**(`name`: string): *Promise‹Block›* -*Defined in [index.ts:321](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L321)* +*Defined in [index.ts:739](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L739)* + +Returns the specified iterator head. + +**`deprecated`** use `getIteratorHead()` instead. Note that `getIteratorHead()` +doesn't return the `headHeader` but the genesis hash as an initial +iterator head value (now matching the behavior of the `iterator()` +method on a first run) + +**Parameters:** + +Name | Type | Default | Description | +------ | ------ | ------ | ------ | +`name` | string | "vm" | Optional name of the iterator head (default: 'vm') | + +**Returns:** *Promise‹Block›* + +___ + +### getIteratorHead + +▸ **getIteratorHead**(`name`: string): *Promise‹Block›* + +*Defined in [index.ts:716](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L716)* Returns the specified iterator head. +This function replaces the old `getHead()` method. Note that +the function deviates from the old behavior and returns the +genesis hash instead of the current head block if an iterator +has not been run. This matches the behavior of the `iterator()` +method. + **Parameters:** Name | Type | Default | Description | ------ | ------ | ------ | ------ | -`name` | string | "vm" | Optional name of the state root head (default: 'vm') | +`name` | string | "vm" | Optional name of the iterator head (default: 'vm') | **Returns:** *Promise‹Block›* @@ -209,7 +256,7 @@ ___ ▸ **getLatestBlock**(): *Promise‹Block›* -*Defined in [index.ts:351](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L351)* +*Defined in [index.ts:769](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L769)* Returns the latest full block in the canonical chain. @@ -221,7 +268,7 @@ ___ ▸ **getLatestHeader**(): *Promise‹BlockHeader›* -*Defined in [index.ts:337](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L337)* +*Defined in [index.ts:755](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L755)* Returns the latest header in the canonical chain. @@ -233,7 +280,7 @@ ___ ▸ **getTotalDifficulty**(`hash`: Buffer, `number?`: BN): *Promise‹BN›* -*Defined in [index.ts:547](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L547)* +*Defined in [index.ts:1015](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L1015)* Gets total difficulty for a block specified by hash and number @@ -250,11 +297,9 @@ ___ ### iterator -▸ **iterator**(`name`: string, `onBlock`: OnBlock): *Promise‹void›* - -*Implementation of [BlockchainInterface](../interfaces/_index_.blockchaininterface.md)* +▸ **iterator**(`name`: string, `onBlock`: OnBlock, `maxBlocks?`: undefined | number): *Promise‹number›* -*Defined in [index.ts:740](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L740)* +*Defined in [index.ts:1210](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L1210)* Iterates through blocks starting at the specified iterator head and calls the onBlock function on each block. The current location of an iterator @@ -265,9 +310,12 @@ head can be retrieved using the `getHead()` method. Name | Type | Description | ------ | ------ | ------ | `name` | string | Name of the state root head | -`onBlock` | OnBlock | Function called on each block with params (block, reorg) | +`onBlock` | OnBlock | Function called on each block with params (block, reorg) | +`maxBlocks?` | undefined | number | How many blocks to run. By default, run all unprocessed blocks in the canonical chain. | -**Returns:** *Promise‹void›* +**Returns:** *Promise‹number›* + +number of blocks actually iterated ___ @@ -277,7 +325,7 @@ ___ *Implementation of [BlockchainInterface](../interfaces/_index_.blockchaininterface.md)* -*Defined in [index.ts:386](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L386)* +*Defined in [index.ts:804](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L804)* Adds a block to the blockchain. @@ -299,7 +347,7 @@ ___ ▸ **putBlocks**(`blocks`: Block[]): *Promise‹void›* -*Defined in [index.ts:371](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L371)* +*Defined in [index.ts:789](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L789)* Adds blocks to the blockchain. @@ -322,7 +370,7 @@ ___ ▸ **putHeader**(`header`: BlockHeader): *Promise‹void›* -*Defined in [index.ts:415](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L415)* +*Defined in [index.ts:833](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L833)* Adds a header to the blockchain. @@ -344,7 +392,7 @@ ___ ▸ **putHeaders**(`headers`: Array‹any›): *Promise‹void›* -*Defined in [index.ts:400](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L400)* +*Defined in [index.ts:818](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L818)* Adds many headers to the blockchain. @@ -367,7 +415,7 @@ ___ ▸ **safeNumberToHash**(`number`: BN): *Promise‹Buffer | false›* -*Defined in [index.ts:962](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L962)* +*Defined in [index.ts:1478](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L1478)* This method either returns a Buffer if there exists one in the DB or if it does not exist (DB throws a `NotFoundError`) then return false If DB throws @@ -387,7 +435,7 @@ ___ ▸ **selectNeededHashes**(`hashes`: Array‹Buffer›): *Promise‹Buffer[]›* -*Defined in [index.ts:604](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L604)* +*Defined in [index.ts:1072](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L1072)* Given an ordered array, returns an array of hashes that are not in the blockchain yet. Uses binary search to find out what hashes are missing. @@ -403,21 +451,81 @@ Name | Type | Description | ___ +### setHead + +▸ **setHead**(`tag`: string, `headHash`: Buffer): *Promise‹void›* + +*Defined in [index.ts:1277](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L1277)* + +Set header hash of a certain `tag`. +When calling the iterator, the iterator will start running the first child block after the header hash currenntly stored. + +**`deprecated`** use `setIteratorHead()` instead + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`tag` | string | The tag to save the headHash to | +`headHash` | Buffer | The head hash to save | + +**Returns:** *Promise‹void›* + +___ + +### setIteratorHead + +▸ **setIteratorHead**(`tag`: string, `headHash`: Buffer): *Promise‹void›* + +*Defined in [index.ts:1265](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L1265)* + +Set header hash of a certain `tag`. +When calling the iterator, the iterator will start running the first child block after the header hash currenntly stored. + +**Parameters:** + +Name | Type | Description | +------ | ------ | ------ | +`tag` | string | The tag to save the headHash to | +`headHash` | Buffer | The head hash to save | + +**Returns:** *Promise‹void›* + +___ + ### `Static` create ▸ **create**(`opts`: [BlockchainOptions](../interfaces/_index_.blockchainoptions.md)): *Promise‹[Blockchain](_index_.blockchain.md)‹››* -*Defined in [index.ts:182](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L182)* +*Defined in [index.ts:190](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L190)* + +Safe creation of a new Blockchain object awaiting the initialization function, +encouraged method to use when creating a blockchain object. + +**Parameters:** + +Name | Type | Default | Description | +------ | ------ | ------ | ------ | +`opts` | [BlockchainOptions](../interfaces/_index_.blockchainoptions.md) | {} | Constructor options, see [BlockchainOptions](../interfaces/_index_.blockchainoptions.md) | + +**Returns:** *Promise‹[Blockchain](_index_.blockchain.md)‹››* + +___ + +### `Static` fromBlocksData + +▸ **fromBlocksData**(`blocksData`: BlockData[], `opts`: [BlockchainOptions](../interfaces/_index_.blockchainoptions.md)): *Promise‹[Blockchain](_index_.blockchain.md)‹››* + +*Defined in [index.ts:205](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L205)* -This static constructor safely creates a new Blockchain object, which also -awaits the initialization function. If this initialization function throws, -then this constructor will throw as well, and is therefore the encouraged -method to use when creating a blockchain object. +Creates a blockchain from a list of block objects, +objects must be readable by the `Block.fromBlockData()` method **Parameters:** Name | Type | Default | Description | ------ | ------ | ------ | ------ | +`blocksData` | BlockData[] | - | - | `opts` | [BlockchainOptions](../interfaces/_index_.blockchainoptions.md) | {} | Constructor options, see [BlockchainOptions](../interfaces/_index_.blockchainoptions.md) | **Returns:** *Promise‹[Blockchain](_index_.blockchain.md)‹››* diff --git a/packages/blockchain/docs/enums/_db_operation_.dbtarget.md b/packages/blockchain/docs/enums/_db_operation_.dbtarget.md deleted file mode 100644 index 3a2fd8e385..0000000000 --- a/packages/blockchain/docs/enums/_db_operation_.dbtarget.md +++ /dev/null @@ -1,80 +0,0 @@ -[@ethereumjs/blockchain](../README.md) › ["db/operation"](../modules/_db_operation_.md) › [DBTarget](_db_operation_.dbtarget.md) - -# Enumeration: DBTarget - -## Index - -### Enumeration members - -* [Body](_db_operation_.dbtarget.md#body) -* [HashToNumber](_db_operation_.dbtarget.md#hashtonumber) -* [HeadBlock](_db_operation_.dbtarget.md#headblock) -* [HeadHeader](_db_operation_.dbtarget.md#headheader) -* [Header](_db_operation_.dbtarget.md#header) -* [Heads](_db_operation_.dbtarget.md#heads) -* [NumberToHash](_db_operation_.dbtarget.md#numbertohash) -* [TotalDifficulty](_db_operation_.dbtarget.md#totaldifficulty) - -## Enumeration members - -### Body - -• **Body**: - -*Defined in [db/operation.ts:22](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L22)* - -___ - -### HashToNumber - -• **HashToNumber**: - -*Defined in [db/operation.ts:19](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L19)* - -___ - -### HeadBlock - -• **HeadBlock**: - -*Defined in [db/operation.ts:18](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L18)* - -___ - -### HeadHeader - -• **HeadHeader**: - -*Defined in [db/operation.ts:17](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L17)* - -___ - -### Header - -• **Header**: - -*Defined in [db/operation.ts:23](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L23)* - -___ - -### Heads - -• **Heads**: - -*Defined in [db/operation.ts:16](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L16)* - -___ - -### NumberToHash - -• **NumberToHash**: - -*Defined in [db/operation.ts:20](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L20)* - -___ - -### TotalDifficulty - -• **TotalDifficulty**: - -*Defined in [db/operation.ts:21](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L21)* diff --git a/packages/blockchain/docs/interfaces/_index_.blockchaininterface.md b/packages/blockchain/docs/interfaces/_index_.blockchaininterface.md index 7a5cde5ea5..0783ef2355 100644 --- a/packages/blockchain/docs/interfaces/_index_.blockchaininterface.md +++ b/packages/blockchain/docs/interfaces/_index_.blockchaininterface.md @@ -25,7 +25,7 @@ ▸ **delBlock**(`blockHash`: Buffer): *Promise‹void›* -*Defined in [index.ts:29](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L29)* +*Defined in [index.ts:42](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L42)* Deletes a block from the blockchain. All child blocks in the chain are deleted and any encountered heads are set to the parent block. @@ -44,7 +44,7 @@ ___ ▸ **getBlock**(`blockId`: Buffer | number | BN): *Promise‹Block | null›* -*Defined in [index.ts:34](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L34)* +*Defined in [index.ts:47](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L47)* Returns a block by its hash or number. @@ -60,9 +60,9 @@ ___ ### iterator -▸ **iterator**(`name`: string, `onBlock`: OnBlock): *Promise‹void›* +▸ **iterator**(`name`: string, `onBlock`: OnBlock): *Promise‹void | number›* -*Defined in [index.ts:44](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L44)* +*Defined in [index.ts:57](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L57)* Iterates through blocks starting at the specified iterator head and calls the onBlock function on each block. @@ -74,7 +74,7 @@ Name | Type | Description | `name` | string | Name of the state root head | `onBlock` | OnBlock | Function called on each block with params (block: Block, reorg: boolean) | -**Returns:** *Promise‹void›* +**Returns:** *Promise‹void | number›* ___ @@ -82,7 +82,7 @@ ___ ▸ **putBlock**(`block`: Block): *Promise‹void›* -*Defined in [index.ts:21](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L21)* +*Defined in [index.ts:34](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L34)* Adds a block to the blockchain. diff --git a/packages/blockchain/docs/interfaces/_index_.blockchainoptions.md b/packages/blockchain/docs/interfaces/_index_.blockchainoptions.md index 0d82fb5084..ed702bc343 100644 --- a/packages/blockchain/docs/interfaces/_index_.blockchainoptions.md +++ b/packages/blockchain/docs/interfaces/_index_.blockchainoptions.md @@ -24,7 +24,7 @@ This are the options that the Blockchain constructor can receive. • **common**? : *Common* -*Defined in [index.ts:57](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L57)* +*Defined in [index.ts:70](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L70)* Specify the chain and hardfork by passing a Common instance. @@ -36,7 +36,7 @@ ___ • **db**? : *LevelUp* -*Defined in [index.ts:63](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L63)* +*Defined in [index.ts:76](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L76)* Database to store blocks and metadata. Should be an abstract-leveldown compliant store. @@ -47,13 +47,13 @@ ___ • **genesisBlock**? : *Block* -*Defined in [index.ts:89](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L89)* +*Defined in [index.ts:104](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L104)* The blockchain only initializes succesfully if it has a genesis block. If there is no block available in the DB and a `genesisBlock` is provided, -then the provided `genesisBlock` will be used as genesis If no block is +then the provided `genesisBlock` will be used as genesis. If no block is present in the DB and no block is provided, then the genesis block as -provided from the `common` will be used +provided from the `common` will be used. ___ @@ -61,7 +61,7 @@ ___ • **validateBlocks**? : *undefined | false | true* -*Defined in [index.ts:80](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L80)* +*Defined in [index.ts:95](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L95)* This flag indicates if protocol-given consistency checks on block headers and included uncles and transactions should be performed, @@ -73,10 +73,12 @@ ___ • **validateConsensus**? : *undefined | false | true* -*Defined in [index.ts:72](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L72)* +*Defined in [index.ts:87](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/index.ts#L87)* This flags indicates if a block should be validated along the consensus algorithm or protocol used by the chain, e.g. by verifying the PoW on the block. -Supported: 'pow' with 'ethash' algorithm (taken from the `Common` instance) +Supported consensus types and algorithms (taken from the `Common` instance): +- 'pow' with 'ethash' algorithm (validates the proof-of-work) +- 'poa' with 'clique' algorithm (verifies the block signatures) Default: `true`. diff --git a/packages/blockchain/docs/modules/_db_cache_.md b/packages/blockchain/docs/modules/_db_cache_.md deleted file mode 100644 index dc9cad9b00..0000000000 --- a/packages/blockchain/docs/modules/_db_cache_.md +++ /dev/null @@ -1,5 +0,0 @@ -[@ethereumjs/blockchain](../README.md) › ["db/cache"](_db_cache_.md) - -# Module: "db/cache" - - diff --git a/packages/blockchain/docs/modules/_db_constants_.md b/packages/blockchain/docs/modules/_db_constants_.md deleted file mode 100644 index 5df91ec9b0..0000000000 --- a/packages/blockchain/docs/modules/_db_constants_.md +++ /dev/null @@ -1,149 +0,0 @@ -[@ethereumjs/blockchain](../README.md) › ["db/constants"](_db_constants_.md) - -# Module: "db/constants" - -## Index - -### Variables - -* [HEADS_KEY](_db_constants_.md#const-heads_key) -* [HEAD_BLOCK_KEY](_db_constants_.md#const-head_block_key) -* [HEAD_HEADER_KEY](_db_constants_.md#const-head_header_key) - -### Functions - -* [bodyKey](_db_constants_.md#const-bodykey) -* [bufBE8](_db_constants_.md#const-bufbe8) -* [hashToNumberKey](_db_constants_.md#const-hashtonumberkey) -* [headerKey](_db_constants_.md#const-headerkey) -* [numberToHashKey](_db_constants_.md#const-numbertohashkey) -* [tdKey](_db_constants_.md#const-tdkey) - -## Variables - -### `Const` HEADS_KEY - -• **HEADS_KEY**: *"heads"* = "heads" - -*Defined in [db/constants.ts:5](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/constants.ts#L5)* - -___ - -### `Const` HEAD_BLOCK_KEY - -• **HEAD_BLOCK_KEY**: *"LastBlock"* = "LastBlock" - -*Defined in [db/constants.ts:15](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/constants.ts#L15)* - -Current canonical head for full sync - -___ - -### `Const` HEAD_HEADER_KEY - -• **HEAD_HEADER_KEY**: *"LastHeader"* = "LastHeader" - -*Defined in [db/constants.ts:10](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/constants.ts#L10)* - -Current canonical head for light sync - -## Functions - -### `Const` bodyKey - -▸ **bodyKey**(`n`: BN, `hash`: Buffer): *Buffer‹›* - -*Defined in [db/constants.ts:53](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/constants.ts#L53)* - -**Parameters:** - -Name | Type | ------- | ------ | -`n` | BN | -`hash` | Buffer | - -**Returns:** *Buffer‹›* - -___ - -### `Const` bufBE8 - -▸ **bufBE8**(`n`: BN): *Buffer‹›* - -*Defined in [db/constants.ts:47](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/constants.ts#L47)* - -Convert BN to big endian Buffer - -**Parameters:** - -Name | Type | ------- | ------ | -`n` | BN | - -**Returns:** *Buffer‹›* - -___ - -### `Const` hashToNumberKey - -▸ **hashToNumberKey**(`hash`: Buffer): *Buffer‹›* - -*Defined in [db/constants.ts:57](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/constants.ts#L57)* - -**Parameters:** - -Name | Type | ------- | ------ | -`hash` | Buffer | - -**Returns:** *Buffer‹›* - -___ - -### `Const` headerKey - -▸ **headerKey**(`n`: BN, `hash`: Buffer): *Buffer‹›* - -*Defined in [db/constants.ts:51](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/constants.ts#L51)* - -**Parameters:** - -Name | Type | ------- | ------ | -`n` | BN | -`hash` | Buffer | - -**Returns:** *Buffer‹›* - -___ - -### `Const` numberToHashKey - -▸ **numberToHashKey**(`n`: BN): *Buffer‹›* - -*Defined in [db/constants.ts:55](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/constants.ts#L55)* - -**Parameters:** - -Name | Type | ------- | ------ | -`n` | BN | - -**Returns:** *Buffer‹›* - -___ - -### `Const` tdKey - -▸ **tdKey**(`n`: BN, `hash`: Buffer): *Buffer‹›* - -*Defined in [db/constants.ts:49](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/constants.ts#L49)* - -**Parameters:** - -Name | Type | ------- | ------ | -`n` | BN | -`hash` | Buffer | - -**Returns:** *Buffer‹›* diff --git a/packages/blockchain/docs/modules/_db_helpers_.md b/packages/blockchain/docs/modules/_db_helpers_.md deleted file mode 100644 index 373032dfd9..0000000000 --- a/packages/blockchain/docs/modules/_db_helpers_.md +++ /dev/null @@ -1,84 +0,0 @@ -[@ethereumjs/blockchain](../README.md) › ["db/helpers"](_db_helpers_.md) - -# Module: "db/helpers" - -## Index - -### Classes - -* [DBOp](../classes/_db_helpers_.dbop.md) - -### Functions - -* [DBSaveLookups](_db_helpers_.md#dbsavelookups) -* [DBSetBlockOrHeader](_db_helpers_.md#dbsetblockorheader) -* [DBSetHashToNumber](_db_helpers_.md#dbsethashtonumber) -* [DBSetTD](_db_helpers_.md#dbsettd) - -## Functions - -### DBSaveLookups - -▸ **DBSaveLookups**(`blockHash`: Buffer, `blockNumber`: BN): *[DBOp](../classes/_db_helpers_.dbop.md)[]* - -*Defined in [db/helpers.ts:65](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/helpers.ts#L65)* - -**Parameters:** - -Name | Type | ------- | ------ | -`blockHash` | Buffer | -`blockNumber` | BN | - -**Returns:** *[DBOp](../classes/_db_helpers_.dbop.md)[]* - -___ - -### DBSetBlockOrHeader - -▸ **DBSetBlockOrHeader**(`blockBody`: Block | BlockHeader): *[DBOp](../classes/_db_helpers_.dbop.md)[]* - -*Defined in [db/helpers.ts:25](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/helpers.ts#L25)* - -**Parameters:** - -Name | Type | ------- | ------ | -`blockBody` | Block | BlockHeader | - -**Returns:** *[DBOp](../classes/_db_helpers_.dbop.md)[]* - -___ - -### DBSetHashToNumber - -▸ **DBSetHashToNumber**(`blockHash`: Buffer, `blockNumber`: BN): *[DBOp](../classes/_db_helpers_.dbop.md)* - -*Defined in [db/helpers.ts:58](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/helpers.ts#L58)* - -**Parameters:** - -Name | Type | ------- | ------ | -`blockHash` | Buffer | -`blockNumber` | BN | - -**Returns:** *[DBOp](../classes/_db_helpers_.dbop.md)* - -___ - -### DBSetTD - -▸ **DBSetTD**(`TD`: BN, `blockNumber`: BN, `blockHash`: Buffer): *[DBOp](../classes/_db_helpers_.dbop.md)* - -*Defined in [db/helpers.ts:11](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/helpers.ts#L11)* - -**Parameters:** - -Name | Type | ------- | ------ | -`TD` | BN | -`blockNumber` | BN | -`blockHash` | Buffer | - -**Returns:** *[DBOp](../classes/_db_helpers_.dbop.md)* diff --git a/packages/blockchain/docs/modules/_db_manager_.md b/packages/blockchain/docs/modules/_db_manager_.md deleted file mode 100644 index 8bb263a698..0000000000 --- a/packages/blockchain/docs/modules/_db_manager_.md +++ /dev/null @@ -1,21 +0,0 @@ -[@ethereumjs/blockchain](../README.md) › ["db/manager"](_db_manager_.md) - -# Module: "db/manager" - -## Index - -### Type aliases - -* [CacheMap](_db_manager_.md#cachemap) - -## Type aliases - -### CacheMap - -Ƭ **CacheMap**: *object* - -*Defined in [db/manager.ts:27](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/manager.ts#L27)* - -#### Type declaration: - -* \[ **key**: *string*\]: Cache‹Buffer› diff --git a/packages/blockchain/docs/modules/_db_operation_.md b/packages/blockchain/docs/modules/_db_operation_.md deleted file mode 100644 index 5d6d59d7eb..0000000000 --- a/packages/blockchain/docs/modules/_db_operation_.md +++ /dev/null @@ -1,31 +0,0 @@ -[@ethereumjs/blockchain](../README.md) › ["db/operation"](_db_operation_.md) - -# Module: "db/operation" - -## Index - -### Enumerations - -* [DBTarget](../enums/_db_operation_.dbtarget.md) - -### Classes - -* [DBOp](../classes/_db_operation_.dbop.md) - -### Type aliases - -* [DatabaseKey](_db_operation_.md#databasekey) - -## Type aliases - -### DatabaseKey - -Ƭ **DatabaseKey**: *object* - -*Defined in [db/operation.ts:39](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/blockchain/src/db/operation.ts#L39)* - -#### Type declaration: - -* **blockHash**? : *Buffer* - -* **blockNumber**? : *BN* diff --git a/packages/blockchain/package.json b/packages/blockchain/package.json index 5ec4b5e3c5..2e6d360135 100644 --- a/packages/blockchain/package.json +++ b/packages/blockchain/package.json @@ -1,6 +1,6 @@ { "name": "@ethereumjs/blockchain", - "version": "5.0.0", + "version": "5.1.0", "description": "A module to store and interact with blocks", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -36,8 +36,8 @@ }, "homepage": "https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/blockchain#readme", "dependencies": { - "@ethereumjs/block": "^3.0.0", - "@ethereumjs/common": "^2.0.0", + "@ethereumjs/block": "^3.1.0", + "@ethereumjs/common": "^2.1.0", "@ethereumjs/ethash": "^1.0.0", "debug": "^2.2.0", "ethereumjs-util": "^7.0.8", diff --git a/packages/blockchain/test/clique.spec.ts b/packages/blockchain/test/clique.spec.ts index 383f8eee6e..cd4bc855cf 100644 --- a/packages/blockchain/test/clique.spec.ts +++ b/packages/blockchain/test/clique.spec.ts @@ -15,7 +15,7 @@ tape('Clique: Initialization', (t) => { st.deepEquals( blockchain.cliqueActiveSigners(), - head.cliqueEpochTransitionSigners(), + head.header.cliqueEpochTransitionSigners(), 'correct genesis signers' ) st.end() diff --git a/packages/blockchain/typedoc.js b/packages/blockchain/typedoc.js index 4bfce1e97c..8fa4fe76b0 100644 --- a/packages/blockchain/typedoc.js +++ b/packages/blockchain/typedoc.js @@ -5,7 +5,11 @@ module.exports = { plugin: 'typedoc-plugin-markdown', readme: 'none', gitRevision: 'master', - exclude: ['test/**/*.ts', 'src/cache.ts', 'src/dbManager.ts', 'src/util.ts'], + exclude: [ + 'test/**/*.ts', + 'src/db/**', + 'src/clique.ts', + ], excludeNotExported: true, excludePrivate: true, excludeProtected: true, diff --git a/packages/client/package.json b/packages/client/package.json index 693a4fe718..7b1aa63c05 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -51,12 +51,12 @@ }, "homepage": "https://github.com/ethereumjs/ethereumjs-client#readme", "dependencies": { - "@ethereumjs/block": "^3.0.0", - "@ethereumjs/blockchain": "^5.0.0", - "@ethereumjs/common": "^2.0.0", + "@ethereumjs/block": "^3.1.0", + "@ethereumjs/blockchain": "^5.1.0", + "@ethereumjs/common": "^2.1.0", "@ethereumjs/devp2p": "^3.0.3", "merkle-patricia-tree": "^4.1.0", - "@ethereumjs/vm": "^5.0.0", + "@ethereumjs/vm": "^5.1.0", "chalk": "^2.4.2", "ethereumjs-util": "^7.0.8", "fs-extra": "^7.0.1", diff --git a/packages/common/CHANGELOG.md b/packages/common/CHANGELOG.md index 1665cc1078..7692ce556b 100644 --- a/packages/common/CHANGELOG.md +++ b/packages/common/CHANGELOG.md @@ -6,6 +6,64 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) (modification: no type change headlines) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 2.1.0 - 2021-02-22 + +### Clique/PoA Support + +This release completes on Clique/PoA support (see also Clique/PoA related changes in `v2.0.0`), see PR [#1032](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1032). The chain configuration files (e.g. `chains/goerli.json`) are extended by a consensus algorithm-specific config parameter section, here is a sample `consensus` parameter section, note that the `config` parameter dict must be named after the consensus algorithm: + +```json +{ + "consensus": { + "type": "poa", + "algorithm": "clique", + "clique": { + "period": 15, + "epoch": 30000 + } + } +} +``` + +For now this is done in a backwards-compatible way and the `consensus` parameter section is still marked as optional. You nevertheless might want to add this section already to your custom chain files - even if you don't make usage of the parameters - to remain compatible in the future. + +The new parameter section is complemented by a new `Common.consensusConfig()` function to request these parameters in addition to the `Common.consensusType()` and `Common.consensusAlgorithm()` methods introduced in `v2.0.0`. + +### Custom Chain File Support + +There is now a more convenient and flexible way to integrate custom chains into Common instances complementing the existing `Common.fromCustomChain()` static constructor, see PR [#1034](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1034). + +This new way adds a new `customChains` constructor option and can be used as following: + +```typescript +import myCustomChain1 from './[PATH]/myCustomChain1.json' +import myCustomChain2 from './[PATH]/myCustomChain2.json' +// Add two custom chains, initial mainnet activation +const common1 = new Common({ chain: 'mainnet', customChains: [ myCustomChain1, myCustomChain2 ] }) +// Somewhat later down the road... +common1.setChain('customChain1') +// Add two custom chains, activate customChain1 +const common1 = new Common({ chain: 'customChain1', customChains: [ myCustomChain1, myCustomChain2 ] }) +``` + +The [README section](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/common#working-with-privatecustom-chains) on working with custom chains has been significantly expanded along the way and is a recommended read if you use common for custom chain initialization. + +### New EIPs + +#### EIP-1459 DNS Peer Discovery + +[EIP-1459](https://eips.ethereum.org/EIPS/eip-1459) introduces a way to discover nodes for an Ethereum network connection via DNS. This release adds a new optional chain config file parameter `dnsNetworks` and an associated method `Common.dnsNetworks()` to request DNS networks for a chain. + +#### EIP-2565 ModExp Precompile Gas Costs + +[EIP-2565](https://eips.ethereum.org/EIPS/eip-2565) introduces a new algorithm for ModExp precompile gas cost calculation. A new EIP file `eips/2565.json` has been added along the work on PR [#1026](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1026) with respective parameter updates. + +### Other Changes + +- `Common` is now implemented as an `EventEmitter` and emits a `hardforkChanged` event upon a HF change, PR [#1112](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1112) +- New `Common.isActivatedEIP()` method, PR [#1125](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1125) +- Updated `Goerli` bootnodes, PR [#1031](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1031) + ## 2.0.0 - 2020-11-24 ### New Package Name diff --git a/packages/common/README.md b/packages/common/README.md index 5a1d9b217e..cfb699fd54 100644 --- a/packages/common/README.md +++ b/packages/common/README.md @@ -104,9 +104,11 @@ The following chain-specific parameters are provided: - `networkId` - `consensusType` (e.g. `pow` or `poa`) - `consensusAlgorithm` (e.g. `ethash` or `clique`) +- `consensusConfig` (depends on `consensusAlgorithm`, e.g. `period` and `epoch` for `clique`) - `genesis` block header values - `hardforks` block numbers - `bootstrapNodes` list +- `dnsNetworks` list ([EIP-1459](https://eips.ethereum.org/EIPS/eip-1459)-compliant list of DNS networks for peer discovery) To get an overview of the different parameters have a look at one of the chain-specifc files like `mainnet.json` in the `chains` directory, or to the `Chain` type in [./src/types.ts](./src/types.ts). @@ -115,7 +117,7 @@ files like `mainnet.json` in the `chains` directory, or to the `Chain` type in [ There are two distinct APIs available for setting up custom(ized) chains. -### Activate with a single custom Chain setup +#### Activate with a single custom Chain setup If you want to initialize a `Common` instance with a single custom chain which is then directly activated you can pass a dictionary - conforming to the parameter format described above - with your custom chain @@ -136,7 +138,7 @@ const customChainParams = { name: 'custom', chainId: 123, networkId: 678 } const customChainCommon = Common.forCustomChain('mainnet', customChainParams, 'byzantium') ``` -### Initialize using customChains Array +#### Initialize using customChains Array A second way for custom chain initialization is to use the `customChains` constructor option. This option comes with more flexibility and allows for an arbitrary number of custom chains to be initialized on @@ -216,13 +218,14 @@ const c = new Common({ chain: 'mainnet', eips: [2537] }) The following EIPs are currently supported: +- [EIP-2315](https://eips.ethereum.org/EIPS/eip-2315): Simple subroutines for the EVM - [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537): BLS precompiles +- [EIP-2565](https://eips.ethereum.org/EIPS/eip-2565): ModExp gas cost - [EIP-2929](https://eips.ethereum.org/EIPS/eip-2929): gas cost increases for state access opcodes ## Bootstrap Nodes -There is no separate config file for bootstrap nodes like in the old `ethereum-common` library. -Instead use the `common.bootstrapNodes()` function to get nodes for a specific chain/network. +You can use `common.bootstrapNodes()` function to get nodes for a specific chain/network. ## Genesis States diff --git a/packages/common/docs/README.md b/packages/common/docs/README.md index 1fcf0206f6..7f975fa4ee 100644 --- a/packages/common/docs/README.md +++ b/packages/common/docs/README.md @@ -6,7 +6,6 @@ ### Modules -* ["eips/index"](modules/_eips_index_.md) * ["genesisStates/index"](modules/_genesisstates_index_.md) * ["index"](modules/_index_.md) * ["types"](modules/_types_.md) diff --git a/packages/common/docs/classes/_index_.common.md b/packages/common/docs/classes/_index_.common.md index a839443f46..b97eceeda2 100644 --- a/packages/common/docs/classes/_index_.common.md +++ b/packages/common/docs/classes/_index_.common.md @@ -6,10 +6,16 @@ Common class to access chain and hardfork parameters ## Hierarchy -* **Common** +* EventEmitter + + ↳ **Common** ## Index +### References + +* [EventEmitter](_index_.common.md#eventemitter) + ### Constructors * [constructor](_index_.common.md#constructor) @@ -17,6 +23,7 @@ Common class to access chain and hardfork parameters ### Properties * [DEFAULT_HARDFORK](_index_.common.md#default_hardfork) +* [defaultMaxListeners](_index_.common.md#static-defaultmaxlisteners) ### Methods @@ -27,14 +34,21 @@ Common class to access chain and hardfork parameters * [activeHardfork](_index_.common.md#activehardfork) * [activeHardforks](_index_.common.md#activehardforks) * [activeOnBlock](_index_.common.md#activeonblock) +* [addListener](_index_.common.md#addlistener) * [bootstrapNodes](_index_.common.md#bootstrapnodes) * [chainId](_index_.common.md#chainid) * [chainName](_index_.common.md#chainname) * [consensusAlgorithm](_index_.common.md#consensusalgorithm) +* [consensusConfig](_index_.common.md#consensusconfig) * [consensusType](_index_.common.md#consensustype) +* [dnsNetworks](_index_.common.md#dnsnetworks) * [eips](_index_.common.md#eips) +* [emit](_index_.common.md#emit) +* [eventNames](_index_.common.md#eventnames) * [forkHash](_index_.common.md#forkhash) * [genesis](_index_.common.md#genesis) +* [getHardforkByBlockNumber](_index_.common.md#gethardforkbyblocknumber) +* [getMaxListeners](_index_.common.md#getmaxlisteners) * [gteHardfork](_index_.common.md#gtehardfork) * [hardfork](_index_.common.md#hardfork) * [hardforkBlock](_index_.common.md#hardforkblock) @@ -45,17 +59,36 @@ Common class to access chain and hardfork parameters * [hardforks](_index_.common.md#hardforks) * [isHardforkBlock](_index_.common.md#ishardforkblock) * [isNextHardforkBlock](_index_.common.md#isnexthardforkblock) +* [listenerCount](_index_.common.md#listenercount) +* [listeners](_index_.common.md#listeners) * [networkId](_index_.common.md#networkid) * [nextHardforkBlock](_index_.common.md#nexthardforkblock) +* [off](_index_.common.md#off) +* [on](_index_.common.md#on) +* [once](_index_.common.md#once) * [param](_index_.common.md#param) * [paramByBlock](_index_.common.md#parambyblock) * [paramByEIP](_index_.common.md#parambyeip) * [paramByHardfork](_index_.common.md#parambyhardfork) +* [prependListener](_index_.common.md#prependlistener) +* [prependOnceListener](_index_.common.md#prependoncelistener) +* [rawListeners](_index_.common.md#rawlisteners) +* [removeAllListeners](_index_.common.md#removealllisteners) +* [removeListener](_index_.common.md#removelistener) * [setChain](_index_.common.md#setchain) * [setEIPs](_index_.common.md#seteips) * [setHardfork](_index_.common.md#sethardfork) * [setHardforkByBlockNumber](_index_.common.md#sethardforkbyblocknumber) +* [setMaxListeners](_index_.common.md#setmaxlisteners) * [forCustomChain](_index_.common.md#static-forcustomchain) +* [listenerCount](_index_.common.md#static-listenercount) +* [once](_index_.common.md#static-once) + +## References + +### EventEmitter + +• **EventEmitter**: ## Constructors @@ -63,7 +96,9 @@ Common class to access chain and hardfork parameters \+ **new Common**(`opts`: [CommonOpts](../interfaces/_index_.commonopts.md)): *[Common](_index_.common.md)* -*Defined in [index.ts:96](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L96)* +*Overrides void* + +*Defined in [packages/common/src/index.ts:113](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L113)* **`constructor`** @@ -79,9 +114,19 @@ Name | Type | ### DEFAULT_HARDFORK -• **DEFAULT_HARDFORK**: *string* = "istanbul" +• **DEFAULT_HARDFORK**: *string* + +*Defined in [packages/common/src/index.ts:61](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L61)* + +___ -*Defined in [index.ts:47](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L47)* +### `Static` defaultMaxListeners + +▪ **defaultMaxListeners**: *number* + +*Inherited from [Common](_index_.common.md).[defaultMaxListeners](_index_.common.md#static-defaultmaxlisteners)* + +Defined in node_modules/@types/node/events.d.ts:20 ## Methods @@ -89,7 +134,7 @@ Name | Type | ▸ **_calcForkHash**(`hardfork`: string): *string* -*Defined in [index.ts:516](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L516)* +*Defined in [packages/common/src/index.ts:554](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L554)* Internal helper function to calculate a fork hash @@ -109,7 +154,7 @@ ___ ▸ **_chooseHardfork**(`hardfork?`: string | null, `onlySupported`: boolean): *string* -*Defined in [index.ts:186](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L186)* +*Defined in [packages/common/src/index.ts:224](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L224)* Internal helper function to choose between hardfork set and hardfork provided as param @@ -130,7 +175,7 @@ ___ ▸ **_getHardfork**(`hardfork`: string): *any* -*Defined in [index.ts:200](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L200)* +*Defined in [packages/common/src/index.ts:238](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L238)* Internal helper function, returns the params for the given hardfork for the chain set @@ -150,7 +195,7 @@ ___ ▸ **_isSupportedHardfork**(`hardfork`: string | null): *boolean* -*Defined in [index.ts:213](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L213)* +*Defined in [packages/common/src/index.ts:251](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L251)* Internal helper function to check if a hardfork is set to be supported by the library @@ -170,7 +215,7 @@ ___ ▸ **activeHardfork**(`blockNumber?`: number | null, `opts?`: hardforkOptions): *string* -*Defined in [index.ts:451](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L451)* +*Defined in [packages/common/src/index.ts:489](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L489)* Returns the latest active hardfork name for chain or block or throws if unavailable @@ -191,7 +236,7 @@ ___ ▸ **activeHardforks**(`blockNumber?`: number | null, `opts?`: hardforkOptions): *Array‹any›* -*Defined in [index.ts:431](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L431)* +*Defined in [packages/common/src/index.ts:469](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L469)* Returns the active hardfork switches for the current chain @@ -212,7 +257,7 @@ ___ ▸ **activeOnBlock**(`blockNumber`: number, `opts?`: hardforkOptions): *boolean* -*Defined in [index.ts:361](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L361)* +*Defined in [packages/common/src/index.ts:399](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L399)* Alias to hardforkIsActiveOnBlock when hardfork is set @@ -229,11 +274,37 @@ True if HF is active on block number ___ +### addListener + +▸ **addListener**(`event`: string | symbol, `listener`: function): *this* + +*Inherited from [Common](_index_.common.md).[addListener](_index_.common.md#addlistener)* + +Defined in node_modules/@types/node/globals.d.ts:595 + +**Parameters:** + +▪ **event**: *string | symbol* + +▪ **listener**: *function* + +▸ (...`args`: any[]): *void* + +**Parameters:** + +Name | Type | +------ | ------ | +`...args` | any[] | + +**Returns:** *this* + +___ + ### bootstrapNodes ▸ **bootstrapNodes**(): *any* -*Defined in [index.ts:591](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L591)* +*Defined in [packages/common/src/index.ts:629](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L629)* Returns bootstrap nodes for the current chain @@ -247,7 +318,7 @@ ___ ▸ **chainId**(): *number* -*Defined in [index.ts:607](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L607)* +*Defined in [packages/common/src/index.ts:653](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L653)* Returns the Id of current chain @@ -261,7 +332,7 @@ ___ ▸ **chainName**(): *string* -*Defined in [index.ts:615](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L615)* +*Defined in [packages/common/src/index.ts:661](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L661)* Returns the name of current chain @@ -275,7 +346,7 @@ ___ ▸ **consensusAlgorithm**(): *string* -*Defined in [index.ts:649](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L649)* +*Defined in [packages/common/src/index.ts:695](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L695)* Returns the concrete consensus implementation algorithm or protocol for the network @@ -286,11 +357,31 @@ e.g. "ethash" for "pow" consensus type or ___ +### consensusConfig + +▸ **consensusConfig**(): *any* + +*Defined in [packages/common/src/index.ts:710](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L710)* + +Returns a dictionary with consensus configuration +parameters based on the consensus algorithm + +Expected returns (parameters must be present in +the respective chain json files): + +ethash: - +clique: period, epoch +aura: - + +**Returns:** *any* + +___ + ### consensusType ▸ **consensusType**(): *string* -*Defined in [index.ts:639](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L639)* +*Defined in [packages/common/src/index.ts:685](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L685)* Returns the consensus type of the network Possible values: "pow"|"poa" @@ -299,11 +390,25 @@ Possible values: "pow"|"poa" ___ +### dnsNetworks + +▸ **dnsNetworks**(): *any* + +*Defined in [packages/common/src/index.ts:637](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L637)* + +Returns DNS networks for the current chain + +**Returns:** *any* + +Array of DNS ENR urls + +___ + ### eips ▸ **eips**(): *number[]* -*Defined in [index.ts:631](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L631)* +*Defined in [packages/common/src/index.ts:677](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L677)* Returns the active EIPs @@ -313,11 +418,42 @@ List of EIPs ___ +### emit + +▸ **emit**(`event`: string | symbol, ...`args`: any[]): *boolean* + +*Inherited from [Common](_index_.common.md).[emit](_index_.common.md#emit)* + +Defined in node_modules/@types/node/globals.d.ts:605 + +**Parameters:** + +Name | Type | +------ | ------ | +`event` | string | symbol | +`...args` | any[] | + +**Returns:** *boolean* + +___ + +### eventNames + +▸ **eventNames**(): *Array‹string | symbol›* + +*Inherited from [Common](_index_.common.md).[eventNames](_index_.common.md#eventnames)* + +Defined in node_modules/@types/node/globals.d.ts:610 + +**Returns:** *Array‹string | symbol›* + +___ + ### forkHash ▸ **forkHash**(`hardfork?`: undefined | string): *any* -*Defined in [index.ts:546](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L546)* +*Defined in [packages/common/src/index.ts:584](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L584)* Returns an eth/64 compliant fork hash (EIP-2124) @@ -335,7 +471,7 @@ ___ ▸ **genesis**(): *any* -*Defined in [index.ts:575](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L575)* +*Defined in [packages/common/src/index.ts:613](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L613)* Returns the Genesis parameters of current chain @@ -345,11 +481,43 @@ Genesis dictionary ___ +### getHardforkByBlockNumber + +▸ **getHardforkByBlockNumber**(`blockNumber`: number): *string* + +*Defined in [packages/common/src/index.ts:191](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L191)* + +Returns the hardfork based on the block number provided + +**Parameters:** + +Name | Type | +------ | ------ | +`blockNumber` | number | + +**Returns:** *string* + +The name of the HF + +___ + +### getMaxListeners + +▸ **getMaxListeners**(): *number* + +*Inherited from [Common](_index_.common.md).[getMaxListeners](_index_.common.md#getmaxlisteners)* + +Defined in node_modules/@types/node/globals.d.ts:602 + +**Returns:** *number* + +___ + ### gteHardfork ▸ **gteHardfork**(`hardfork`: string, `opts?`: hardforkOptions): *boolean* -*Defined in [index.ts:405](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L405)* +*Defined in [packages/common/src/index.ts:443](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L443)* Alias to hardforkGteHardfork when hardfork is set @@ -370,7 +538,7 @@ ___ ▸ **hardfork**(): *string* -*Defined in [index.ts:599](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L599)* +*Defined in [packages/common/src/index.ts:645](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L645)* Returns the hardfork set @@ -384,7 +552,7 @@ ___ ▸ **hardforkBlock**(`hardfork?`: undefined | string): *number* -*Defined in [index.ts:466](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L466)* +*Defined in [packages/common/src/index.ts:504](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L504)* Returns the hardfork change block for hardfork provided or set @@ -404,7 +572,7 @@ ___ ▸ **hardforkForForkHash**(`forkHash`: string): *any | null* -*Defined in [index.ts:564](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L564)* +*Defined in [packages/common/src/index.ts:602](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L602)* **Parameters:** @@ -422,7 +590,7 @@ ___ ▸ **hardforkGteHardfork**(`hardfork1`: string | null, `hardfork2`: string, `opts?`: hardforkOptions): *boolean* -*Defined in [index.ts:372](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L372)* +*Defined in [packages/common/src/index.ts:410](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L410)* Sequence based check if given or set HF1 is greater than or equal HF2 @@ -444,7 +612,7 @@ ___ ▸ **hardforkIsActiveOnBlock**(`hardfork`: string | null, `blockNumber`: number, `opts?`: hardforkOptions): *boolean* -*Defined in [index.ts:342](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L342)* +*Defined in [packages/common/src/index.ts:380](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L380)* Checks if set or provided hardfork is active on block number @@ -466,7 +634,7 @@ ___ ▸ **hardforkIsActiveOnChain**(`hardfork?`: string | null, `opts?`: hardforkOptions): *boolean* -*Defined in [index.ts:415](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L415)* +*Defined in [packages/common/src/index.ts:453](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L453)* Checks if given or set hardfork is active on the chain @@ -487,7 +655,7 @@ ___ ▸ **hardforks**(): *any* -*Defined in [index.ts:583](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L583)* +*Defined in [packages/common/src/index.ts:621](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L621)* Returns the hardforks for current chain @@ -501,7 +669,7 @@ ___ ▸ **isHardforkBlock**(`blockNumber`: number, `hardfork?`: undefined | string): *boolean* -*Defined in [index.ts:477](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L477)* +*Defined in [packages/common/src/index.ts:515](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L515)* True if block number provided is the hardfork (given or set) change block @@ -522,7 +690,7 @@ ___ ▸ **isNextHardforkBlock**(`blockNumber`: number, `hardfork?`: undefined | string): *boolean* -*Defined in [index.ts:506](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L506)* +*Defined in [packages/common/src/index.ts:544](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L544)* True if block number provided is the hardfork change block following the hardfork given or set @@ -539,11 +707,47 @@ True if blockNumber is HF block ___ +### listenerCount + +▸ **listenerCount**(`type`: string | symbol): *number* + +*Inherited from [Common](_index_.common.md).[listenerCount](_index_.common.md#listenercount)* + +Defined in node_modules/@types/node/globals.d.ts:606 + +**Parameters:** + +Name | Type | +------ | ------ | +`type` | string | symbol | + +**Returns:** *number* + +___ + +### listeners + +▸ **listeners**(`event`: string | symbol): *Function[]* + +*Inherited from [Common](_index_.common.md).[listeners](_index_.common.md#listeners)* + +Defined in node_modules/@types/node/globals.d.ts:603 + +**Parameters:** + +Name | Type | +------ | ------ | +`event` | string | symbol | + +**Returns:** *Function[]* + +___ + ### networkId ▸ **networkId**(): *number* -*Defined in [index.ts:623](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L623)* +*Defined in [packages/common/src/index.ts:669](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L669)* Returns the Id of current network @@ -557,7 +761,7 @@ ___ ▸ **nextHardforkBlock**(`hardfork?`: undefined | string): *number | null* -*Defined in [index.ts:487](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L487)* +*Defined in [packages/common/src/index.ts:525](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L525)* Returns the change block for the next hardfork after the hardfork provided or set @@ -573,11 +777,89 @@ Block number or null if not available ___ +### off + +▸ **off**(`event`: string | symbol, `listener`: function): *this* + +*Inherited from [Common](_index_.common.md).[off](_index_.common.md#off)* + +Defined in node_modules/@types/node/globals.d.ts:599 + +**Parameters:** + +▪ **event**: *string | symbol* + +▪ **listener**: *function* + +▸ (...`args`: any[]): *void* + +**Parameters:** + +Name | Type | +------ | ------ | +`...args` | any[] | + +**Returns:** *this* + +___ + +### on + +▸ **on**(`event`: string | symbol, `listener`: function): *this* + +*Inherited from [Common](_index_.common.md).[on](_index_.common.md#on)* + +Defined in node_modules/@types/node/globals.d.ts:596 + +**Parameters:** + +▪ **event**: *string | symbol* + +▪ **listener**: *function* + +▸ (...`args`: any[]): *void* + +**Parameters:** + +Name | Type | +------ | ------ | +`...args` | any[] | + +**Returns:** *this* + +___ + +### once + +▸ **once**(`event`: string | symbol, `listener`: function): *this* + +*Inherited from [Common](_index_.common.md).[once](_index_.common.md#once)* + +Defined in node_modules/@types/node/globals.d.ts:597 + +**Parameters:** + +▪ **event**: *string | symbol* + +▪ **listener**: *function* + +▸ (...`args`: any[]): *void* + +**Parameters:** + +Name | Type | +------ | ------ | +`...args` | any[] | + +**Returns:** *this* + +___ + ### param ▸ **param**(`topic`: string, `name`: string): *any* -*Defined in [index.ts:254](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L254)* +*Defined in [packages/common/src/index.ts:292](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L292)* Returns a parameter for the current chain setup @@ -602,7 +884,7 @@ ___ ▸ **paramByBlock**(`topic`: string, `name`: string, `blockNumber`: number): *any* -*Defined in [index.ts:329](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L329)* +*Defined in [packages/common/src/index.ts:367](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L367)* Returns a parameter for the hardfork active on block number @@ -622,7 +904,7 @@ ___ ▸ **paramByEIP**(`topic`: string, `name`: string, `eip`: number): *any* -*Defined in [index.ts:307](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L307)* +*Defined in [packages/common/src/index.ts:345](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L345)* Returns a parameter corresponding to an EIP @@ -644,7 +926,7 @@ ___ ▸ **paramByHardfork**(`topic`: string, `name`: string, `hardfork`: string): *any* -*Defined in [index.ts:274](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L274)* +*Defined in [packages/common/src/index.ts:312](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L312)* Returns the parameter corresponding to a hardfork @@ -662,11 +944,125 @@ The value requested or `null` if not found ___ +### prependListener + +▸ **prependListener**(`event`: string | symbol, `listener`: function): *this* + +*Inherited from [Common](_index_.common.md).[prependListener](_index_.common.md#prependlistener)* + +Defined in node_modules/@types/node/globals.d.ts:608 + +**Parameters:** + +▪ **event**: *string | symbol* + +▪ **listener**: *function* + +▸ (...`args`: any[]): *void* + +**Parameters:** + +Name | Type | +------ | ------ | +`...args` | any[] | + +**Returns:** *this* + +___ + +### prependOnceListener + +▸ **prependOnceListener**(`event`: string | symbol, `listener`: function): *this* + +*Inherited from [Common](_index_.common.md).[prependOnceListener](_index_.common.md#prependoncelistener)* + +Defined in node_modules/@types/node/globals.d.ts:609 + +**Parameters:** + +▪ **event**: *string | symbol* + +▪ **listener**: *function* + +▸ (...`args`: any[]): *void* + +**Parameters:** + +Name | Type | +------ | ------ | +`...args` | any[] | + +**Returns:** *this* + +___ + +### rawListeners + +▸ **rawListeners**(`event`: string | symbol): *Function[]* + +*Inherited from [Common](_index_.common.md).[rawListeners](_index_.common.md#rawlisteners)* + +Defined in node_modules/@types/node/globals.d.ts:604 + +**Parameters:** + +Name | Type | +------ | ------ | +`event` | string | symbol | + +**Returns:** *Function[]* + +___ + +### removeAllListeners + +▸ **removeAllListeners**(`event?`: string | symbol): *this* + +*Inherited from [Common](_index_.common.md).[removeAllListeners](_index_.common.md#removealllisteners)* + +Defined in node_modules/@types/node/globals.d.ts:600 + +**Parameters:** + +Name | Type | +------ | ------ | +`event?` | string | symbol | + +**Returns:** *this* + +___ + +### removeListener + +▸ **removeListener**(`event`: string | symbol, `listener`: function): *this* + +*Inherited from [Common](_index_.common.md).[removeListener](_index_.common.md#removelistener)* + +Defined in node_modules/@types/node/globals.d.ts:598 + +**Parameters:** + +▪ **event**: *string | symbol* + +▪ **listener**: *function* + +▸ (...`args`: any[]): *void* + +**Parameters:** + +Name | Type | +------ | ------ | +`...args` | any[] | + +**Returns:** *this* + +___ + ### setChain ▸ **setChain**(`chain`: string | number | object): *any* -*Defined in [index.ts:121](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L121)* +*Defined in [packages/common/src/index.ts:141](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L141)* Sets the chain @@ -686,7 +1082,7 @@ ___ ▸ **setEIPs**(`eips`: number[]): *void* -*Defined in [index.ts:228](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L228)* +*Defined in [packages/common/src/index.ts:266](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L266)* Sets the active EIPs @@ -704,7 +1100,7 @@ ___ ▸ **setHardfork**(`hardfork`: string): *void* -*Defined in [index.ts:142](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L142)* +*Defined in [packages/common/src/index.ts:167](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L167)* Sets the hardfork to get params for @@ -722,7 +1118,7 @@ ___ ▸ **setHardforkByBlockNumber**(`blockNumber`: number): *string* -*Defined in [index.ts:163](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L163)* +*Defined in [packages/common/src/index.ts:213](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L213)* Sets a new hardfork based on the block number provided @@ -738,11 +1134,29 @@ The name of the HF set ___ +### setMaxListeners + +▸ **setMaxListeners**(`n`: number): *this* + +*Inherited from [Common](_index_.common.md).[setMaxListeners](_index_.common.md#setmaxlisteners)* + +Defined in node_modules/@types/node/globals.d.ts:601 + +**Parameters:** + +Name | Type | +------ | ------ | +`n` | number | + +**Returns:** *this* + +___ + ### `Static` forCustomChain ▸ **forCustomChain**(`baseChain`: string | number, `customChainParams`: Partial‹[Chain](../interfaces/_types_.chain.md)›, `hardfork?`: undefined | string, `supportedHardforks?`: Array‹string›): *[Common](_index_.common.md)* -*Defined in [index.ts:64](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L64)* +*Defined in [packages/common/src/index.ts:79](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L79)* Creates a Common object for a custom chain, based on a standard one. It uses all the [Chain](../interfaces/_types_.chain.md) params from [[baseChain]] except the ones overridden in [[customChainParams]]. @@ -757,3 +1171,58 @@ Name | Type | Description | `supportedHardforks?` | Array‹string› | Limit parameter returns to the given hardforks (optional) | **Returns:** *[Common](_index_.common.md)* + +___ + +### `Static` listenerCount + +▸ **listenerCount**(`emitter`: EventEmitter, `event`: string | symbol): *number* + +*Inherited from [Common](_index_.common.md).[listenerCount](_index_.common.md#static-listenercount)* + +Defined in node_modules/@types/node/events.d.ts:17 + +**`deprecated`** since v4.0.0 + +**Parameters:** + +Name | Type | +------ | ------ | +`emitter` | EventEmitter | +`event` | string | symbol | + +**Returns:** *number* + +___ + +### `Static` once + +▸ **once**(`emitter`: NodeEventTarget, `event`: string | symbol): *Promise‹any[]›* + +*Inherited from [Common](_index_.common.md).[once](_index_.common.md#static-once)* + +Defined in node_modules/@types/node/events.d.ts:13 + +**Parameters:** + +Name | Type | +------ | ------ | +`emitter` | NodeEventTarget | +`event` | string | symbol | + +**Returns:** *Promise‹any[]›* + +▸ **once**(`emitter`: DOMEventTarget, `event`: string): *Promise‹any[]›* + +*Inherited from [Common](_index_.common.md).[once](_index_.common.md#static-once)* + +Defined in node_modules/@types/node/events.d.ts:14 + +**Parameters:** + +Name | Type | +------ | ------ | +`emitter` | DOMEventTarget | +`event` | string | + +**Returns:** *Promise‹any[]›* diff --git a/packages/common/docs/interfaces/_index_.commonopts.md b/packages/common/docs/interfaces/_index_.commonopts.md index 28deae0cfc..a03c2f023d 100644 --- a/packages/common/docs/interfaces/_index_.commonopts.md +++ b/packages/common/docs/interfaces/_index_.commonopts.md @@ -13,6 +13,7 @@ Options for instantiating a [Common](../classes/_index_.common.md) instance. ### Properties * [chain](_index_.commonopts.md#chain) +* [customChains](_index_.commonopts.md#optional-customchains) * [eips](_index_.commonopts.md#optional-eips) * [hardfork](_index_.commonopts.md#optional-hardfork) * [supportedHardforks](_index_.commonopts.md#optional-supportedhardforks) @@ -23,9 +24,28 @@ Options for instantiating a [Common](../classes/_index_.common.md) instance. • **chain**: *string | number | object* -*Defined in [index.ts:14](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L14)* +*Defined in [packages/common/src/index.ts:16](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L16)* -String ('mainnet') or Number (1) chain +Chain name ('mainnet') or id (1), either from a chain directly supported +or a custom chain passed in via `customChains` + +___ + +### `Optional` customChains + +• **customChains**? : *[Chain](_types_.chain.md)[]* + +*Defined in [packages/common/src/index.ts:47](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L47)* + +Initialize (in addition to the supported chains) with the selected +custom chains + +Usage (directly with the respective chain intialization via the `chain` option): + +```javascript +import myCustomChain1 from '[PATH_TO_MY_CHAINS]/myCustomChain1.json' +const common = new Common({ chain: 'myCustomChain1', customChains: [ myCustomChain1 ]}) +``` ___ @@ -33,7 +53,7 @@ ___ • **eips**? : *number[]* -*Defined in [index.ts:33](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L33)* +*Defined in [packages/common/src/index.ts:35](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L35)* Selected EIPs which can be activated, please use an array for instantiation (e.g. `eips: [ 2537, ]`) @@ -48,7 +68,7 @@ ___ • **hardfork**? : *undefined | string* -*Defined in [index.ts:20](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L20)* +*Defined in [packages/common/src/index.ts:22](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L22)* String identifier ('byzantium') for hardfork @@ -60,6 +80,6 @@ ___ • **supportedHardforks**? : *Array‹string›* -*Defined in [index.ts:24](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L24)* +*Defined in [packages/common/src/index.ts:26](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/index.ts#L26)* Limit parameter returns to the given hardforks diff --git a/packages/common/docs/interfaces/_types_.bootstrapnode.md b/packages/common/docs/interfaces/_types_.bootstrapnode.md index d580c01d54..6e63cae6a1 100644 --- a/packages/common/docs/interfaces/_types_.bootstrapnode.md +++ b/packages/common/docs/interfaces/_types_.bootstrapnode.md @@ -24,7 +24,7 @@ • **chainId**? : *undefined | number* -*Defined in [types.ts:49](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L49)* +*Defined in [packages/common/src/types.ts:63](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L63)* ___ @@ -32,7 +32,7 @@ ___ • **comment**: *string* -*Defined in [types.ts:52](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L52)* +*Defined in [packages/common/src/types.ts:66](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L66)* ___ @@ -40,7 +40,7 @@ ___ • **id**: *string* -*Defined in [types.ts:50](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L50)* +*Defined in [packages/common/src/types.ts:64](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L64)* ___ @@ -48,7 +48,7 @@ ___ • **ip**: *string* -*Defined in [types.ts:46](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L46)* +*Defined in [packages/common/src/types.ts:60](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L60)* ___ @@ -56,7 +56,7 @@ ___ • **location**: *string* -*Defined in [types.ts:51](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L51)* +*Defined in [packages/common/src/types.ts:65](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L65)* ___ @@ -64,7 +64,7 @@ ___ • **network**? : *undefined | string* -*Defined in [types.ts:48](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L48)* +*Defined in [packages/common/src/types.ts:62](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L62)* ___ @@ -72,4 +72,4 @@ ___ • **port**: *number | string* -*Defined in [types.ts:47](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L47)* +*Defined in [packages/common/src/types.ts:61](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L61)* diff --git a/packages/common/docs/interfaces/_types_.chain.md b/packages/common/docs/interfaces/_types_.chain.md index 588f674aa6..06dacdd606 100644 --- a/packages/common/docs/interfaces/_types_.chain.md +++ b/packages/common/docs/interfaces/_types_.chain.md @@ -13,6 +13,9 @@ * [bootstrapNodes](_types_.chain.md#bootstrapnodes) * [chainId](_types_.chain.md#chainid) * [comment](_types_.chain.md#comment) +* [consensus](_types_.chain.md#optional-consensus) +* [defaultHardfork](_types_.chain.md#optional-defaulthardfork) +* [dnsNetworks](_types_.chain.md#optional-dnsnetworks) * [genesis](_types_.chain.md#genesis) * [hardforks](_types_.chain.md#hardforks) * [name](_types_.chain.md#name) @@ -25,7 +28,7 @@ • **bootstrapNodes**: *[BootstrapNode](_types_.bootstrapnode.md)[]* -*Defined in [types.ts:23](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L23)* +*Defined in [packages/common/src/types.ts:25](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L25)* ___ @@ -33,7 +36,7 @@ ___ • **chainId**: *number* -*Defined in [types.ts:17](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L17)* +*Defined in [packages/common/src/types.ts:17](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L17)* ___ @@ -41,7 +44,31 @@ ___ • **comment**: *string* -*Defined in [types.ts:19](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L19)* +*Defined in [packages/common/src/types.ts:21](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L21)* + +___ + +### `Optional` consensus + +• **consensus**? : *undefined | object* + +*Defined in [packages/common/src/types.ts:28](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L28)* + +___ + +### `Optional` defaultHardfork + +• **defaultHardfork**? : *undefined | string* + +*Defined in [packages/common/src/types.ts:20](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L20)* + +___ + +### `Optional` dnsNetworks + +• **dnsNetworks**? : *string[]* + +*Defined in [packages/common/src/types.ts:26](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L26)* ___ @@ -49,7 +76,7 @@ ___ • **genesis**: *[GenesisBlock](_types_.genesisblock.md)* -*Defined in [types.ts:21](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L21)* +*Defined in [packages/common/src/types.ts:23](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L23)* ___ @@ -57,7 +84,7 @@ ___ • **hardforks**: *[Hardfork](_types_.hardfork.md)[]* -*Defined in [types.ts:22](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L22)* +*Defined in [packages/common/src/types.ts:24](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L24)* ___ @@ -65,7 +92,7 @@ ___ • **name**: *string* -*Defined in [types.ts:16](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L16)* +*Defined in [packages/common/src/types.ts:16](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L16)* ___ @@ -73,7 +100,7 @@ ___ • **networkId**: *number* -*Defined in [types.ts:18](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L18)* +*Defined in [packages/common/src/types.ts:18](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L18)* ___ @@ -81,4 +108,4 @@ ___ • **url**: *string* -*Defined in [types.ts:20](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L20)* +*Defined in [packages/common/src/types.ts:22](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L22)* diff --git a/packages/common/docs/interfaces/_types_.chainstype.md b/packages/common/docs/interfaces/_types_.chainstype.md index 5c939581ab..5e426681e7 100644 --- a/packages/common/docs/interfaces/_types_.chainstype.md +++ b/packages/common/docs/interfaces/_types_.chainstype.md @@ -22,7 +22,7 @@ • **names**: *object* -*Defined in [types.ts:9](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L9)* +*Defined in [packages/common/src/types.ts:9](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L9)* #### Type declaration: diff --git a/packages/common/docs/interfaces/_types_.genesisblock.md b/packages/common/docs/interfaces/_types_.genesisblock.md index 42385f63a6..b90033746e 100644 --- a/packages/common/docs/interfaces/_types_.genesisblock.md +++ b/packages/common/docs/interfaces/_types_.genesisblock.md @@ -24,7 +24,7 @@ • **difficulty**: *number* -*Defined in [types.ts:34](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L34)* +*Defined in [packages/common/src/types.ts:47](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L47)* ___ @@ -32,7 +32,7 @@ ___ • **extraData**: *string* -*Defined in [types.ts:36](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L36)* +*Defined in [packages/common/src/types.ts:49](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L49)* ___ @@ -40,7 +40,7 @@ ___ • **gasLimit**: *number* -*Defined in [types.ts:33](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L33)* +*Defined in [packages/common/src/types.ts:46](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L46)* ___ @@ -48,7 +48,7 @@ ___ • **hash**: *string* -*Defined in [types.ts:31](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L31)* +*Defined in [packages/common/src/types.ts:44](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L44)* ___ @@ -56,7 +56,7 @@ ___ • **nonce**: *string* -*Defined in [types.ts:35](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L35)* +*Defined in [packages/common/src/types.ts:48](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L48)* ___ @@ -64,7 +64,7 @@ ___ • **stateRoot**: *string* -*Defined in [types.ts:37](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L37)* +*Defined in [packages/common/src/types.ts:50](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L50)* ___ @@ -72,4 +72,4 @@ ___ • **timestamp**: *string | null* -*Defined in [types.ts:32](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L32)* +*Defined in [packages/common/src/types.ts:45](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L45)* diff --git a/packages/common/docs/interfaces/_types_.genesisstatestype.md b/packages/common/docs/interfaces/_types_.genesisstatestype.md index 3159341be5..a0adf01ee8 100644 --- a/packages/common/docs/interfaces/_types_.genesisstatestype.md +++ b/packages/common/docs/interfaces/_types_.genesisstatestype.md @@ -22,7 +22,7 @@ • **names**: *object* -*Defined in [types.ts:2](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L2)* +*Defined in [packages/common/src/types.ts:2](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L2)* #### Type declaration: diff --git a/packages/common/docs/interfaces/_types_.hardfork.md b/packages/common/docs/interfaces/_types_.hardfork.md index 8cd468689d..d641709c4d 100644 --- a/packages/common/docs/interfaces/_types_.hardfork.md +++ b/packages/common/docs/interfaces/_types_.hardfork.md @@ -11,6 +11,7 @@ ### Properties * [block](_types_.hardfork.md#block) +* [forkHash](_types_.hardfork.md#optional-forkhash) * [name](_types_.hardfork.md#name) ## Properties @@ -19,7 +20,15 @@ • **block**: *number | null* -*Defined in [types.ts:42](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L42)* +*Defined in [packages/common/src/types.ts:55](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L55)* + +___ + +### `Optional` forkHash + +• **forkHash**? : *string | null* + +*Defined in [packages/common/src/types.ts:56](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L56)* ___ @@ -27,4 +36,4 @@ ___ • **name**: *string* -*Defined in [types.ts:41](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L41)* +*Defined in [packages/common/src/types.ts:54](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/types.ts#L54)* diff --git a/packages/common/docs/modules/_eips_index_.md b/packages/common/docs/modules/_eips_index_.md deleted file mode 100644 index a281383db8..0000000000 --- a/packages/common/docs/modules/_eips_index_.md +++ /dev/null @@ -1,35 +0,0 @@ -[@ethereumjs/common](../README.md) › ["eips/index"](_eips_index_.md) - -# Module: "eips/index" - -## Index - -### Object literals - -* [EIPs](_eips_index_.md#const-eips) - -## Object literals - -### `Const` EIPs - -### ▪ **EIPs**: *object* - -*Defined in [eips/index.ts:3](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/eips/index.ts#L3)* - -### 2315 - -• **2315**: *any* = require('./2315.json') - -*Defined in [eips/index.ts:4](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/eips/index.ts#L4)* - -### 2537 - -• **2537**: *any* = require('./2537.json') - -*Defined in [eips/index.ts:5](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/eips/index.ts#L5)* - -### 2929 - -• **2929**: *any* = require('./2929.json') - -*Defined in [eips/index.ts:6](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/eips/index.ts#L6)* diff --git a/packages/common/docs/modules/_genesisstates_index_.md b/packages/common/docs/modules/_genesisstates_index_.md index 8144eb15d0..24556b7f7c 100644 --- a/packages/common/docs/modules/_genesisstates_index_.md +++ b/packages/common/docs/modules/_genesisstates_index_.md @@ -15,7 +15,7 @@ ▸ **genesisStateById**(`id`: number): *any* -*Defined in [genesisStates/index.ts:23](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/genesisStates/index.ts#L23)* +*Defined in [packages/common/src/genesisStates/index.ts:23](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/genesisStates/index.ts#L23)* Returns the genesis state by network ID @@ -35,7 +35,7 @@ ___ ▸ **genesisStateByName**(`name`: string): *any* -*Defined in [genesisStates/index.ts:32](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/genesisStates/index.ts#L32)* +*Defined in [packages/common/src/genesisStates/index.ts:32](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/common/src/genesisStates/index.ts#L32)* Returns the genesis state by network name diff --git a/packages/common/package.json b/packages/common/package.json index 1ca70779c2..4fba801a1f 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@ethereumjs/common", - "version": "2.0.0", + "version": "2.1.0", "description": "Resources common to all Ethereum implementations", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index 95600df693..65881cb35a 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -23,7 +23,7 @@ export interface Chain { genesis: GenesisBlock hardforks: Hardfork[] bootstrapNodes: BootstrapNode[] - dnsNetwork?: string[] + dnsNetworks?: string[] // TODO: make mandatory in next breaking release consensus?: { type: string diff --git a/packages/common/typedoc.js b/packages/common/typedoc.js index 13b5beb3f7..a31a6fe5e5 100644 --- a/packages/common/typedoc.js +++ b/packages/common/typedoc.js @@ -2,10 +2,17 @@ module.exports = { inputFiles: ['src/*.ts', 'src/genesisStates/*.ts'], mode: 'library', out: 'docs', - plugin: 'typedoc-plugin-markdown', + plugin: [ + 'typedoc-plugin-markdown', + ], readme: 'none', gitRevision: 'master', - exclude: ['tests/**/*.ts', 'src/chains/*.ts', 'src/hardforks/*.ts'], + exclude: [ + 'tests/**/**', + 'src/chains/**', + 'src/eips/**', + 'src/hardforks/**' + ], excludeNotExported: true, excludePrivate: true, excludeProtected: true, diff --git a/packages/devp2p/package.json b/packages/devp2p/package.json index 9f4887794c..d71ceb7cf2 100644 --- a/packages/devp2p/package.json +++ b/packages/devp2p/package.json @@ -51,7 +51,7 @@ "test": "tape -r ts-node/register ./test/index.ts" }, "dependencies": { - "@ethereumjs/common": "^2.0.0", + "@ethereumjs/common": "^2.1.0", "@types/bl": "^2.1.0", "@types/k-bucket": "^5.0.0", "@types/lru-cache": "^5.1.0", @@ -71,7 +71,7 @@ "secp256k1": "^4.0.2" }, "devDependencies": { - "@ethereumjs/block": "^3.0.0", + "@ethereumjs/block": "^3.1.0", "@ethereumjs/config-coverage": "^2.0.0", "@ethereumjs/config-typescript": "^2.0.0", "@ethereumjs/eslint-config-defaults": "^2.0.0", diff --git a/packages/ethash/package.json b/packages/ethash/package.json index 1f0dcba0ce..cf2504183f 100644 --- a/packages/ethash/package.json +++ b/packages/ethash/package.json @@ -40,7 +40,7 @@ "miller-rabin": "^4.0.0" }, "devDependencies": { - "@ethereumjs/block": "^3.0.0", + "@ethereumjs/block": "^3.1.0", "@ethereumjs/config-coverage": "^2.0.0", "@ethereumjs/config-typescript": "^2.0.0", "@ethereumjs/eslint-config-defaults": "^2.0.0", diff --git a/packages/tx/CHANGELOG.md b/packages/tx/CHANGELOG.md index 3d7357cda6..f5867b56af 100644 --- a/packages/tx/CHANGELOG.md +++ b/packages/tx/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) Follow-up release on `v3.0.1` which only partly addressed a **critical** bug. An update is - again - strongly recommended. - Fixes `tx.isSigned()` always returning true when using the `Tx.fromValuesArray()` static constructor, see PR [#1077](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1077) +- The `Common` instance passed is now copied to avoid side-effects towards the outer common instance on HF updates, PR [#1088](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1088) ## 3.0.1 - 2021-01-20 diff --git a/packages/tx/package.json b/packages/tx/package.json index e56e71a895..2765e1de25 100644 --- a/packages/tx/package.json +++ b/packages/tx/package.json @@ -31,7 +31,7 @@ "author": "mjbecze ", "license": "MPL-2.0", "dependencies": { - "@ethereumjs/common": "^2.0.0", + "@ethereumjs/common": "^2.1.0", "ethereumjs-util": "^7.0.8" }, "devDependencies": { diff --git a/packages/vm/CHANGELOG.md b/packages/vm/CHANGELOG.md index d0af356749..1b9981f114 100644 --- a/packages/vm/CHANGELOG.md +++ b/packages/vm/CHANGELOG.md @@ -6,6 +6,86 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) (modification: no type change headlines) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +### 5.1.0 - 2021-02-22 + +### Clique/PoA Support + +This release introduces Clique/PoA support, see the main PR [#1032](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1032) as well as the follow-up PRs [#1074](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1074) and PR [#1088](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1088). This means that you now can run a VM with blocks or transactions from the main PoA networks `Goerli` and `Rinkeby` and generally can use the VM in a Clique/PoA context. + +Here is a simple example: + +```typescript +import VM from '@ethereumjs/vm' +import Common from '@ethereumjs/common' + +const common = new Common({ chain: 'goerli' }) +const hardforkByBlockNumber = true +const vm = new VM({ common, hardforkByBlockNumber }) + +const serialized = Buffer.from('f901f7a06bfee7294bf4457...', 'hex') +const block = Block.fromRLPSerializedBlock(serialized, { hardforkByBlockNumber }) +const result = await vm.runBlock(block) +``` + +All the corresponding internal dependencies have been updated to Clique/PoA supporting versions, namely: + +- @ethereumjs/block -> `v3.1.0` +- @ethereumjs/blockchain -> `v5.1.0` +- @ethereumjs/common" -> `v2.1.0` + +Note that you need to also use library versions equal or higher than the ones mentioned above when you pass in an instance from one of the libraries to an API call (e.g. `VM.runBlock()`, see example above) to ensure everything is working properly in a Clique/PoA context. + +New VM behavior in a Clique/PoA context: + +- `VM.runBlock()`: If you do block validation along block runs blocks are now validated to comply with the various Clique/PoA block format specifications (various `extraData` checks e.g.) +- `VM.runBlock()`: There is no assignment of block rewards to the `coinbase` account taking place +- `VM.runTx()`: Tx fees are attributed to the block signer instead of the `coinbase` account +- `COINBASE` opcode: The `COINBASE` opcode returns the block signer instead of the `coinbase` address (Clique specification) + +### StateManager Checkpointing Performance + +This is the first release which reliably exposes performance gains on all checkpointing operations by integrating the respective `merkle-patricia-trie` [v4.1.0](https://github.com/ethereumjs/ethereumjs-monorepo/releases/tag/merkle-patricia-tree%404.1.0) where the checkpointing mechanism has been reworked substantially. + +This leads to linearly growing performance gains on all checkpointing operations (in `VM.runBlock()`, `VM.runTx()` as well as along all `message` calls) along with the size of the trie (state) being operated upon. In practice we have seen 10-50x increases when working on blocks from `mainnet` or the other test networks. + +We would be happy on some feedback if this integration is noticeable in your execution context! 😀 + +### New EIPs + +#### EIP-2565: ModExp precompile gas cost + +This release adds support for [EIP 2565](https://eips.ethereum.org/EIPS/eip-2565), ModExp precompile gas cost, which is planned to be included in the Berlin hardfork, see PR [#1026](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1026). + +#### VM Debug Logger + +The VM now comes with an integrated debug logger which gives you fine-grained control to display selected log output along the VM execution flow, see PR [#1080](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1080). These loggers use the [debug](https://github.com/visionmedia/debug) library and can be activated on the CL with `DEBUG=[Logger Selection] node [Your Script to Run].js` and produce output like the following: + +![EthereumJS VM Debug Logger](./debug.png?raw=true) + +For an overview on the different loggers available see the respective [README section](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/vm#understanding-the-vm). + +### Other Features + +- The `afterBlock` (`VM.runBlock()`) and `afterTx` (`VM.runTx()`) events now expose the respective block or transaction in the event results, PR [#965](https://github.com/ethereumjs/ethereumjs-monorepo/pull/965) +- New `hardforkByBlockNumber` VM constructor option for `VM.runBlock()` runs (see also corresponding `Block` option), PR [#966](https://github.com/ethereumjs/ethereumjs-monorepo/pull/966) and [#967](https://github.com/ethereumjs/ethereumjs-monorepo/pull/967) (option renamed along release PR) +- Added new optional `maxBlocks` option to `VM.runBlockchain()`, PR [#1025](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1025) +- `VM.runBlockchain()` now returns the number of actual blocks run (needs `Blockchain` `v5.1.0` or higher, `void` kept in `TypeScript` function signature for backwards-compatibility), PR [#1065](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1065) +- New option `skipBlockGasLimitValidation` to disable the block gas limit check in `VM.runTx()`, PR [#1039](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1039) +- Added type definition `Log` for logs in `TxReceipt` items returned (result of `VM.runBlocks()` and `afterBlock` event), PR [#1084](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1084) + +### Bug Fixes + +- **Consensus**: fixed `Frontier` consensus bug along `CREATE` with not enough gas, PR [#1081](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1081) +- Update opcodes along HF switches, added a dedicated `tangerineWhistle` opcode list (no need for calls to `VM._updateOpcodes()` on HF switches manually any more), PR [#1101](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1101) and [#1112](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1112) +- Use `common` from VM when creating default blocks in `VM.runCall()` and `VM.runCode()`, PR [#1011](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1011) +- Fixed a bug when the result of the `MODEXP` opcode is 0, PR [#1026](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1026) + +### Maintenance + +- Updated `run-solidity-contract` example, PR [#1104](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1104) +- Updated `ethereum/tests` submodule to `1fcd4e5` (2021-02-02), PR [#1116](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1116) +- Only expose API method on docs, PR [#1119](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1119) + ## 5.0.0 - 2020-11-24 ### New Package Name diff --git a/packages/vm/README.md b/packages/vm/README.md index 5b20ae132d..f1cd97f3ee 100644 --- a/packages/vm/README.md +++ b/packages/vm/README.md @@ -75,6 +75,37 @@ To build the VM for standalone use in the browser, see: [Running the VM in a bro # SETUP +## Chain Support + +Starting with `v5.1.0` the VM supports running both `Ethash/PoW` and `Clique/PoA` blocks and transactions. Clique support has been added along the work on PR [#1032](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1032) and follow-up PRs and (block) validation checks and the switch of the execution context now happens correctly. + +### Ethash/PoW Chains + +`@ethereumjs/blockchain` validates the PoW algorithm with `@ethereumjs/ethash` and validates blocks' difficulty to match their canonical difficulty. + +### Clique/PoA Chains + +For the VM to work correctly in a `Clique/PoA` context you need to use the library with the following library versions or higher: + +- @ethereumjs/block -> `v3.1.0` +- @ethereumjs/blockchain -> `v5.1.0` +- @ethereumjs/common" -> `v2.1.0` + +The following is a simple example for a block run on `Goerli`: + +```typescript +import VM from '@ethereumjs/vm' +import Common from '@ethereumjs/common' + +const common = new Common({ chain: 'goerli' }) +const hardforkByBlockNumber = true +const vm = new VM({ common, hardforkByBlockNumber }) + +const serialized = Buffer.from('f901f7a06bfee7294bf4457...', 'hex') +const block = Block.fromRLPSerializedBlock(serialized, { hardforkByBlockNumber }) +const result = await vm.runBlock(block) +``` + ## Hardfork Support Starting with the `v5` release series all hardforks from `Frontier` (`chainstart`) up to the latest active mainnet hardfork are supported. diff --git a/packages/vm/docs/interfaces/_index_.vmopts.md b/packages/vm/docs/interfaces/_index_.vmopts.md index 418caa4062..39f2954a54 100644 --- a/packages/vm/docs/interfaces/_index_.vmopts.md +++ b/packages/vm/docs/interfaces/_index_.vmopts.md @@ -16,7 +16,7 @@ Options for instantiating a [VM](../classes/_index_.vm.md). * [allowUnlimitedContractSize](_index_.vmopts.md#optional-allowunlimitedcontractsize) * [blockchain](_index_.vmopts.md#optional-blockchain) * [common](_index_.vmopts.md#optional-common) -* [selectHardforkByBlockNumber](_index_.vmopts.md#optional-selecthardforkbyblocknumber) +* [hardforkByBlockNumber](_index_.vmopts.md#optional-hardforkbyblocknumber) * [state](_index_.vmopts.md#optional-state) * [stateManager](_index_.vmopts.md#optional-statemanager) @@ -98,9 +98,9 @@ Default setup if no `Common` instance is provided: ___ -### `Optional` selectHardforkByBlockNumber +### `Optional` hardforkByBlockNumber -• **selectHardforkByBlockNumber**? : *undefined | false | true* +• **hardforkByBlockNumber**? : *undefined | false | true* *Defined in [index.ts:98](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L98)* diff --git a/packages/vm/lib/index.ts b/packages/vm/lib/index.ts index 13ccc12b15..cca5a5f801 100644 --- a/packages/vm/lib/index.ts +++ b/packages/vm/lib/index.ts @@ -95,7 +95,7 @@ export interface VMOpts { * * Default: `false` */ - selectHardforkByBlockNumber?: boolean + hardforkByBlockNumber?: boolean } /** @@ -120,7 +120,7 @@ export default class VM extends AsyncEventEmitter { protected _isInitialized: boolean = false protected readonly _allowUnlimitedContractSize: boolean protected _opcodes: OpcodeList - protected readonly _selectHardforkByBlockNumber: boolean + protected readonly _hardforkByBlockNumber: boolean /** * Cached emit() function, not for public usage @@ -214,7 +214,7 @@ export default class VM extends AsyncEventEmitter { this._allowUnlimitedContractSize = opts.allowUnlimitedContractSize || false - this._selectHardforkByBlockNumber = opts.selectHardforkByBlockNumber ?? false + this._hardforkByBlockNumber = opts.hardforkByBlockNumber ?? false if (this._common.eips().includes(2537)) { if (IS_BROWSER) { diff --git a/packages/vm/lib/runBlock.ts b/packages/vm/lib/runBlock.ts index 77d7962641..eb906fec48 100644 --- a/packages/vm/lib/runBlock.ts +++ b/packages/vm/lib/runBlock.ts @@ -131,7 +131,7 @@ export default async function runBlock(this: VM, opts: RunBlockOpts): Promise { t.end() }) -tape('should correctly use the selectHardforkByBlockNumber option', async (t) => { +tape('should correctly use the hardforkByBlockNumber option', async (t) => { const common1 = new Common({ chain: 'mainnet', hardfork: 'muirGlacier', @@ -148,7 +148,7 @@ tape('should correctly use the selectHardforkByBlockNumber option', async (t) => ) } - const vm = new VM({ common: common1, selectHardforkByBlockNumber: true }) + const vm = new VM({ common: common1, hardforkByBlockNumber: true }) const vm_noSelect = new VM({ common: common2 }) const txResultMuirGlacier = await vm.runBlock({