@@ -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 :: blockdata:: 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 ) ) ]
@@ -71,10 +71,15 @@ impl From<MasternodeListEngineBTreeMapBlockContainer> for MasternodeListEngineBl
7171}
7272
7373impl MasternodeListEngineBlockContainer {
74- pub fn get_height ( & self , block : & BlockHash ) -> Option < & CoreBlockHeight > {
75- match self {
76- MasternodeListEngineBlockContainer :: BTreeMapContainer ( map) => {
77- map. block_heights . get ( block)
74+ pub fn get_height ( & self , block_hash : & BlockHash ) -> Option < CoreBlockHeight > {
75+ if block_hash. as_byte_array ( ) == & [ 0 ; 32 ] {
76+ // rep
77+ Some ( 0 )
78+ } else {
79+ match self {
80+ MasternodeListEngineBlockContainer :: BTreeMapContainer ( map) => {
81+ map. block_heights . get ( block_hash) . copied ( )
82+ }
7883 }
7984 }
8085 }
@@ -222,7 +227,7 @@ impl MasternodeListEngine {
222227 else {
223228 return true ;
224229 } ;
225- !self . masternode_lists . contains_key ( block_height)
230+ !self . masternode_lists . contains_key ( & block_height)
226231 } )
227232 . collect ( )
228233 } else {
@@ -249,7 +254,7 @@ impl MasternodeListEngine {
249254 else {
250255 return true ;
251256 } ;
252- !self . masternode_lists . contains_key ( block_height)
257+ !self . masternode_lists . contains_key ( & block_height)
253258 } )
254259 . collect ( )
255260 } else {
@@ -274,7 +279,7 @@ impl MasternodeListEngine {
274279 ) -> Option < & MasternodeList > {
275280 self . block_container
276281 . get_height ( block_hash)
277- . and_then ( |height| self . masternode_lists . get ( height) )
282+ . and_then ( |height| self . masternode_lists . get ( & height) )
278283 }
279284
280285 pub fn feed_block_height ( & mut self , height : CoreBlockHeight , block_hash : BlockHash ) {
@@ -415,15 +420,18 @@ impl MasternodeListEngine {
415420
416421 let can_verify_previous = quorum_snapshot_and_mn_list_diff_at_h_minus_4c. is_some ( ) ;
417422
418- let h_height = self
419- . block_container
420- . get_height ( & mn_list_diff_h. block_hash )
421- . copied ( )
422- . ok_or ( QuorumValidationError :: RequiredBlockNotPresent ( mn_list_diff_h. block_hash ) ) ?;
423- let tip_height =
424- self . block_container . get_height ( & mn_list_diff_tip. block_hash ) . copied ( ) . ok_or (
425- QuorumValidationError :: RequiredBlockNotPresent ( mn_list_diff_tip. block_hash ) ,
426- ) ?;
423+ let h_height = self . block_container . get_height ( & mn_list_diff_h. block_hash ) . ok_or (
424+ QuorumValidationError :: RequiredBlockNotPresent (
425+ mn_list_diff_h. block_hash ,
426+ "getting height at diff h" . to_string ( ) ,
427+ ) ,
428+ ) ?;
429+ let tip_height = self . block_container . get_height ( & mn_list_diff_tip. block_hash ) . ok_or (
430+ QuorumValidationError :: RequiredBlockNotPresent (
431+ mn_list_diff_tip. block_hash ,
432+ "getting height at diff tip" . to_string ( ) ,
433+ ) ,
434+ ) ?;
427435 let rotation_quorum_type = last_commitment_per_index
428436 . first ( )
429437 . map ( |quorum_entry| quorum_entry. llmq_type )
@@ -677,21 +685,20 @@ impl MasternodeListEngine {
677685 . known_genesis_block_hash ( )
678686 . or_else ( || self . block_container . get_hash ( & 0 ) . cloned ( ) )
679687 {
680- if base_block_hash == known_genesis_block_hash {
688+ if base_block_hash == known_genesis_block_hash
689+ || base_block_hash. as_byte_array ( ) == & [ 0 ; 32 ]
690+ {
681691 // we are going from the start
682692 let masternode_list = masternode_list_diff. try_into_with_block_hash_lookup (
683- |block_hash| {
684- diff_end_height. or ( self . block_container . get_height ( block_hash) . copied ( ) )
685- } ,
693+ |block_hash| diff_end_height. or ( self . block_container . get_height ( block_hash) ) ,
686694 self . network ,
687695 ) ?;
688696
689697 let diff_end_height = match diff_end_height {
690698 None => self
691699 . block_container
692700 . get_height ( & block_hash)
693- . ok_or ( SmlError :: BlockHashLookupFailed ( block_hash) )
694- . cloned ( ) ?,
701+ . ok_or ( SmlError :: BlockHashLookupFailed ( block_hash) ) ?,
695702 Some ( diff_end_height) => {
696703 self . block_container . feed_block_height ( diff_end_height, block_hash) ;
697704 diff_end_height
@@ -707,7 +714,7 @@ impl MasternodeListEngine {
707714 else {
708715 return Err ( SmlError :: BlockHashLookupFailed ( masternode_list_diff. base_block_hash ) ) ;
709716 } ;
710- let Some ( base_masternode_list) = self . masternode_lists . get ( base_height) else {
717+ let Some ( base_masternode_list) = self . masternode_lists . get ( & base_height) else {
711718 return Err ( SmlError :: MissingStartMasternodeList ( masternode_list_diff. base_block_hash ) ) ;
712719 } ;
713720
@@ -717,8 +724,7 @@ impl MasternodeListEngine {
717724 None => self
718725 . block_container
719726 . get_height ( & block_hash)
720- . ok_or ( SmlError :: BlockHashLookupFailed ( block_hash) )
721- . cloned ( ) ?,
727+ . ok_or ( SmlError :: BlockHashLookupFailed ( block_hash) ) ?,
722728 Some ( diff_end_height) => diff_end_height,
723729 } ;
724730
@@ -1130,11 +1136,8 @@ mod tests {
11301136 }
11311137
11321138 masternode_list_engine
1133- . feed_qr_info :: < fn ( & BlockHash ) -> Result < u32 , ClientDataRetrievalError > , fn ( & BlockHash ) -> Result < Option < BLSSignature > , ClientDataRetrievalError > > (
1134- qr_info,
1135- true ,
1136- true ,
1137- None ,
1139+ . feed_qr_info :: < fn ( & BlockHash ) -> Result < u32 , ClientDataRetrievalError > > (
1140+ qr_info, true , true , None ,
11381141 )
11391142 . expect ( "expected to feed_qr_info" ) ;
11401143
0 commit comments