@@ -33,6 +33,8 @@ use clarity::vm::types::*;
33
33
34
34
use crate :: types:: chainstate:: { StacksAddress , StacksBlockId } ;
35
35
36
+ use crate :: core:: StacksEpochId ;
37
+
36
38
#[ derive( Debug , Clone , PartialEq ) ]
37
39
pub struct MinerReward {
38
40
pub address : StacksAddress ,
@@ -873,6 +875,7 @@ impl StacksChainState {
873
875
/// not the miner, for reporting the microblock stream fork.
874
876
fn calculate_miner_reward (
875
877
mainnet : bool ,
878
+ evaluated_epoch : StacksEpochId ,
876
879
participant : & MinerPaymentSchedule ,
877
880
miner : & MinerPaymentSchedule ,
878
881
users : & Vec < MinerPaymentSchedule > ,
@@ -946,7 +949,7 @@ impl StacksChainState {
946
949
)
947
950
} else {
948
951
// users that helped a miner that reported a poison-microblock get nothing
949
- ( StacksAddress :: burn_address ( mainnet) , coinbase_reward , false )
952
+ ( StacksAddress :: burn_address ( mainnet) , 0 , false )
950
953
}
951
954
} else {
952
955
// no poison microblock reported
@@ -963,12 +966,16 @@ impl StacksChainState {
963
966
} else {
964
967
0
965
968
} ,
966
- // TODO: this is wrong, per #3140. It should be
967
- // `participant.streamed_tx_fees_produced()`, since
968
- // `participant.tx_fees_streamed` contains the sum of the microblock
969
- // transaction fees that `participant` confirmed (and thus `participant`'s
970
- // parent produced).
971
- parent. streamed_tx_fees_produced ( ) ,
969
+ if evaluated_epoch < StacksEpochId :: Epoch21 {
970
+ // this is wrong, per #3140. It should be
971
+ // `participant.streamed_tx_fees_produced()`, since
972
+ // `participant.tx_fees_streamed` contains the sum of the microblock
973
+ // transaction fees that `participant` confirmed (and thus `participant`'s
974
+ // parent produced). But we're stuck with it for earlier epochs.
975
+ parent. streamed_tx_fees_produced ( )
976
+ } else {
977
+ participant. streamed_tx_fees_produced ( )
978
+ } ,
972
979
if !punished {
973
980
participant. streamed_tx_fees_confirmed ( )
974
981
} else {
@@ -1016,6 +1023,7 @@ impl StacksChainState {
1016
1023
/// well as an info struct about where the rewards took place on the chain.
1017
1024
pub fn find_mature_miner_rewards (
1018
1025
clarity_tx : & mut ClarityTx ,
1026
+ sortdb_conn : & Connection ,
1019
1027
tip : & StacksHeaderInfo ,
1020
1028
mut latest_matured_miners : Vec < MinerPaymentSchedule > ,
1021
1029
parent_miner : MinerPaymentSchedule ,
@@ -1044,6 +1052,15 @@ impl StacksChainState {
1044
1052
from_parent_block_consensus_hash : parent_miner. consensus_hash . clone ( ) ,
1045
1053
} ;
1046
1054
1055
+ // what epoch was the parent miner's block evaluated in?
1056
+ let evaluated_snapshot =
1057
+ SortitionDB :: get_block_snapshot_consensus ( sortdb_conn, & parent_miner. consensus_hash ) ?
1058
+ . expect ( "FATAL: no snapshot for evaluated block" ) ;
1059
+
1060
+ let evaluated_epoch =
1061
+ SortitionDB :: get_stacks_epoch ( sortdb_conn, evaluated_snapshot. block_height ) ?
1062
+ . expect ( "FATAL: no epoch for evaluated block" ) ;
1063
+
1047
1064
// was this block penalized for mining a forked microblock stream?
1048
1065
// If so, find the principal that detected the poison, and reward them instead.
1049
1066
let poison_recipient_opt =
@@ -1063,6 +1080,7 @@ impl StacksChainState {
1063
1080
// calculate miner reward
1064
1081
let ( parent_miner_reward, miner_reward) = StacksChainState :: calculate_miner_reward (
1065
1082
mainnet,
1083
+ evaluated_epoch. epoch_id ,
1066
1084
& miner,
1067
1085
& miner,
1068
1086
& users,
@@ -1075,6 +1093,7 @@ impl StacksChainState {
1075
1093
for user_reward in users. iter ( ) {
1076
1094
let ( parent_reward, reward) = StacksChainState :: calculate_miner_reward (
1077
1095
mainnet,
1096
+ evaluated_epoch. epoch_id ,
1078
1097
user_reward,
1079
1098
& miner,
1080
1099
& users,
@@ -1102,6 +1121,7 @@ mod test {
1102
1121
use crate :: chainstate:: stacks:: index:: * ;
1103
1122
use crate :: chainstate:: stacks:: Error ;
1104
1123
use crate :: chainstate:: stacks:: * ;
1124
+ use crate :: core:: StacksEpochId ;
1105
1125
use clarity:: vm:: costs:: ExecutionCost ;
1106
1126
use stacks_common:: util:: hash:: * ;
1107
1127
@@ -1378,6 +1398,7 @@ mod test {
1378
1398
1379
1399
let ( parent_reward, miner_reward) = StacksChainState :: calculate_miner_reward (
1380
1400
false ,
1401
+ StacksEpochId :: Epoch2_05 ,
1381
1402
& participant,
1382
1403
& participant,
1383
1404
& vec ! [ ] ,
@@ -1412,6 +1433,7 @@ mod test {
1412
1433
1413
1434
let ( parent_miner_1, reward_miner_1) = StacksChainState :: calculate_miner_reward (
1414
1435
false ,
1436
+ StacksEpochId :: Epoch2_05 ,
1415
1437
& miner,
1416
1438
& miner,
1417
1439
& vec ! [ user. clone( ) ] ,
@@ -1420,6 +1442,7 @@ mod test {
1420
1442
) ;
1421
1443
let ( parent_user_1, reward_user_1) = StacksChainState :: calculate_miner_reward (
1422
1444
false ,
1445
+ StacksEpochId :: Epoch2_05 ,
1423
1446
& user,
1424
1447
& miner,
1425
1448
& vec ! [ user. clone( ) ] ,
@@ -1460,6 +1483,7 @@ mod test {
1460
1483
1461
1484
let ( parent_reward, miner_reward) = StacksChainState :: calculate_miner_reward (
1462
1485
false ,
1486
+ StacksEpochId :: Epoch2_05 ,
1463
1487
& participant,
1464
1488
& participant,
1465
1489
& vec ! [ ] ,
0 commit comments