@@ -1348,7 +1348,6 @@ impl ChainManager {
13481348
13491349 fn add_temp_superblock_votes ( & mut self , ctx : & mut Context < Self > ) {
13501350 let consensus_constants = self . consensus_constants ( ) ;
1351- let protocol = ProtocolVersion :: from_epoch_opt ( self . current_epoch ) ;
13521351
13531352 let superblock_period = u32:: from ( consensus_constants. superblock_period ) ;
13541353
@@ -1360,12 +1359,9 @@ impl ChainManager {
13601359 }
13611360
13621361 // Validate secp256k1 signature
1363- signature_mngr:: verify_signatures (
1364- vec ! [ SignaturesToVerify :: SuperBlockVote {
1365- superblock_vote: superblock_vote. clone( ) ,
1366- } ] ,
1367- protocol,
1368- )
1362+ signature_mngr:: verify_signatures ( vec ! [ SignaturesToVerify :: SuperBlockVote {
1363+ superblock_vote: superblock_vote. clone( ) ,
1364+ } ] )
13691365 . map ( |res| {
13701366 res. map_err ( |e| {
13711367 log:: error!( "Verify superblock vote signature: {}" , e) ;
@@ -1396,7 +1392,6 @@ impl ChainManager {
13961392 self . sm_state
13971393 ) ;
13981394 let consensus_constants = self . consensus_constants ( ) ;
1399- let protocol = ProtocolVersion :: from_epoch_opt ( self . current_epoch ) ;
14001395
14011396 let superblock_period = u32:: from ( consensus_constants. superblock_period ) ;
14021397
@@ -1410,12 +1405,9 @@ impl ChainManager {
14101405 }
14111406
14121407 // Validate secp256k1 signature
1413- signature_mngr:: verify_signatures (
1414- vec ! [ SignaturesToVerify :: SuperBlockVote {
1415- superblock_vote: superblock_vote. clone( ) ,
1416- } ] ,
1417- protocol,
1418- )
1408+ signature_mngr:: verify_signatures ( vec ! [ SignaturesToVerify :: SuperBlockVote {
1409+ superblock_vote: superblock_vote. clone( ) ,
1410+ } ] )
14191411 . into_actor ( self )
14201412 . map_err ( |e, _act, _ctx| {
14211413 log:: error!( "Verify superblock vote signature: {}" , e) ;
@@ -1578,7 +1570,24 @@ impl ChainManager {
15781570 // than or equal to the current epoch
15791571 block_epoch : current_epoch,
15801572 } ;
1581- let protocol_version = ProtocolVersion :: from_epoch ( current_epoch) ;
1573+ // For commit transactions, we want to verify their validity using the protocol version at
1574+ // the time of the data request inclusion. For simplicity's sake when validating signatures,
1575+ // we use the protocol version of the block epoch.
1576+ // For all other transactions which can pass through the add_transaction function and which
1577+ // need the protocol version, we can always use the protocol version of the block epoch.
1578+ let protocol_version = if let Transaction :: Commit ( co_tx) = & msg. transaction {
1579+ if let Some ( dr_state) = self
1580+ . chain_state
1581+ . data_request_pool
1582+ . data_request_state ( & co_tx. body . dr_pointer )
1583+ {
1584+ ProtocolVersion :: from_epoch ( dr_state. epoch )
1585+ } else {
1586+ ProtocolVersion :: from_epoch ( current_epoch)
1587+ }
1588+ } else {
1589+ ProtocolVersion :: from_epoch ( current_epoch)
1590+ } ;
15821591 let collateral_age = self
15831592 . consensus_constants_wit2
15841593 . get_collateral_age ( & active_wips) ;
@@ -1612,7 +1621,7 @@ impl ChainManager {
16121621 ) )
16131622 . into_actor ( self )
16141623 . and_then ( move |fee, act, _ctx| {
1615- signature_mngr:: verify_signatures ( signatures_to_verify, protocol_version )
1624+ signature_mngr:: verify_signatures ( signatures_to_verify)
16161625 . map ( move |res| res. map ( |( ) | fee) )
16171626 . into_actor ( act)
16181627 } )
@@ -2147,7 +2156,7 @@ impl ChainManager {
21472156 // Short-circuit if validation failed
21482157 res?;
21492158
2150- signature_mngr:: verify_signatures ( signatures_to_verify, protocol_version ) . await
2159+ signature_mngr:: verify_signatures ( signatures_to_verify) . await
21512160 }
21522161 . into_actor ( self )
21532162 . and_then ( move |( ) , act, _ctx| {
@@ -2166,13 +2175,12 @@ impl ChainManager {
21662175 & active_wips,
21672176 None ,
21682177 & act. chain_state . stakes ,
2169- protocol_version,
21702178 ) ;
21712179 async move {
21722180 // Short-circuit if validation failed
21732181 let diff = res?;
21742182
2175- signature_mngr:: verify_signatures ( signatures_to_verify, protocol_version )
2183+ signature_mngr:: verify_signatures ( signatures_to_verify)
21762184 . await
21772185 . map ( |( ) | diff)
21782186 }
@@ -2935,7 +2943,7 @@ pub fn process_validations(
29352943 replication_factor,
29362944 ) ?;
29372945 log:: trace!( "Verifying {} block signatures" , signatures_to_verify. len( ) ) ;
2938- verify_signatures ( signatures_to_verify, vrf_ctx, protocol_version ) ?;
2946+ verify_signatures ( signatures_to_verify, vrf_ctx) ?;
29392947 }
29402948
29412949 let mut signatures_to_verify = vec ! [ ] ;
@@ -2953,15 +2961,14 @@ pub fn process_validations(
29532961 active_wips,
29542962 transaction_visitor,
29552963 stakes,
2956- protocol_version,
29572964 ) ?;
29582965
29592966 if !resynchronizing {
29602967 log:: trace!(
29612968 "Verifying {} transaction signatures" ,
29622969 signatures_to_verify. len( )
29632970 ) ;
2964- verify_signatures ( signatures_to_verify, vrf_ctx, protocol_version ) ?;
2971+ verify_signatures ( signatures_to_verify, vrf_ctx) ?;
29652972 }
29662973
29672974 Ok ( utxo_dif)
@@ -3044,6 +3051,10 @@ fn process_wit2_stakes_changes(
30443051
30453052 let mut total_commit_reward = 0 ;
30463053 for co_tx in & block. txns . commit_txns {
3054+ if data_request_is_pre_wit2 ( data_request_pool, & Transaction :: Commit ( co_tx. clone ( ) ) ) {
3055+ continue ;
3056+ }
3057+
30473058 let commit_pkh = co_tx. body . proof . proof . pkh ( ) ;
30483059 total_commit_reward +=
30493060 if let Some ( dr_output) = data_request_pool. get_dr_output ( & co_tx. body . dr_pointer ) {
@@ -3081,6 +3092,10 @@ fn process_wit2_stakes_changes(
30813092 // Add reveal rewards
30823093 let mut total_reveal_reward = 0 ;
30833094 for re_tx in & block. txns . reveal_txns {
3095+ if data_request_is_pre_wit2 ( data_request_pool, & Transaction :: Reveal ( re_tx. clone ( ) ) ) {
3096+ continue ;
3097+ }
3098+
30843099 total_reveal_reward +=
30853100 if let Some ( dr_output) = data_request_pool. get_dr_output ( & re_tx. body . dr_pointer ) {
30863101 dr_output. commit_and_reveal_fee
@@ -3101,6 +3116,10 @@ fn process_wit2_stakes_changes(
31013116 }
31023117
31033118 for ta_tx in & block. txns . tally_txns {
3119+ if data_request_is_pre_wit2 ( data_request_pool, & Transaction :: Tally ( ta_tx. clone ( ) ) ) {
3120+ continue ;
3121+ }
3122+
31043123 let ( collateral, reward) =
31053124 if let Some ( dr_output) = data_request_pool. get_dr_output ( & ta_tx. dr_pointer ) {
31063125 ( dr_output. collateral , dr_output. witness_reward )
@@ -3194,6 +3213,10 @@ fn process_wit2_stakes_changes(
31943213
31953214 // Reset witnessing power
31963215 for co_tx in & block. txns . commit_txns {
3216+ if data_request_is_pre_wit2 ( data_request_pool, & Transaction :: Commit ( co_tx. clone ( ) ) ) {
3217+ continue ;
3218+ }
3219+
31973220 let commit_pkh = co_tx. body . proof . proof . pkh ( ) ;
31983221 log:: debug!(
31993222 "Resetting witnessing age for {} to {}" ,
@@ -3209,6 +3232,10 @@ fn process_wit2_stakes_changes(
32093232 // Collateral was already reserved, so not returning it results in losing it
32103233 // Reset the age for witnessing power to 10 epochs in the future
32113234 for ta_tx in & block. txns . tally_txns {
3235+ if data_request_is_pre_wit2 ( data_request_pool, & Transaction :: Tally ( ta_tx. clone ( ) ) ) {
3236+ continue ;
3237+ }
3238+
32123239 let liar_pkhs: Vec < PublicKeyHash > = ta_tx
32133240 . out_of_consensus
32143241 . iter ( )
@@ -3353,6 +3380,40 @@ fn update_pools(
33533380 rep_info
33543381}
33553382
3383+ fn data_request_is_pre_wit2 (
3384+ data_request_pool : & DataRequestPool ,
3385+ transaction : & Transaction ,
3386+ ) -> bool {
3387+ // Data requests which were included in a block prior to the activation of wit/2 do
3388+ // not need to be processed using the wit/2 business logic.
3389+ match transaction {
3390+ Transaction :: Commit ( co_tx) => {
3391+ if let Some ( dr_state) = data_request_pool. data_request_state ( & co_tx. body . dr_pointer ) {
3392+ if get_protocol_version ( Some ( dr_state. epoch ) ) < ProtocolVersion :: V2_0 {
3393+ return true ;
3394+ }
3395+ }
3396+ }
3397+ Transaction :: Reveal ( re_tx) => {
3398+ if let Some ( dr_state) = data_request_pool. data_request_state ( & re_tx. body . dr_pointer ) {
3399+ if get_protocol_version ( Some ( dr_state. epoch ) ) < ProtocolVersion :: V2_0 {
3400+ return true ;
3401+ }
3402+ }
3403+ }
3404+ Transaction :: Tally ( ta_tx) => {
3405+ if let Some ( dr_state) = data_request_pool. data_request_state ( & ta_tx. dr_pointer ) {
3406+ if get_protocol_version ( Some ( dr_state. epoch ) ) < ProtocolVersion :: V2_0 {
3407+ return true ;
3408+ }
3409+ }
3410+ }
3411+ _ => ( ) ,
3412+ }
3413+
3414+ false
3415+ }
3416+
33563417fn separate_honest_errors_and_liars < K , I > ( rep_info : I ) -> ( Vec < K > , Vec < K > , Vec < ( K , u32 ) > )
33573418where
33583419 I : IntoIterator < Item = ( K , RequestResult ) > ,
@@ -4793,6 +4854,7 @@ mod tests {
47934854 }
47944855
47954856 // Build pools
4857+ let epoch = 200 ;
47964858 let mut data_request_pool = DataRequestPool :: default ( ) ;
47974859 let data_request_state = DataRequestState {
47984860 data_request : DataRequestOutput {
@@ -4810,6 +4872,7 @@ mod tests {
48104872 ..Default :: default ( )
48114873 } ,
48124874 stage : DataRequestStage :: TALLY ,
4875+ epoch,
48134876 ..Default :: default ( )
48144877 } ;
48154878 data_request_pool. data_request_pool =
@@ -4818,7 +4881,6 @@ mod tests {
48184881 let unspent_outputs_pool = UnspentOutputsPool :: default ( ) ;
48194882
48204883 // Test stake changes with a block with a tally with four honests
4821- let epoch = 200 ;
48224884 let tally_transactions = vec ! [ TallyTransaction :: new(
48234885 Hash :: from( vec![ 1 ; 32 ] ) , // dr_pointer
48244886 vec![ ] , // tally
@@ -4827,7 +4889,7 @@ mod tests {
48274889 vec![ ] , // error_committers
48284890 ) ] ;
48294891 let block_one_succesful_tally = build_block_with_tally_transactions (
4830- epoch,
4892+ epoch + 3 ,
48314893 & mut data_request_pool,
48324894 tally_transactions,
48334895 & stakes,
0 commit comments