@@ -55,11 +55,6 @@ use trace::{NoopTracer, NoopVMTracer};
55
55
56
56
pub use ethash:: OptimizeFor ;
57
57
58
- // helper for formatting errors.
59
- fn fmt_err < F : :: std:: fmt:: Display > ( f : F ) -> String {
60
- format ! ( "Spec json is invalid: {}" , f)
61
- }
62
-
63
58
/// Runtime parameters for the spec that are related to how the software should run the chain,
64
59
/// rather than integral properties of the chain itself.
65
60
pub struct SpecParams < ' a > {
@@ -219,7 +214,7 @@ pub struct Spec {
219
214
/// Contract constructors to be executed on genesis.
220
215
pub constructors : Vec < ( Address , Bytes ) > ,
221
216
/// May be prepopulated if we know this in advance.
222
- pub state_root_memo : H256 ,
217
+ pub state_root : H256 ,
223
218
/// Genesis state as plain old data.
224
219
pub genesis_state : PodState ,
225
220
}
@@ -279,7 +274,7 @@ fn load_from(spec_params: SpecParams, s: ethjson::spec::Spec) -> Result<Spec, Er
279
274
. collect ( ) ;
280
275
let genesis_state: PodState = s. accounts . into ( ) ;
281
276
282
- let ( state_root_memo , _) = run_constructors (
277
+ let ( state_root , _) = run_constructors (
283
278
& genesis_state,
284
279
& constructors,
285
280
& * engine,
@@ -308,7 +303,7 @@ fn load_from(spec_params: SpecParams, s: ethjson::spec::Spec) -> Result<Spec, Er
308
303
hardcoded_sync,
309
304
constructors,
310
305
genesis_state,
311
- state_root_memo ,
306
+ state_root ,
312
307
} ;
313
308
314
309
Ok ( s)
@@ -351,11 +346,6 @@ impl Spec {
351
346
}
352
347
}
353
348
354
- /// Return the state root for the genesis state, memoising accordingly.
355
- pub fn state_root ( & self ) -> H256 {
356
- self . state_root_memo
357
- }
358
-
359
349
/// Get common blockchain parameters.
360
350
pub fn params ( & self ) -> & CommonParams {
361
351
& self . engine . params ( )
@@ -391,7 +381,7 @@ impl Spec {
391
381
header. set_transactions_root ( self . transactions_root . clone ( ) ) ;
392
382
header. set_uncles_hash ( keccak ( RlpStream :: new_list ( 0 ) . out ( ) ) ) ;
393
383
header. set_extra_data ( self . extra_data . clone ( ) ) ;
394
- header. set_state_root ( self . state_root ( ) ) ;
384
+ header. set_state_root ( self . state_root ) ;
395
385
header. set_receipts_root ( self . receipts_root . clone ( ) ) ;
396
386
header. set_log_bloom ( Bloom :: default ( ) ) ;
397
387
header. set_gas_used ( self . gas_used . clone ( ) ) ;
@@ -445,13 +435,13 @@ impl Spec {
445
435
BasicBackend ( journaldb:: new_memory_db ( ) ) ,
446
436
) ?;
447
437
448
- self . state_root_memo = root;
438
+ self . state_root = root;
449
439
Ok ( ( ) )
450
440
}
451
441
452
442
/// Ensure that the given state DB has the trie nodes in for the genesis state.
453
443
pub fn ensure_db_good < T : Backend > ( & self , db : T , factories : & Factories ) -> Result < T , Error > {
454
- if db. as_hash_db ( ) . contains ( & self . state_root ( ) , hash_db:: EMPTY_PREFIX ) {
444
+ if db. as_hash_db ( ) . contains ( & self . state_root , hash_db:: EMPTY_PREFIX ) {
455
445
return Ok ( db) ;
456
446
}
457
447
@@ -468,14 +458,14 @@ impl Spec {
468
458
db
469
459
) ?;
470
460
471
- assert_eq ! ( root, self . state_root( ) , "Spec's state root has not been precomputed correctly." ) ;
461
+ assert_eq ! ( root, self . state_root, "Spec's state root has not been precomputed correctly." ) ;
472
462
Ok ( db)
473
463
}
474
464
475
465
/// Loads just the state machine from a json file.
476
- pub fn load_machine < R : Read > ( reader : R ) -> Result < Machine , String > {
466
+ pub fn load_machine < R : Read > ( reader : R ) -> Result < Machine , Error > {
477
467
ethjson:: spec:: Spec :: load ( reader)
478
- . map_err ( fmt_err )
468
+ . map_err ( |e| Error :: Msg ( e . to_string ( ) ) )
479
469
. map ( |s| {
480
470
let builtins = s. accounts . builtins ( ) . into_iter ( ) . map ( |p| ( p. 0 . into ( ) , From :: from ( p. 1 ) ) ) . collect ( ) ;
481
471
let params = CommonParams :: from ( s. params ) ;
@@ -485,10 +475,10 @@ impl Spec {
485
475
486
476
/// Loads spec from json file. Provide factories for executing contracts and ensuring
487
477
/// storage goes to the right place.
488
- pub fn load < ' a , T : Into < SpecParams < ' a > > , R : Read > ( params : T , reader : R ) -> Result < Self , String > {
478
+ pub fn load < ' a , T : Into < SpecParams < ' a > > , R : Read > ( params : T , reader : R ) -> Result < Self , Error > {
489
479
ethjson:: spec:: Spec :: load ( reader)
490
- . map_err ( fmt_err )
491
- . and_then ( |x| load_from ( params. into ( ) , x) . map_err ( fmt_err ) )
480
+ . map_err ( |e| Error :: Msg ( e . to_string ( ) ) )
481
+ . and_then ( |x| load_from ( params. into ( ) , x) )
492
482
}
493
483
494
484
/// initialize genesis epoch data, using in-memory database for
@@ -570,7 +560,7 @@ mod tests {
570
560
let test_spec = spec:: new_test ( ) ;
571
561
572
562
assert_eq ! (
573
- test_spec. state_root( ) ,
563
+ test_spec. state_root,
574
564
H256 :: from_str( "f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9" ) . unwrap( )
575
565
) ;
576
566
let genesis = test_spec. genesis_block ( ) ;
@@ -588,7 +578,7 @@ mod tests {
588
578
. unwrap ( ) ;
589
579
let state = State :: from_existing (
590
580
db. boxed_clone ( ) ,
591
- spec. state_root ( ) ,
581
+ spec. state_root ,
592
582
spec. engine . account_start_nonce ( 0 ) ,
593
583
Default :: default ( ) ,
594
584
) . unwrap ( ) ;
0 commit comments