@@ -40,7 +40,7 @@ use crate::{
4040 } ,
4141 get_environment,
4242 proto:: {
43- versioning:: { ProtocolVersion , Versioned } ,
43+ versioning:: { ProtocolVersion , Versioned , VersionedHashable } ,
4444 ProtobufConvert ,
4545 } ,
4646 staking:: prelude:: * ,
@@ -756,13 +756,13 @@ pub struct BlockMerkleRoots {
756756}
757757
758758/// Function to calculate a merkle tree from a transaction vector
759- pub fn merkle_tree_root < T > ( transactions : & [ T ] ) -> Hash
759+ pub fn merkle_tree_root < T > ( transactions : & [ T ] , protocol_version : ProtocolVersion ) -> Hash
760760where
761- T : Hashable ,
761+ T : VersionedHashable ,
762762{
763763 let transactions_hashes: Vec < Sha256 > = transactions
764764 . iter ( )
765- . map ( |x| match x. hash ( ) {
765+ . map ( |x| match x. versioned_hash ( protocol_version ) {
766766 Hash :: SHA256 ( x) => Sha256 ( x) ,
767767 } )
768768 . collect ( ) ;
@@ -773,16 +773,16 @@ where
773773}
774774
775775impl BlockMerkleRoots {
776- pub fn from_transactions ( txns : & BlockTransactions ) -> Self {
776+ pub fn from_transactions ( txns : & BlockTransactions , protocol_version : ProtocolVersion ) -> Self {
777777 BlockMerkleRoots {
778- mint_hash : txns. mint . hash ( ) ,
779- vt_hash_merkle_root : merkle_tree_root ( & txns. value_transfer_txns ) ,
780- dr_hash_merkle_root : merkle_tree_root ( & txns. data_request_txns ) ,
781- commit_hash_merkle_root : merkle_tree_root ( & txns. commit_txns ) ,
782- reveal_hash_merkle_root : merkle_tree_root ( & txns. reveal_txns ) ,
783- tally_hash_merkle_root : merkle_tree_root ( & txns. tally_txns ) ,
784- stake_hash_merkle_root : merkle_tree_root ( & txns. stake_txns ) ,
785- unstake_hash_merkle_root : merkle_tree_root ( & txns. unstake_txns ) ,
778+ mint_hash : txns. mint . versioned_hash ( protocol_version ) ,
779+ vt_hash_merkle_root : merkle_tree_root ( & txns. value_transfer_txns , protocol_version ) ,
780+ dr_hash_merkle_root : merkle_tree_root ( & txns. data_request_txns , protocol_version ) ,
781+ commit_hash_merkle_root : merkle_tree_root ( & txns. commit_txns , protocol_version ) ,
782+ reveal_hash_merkle_root : merkle_tree_root ( & txns. reveal_txns , protocol_version ) ,
783+ tally_hash_merkle_root : merkle_tree_root ( & txns. tally_txns , protocol_version ) ,
784+ stake_hash_merkle_root : merkle_tree_root ( & txns. stake_txns , protocol_version ) ,
785+ unstake_hash_merkle_root : merkle_tree_root ( & txns. unstake_txns , protocol_version ) ,
786786 }
787787 }
788788}
@@ -901,13 +901,13 @@ impl SuperBlock {
901901 & self ,
902902 blocks : & [ Block ] ,
903903 tally_tx : & TallyTransaction ,
904+ protocol_version : ProtocolVersion ,
904905 ) -> Option < TxInclusionProof > {
905906 // Get the PoI for the block root, if the tally transaction is found on the list of blocks
906907 // Obtain also the index of the tally root of the block containing the tally TX.
907- let ( mut poi, tally_root_idx) = blocks
908- . iter ( )
909- . enumerate ( )
910- . find_map ( |( idx, b) | Some ( ( tally_tx. data_proof_of_inclusion ( b) ?, idx) ) ) ?;
908+ let ( mut poi, tally_root_idx) = blocks. iter ( ) . enumerate ( ) . find_map ( |( idx, b) | {
909+ Some ( ( tally_tx. data_proof_of_inclusion ( b, protocol_version) ?, idx) )
910+ } ) ?;
911911
912912 // Collect all tally roots from the blocks
913913 let tally_roots = blocks
@@ -4726,10 +4726,11 @@ mod tests {
47264726 expected_lemma_lengths : Vec < usize > ,
47274727 blocks : Vec < Block > ,
47284728 tally_txs : Vec < TallyTransaction > ,
4729+ protocol_version : ProtocolVersion ,
47294730 ) {
47304731 for index in 0 ..expected_indices. len ( ) {
47314732 let result = sb
4732- . tally_proof_of_inclusion ( & blocks, & tally_txs[ index] )
4733+ . tally_proof_of_inclusion ( & blocks, & tally_txs[ index] , protocol_version )
47334734 . unwrap ( ) ;
47344735 assert_eq ! ( result. index, expected_indices[ index] ) ;
47354736 assert_eq ! ( result. lemma. len( ) , expected_lemma_lengths[ index] ) ;
@@ -6883,6 +6884,7 @@ mod tests {
68836884 1 ,
68846885 Hash :: default ( ) ,
68856886 1 ,
6887+ ProtocolVersion :: default ( ) ,
68866888 ) ;
68876889
68886890 let expected_indices = vec ! [ 0 , 2 , 2 ] ;
@@ -6937,6 +6939,7 @@ mod tests {
69376939 1 ,
69386940 Hash :: default ( ) ,
69396941 1 ,
6942+ ProtocolVersion :: default ( ) ,
69406943 ) ;
69416944
69426945 let expected_indices = vec ! [ 0 , 2 , 2 , 8 , 10 , 6 , 4 , 6 ] ;
@@ -6972,6 +6975,7 @@ mod tests {
69726975 1 ,
69736976 Hash :: default ( ) ,
69746977 1 ,
6978+ ProtocolVersion :: default ( ) ,
69756979 ) ;
69766980
69776981 let result = sb. dr_proof_of_inclusion ( & [ b1, b2] , & dr_txs[ 2 ] ) ;
@@ -6982,7 +6986,14 @@ mod tests {
69826986 fn test_dr_merkle_root_no_block ( ) {
69836987 let dr_txs = build_test_dr_txs ( 3 ) ;
69846988
6985- let sb = mining_build_superblock ( & [ ] , & [ Hash :: default ( ) ] , 1 , Hash :: default ( ) , 1 ) ;
6989+ let sb = mining_build_superblock (
6990+ & [ ] ,
6991+ & [ Hash :: default ( ) ] ,
6992+ 1 ,
6993+ Hash :: default ( ) ,
6994+ 1 ,
6995+ ProtocolVersion :: default ( ) ,
6996+ ) ;
69866997
69876998 let result = sb. dr_proof_of_inclusion ( & [ ] , & dr_txs[ 2 ] ) ;
69886999 assert ! ( result. is_none( ) ) ;
@@ -7008,6 +7019,7 @@ mod tests {
70087019 1 ,
70097020 Hash :: default ( ) ,
70107021 1 ,
7022+ ProtocolVersion :: default ( ) ,
70117023 ) ;
70127024
70137025 let expected_indices = vec ! [ 0 , 2 ] ;
@@ -7046,6 +7058,7 @@ mod tests {
70467058 1 ,
70477059 Hash :: default ( ) ,
70487060 1 ,
7061+ ProtocolVersion :: default ( ) ,
70497062 ) ;
70507063
70517064 let expected_indices = vec ! [ 0 , 2 , 2 ] ;
@@ -7057,6 +7070,7 @@ mod tests {
70577070 expected_lemma_lengths,
70587071 vec ! [ b1, b2] ,
70597072 tally_txs,
7073+ ProtocolVersion :: default ( ) ,
70607074 ) ;
70617075 }
70627076
@@ -7108,6 +7122,7 @@ mod tests {
71087122 1 ,
71097123 Hash :: default ( ) ,
71107124 1 ,
7125+ ProtocolVersion :: default ( ) ,
71117126 ) ;
71127127
71137128 let expected_indices = vec ! [ 0 , 2 , 2 , 8 , 10 , 6 , 4 , 6 ] ;
@@ -7119,12 +7134,14 @@ mod tests {
71197134 expected_lemma_lengths,
71207135 vec ! [ b1, b2, b3] ,
71217136 tally_txs,
7137+ ProtocolVersion :: default ( ) ,
71227138 ) ;
71237139 }
71247140
71257141 #[ test]
71267142 fn test_tally_merkle_root_none ( ) {
71277143 let tally_txs = build_test_tally_txs ( 3 ) ;
7144+ let protocol_version = ProtocolVersion :: default ( ) ;
71287145
71297146 let mut b1 = block_example ( ) ;
71307147 let mut b2 = block_example ( ) ;
@@ -7143,9 +7160,10 @@ mod tests {
71437160 1 ,
71447161 Hash :: default ( ) ,
71457162 1 ,
7163+ ProtocolVersion :: default ( ) ,
71467164 ) ;
71477165
7148- let result = sb. tally_proof_of_inclusion ( & [ b1, b2] , & tally_txs[ 2 ] ) ;
7166+ let result = sb. tally_proof_of_inclusion ( & [ b1, b2] , & tally_txs[ 2 ] , protocol_version ) ;
71497167 assert ! ( result. is_none( ) ) ;
71507168 }
71517169
@@ -7174,6 +7192,7 @@ mod tests {
71747192 1 ,
71757193 Hash :: default ( ) ,
71767194 1 ,
7195+ ProtocolVersion :: default ( ) ,
71777196 ) ;
71787197
71797198 let expected_indices = vec ! [ 0 , 2 , 2 ] ;
@@ -7185,6 +7204,7 @@ mod tests {
71857204 expected_lemma_lengths,
71867205 vec ! [ b1] ,
71877206 tally_txs,
7207+ ProtocolVersion :: default ( ) ,
71887208 ) ;
71897209 }
71907210
0 commit comments