@@ -8,11 +8,6 @@ mod validation;
88
99use std:: collections:: { BTreeMap , BTreeSet } ;
1010
11- #[ cfg( feature = "bincode" ) ]
12- use bincode:: { Decode , Encode } ;
13- #[ cfg( feature = "serde" ) ]
14- use serde:: { Deserialize , Serialize } ;
15-
1611use crate :: bls_sig_utils:: { BLSPublicKey , BLSSignature } ;
1712use crate :: network:: message_qrinfo:: { QRInfo , QuorumSnapshot } ;
1813use crate :: network:: message_sml:: MnListDiff ;
@@ -28,6 +23,11 @@ use crate::sml::quorum_entry::qualified_quorum_entry::{
2823use crate :: sml:: quorum_validation_error:: { ClientDataRetrievalError , QuorumValidationError } ;
2924use crate :: transaction:: special_transaction:: quorum_commitment:: QuorumEntry ;
3025use crate :: { BlockHash , Network , QuorumHash } ;
26+ #[ cfg( feature = "bincode" ) ]
27+ use bincode:: { Decode , Encode } ;
28+ use hashes:: Hash ;
29+ #[ cfg( feature = "serde" ) ]
30+ use serde:: { Deserialize , Serialize } ;
3131
3232#[ derive( Clone , Eq , PartialEq , Default ) ]
3333#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -66,10 +66,15 @@ impl From<MasternodeListEngineBTreeMapBlockContainer> for MasternodeListEngineBl
6666}
6767
6868impl MasternodeListEngineBlockContainer {
69- pub fn get_height ( & self , block : & BlockHash ) -> Option < & CoreBlockHeight > {
70- match self {
71- MasternodeListEngineBlockContainer :: BTreeMapContainer ( map) => {
72- map. block_heights . get ( block)
69+ pub fn get_height ( & self , block_hash : & BlockHash ) -> Option < CoreBlockHeight > {
70+ if block_hash. as_byte_array ( ) == & [ 0 ; 32 ] {
71+ // rep
72+ Some ( 0 )
73+ } else {
74+ match self {
75+ MasternodeListEngineBlockContainer :: BTreeMapContainer ( map) => {
76+ map. block_heights . get ( block_hash) . copied ( )
77+ }
7378 }
7479 }
7580 }
@@ -203,7 +208,7 @@ impl MasternodeListEngine {
203208 else {
204209 return true ;
205210 } ;
206- !self . masternode_lists . contains_key ( block_height)
211+ !self . masternode_lists . contains_key ( & block_height)
207212 } )
208213 . collect ( )
209214 } else {
@@ -230,7 +235,7 @@ impl MasternodeListEngine {
230235 else {
231236 return true ;
232237 } ;
233- !self . masternode_lists . contains_key ( block_height)
238+ !self . masternode_lists . contains_key ( & block_height)
234239 } )
235240 . collect ( )
236241 } else {
@@ -255,7 +260,7 @@ impl MasternodeListEngine {
255260 ) -> Option < & MasternodeList > {
256261 self . block_container
257262 . get_height ( block_hash)
258- . and_then ( |height| self . masternode_lists . get ( height) )
263+ . and_then ( |height| self . masternode_lists . get ( & height) )
259264 }
260265
261266 pub fn feed_block_height ( & mut self , height : CoreBlockHeight , block_hash : BlockHash ) {
@@ -357,7 +362,7 @@ impl MasternodeListEngine {
357362 Ok ( ( ) )
358363 }
359364
360- pub fn feed_qr_info < FH , FS > (
365+ pub fn feed_qr_info < FH > (
361366 & mut self ,
362367 qr_info : QRInfo ,
363368 verify_tip_non_rotated_quorums : bool ,
@@ -366,7 +371,6 @@ impl MasternodeListEngine {
366371 ) -> Result < ( ) , QuorumValidationError >
367372 where
368373 FH : Fn ( & BlockHash ) -> Result < u32 , ClientDataRetrievalError > ,
369- FS : Fn ( & BlockHash ) -> Result < Option < BLSSignature > , ClientDataRetrievalError > ,
370374 {
371375 // Fetch and process block heights using the provided callback
372376 if let Some ( fetch_height) = fetch_block_height {
@@ -397,15 +401,18 @@ impl MasternodeListEngine {
397401
398402 let can_verify_previous = quorum_snapshot_and_mn_list_diff_at_h_minus_4c. is_some ( ) ;
399403
400- let h_height = self
401- . block_container
402- . get_height ( & mn_list_diff_h. block_hash )
403- . copied ( )
404- . ok_or ( QuorumValidationError :: RequiredBlockNotPresent ( mn_list_diff_h. block_hash ) ) ?;
405- let tip_height =
406- self . block_container . get_height ( & mn_list_diff_tip. block_hash ) . copied ( ) . ok_or (
407- QuorumValidationError :: RequiredBlockNotPresent ( mn_list_diff_tip. block_hash ) ,
408- ) ?;
404+ let h_height = self . block_container . get_height ( & mn_list_diff_h. block_hash ) . ok_or (
405+ QuorumValidationError :: RequiredBlockNotPresent (
406+ mn_list_diff_h. block_hash ,
407+ "getting height at diff h" . to_string ( ) ,
408+ ) ,
409+ ) ?;
410+ let tip_height = self . block_container . get_height ( & mn_list_diff_tip. block_hash ) . ok_or (
411+ QuorumValidationError :: RequiredBlockNotPresent (
412+ mn_list_diff_tip. block_hash ,
413+ "getting height at diff tip" . to_string ( ) ,
414+ ) ,
415+ ) ?;
409416 let rotation_quorum_type = last_commitment_per_index
410417 . first ( )
411418 . map ( |quorum_entry| quorum_entry. llmq_type )
@@ -657,23 +664,22 @@ impl MasternodeListEngine {
657664 . known_genesis_block_hash ( )
658665 . or_else ( || self . block_container . get_hash ( & 0 ) . cloned ( ) )
659666 {
660- if masternode_list_diff. base_block_hash == known_genesis_block_hash {
667+ if masternode_list_diff. base_block_hash == known_genesis_block_hash
668+ || masternode_list_diff. base_block_hash . as_byte_array ( ) == & [ 0 ; 32 ]
669+ {
661670 // we are going from the start
662671 let block_hash = masternode_list_diff. block_hash ;
663672
664673 let masternode_list = masternode_list_diff. try_into_with_block_hash_lookup (
665- |block_hash| {
666- diff_end_height. or ( self . block_container . get_height ( block_hash) . copied ( ) )
667- } ,
674+ |block_hash| diff_end_height. or ( self . block_container . get_height ( block_hash) ) ,
668675 self . network ,
669676 ) ?;
670677
671678 let diff_end_height = match diff_end_height {
672679 None => self
673680 . block_container
674681 . get_height ( & block_hash)
675- . ok_or ( SmlError :: BlockHashLookupFailed ( block_hash) )
676- . cloned ( ) ?,
682+ . ok_or ( SmlError :: BlockHashLookupFailed ( block_hash) ) ?,
677683 Some ( diff_end_height) => {
678684 self . block_container . feed_block_height ( diff_end_height, block_hash) ;
679685 diff_end_height
@@ -689,7 +695,7 @@ impl MasternodeListEngine {
689695 else {
690696 return Err ( SmlError :: BlockHashLookupFailed ( masternode_list_diff. base_block_hash ) ) ;
691697 } ;
692- let Some ( base_masternode_list) = self . masternode_lists . get ( base_height) else {
698+ let Some ( base_masternode_list) = self . masternode_lists . get ( & base_height) else {
693699 return Err ( SmlError :: MissingStartMasternodeList ( masternode_list_diff. base_block_hash ) ) ;
694700 } ;
695701
@@ -699,8 +705,7 @@ impl MasternodeListEngine {
699705 None => self
700706 . block_container
701707 . get_height ( & block_hash)
702- . ok_or ( SmlError :: BlockHashLookupFailed ( block_hash) )
703- . cloned ( ) ?,
708+ . ok_or ( SmlError :: BlockHashLookupFailed ( block_hash) ) ?,
704709 Some ( diff_end_height) => diff_end_height,
705710 } ;
706711
@@ -1107,11 +1112,8 @@ mod tests {
11071112 }
11081113
11091114 masternode_list_engine
1110- . feed_qr_info :: < fn ( & BlockHash ) -> Result < u32 , ClientDataRetrievalError > , fn ( & BlockHash ) -> Result < Option < BLSSignature > , ClientDataRetrievalError > > (
1111- qr_info,
1112- true ,
1113- true ,
1114- None ,
1115+ . feed_qr_info :: < fn ( & BlockHash ) -> Result < u32 , ClientDataRetrievalError > > (
1116+ qr_info, true , true , None ,
11151117 )
11161118 . expect ( "expected to feed_qr_info" ) ;
11171119
0 commit comments