Skip to content

Commit fa84b93

Browse files
authored
Merge pull request #1120 from ethereumjs/new-clique-minor-releases
New Clique Minor Release Series
2 parents e0fd561 + a04c538 commit fa84b93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1691
-1071
lines changed

packages/block/CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,38 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
(modification: no type change headlines) and this project adheres to
77
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).
88

9+
## 3.1.0 - 2021-02-22
10+
11+
### Clique/PoA Support
12+
13+
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.
14+
15+
For sealing a block on instantiation there is a new `cliqueSigner` constructor option:
16+
17+
```typescript
18+
const cliqueSigner = Buffer.from('PRIVATE_KEY_HEX_STRING', 'hex')
19+
const block = Block.fromHeaderData(headerData, { cliqueSigner })
20+
```
21+
22+
Additionally there are the following new utility methods for Clique/PoA related functionality in the `BlockHeader` class:
23+
24+
- `BlockHeader.validateCliqueDifficulty(blockchain: Blockchain): boolean`
25+
- `BlockHeader.cliqueSigHash()`
26+
- `BlockHeader.cliqueIsEpochTransition(): boolean`
27+
- `BlockHeader.cliqueExtraVanity(): Buffer`
28+
- `BlockHeader.cliqueExtraSeal(): Buffer`
29+
- `BlockHeader.cliqueEpochTransitionSigners(): Address[]`
30+
- `BlockHeader.cliqueVerifySignature(signerList: Address[]): boolean`
31+
- `BlockHeader.cliqueSigner(): Address`
32+
33+
See the API docs for a detailed documentation. Note that these methods will throw if called in a non-Clique/PoA context.
34+
35+
### Other Changes
36+
37+
- 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)
38+
- 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)
39+
- 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)
40+
941
## 3.0.0 - 2020-11-24
1042

1143
### New Package Name

packages/block/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,62 @@ try {
5757

5858
[Documentation](./docs/README.md)
5959

60+
# CONSENSUS TYPES
61+
62+
The block library supports the creation as well as format and consensus validation of PoW `ethash` and PoA `clique` blocks.
63+
64+
## Ethash/PoW
65+
66+
An Ethash/PoW block can be instantiated as follows:
67+
68+
```typescript
69+
import { Block } from '@ethereumjs/block'
70+
import Common from '@ethereumjs/common'
71+
const common = new Common({ chain: 'mainnet' })
72+
console.log(common.consensusType()) // 'pow'
73+
console.log(common.consensusAlgorithm()) // 'ethash'
74+
const block = Block.fromBlockData({}, { common })
75+
```
76+
77+
To validate that the difficulty of the block matches the canonical difficulty use `block.validate(blockchain)`.
78+
79+
To calculate the difficulty when creating the block pass in the block option `calcDifficultyFromHeader` with the preceding (parent) `BlockHeader`.
80+
81+
## Clique/PoA (since v3.1.0)
82+
83+
A clique block can be instantiated as follows:
84+
85+
```typescript
86+
import { Block } from '@ethereumjs/block'
87+
import Common from '@ethereumjs/common'
88+
const common = new Common({ chain: 'goerli' })
89+
console.log(common.consensusType()) // 'poa'
90+
console.log(common.consensusAlgorithm()) // 'clique'
91+
const block = Block.fromBlockData({}, { common })
92+
```
93+
94+
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.
95+
96+
For sealing a block on instantiation you can use the `cliqueSigner` constructor option:
97+
98+
```typescript
99+
const cliqueSigner = Buffer.from('PRIVATE_KEY_HEX_STRING', 'hex')
100+
const block = Block.fromHeaderData(headerData, { cliqueSigner })
101+
```
102+
103+
Additionally there are the following utility methods for Clique/PoA related functionality in the `BlockHeader` class:
104+
105+
- `BlockHeader.validateCliqueDifficulty(blockchain: Blockchain): boolean`
106+
- `BlockHeader.cliqueSigHash()`
107+
- `BlockHeader.cliqueIsEpochTransition(): boolean`
108+
- `BlockHeader.cliqueExtraVanity(): Buffer`
109+
- `BlockHeader.cliqueExtraSeal(): Buffer`
110+
- `BlockHeader.cliqueEpochTransitionSigners(): Address[]`
111+
- `BlockHeader.cliqueVerifySignature(signerList: Address[]): boolean`
112+
- `BlockHeader.cliqueSigner(): Address`
113+
114+
See the API docs for detailed documentation. Note that these methods will throw if called in a non-Clique/PoA context.
115+
60116
# TESTING
61117

62118
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.

packages/block/docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Modules
88

99
* ["block"](modules/_block_.md)
10+
* ["clique"](modules/_clique_.md)
1011
* ["from-rpc"](modules/_from_rpc_.md)
1112
* ["header"](modules/_header_.md)
1213
* ["header-from-rpc"](modules/_header_from_rpc_.md)

packages/block/docs/classes/_block_.block.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ An object that represents the block.
5050

5151
\+ **new Block**(`header?`: [BlockHeader](_header_.blockheader.md), `transactions`: Transaction[], `uncleHeaders`: [BlockHeader](_header_.blockheader.md)[], `opts`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[Block](_block_.block.md)*
5252

53-
*Defined in [block.ts:92](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L92)*
53+
*Defined in [block.ts:107](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L107)*
5454

5555
This constructor takes the values, validates them, assigns them and freezes the object.
5656
Use the static factory methods to assist in creating a Block object from varying data types and options.
@@ -112,7 +112,7 @@ ___
112112

113113
**canonicalDifficulty**(`parentBlock`: [Block](_block_.block.md)): *BN*
114114

115-
*Defined in [block.ts:286](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L286)*
115+
*Defined in [block.ts:307](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L307)*
116116

117117
Returns the canonical difficulty for this block.
118118

@@ -130,7 +130,7 @@ ___
130130

131131
**genTxTrie**(): *Promise‹void›*
132132

133-
*Defined in [block.ts:150](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L150)*
133+
*Defined in [block.ts:168](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L168)*
134134

135135
Generates transaction trie for validation.
136136

@@ -142,7 +142,7 @@ ___
142142

143143
**hash**(): *Buffer*
144144

145-
*Defined in [block.ts:129](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L129)*
145+
*Defined in [block.ts:147](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L147)*
146146

147147
Produces a hash the RLP of the block.
148148

@@ -154,7 +154,7 @@ ___
154154

155155
**isGenesis**(): *boolean*
156156

157-
*Defined in [block.ts:136](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L136)*
157+
*Defined in [block.ts:154](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L154)*
158158

159159
Determines if this block is the genesis block.
160160

@@ -166,7 +166,7 @@ ___
166166

167167
**raw**(): *[BlockBuffer](../modules/_index_.md#blockbuffer)*
168168

169-
*Defined in [block.ts:118](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L118)*
169+
*Defined in [block.ts:136](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L136)*
170170

171171
Returns a Buffer Array of the raw Buffers of this block, in order.
172172

@@ -178,7 +178,7 @@ ___
178178

179179
**serialize**(): *Buffer*
180180

181-
*Defined in [block.ts:143](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L143)*
181+
*Defined in [block.ts:161](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L161)*
182182

183183
Returns the rlp encoding of the block.
184184

@@ -190,7 +190,7 @@ ___
190190

191191
**toJSON**(): *[JsonBlock](../interfaces/_index_.jsonblock.md)*
192192

193-
*Defined in [block.ts:312](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L312)*
193+
*Defined in [block.ts:333](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L333)*
194194

195195
Returns the block in JSON format.
196196

@@ -202,7 +202,7 @@ ___
202202

203203
**validate**(`blockchain`: [Blockchain](../interfaces/_index_.blockchain.md)): *Promise‹void›*
204204

205-
*Defined in [block.ts:209](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L209)*
205+
*Defined in [block.ts:229](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L229)*
206206

207207
Performs the following consistency checks on the block:
208208

@@ -227,7 +227,7 @@ ___
227227

228228
**validateData**(): *Promise‹void›*
229229

230-
*Defined in [block.ts:222](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L222)*
230+
*Defined in [block.ts:242](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L242)*
231231

232232
Validates the block data, throwing if invalid.
233233
This can be checked on the Block itself without needing access to any parent block
@@ -244,7 +244,7 @@ ___
244244

245245
**validateDifficulty**(`parentBlock`: [Block](_block_.block.md)): *boolean*
246246

247-
*Defined in [block.ts:295](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L295)*
247+
*Defined in [block.ts:316](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L316)*
248248

249249
Checks that the block's `difficulty` matches the canonical difficulty.
250250

@@ -262,7 +262,7 @@ ___
262262

263263
**validateGasLimit**(`parentBlock`: [Block](_block_.block.md)): *boolean*
264264

265-
*Defined in [block.ts:305](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L305)*
265+
*Defined in [block.ts:326](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L326)*
266266

267267
Validates if the block gasLimit remains in the
268268
boundaries set by the protocol.
@@ -281,15 +281,15 @@ ___
281281

282282
**validateTransactions**(): *boolean*
283283

284-
*Defined in [block.ts:181](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L181)*
284+
*Defined in [block.ts:201](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L201)*
285285

286286
Validates transaction signatures and minimum gas requirements.
287287

288288
**Returns:** *boolean*
289289

290290
**validateTransactions**(`stringError`: false): *boolean*
291291

292-
*Defined in [block.ts:182](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L182)*
292+
*Defined in [block.ts:202](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L202)*
293293

294294
**Parameters:**
295295

@@ -301,7 +301,7 @@ Name | Type |
301301

302302
**validateTransactions**(`stringError`: true): *string[]*
303303

304-
*Defined in [block.ts:183](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L183)*
304+
*Defined in [block.ts:203](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L203)*
305305

306306
**Parameters:**
307307

@@ -317,7 +317,7 @@ ___
317317

318318
**validateTransactionsTrie**(): *Promise‹boolean›*
319319

320-
*Defined in [block.ts:164](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L164)*
320+
*Defined in [block.ts:182](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L182)*
321321

322322
Validates the transaction trie by generating a trie
323323
and do a check on the root hash.
@@ -330,7 +330,7 @@ ___
330330

331331
**validateUncles**(`blockchain`: [Blockchain](../interfaces/_index_.blockchain.md)): *Promise‹void›*
332332

333-
*Defined in [block.ts:262](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L262)*
333+
*Defined in [block.ts:283](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L283)*
334334

335335
Consistency checks and header validation for uncles included,
336336
in the block, if any.
@@ -359,7 +359,7 @@ ___
359359

360360
**validateUnclesHash**(): *boolean*
361361

362-
*Defined in [block.ts:241](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L241)*
362+
*Defined in [block.ts:262](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L262)*
363363

364364
Validates the uncle's hash.
365365

@@ -388,7 +388,7 @@ ___
388388

389389
**fromRLPSerializedBlock**(`serialized`: Buffer, `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[Block](_block_.block.md)‹›*
390390

391-
*Defined in [block.ts:46](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L46)*
391+
*Defined in [block.ts:53](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L53)*
392392

393393
**Parameters:**
394394

@@ -405,7 +405,7 @@ ___
405405

406406
**fromValuesArray**(`values`: [BlockBuffer](../modules/_index_.md#blockbuffer), `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[Block](_block_.block.md)‹›*
407407

408-
*Defined in [block.ts:56](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L56)*
408+
*Defined in [block.ts:63](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L63)*
409409

410410
**Parameters:**
411411

@@ -422,7 +422,7 @@ ___
422422

423423
**genesis**(`blockData`: [BlockData](../interfaces/_index_.blockdata.md), `opts?`: [BlockOptions](../interfaces/_index_.blockoptions.md)): *[Block](_block_.block.md)‹›*
424424

425-
*Defined in [block.ts:89](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L89)*
425+
*Defined in [block.ts:104](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/src/block.ts#L104)*
426426

427427
Alias for Block.fromBlockData() with initWithGenesisHeader set to true.
428428

0 commit comments

Comments
 (0)