@@ -93,10 +93,26 @@ export interface BlockchainOptions {
93
93
db ?: any
94
94
95
95
/**
96
- * This the flag indicates if blocks should be validated (e.g. Proof-of-Work), latest HF rules
97
- * supported: `Petersburg`.
96
+ * This the flag indicates if blocks and Proof-of-Work should be validated.
97
+ * This option can't be used in conjunction with `validatePow` nor `validateBlocks`.
98
+ *
99
+ * @deprecated
98
100
*/
99
101
validate ?: boolean
102
+
103
+ /**
104
+ * This flags indicates if Proof-of-work should be validated. If `validate` is provided, this
105
+ * option takes its value. If neither `validate` nor this option are provided, it defaults to
106
+ * `true`.
107
+ */
108
+ validatePow ?: boolean
109
+
110
+ /**
111
+ * This flags indicates if blocks should be validated. See Block#validate for details. If
112
+ * `validate` is provided, this option takes its value. If neither `validate` nor this option are
113
+ * provided, it defaults to `true`.
114
+ */
115
+ validateBlocks ?: boolean
100
116
}
101
117
102
118
/**
@@ -158,9 +174,14 @@ export default class Blockchain implements BlockchainInterface {
158
174
ethash : any
159
175
160
176
/**
161
- * A flag indicating if this Blockchain validates blocks or not.
177
+ * This field is always `true`. It's here only for backwards compatibility.
178
+ *
179
+ * @deprecated
162
180
*/
163
- validate : boolean
181
+ public readonly validate : boolean = true
182
+
183
+ private readonly _validatePow : boolean
184
+ private readonly _validateBlocks : boolean
164
185
165
186
/**
166
187
* Creates new Blockchain object
@@ -179,11 +200,27 @@ export default class Blockchain implements BlockchainInterface {
179
200
this . _common = new Common ( chain , hardfork )
180
201
}
181
202
203
+ if ( opts . validate !== undefined ) {
204
+ if ( opts . validatePow !== undefined || opts . validateBlocks !== undefined ) {
205
+ throw new Error (
206
+ "opts.validate can't be used at the same time than opts.validatePow nor opts.validateBlocks" ,
207
+ )
208
+ }
209
+ }
210
+
182
211
// defaults
212
+
213
+ if ( opts . validate !== undefined ) {
214
+ this . _validatePow = opts . validate
215
+ this . _validateBlocks = opts . validate
216
+ } else {
217
+ this . _validatePow = opts . validatePow !== undefined ? opts . validatePow : true
218
+ this . _validateBlocks = opts . validateBlocks !== undefined ? opts . validateBlocks : true
219
+ }
220
+
183
221
this . db = opts . db ? opts . db : level ( )
184
222
this . dbManager = new DBManager ( this . db , this . _common )
185
- this . validate = opts . validate === undefined ? true : opts . validate
186
- this . ethash = this . validate ? new Ethash ( this . db ) : null
223
+ this . ethash = this . _validatePow ? new Ethash ( this . db ) : null
187
224
this . _heads = { }
188
225
this . _genesis = null
189
226
this . _headHeader = null
@@ -444,7 +481,7 @@ export default class Blockchain implements BlockchainInterface {
444
481
)
445
482
446
483
function verify ( next : any ) {
447
- if ( ! self . validate ) {
484
+ if ( ! self . _validateBlocks ) {
448
485
return next ( )
449
486
}
450
487
@@ -456,7 +493,7 @@ export default class Blockchain implements BlockchainInterface {
456
493
}
457
494
458
495
function verifyPOW ( next : any ) {
459
- if ( ! self . validate ) {
496
+ if ( ! self . _validatePow ) {
460
497
return next ( )
461
498
}
462
499
0 commit comments