15
15
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
16
16
17
17
use std:: cmp;
18
- use std:: collections:: { HashSet , BTreeMap , VecDeque } ;
19
- use std:: sync:: atomic:: { AtomicUsize , AtomicBool , Ordering as AtomicOrdering } ;
18
+ use std:: collections:: { BTreeMap , HashSet , VecDeque } ;
19
+ use std:: io:: { BufRead , BufReader } ;
20
+ use std:: str:: from_utf8;
20
21
use std:: sync:: { Arc , Weak } ;
21
- use std:: time:: { Instant , Duration } ;
22
+ use std:: sync:: atomic:: { AtomicBool , AtomicUsize , Ordering as AtomicOrdering } ;
23
+ use std:: time:: { Duration , Instant } ;
22
24
23
- use account_state:: state:: StateInfo ;
24
- use blockchain:: { BlockReceipts , BlockChain , BlockChainDB , BlockProvider , TreeRoute , TransactionAddress , ExtrasInsert , BlockNumberKey } ;
25
+ use ansi_term:: Colour ;
25
26
use bytes:: Bytes ;
26
- use call_contract:: { CallContract , RegistryInfo } ;
27
- use ethcore_miner:: pool:: VerifiedTransaction ;
28
- use ethereum_types:: { H256 , H264 , Address , U256 } ;
29
- use evm:: Schedule ;
27
+ use bytes:: ToPretty ;
28
+ use ethereum_types:: { Address , H256 , H264 , U256 } ;
30
29
use hash:: keccak;
31
- use io :: IoChannel ;
30
+ use hash_db :: EMPTY_PREFIX ;
32
31
use itertools:: Itertools ;
33
- use journaldb;
34
- use kvdb:: { DBValue , KeyValueDB , DBTransaction } ;
32
+ use kvdb:: { DBTransaction , DBValue , KeyValueDB } ;
35
33
use parking_lot:: { Mutex , RwLock } ;
36
34
use rand:: rngs:: OsRng ;
37
- use trie:: { TrieSpec , TrieFactory , Trie } ;
38
- use vm:: { EnvInfo , LastHashes , CreateContractAddress } ;
39
- use hash_db:: EMPTY_PREFIX ;
40
- use block:: { LockedBlock , Drain , ClosedBlock , OpenBlock , enact_verified, SealedBlock } ;
41
- use client:: ancient_import:: AncientVerifier ;
35
+ use rlp:: PayloadInfo ;
36
+ use rustc_hex:: FromHex ;
37
+ use trie:: { Trie , TrieFactory , TrieSpec } ;
38
+
39
+ use account_state:: State ;
40
+ use account_state:: state:: StateInfo ;
41
+ use block:: { ClosedBlock , Drain , enact_verified, LockedBlock , OpenBlock , SealedBlock } ;
42
+ use blockchain:: {
43
+ BlockChain ,
44
+ BlockChainDB ,
45
+ BlockNumberKey ,
46
+ BlockProvider ,
47
+ BlockReceipts ,
48
+ ExtrasInsert ,
49
+ TransactionAddress ,
50
+ TreeRoute
51
+ } ;
52
+ // re-export
53
+ pub use blockchain:: CacheSize as BlockChainCacheSize ;
54
+ use call_contract:: { CallContract , RegistryInfo } ;
42
55
use client:: {
43
- ReopenBlock , PrepareOpenBlock , ImportSealedBlock , BroadcastProposalBlock ,
44
- Call , BlockProducer , SealedBlockImporter , EngineInfo ,
45
- ClientConfig , bad_blocks ,
56
+ bad_blocks , BlockProducer , BroadcastProposalBlock , Call ,
57
+ ClientConfig , EngineInfo , ImportSealedBlock , PrepareOpenBlock ,
58
+ ReopenBlock , SealedBlockImporter ,
46
59
} ;
60
+ use client:: ancient_import:: AncientVerifier ;
47
61
use client_traits:: {
48
- BlockInfo ,
49
- ScheduleInfo ,
50
- StateClient ,
51
- BlockChainReset ,
52
- Nonce ,
53
- Balance ,
54
- ChainInfo ,
55
- TransactionInfo ,
56
- ImportBlock ,
57
62
AccountData ,
63
+ BadBlocks ,
64
+ Balance ,
58
65
BlockChain as BlockChainTrait ,
59
66
BlockChainClient ,
67
+ BlockChainReset ,
68
+ BlockInfo ,
69
+ ChainInfo ,
70
+ ChainNotify ,
71
+ DatabaseRestore ,
72
+ ImportBlock ,
73
+ ImportExportBlocks ,
60
74
IoClient ,
61
- BadBlocks ,
75
+ Nonce ,
62
76
ProvingBlockChainClient ,
77
+ ScheduleInfo ,
78
+ SnapshotClient ,
79
+ SnapshotWriter ,
80
+ StateClient ,
63
81
StateOrBlock ,
64
- ExportBlocks ,
65
- DataFormat ,
66
- ImportBlocks
82
+ Tick ,
83
+ TransactionInfo
67
84
} ;
85
+ use db:: { keys:: BlockDetails , Readable , Writable } ;
68
86
use engine:: Engine ;
87
+ use ethcore_miner:: pool:: VerifiedTransaction ;
88
+ use ethtrie:: Layout ;
89
+ use evm:: Schedule ;
90
+ use executive_state;
91
+ use io:: IoChannel ;
92
+ use journaldb;
69
93
use machine:: {
70
94
executed:: Executed ,
71
- executive:: { Executive , TransactOptions , contract_address } ,
95
+ executive:: { contract_address , Executive , TransactOptions } ,
72
96
transaction_ext:: Transaction ,
73
97
} ;
74
- use trie_vm_factories:: { Factories , VmFactory } ;
75
98
use miner:: { Miner , MinerService } ;
76
99
use snapshot;
77
100
use spec:: Spec ;
78
- use account_state:: State ;
79
- use executive_state;
80
101
use state_db:: StateDB ;
81
- use trace:: { self , TraceDB , ImportRequest as TraceImportRequest , LocalizedTrace , Database as TraceDatabase } ;
102
+ use trace:: { self , Database as TraceDatabase , ImportRequest as TraceImportRequest , LocalizedTrace , TraceDB } ;
103
+ use trie_vm_factories:: { Factories , VmFactory } ;
82
104
use types:: {
83
105
ancestry_action:: AncestryAction ,
84
- BlockNumber ,
85
106
block:: PreverifiedBlock ,
86
107
block_status:: BlockStatus ,
87
108
blockchain_info:: BlockChainInfo ,
88
- chain_notify:: { NewBlocks , ChainRoute , ChainMessageType } ,
109
+ BlockNumber ,
110
+ call_analytics:: CallAnalytics ,
111
+ chain_notify:: { ChainMessageType , ChainRoute , NewBlocks } ,
89
112
client_types:: ClientReport ,
90
- import_route:: ImportRoute ,
91
- io_message:: ClientIoMessage ,
113
+ client_types:: Mode ,
92
114
encoded,
93
115
engines:: {
94
- ForkChoice ,
95
- SealingState ,
96
- MAX_UNCLE_AGE ,
97
116
epoch:: { PendingTransition , Transition as EpochTransition } ,
117
+ ForkChoice ,
98
118
machine:: { AuxiliaryData , Call as MachineCall } ,
119
+ MAX_UNCLE_AGE ,
120
+ SealingState ,
99
121
} ,
100
- errors:: { EngineError , ExecutionError , BlockError , EthcoreError , SnapshotError , ImportError , EthcoreResult } ,
101
- ids:: { BlockId , TransactionId , UncleId , TraceId } ,
102
- transaction:: { self , LocalizedTransaction , UnverifiedTransaction , SignedTransaction , Action , CallError } ,
122
+ errors:: { BlockError , EngineError , EthcoreError , EthcoreResult , ExecutionError , ImportError , SnapshotError } ,
103
123
filter:: Filter ,
104
- log_entry:: LocalizedLogEntry ,
105
- receipt:: { Receipt , LocalizedReceipt } ,
106
124
header:: Header ,
125
+ ids:: { BlockId , TraceId , TransactionId , UncleId } ,
126
+ import_route:: ImportRoute ,
127
+ io_message:: ClientIoMessage ,
128
+ log_entry:: LocalizedLogEntry ,
129
+ pruning_info:: PruningInfo ,
130
+ receipt:: { LocalizedReceipt , Receipt } ,
107
131
snapshot:: { Progress , Snapshotting } ,
108
132
trace_filter:: Filter as TraceFilter ,
109
- pruning_info:: PruningInfo ,
110
- call_analytics:: CallAnalytics ,
111
- client_types:: Mode ,
133
+ transaction:: { self , Action , CallError , LocalizedTransaction , SignedTransaction , UnverifiedTransaction } ,
112
134
verification:: { Unverified , VerificationQueueInfo as BlockQueueInfo } ,
113
135
} ;
114
-
115
- use verification:: queue:: kind:: BlockLike ;
116
- use verification:: { Verifier , BlockQueue } ;
136
+ use types:: data_format:: DataFormat ;
137
+ use verification:: { BlockQueue , Verifier } ;
117
138
use verification;
118
- use ansi_term:: Colour ;
119
- use ethtrie:: Layout ;
120
- // re-export
121
- pub use blockchain:: CacheSize as BlockChainCacheSize ;
122
- use db:: { Writable , Readable , keys:: BlockDetails } ;
123
- use rlp:: PayloadInfo ;
124
- use std:: io:: { BufReader , BufRead } ;
125
- use rustc_hex:: FromHex ;
126
- use std:: str:: from_utf8;
127
- use bytes:: ToPretty ;
139
+ use verification:: queue:: kind:: BlockLike ;
140
+ use vm:: { CreateContractAddress , EnvInfo , LastHashes } ;
128
141
129
142
use_contract ! ( registry, "res/contracts/registrar.json" ) ;
130
143
@@ -2573,10 +2586,16 @@ impl SnapshotClient for Client {
2573
2586
2574
2587
}
2575
2588
2576
- impl ExportBlocks for Client {
2577
- fn export_blocks < ' a > ( & self , mut out : Box < dyn std:: io:: Write + ' a > , from : BlockId , to : BlockId , format : Option < DataFormat > ) -> Result < ( ) , String > {
2578
- let from = self . block_number ( from) . ok_or ( "From block could not be found" ) ?;
2579
- let to = self . block_number ( to) . ok_or ( "To block could not be found" ) ?;
2589
+ impl ImportExportBlocks for Client {
2590
+ fn export_blocks < ' a > (
2591
+ & self ,
2592
+ mut out : Box < dyn std:: io:: Write + ' a > ,
2593
+ from : BlockId ,
2594
+ to : BlockId ,
2595
+ format : Option < DataFormat >
2596
+ ) -> Result < ( ) , String > {
2597
+ let from = self . block_number ( from) . ok_or ( "Starting block could not be found" ) ?;
2598
+ let to = self . block_number ( to) . ok_or ( "End block could not be found" ) ?;
2580
2599
let format = format. unwrap_or_default ( ) ;
2581
2600
2582
2601
for i in from..=to {
@@ -2595,10 +2614,7 @@ impl ExportBlocks for Client {
2595
2614
}
2596
2615
Ok ( ( ) )
2597
2616
}
2598
- }
2599
-
2600
2617
2601
- impl ImportBlocks for Client {
2602
2618
fn import_blocks < ' a > (
2603
2619
& self ,
2604
2620
mut source : Box < dyn std:: io:: Read + ' a > ,
@@ -2620,7 +2636,7 @@ impl ImportBlocks for Client {
2620
2636
}
2621
2637
} ;
2622
2638
2623
- let do_import = |bytes| {
2639
+ let do_import = |bytes : Vec < u8 > | {
2624
2640
let block = Unverified :: from_rlp ( bytes) . map_err ( |_| "Invalid block rlp" ) ?;
2625
2641
while self . queue_info ( ) . is_full ( ) { std:: thread:: sleep ( Duration :: from_secs ( 1 ) ) ; }
2626
2642
match self . import_block ( block) {
@@ -2658,7 +2674,8 @@ impl ImportBlocks for Client {
2658
2674
}
2659
2675
DataFormat :: Hex => {
2660
2676
for line in BufReader :: new ( source) . lines ( ) {
2661
- let s = line. map_err ( |err| format ! ( "Error reading from the file/stream: {:?}" , err) ) ?;
2677
+ let s = line
2678
+ . map_err ( |err| format ! ( "Error reading from the file/stream: {:?}" , err) ) ?;
2662
2679
let s = if first_read > 0 {
2663
2680
from_utf8 ( & first_bytes)
2664
2681
. map_err ( |err| format ! ( "Invalid UTF-8: {:?}" , err) ) ?
@@ -2667,7 +2684,8 @@ impl ImportBlocks for Client {
2667
2684
s
2668
2685
} ;
2669
2686
first_read = 0 ;
2670
- let bytes = s. from_hex ( ) . map_err ( |err| format ! ( "Invalid hex in file/stream: {:?}" , err) ) ?;
2687
+ let bytes = s. from_hex ( )
2688
+ . map_err ( |err| format ! ( "Invalid hex in file/stream: {:?}" , err) ) ?;
2671
2689
do_import ( bytes) ?;
2672
2690
}
2673
2691
}
@@ -2756,26 +2774,29 @@ impl IoChannelQueue {
2756
2774
2757
2775
#[ cfg( test) ]
2758
2776
mod tests {
2759
- use ethereum_types:: { H256 , Address } ;
2777
+ use std:: sync:: Arc ;
2778
+ use std:: sync:: atomic:: { AtomicBool , Ordering } ;
2779
+ use std:: thread;
2780
+ use std:: time:: Duration ;
2781
+
2782
+ use ethereum_types:: { Address , H256 } ;
2783
+ use hash:: keccak;
2784
+ use kvdb:: DBTransaction ;
2785
+
2786
+ use blockchain:: ExtrasInsert ;
2760
2787
use client_traits:: { BlockChainClient , ChainInfo } ;
2788
+ use ethkey:: KeyPair ;
2789
+ use test_helpers:: { generate_dummy_client, generate_dummy_client_with_data, get_good_dummy_block_hash} ;
2761
2790
use types:: {
2762
2791
encoded,
2763
2792
engines:: ForkChoice ,
2764
2793
ids:: { BlockId , TransactionId } ,
2765
- log_entry:: { LogEntry , LocalizedLogEntry } ,
2766
- receipt:: { Receipt , LocalizedReceipt , TransactionOutcome } ,
2767
- transaction:: { Transaction , LocalizedTransaction , Action } ,
2794
+ log_entry:: { LocalizedLogEntry , LogEntry } ,
2795
+ receipt:: { LocalizedReceipt , Receipt , TransactionOutcome } ,
2796
+ transaction:: { Action , LocalizedTransaction , Transaction } ,
2768
2797
} ;
2769
- use test_helpers:: { generate_dummy_client, get_good_dummy_block_hash, generate_dummy_client_with_data} ;
2770
- use std:: thread;
2771
- use std:: time:: Duration ;
2772
- use std:: sync:: Arc ;
2773
- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
2774
- use kvdb:: DBTransaction ;
2775
- use blockchain:: ExtrasInsert ;
2776
- use hash:: keccak;
2798
+
2777
2799
use super :: transaction_receipt;
2778
- use ethkey:: KeyPair ;
2779
2800
2780
2801
#[ test]
2781
2802
fn should_not_cache_details_before_commit ( ) {
0 commit comments