@@ -83,7 +83,7 @@ pub fn handle_input(
83
83
TaskAction :: GetHeaders ( handle. async_reply ( get_headers ( task_data. storage . clone ( ) , ids) ) )
84
84
}
85
85
ClientMsg :: GetHeadersRange ( checkpoints, to, handle) => TaskAction :: GetHeadersRange (
86
- handle_get_headers_range ( task_data. storage . clone ( ) , checkpoints, to, handle) ,
86
+ handle_get_headers_range ( task_data, checkpoints, to, handle) ,
87
87
) ,
88
88
ClientMsg :: GetBlocks ( ids, handle) => {
89
89
TaskAction :: GetBlocks ( handle. async_reply ( get_blocks ( task_data. storage . clone ( ) , ids) ) )
@@ -92,12 +92,7 @@ pub fn handle_input(
92
92
handle_get_blocks_range ( & task_data. storage , from, to, handle) ,
93
93
) ,
94
94
ClientMsg :: PullBlocksToTip ( from, handle) => {
95
- TaskAction :: PullBlocksToTip ( handle_pull_blocks_to_tip (
96
- task_data. storage . clone ( ) ,
97
- task_data. blockchain_tip . clone ( ) ,
98
- from,
99
- handle,
100
- ) )
95
+ TaskAction :: PullBlocksToTip ( handle_pull_blocks_to_tip ( task_data, from, handle) )
101
96
}
102
97
}
103
98
}
@@ -109,15 +104,18 @@ fn get_block_tip(blockchain_tip: &Tip) -> impl Future<Item = Header, Error = Err
109
104
}
110
105
111
106
fn handle_get_headers_range (
112
- storage : Storage ,
107
+ task_data : & TaskData ,
113
108
checkpoints : Vec < HeaderHash > ,
114
109
to : HeaderHash ,
115
110
handle : ReplyStreamHandle < Header > ,
116
111
) -> impl Future < Item = ( ) , Error = ( ) > {
112
+ let storage = task_data. storage . clone ( ) ;
113
+ let block0_hash = task_data. block0_hash ;
117
114
storage
118
115
. find_closest_ancestor ( checkpoints, to)
119
116
. then ( move |res| match res {
120
- Ok ( Some ( from) ) => {
117
+ Ok ( maybe_ancestor) => {
118
+ let from = maybe_ancestor. unwrap_or ( block0_hash) ;
121
119
let fut = storage
122
120
. send_from_to (
123
121
from,
@@ -127,10 +125,6 @@ fn handle_get_headers_range(
127
125
. map_err ( |_: ReplySendError | ( ) ) ;
128
126
Either :: A ( fut)
129
127
}
130
- Ok ( None ) => Either :: B ( handle. async_error ( Error :: not_found (
131
- "none of the checkpoints found in the local storage \
132
- are ancestors of the requested end block",
133
- ) ) ) ,
134
128
Err ( e) => Either :: B ( handle. async_error ( e. into ( ) ) ) ,
135
129
} )
136
130
}
@@ -178,27 +172,27 @@ fn get_headers(
178
172
}
179
173
180
174
fn handle_pull_blocks_to_tip (
181
- storage : Storage ,
182
- blockchain_tip : Tip ,
175
+ task_data : & TaskData ,
183
176
checkpoints : Vec < HeaderHash > ,
184
177
handle : ReplyStreamHandle < Block > ,
185
178
) -> impl Future < Item = ( ) , Error = ( ) > {
186
- blockchain_tip
179
+ let storage = task_data. storage . clone ( ) ;
180
+ let block0_hash = task_data. block0_hash ;
181
+ task_data
182
+ . blockchain_tip
187
183
. get_ref ( )
188
184
. and_then ( move |tip| {
189
185
let tip_hash = tip. hash ( ) ;
190
186
storage
191
187
. find_closest_ancestor ( checkpoints, tip_hash)
192
- . map ( move |maybe_ancestor| ( storage, maybe_ancestor, tip_hash) )
188
+ . map ( move |maybe_ancestor| {
189
+ ( storage, maybe_ancestor. unwrap_or ( block0_hash) , tip_hash)
190
+ } )
193
191
} )
194
192
. then ( move |res| match res {
195
- Ok ( ( storage, Some ( from) , to) ) => {
193
+ Ok ( ( storage, from, to) ) => {
196
194
Either :: A ( storage. send_from_to ( from, to, handle) . map_err ( |_| ( ) ) )
197
195
}
198
- Ok ( ( _, None , _) ) => Either :: B ( handle. async_error ( Error :: not_found (
199
- "none of the checkpoints found in the local storage \
200
- are ancestors of the current tip",
201
- ) ) ) ,
202
196
Err ( e) => Either :: B ( handle. async_error ( e. into ( ) ) ) ,
203
197
} )
204
198
}
0 commit comments