@@ -40,7 +40,7 @@ use crate::{
40
40
} ,
41
41
get_environment,
42
42
proto:: {
43
- versioning:: { ProtocolVersion , Versioned } ,
43
+ versioning:: { ProtocolVersion , Versioned , VersionedHashable } ,
44
44
ProtobufConvert ,
45
45
} ,
46
46
staking:: prelude:: * ,
@@ -756,13 +756,13 @@ pub struct BlockMerkleRoots {
756
756
}
757
757
758
758
/// 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
760
760
where
761
- T : Hashable ,
761
+ T : VersionedHashable ,
762
762
{
763
763
let transactions_hashes: Vec < Sha256 > = transactions
764
764
. iter ( )
765
- . map ( |x| match x. hash ( ) {
765
+ . map ( |x| match x. versioned_hash ( protocol_version ) {
766
766
Hash :: SHA256 ( x) => Sha256 ( x) ,
767
767
} )
768
768
. collect ( ) ;
@@ -773,16 +773,16 @@ where
773
773
}
774
774
775
775
impl BlockMerkleRoots {
776
- pub fn from_transactions ( txns : & BlockTransactions ) -> Self {
776
+ pub fn from_transactions ( txns : & BlockTransactions , protocol_version : ProtocolVersion ) -> Self {
777
777
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 ) ,
786
786
}
787
787
}
788
788
}
@@ -901,13 +901,13 @@ impl SuperBlock {
901
901
& self ,
902
902
blocks : & [ Block ] ,
903
903
tally_tx : & TallyTransaction ,
904
+ protocol_version : ProtocolVersion ,
904
905
) -> Option < TxInclusionProof > {
905
906
// Get the PoI for the block root, if the tally transaction is found on the list of blocks
906
907
// 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
+ } ) ?;
911
911
912
912
// Collect all tally roots from the blocks
913
913
let tally_roots = blocks
@@ -4726,10 +4726,11 @@ mod tests {
4726
4726
expected_lemma_lengths : Vec < usize > ,
4727
4727
blocks : Vec < Block > ,
4728
4728
tally_txs : Vec < TallyTransaction > ,
4729
+ protocol_version : ProtocolVersion ,
4729
4730
) {
4730
4731
for index in 0 ..expected_indices. len ( ) {
4731
4732
let result = sb
4732
- . tally_proof_of_inclusion ( & blocks, & tally_txs[ index] )
4733
+ . tally_proof_of_inclusion ( & blocks, & tally_txs[ index] , protocol_version )
4733
4734
. unwrap ( ) ;
4734
4735
assert_eq ! ( result. index, expected_indices[ index] ) ;
4735
4736
assert_eq ! ( result. lemma. len( ) , expected_lemma_lengths[ index] ) ;
@@ -6883,6 +6884,7 @@ mod tests {
6883
6884
1 ,
6884
6885
Hash :: default ( ) ,
6885
6886
1 ,
6887
+ ProtocolVersion :: default ( ) ,
6886
6888
) ;
6887
6889
6888
6890
let expected_indices = vec ! [ 0 , 2 , 2 ] ;
@@ -6937,6 +6939,7 @@ mod tests {
6937
6939
1 ,
6938
6940
Hash :: default ( ) ,
6939
6941
1 ,
6942
+ ProtocolVersion :: default ( ) ,
6940
6943
) ;
6941
6944
6942
6945
let expected_indices = vec ! [ 0 , 2 , 2 , 8 , 10 , 6 , 4 , 6 ] ;
@@ -6972,6 +6975,7 @@ mod tests {
6972
6975
1 ,
6973
6976
Hash :: default ( ) ,
6974
6977
1 ,
6978
+ ProtocolVersion :: default ( ) ,
6975
6979
) ;
6976
6980
6977
6981
let result = sb. dr_proof_of_inclusion ( & [ b1, b2] , & dr_txs[ 2 ] ) ;
@@ -6982,7 +6986,14 @@ mod tests {
6982
6986
fn test_dr_merkle_root_no_block ( ) {
6983
6987
let dr_txs = build_test_dr_txs ( 3 ) ;
6984
6988
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
+ ) ;
6986
6997
6987
6998
let result = sb. dr_proof_of_inclusion ( & [ ] , & dr_txs[ 2 ] ) ;
6988
6999
assert ! ( result. is_none( ) ) ;
@@ -7008,6 +7019,7 @@ mod tests {
7008
7019
1 ,
7009
7020
Hash :: default ( ) ,
7010
7021
1 ,
7022
+ ProtocolVersion :: default ( ) ,
7011
7023
) ;
7012
7024
7013
7025
let expected_indices = vec ! [ 0 , 2 ] ;
@@ -7046,6 +7058,7 @@ mod tests {
7046
7058
1 ,
7047
7059
Hash :: default ( ) ,
7048
7060
1 ,
7061
+ ProtocolVersion :: default ( ) ,
7049
7062
) ;
7050
7063
7051
7064
let expected_indices = vec ! [ 0 , 2 , 2 ] ;
@@ -7057,6 +7070,7 @@ mod tests {
7057
7070
expected_lemma_lengths,
7058
7071
vec ! [ b1, b2] ,
7059
7072
tally_txs,
7073
+ ProtocolVersion :: default ( ) ,
7060
7074
) ;
7061
7075
}
7062
7076
@@ -7108,6 +7122,7 @@ mod tests {
7108
7122
1 ,
7109
7123
Hash :: default ( ) ,
7110
7124
1 ,
7125
+ ProtocolVersion :: default ( ) ,
7111
7126
) ;
7112
7127
7113
7128
let expected_indices = vec ! [ 0 , 2 , 2 , 8 , 10 , 6 , 4 , 6 ] ;
@@ -7119,12 +7134,14 @@ mod tests {
7119
7134
expected_lemma_lengths,
7120
7135
vec ! [ b1, b2, b3] ,
7121
7136
tally_txs,
7137
+ ProtocolVersion :: default ( ) ,
7122
7138
) ;
7123
7139
}
7124
7140
7125
7141
#[ test]
7126
7142
fn test_tally_merkle_root_none ( ) {
7127
7143
let tally_txs = build_test_tally_txs ( 3 ) ;
7144
+ let protocol_version = ProtocolVersion :: default ( ) ;
7128
7145
7129
7146
let mut b1 = block_example ( ) ;
7130
7147
let mut b2 = block_example ( ) ;
@@ -7143,9 +7160,10 @@ mod tests {
7143
7160
1 ,
7144
7161
Hash :: default ( ) ,
7145
7162
1 ,
7163
+ ProtocolVersion :: default ( ) ,
7146
7164
) ;
7147
7165
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 ) ;
7149
7167
assert ! ( result. is_none( ) ) ;
7150
7168
}
7151
7169
@@ -7174,6 +7192,7 @@ mod tests {
7174
7192
1 ,
7175
7193
Hash :: default ( ) ,
7176
7194
1 ,
7195
+ ProtocolVersion :: default ( ) ,
7177
7196
) ;
7178
7197
7179
7198
let expected_indices = vec ! [ 0 , 2 , 2 ] ;
@@ -7185,6 +7204,7 @@ mod tests {
7185
7204
expected_lemma_lengths,
7186
7205
vec ! [ b1] ,
7187
7206
tally_txs,
7207
+ ProtocolVersion :: default ( ) ,
7188
7208
) ;
7189
7209
}
7190
7210
0 commit comments