@@ -123,9 +123,11 @@ impl BlockEventStream {
123123 pub fn pause ( mut self , prev : Option < & [ u8 ] > ) -> Vec < u8 > {
124124 self . hasher
125125 . write ( & self . vec_length , & [ 1 , 0 , self . block_index , 0 ] ) ;
126- match self . hasher {
126+ let hash = match self . hasher {
127127 Hashers :: Legacy ( mut digest) => {
128128 if let Some ( prev) = prev {
129+ println ! ( ) ;
130+ // println!("OLD PREV: {}", hex::encode(prev));
129131 let prev = SetHasher :: from_bytes ( prev) ;
130132 // SequenceNumber::root() is misleading here since the parameter
131133 // is unused.
@@ -139,16 +141,25 @@ impl BlockEventStream {
139141 prev. try_into ( )
140142 . expect ( "Expected valid fast stable hash representation" )
141143 } else {
144+ println ! ( ) ;
145+ println ! ( "NEW DIFFERENT PREV2: {}" , hex:: encode( prev) ) ;
146+ // prev[..32]
147+ // .try_into()
148+ // .expect("Expected valid fast stable hash representation")
142149 let mut hasher = Sha256 :: new ( ) ;
143150 hasher. update ( prev) ;
144151 hasher. finalize ( ) . into ( )
145152 } ;
153+ println ! ( ) ;
154+ // println!("NEW PREV: {}", hex::encode(prev));
146155 let prev = FastStableHasher :: from_bytes ( prev) ;
147156 digest. mixin ( & prev) ;
148157 }
149158 digest. to_bytes ( ) . to_vec ( )
150159 }
151- }
160+ } ;
161+ // println!("HASH: {}", hex::encode(hash.clone()));
162+ hash
152163 }
153164
154165 fn write ( & mut self , event : & ProofOfIndexingEvent < ' _ > ) {
@@ -186,6 +197,7 @@ impl fmt::Debug for ProofOfIndexing {
186197
187198impl ProofOfIndexing {
188199 pub fn new ( block_number : BlockNumber , version : ProofOfIndexingVersion ) -> Self {
200+ // println!("ProofOfIndexing::new()");
189201 Self {
190202 version,
191203 block_number,
@@ -196,6 +208,7 @@ impl ProofOfIndexing {
196208
197209impl ProofOfIndexing {
198210 pub fn write_deterministic_error ( & mut self , logger : & Logger , causality_region : & str ) {
211+ // println!("ProofOfIndexing::write_deterministic_error()");
199212 let redacted_events = self . with_causality_region ( causality_region, |entry| {
200213 entry. vec_length - entry. handler_start
201214 } ) ;
@@ -214,6 +227,7 @@ impl ProofOfIndexing {
214227 causality_region : & str ,
215228 event : & ProofOfIndexingEvent < ' _ > ,
216229 ) {
230+ // println!("ProofOfIndexing::write()");
217231 if ENV_VARS . log_poi_events {
218232 debug ! (
219233 logger,
@@ -236,6 +250,7 @@ impl ProofOfIndexing {
236250 where
237251 F : FnOnce ( & mut BlockEventStream ) -> T ,
238252 {
253+ // println!("ProofOfIndexing::with_causality_region()");
239254 let causality_region = Id :: String ( causality_region. to_owned ( ) . into ( ) ) ;
240255 if let Some ( causality_region) = self . per_causality_region . get_mut ( & causality_region) {
241256 f ( causality_region)
@@ -248,10 +263,12 @@ impl ProofOfIndexing {
248263 }
249264
250265 pub fn take ( self ) -> HashMap < Id , BlockEventStream > {
266+ // println!("ProofOfIndexing::take()");
251267 self . per_causality_region
252268 }
253269
254270 pub fn get_block ( & self ) -> BlockNumber {
271+ // println!("ProofOfIndexing::get_block()");
255272 self . block_number
256273 }
257274}
@@ -269,16 +286,29 @@ impl ProofOfIndexingFinisher {
269286 indexer : & Option < Address > ,
270287 version : ProofOfIndexingVersion ,
271288 ) -> Self {
289+ println ! ( "ProofOfIndexingFinisher::new(): {}" , block) ;
272290 let mut state = Hashers :: new ( version) ;
291+ if let Hashers :: Fast ( st) = & state {
292+ println ! ( "NEW state1: {:?}" , st) ;
293+ }
273294
274295 // Add PoI.subgraph_id
275296 state. write ( & subgraph_id, & [ 1 ] ) ;
297+ if let Hashers :: Fast ( st) = & state {
298+ println ! ( "NEW state2: {:?}" , st) ;
299+ }
276300
277301 // Add PoI.block_hash
278302 state. write ( & AsBytes ( block. hash_slice ( ) ) , & [ 2 ] ) ;
303+ if let Hashers :: Fast ( st) = & state {
304+ println ! ( "NEW state3: {:?}" , st) ;
305+ }
279306
280307 // Add PoI.indexer
281308 state. write ( & indexer. as_ref ( ) . map ( |i| AsBytes ( i. as_bytes ( ) ) ) , & [ 3 ] ) ;
309+ if let Hashers :: Fast ( st) = & state {
310+ println ! ( "NEW state4: {:?}" , st) ;
311+ }
282312
283313 ProofOfIndexingFinisher {
284314 block_number : block. number ,
@@ -288,6 +318,10 @@ impl ProofOfIndexingFinisher {
288318 }
289319
290320 pub fn add_causality_region ( & mut self , name : & Id , region : & [ u8 ] ) {
321+ println ! (
322+ "ProofOfIndexingFinisher::add_causality_region(): {}" ,
323+ hex:: encode( region)
324+ ) ;
291325 let mut state = Hashers :: from_bytes ( region) ;
292326
293327 // Finish the blocks vec by writing kvp[v], PoICausalityRegion.blocks.len()
@@ -308,11 +342,15 @@ impl ProofOfIndexingFinisher {
308342 self . state . write ( & AsBytes ( & state) , & [ 0 ] ) ;
309343 }
310344 }
345+ if let Hashers :: Fast ( st) = & self . state {
346+ println ! ( "ADD CAS state: {:?}" , st) ;
347+ }
311348
312349 self . causality_count += 1 ;
313350 }
314351
315352 pub fn finish ( mut self ) -> [ u8 ; 32 ] {
353+ println ! ( "ProofOfIndexingFinisher::finish()" ) ;
316354 if let Hashers :: Legacy ( _) = self . state {
317355 // Add PoI.causality_regions.len()
318356 // Note that technically to get the same sequence number one would need
@@ -321,10 +359,15 @@ impl ProofOfIndexingFinisher {
321359 // non-negative numbers.
322360 self . state . write ( & self . causality_count , & [ 0 , 2 ] ) ;
323361 }
362+ if let Hashers :: Fast ( st) = & self . state {
363+ println ! ( "FINISH state: {:?}" , st) ;
364+ }
324365
325- match self . state {
366+ let res = match self . state {
326367 Hashers :: Legacy ( legacy) => legacy. finish ( ) ,
327368 Hashers :: Fast ( fast) => tiny_keccak:: keccak256 ( & fast. finish ( ) . to_le_bytes ( ) ) ,
328- }
369+ } ;
370+ println ! ( "POI FINISH: {:?}" , hex:: encode( res) ) ;
371+ res
329372 }
330373}
0 commit comments