@@ -42,8 +42,10 @@ impl LedgerInfo {
4242 . get_data_manager ( )
4343 . block_by_hash ( & hash, false /* update_cache */ )
4444 . map ( |b| ( * b) . clone ( ) )
45- // FIXME: what's this internal error?
46- . ok_or ( ErrorKind :: InternalError . into ( ) )
45+ . ok_or_else ( || {
46+ ErrorKind :: InternalError ( format ! ( "Block {:?} not found" , hash) )
47+ . into ( )
48+ } )
4749 }
4850
4951 /// Get header `hash`, if it exists.
@@ -53,12 +55,15 @@ impl LedgerInfo {
5355 . get_data_manager ( )
5456 . block_header_by_hash ( & hash)
5557 . map ( |h| ( * h) . clone ( ) )
56- . ok_or ( ErrorKind :: InternalError . into ( ) )
58+ . ok_or_else ( || {
59+ ErrorKind :: InternalError ( format ! ( "Header {:?} not found" , hash) )
60+ . into ( )
61+ } )
5762 }
5863
5964 /// Get hash of block at `height` on the pivot chain, if it exists.
6065 #[ inline]
61- pub fn pivot_hash_of ( & self , height : u64 ) -> Result < H256 , Error > {
66+ fn pivot_hash_of ( & self , height : u64 ) -> Result < H256 , Error > {
6267 let epoch = EpochNumber :: Number ( height) ;
6368 Ok ( self . consensus . get_hash_from_epoch_number ( epoch) ?)
6469 }
@@ -81,7 +86,7 @@ impl LedgerInfo {
8186 /// Get the correct deferred state root of the block at `height` on the
8287 /// pivot chain based on local execution information.
8388 #[ inline]
84- pub fn correct_deferred_state_root_hash_of (
89+ fn correct_deferred_state_root_hash_of (
8590 & self , height : u64 ,
8691 ) -> Result < H256 , Error > {
8792 let epoch = height. saturating_sub ( DEFERRED_STATE_EPOCH_COUNT ) ;
@@ -92,7 +97,7 @@ impl LedgerInfo {
9297 /// Get the correct deferred receipts root of the block at `height` on the
9398 /// pivot chain based on local execution information.
9499 #[ inline]
95- pub fn correct_deferred_receipts_root_hash_of (
100+ fn correct_deferred_receipts_root_hash_of (
96101 & self , height : u64 ,
97102 ) -> Result < H256 , Error > {
98103 let epoch = height. saturating_sub ( DEFERRED_STATE_EPOCH_COUNT ) ;
@@ -102,13 +107,19 @@ impl LedgerInfo {
102107 . get_data_manager ( )
103108 . get_epoch_execution_commitment ( & pivot)
104109 . map ( |c| c. receipts_root )
105- . ok_or ( ErrorKind :: InternalError . into ( ) )
110+ . ok_or_else ( || {
111+ ErrorKind :: InternalError ( format ! (
112+ "Execution commitments for {:?} not found" ,
113+ pivot
114+ ) )
115+ . into ( )
116+ } )
106117 }
107118
108119 /// Get the correct deferred logs bloom root of the block at `height` on the
109120 /// pivot chain based on local execution information.
110121 #[ inline]
111- pub fn correct_deferred_logs_root_hash_of (
122+ fn correct_deferred_logs_root_hash_of (
112123 & self , height : u64 ,
113124 ) -> Result < H256 , Error > {
114125 let epoch = height. saturating_sub ( DEFERRED_STATE_EPOCH_COUNT ) ;
@@ -118,7 +129,13 @@ impl LedgerInfo {
118129 . get_data_manager ( )
119130 . get_epoch_execution_commitment ( & pivot)
120131 . map ( |c| c. logs_bloom_hash )
121- . ok_or ( ErrorKind :: InternalError . into ( ) )
132+ . ok_or_else ( || {
133+ ErrorKind :: InternalError ( format ! (
134+ "Execution commitments for {:?} not found" ,
135+ pivot
136+ ) )
137+ . into ( )
138+ } )
122139 }
123140
124141 /// Get the number of epochs per snapshot period.
@@ -129,7 +146,7 @@ impl LedgerInfo {
129146
130147 /// Get the state trie corresponding to the execution of `epoch`.
131148 #[ inline]
132- pub fn state_of ( & self , epoch : u64 ) -> Result < State , Error > {
149+ fn state_of ( & self , epoch : u64 ) -> Result < State , Error > {
133150 let pivot = self . pivot_hash_of ( epoch) ?;
134151
135152 let maybe_state_index = self
@@ -145,7 +162,12 @@ impl LedgerInfo {
145162
146163 match state {
147164 Some ( Ok ( Some ( state) ) ) => Ok ( state) ,
148- _ => Err ( ErrorKind :: InternalError . into ( ) ) ,
165+ _ => {
166+ bail ! ( ErrorKind :: InternalError ( format!(
167+ "State of epoch {} not found" ,
168+ epoch
169+ ) ) ) ;
170+ }
149171 }
150172 }
151173
@@ -156,7 +178,12 @@ impl LedgerInfo {
156178 ) -> Result < StateRootWithAuxInfo , Error > {
157179 match self . state_of ( epoch) ?. get_state_root ( ) {
158180 Ok ( root) => Ok ( root) ,
159- _ => Err ( ErrorKind :: InternalError . into ( ) ) ,
181+ Err ( e) => {
182+ bail ! ( ErrorKind :: InternalError ( format!(
183+ "State root of epoch {} not found: {:?}" ,
184+ epoch, e
185+ ) ) ) ;
186+ }
160187 }
161188 }
162189
@@ -207,7 +234,13 @@ impl LedgerInfo {
207234 false , /* update_cache */
208235 )
209236 . map ( |res| ( * res. block_receipts ) . clone ( ) )
210- . ok_or ( ErrorKind :: InternalError . into ( ) )
237+ . ok_or_else ( || {
238+ ErrorKind :: InternalError ( format ! (
239+ "Receipts of epoch {} not found" ,
240+ epoch
241+ ) )
242+ . into ( )
243+ } )
211244 } )
212245 . collect ( )
213246 }
@@ -232,7 +265,13 @@ impl LedgerInfo {
232265 false , /* update_cache */
233266 )
234267 . map ( |res| res. bloom )
235- . ok_or ( ErrorKind :: InternalError . into ( ) )
268+ . ok_or_else ( || {
269+ ErrorKind :: InternalError ( format ! (
270+ "Logs bloom of epoch {} not found" ,
271+ epoch
272+ ) )
273+ . into ( )
274+ } )
236275 } )
237276 . collect :: < Result < Vec < Bloom > , Error > > ( ) ?;
238277
0 commit comments