@@ -227,6 +227,16 @@ pub mod pallet {
227227 worker : WorkerPublicKey ,
228228 amount : BalanceOf < T > ,
229229 } ,
230+
231+ /// Some to-distribute reward is dismissed because the amount is too tiny (dust)
232+ ///
233+ /// There's no affected state.
234+ RewardToOwnerDismissedDust { pid : u64 , amount : BalanceOf < T > } ,
235+
236+ /// Some to-distribute reward is dismissed because the amount is too tiny (dust)
237+ ///
238+ /// There's no affected state.
239+ RewardToDistributionDismissedDust { pid : u64 , amount : BalanceOf < T > } ,
230240 }
231241
232242 #[ pallet:: error]
@@ -1074,51 +1084,69 @@ pub mod pallet {
10741084 pool_info : & mut StakePool < T :: AccountId , BalanceOf < T > > ,
10751085 rewards : BalanceOf < T > ,
10761086 ) {
1077- if rewards > Zero :: zero ( ) {
1078- computation:: Pallet :: < T > :: withdraw_subsidy_pool (
1079- & <T as wrapped_balances:: Config >:: WrappedBalancesAccountId :: get ( ) ,
1080- rewards,
1081- )
1082- . expect ( "this should not happen" ) ;
1083- if base_pool:: balance_close_to_zero ( pool_info. basepool . total_shares ) {
1084- Self :: deposit_event ( Event :: < T > :: RewardDismissedNoShare {
1085- pid : pool_info. basepool . pid ,
1086- amount : rewards,
1087- } ) ;
1088- return ;
1089- }
1090- let commission = pool_info. payout_commission . unwrap_or_default ( ) * rewards;
1091-
1092- wrapped_balances:: Pallet :: < T > :: mint_into (
1093- & pool_info. owner_reward_account ,
1094- commission,
1095- )
1096- . expect ( "mint into should be success" ) ;
1097- let to_distribute = rewards - commission;
1098- wrapped_balances:: Pallet :: < T > :: mint_into (
1099- & pool_info. basepool . pool_account_id ,
1100- to_distribute,
1101- )
1102- . expect ( "mint into should be success" ) ;
1103- let distributed = if base_pool:: is_nondust_balance ( to_distribute) {
1087+ if rewards == Zero :: zero ( ) {
1088+ return ;
1089+ }
1090+ // Dismiss if the reward is dust
1091+ if base_pool:: balance_close_to_zero ( rewards) {
1092+ Self :: deposit_event ( Event :: < T > :: RewardDismissedDust {
1093+ pid : pool_info. basepool . pid ,
1094+ amount : rewards,
1095+ } ) ;
1096+ return ;
1097+ }
1098+ // Dismiss if the share is dust (pool is frozen)
1099+ if base_pool:: balance_close_to_zero ( pool_info. basepool . total_shares ) {
1100+ Self :: deposit_event ( Event :: < T > :: RewardDismissedNoShare {
1101+ pid : pool_info. basepool . pid ,
1102+ amount : rewards,
1103+ } ) ;
1104+ return ;
1105+ }
1106+ computation:: Pallet :: < T > :: withdraw_subsidy_pool (
1107+ & <T as wrapped_balances:: Config >:: WrappedBalancesAccountId :: get ( ) ,
1108+ rewards,
1109+ )
1110+ . expect ( "withdrawal from the subsidy pool should always success; qed." ) ;
1111+ // Handle the owner commission. Be careful about minting as it may fail (dust)
1112+ let commission = pool_info. payout_commission . unwrap_or_default ( ) * rewards;
1113+ let owner_minted = wrapped_balances:: Pallet :: < T > :: mint_into (
1114+ & pool_info. owner_reward_account ,
1115+ commission,
1116+ )
1117+ . expect ( "mint owner reward should succeed; qed." ) ;
1118+ if !owner_minted {
1119+ Self :: deposit_event ( Event :: < T > :: RewardToOwnerDismissedDust {
1120+ pid : pool_info. basepool . pid ,
1121+ amount : commission,
1122+ } ) ;
1123+ }
1124+ // Handle the to-distribute commission. Be careful about minting as it may fail (dust).
1125+ let to_distribute = rewards - commission;
1126+ let to_distribute_minted = wrapped_balances:: Pallet :: < T > :: mint_into (
1127+ & pool_info. basepool . pool_account_id ,
1128+ to_distribute,
1129+ )
1130+ . expect ( "mint to_distribute should succeed; qed." ) ;
1131+ let distributed =
1132+ if to_distribute_minted && base_pool:: is_nondust_balance ( to_distribute) {
11041133 pool_info. basepool . distribute_reward :: < T > ( to_distribute) ;
11051134 true
11061135 } else if to_distribute > Zero :: zero ( ) {
1107- Self :: deposit_event ( Event :: < T > :: RewardDismissedDust {
1136+ Self :: deposit_event ( Event :: < T > :: RewardToDistributionDismissedDust {
11081137 pid : pool_info. basepool . pid ,
11091138 amount : to_distribute,
11101139 } ) ;
11111140 false
11121141 } else {
11131142 false
11141143 } ;
1115- if distributed || commission > Zero :: zero ( ) {
1116- Self :: deposit_event ( Event :: < T > :: RewardReceived {
1117- pid : pool_info. basepool . pid ,
1118- to_owner : commission,
1119- to_stakers : to_distribute,
1120- } ) ;
1121- }
1144+ if distributed || owner_minted {
1145+ Self :: deposit_event ( Event :: < T > :: RewardReceived {
1146+ pid : pool_info. basepool . pid ,
1147+ to_owner : commission,
1148+ to_stakers : to_distribute,
1149+ } ) ;
11221150 }
11231151 }
11241152
@@ -1195,7 +1223,7 @@ pub mod pallet {
11951223 worker : info. pubkey ,
11961224 amount : reward,
11971225 } ) ;
1198- return ;
1226+ continue ;
11991227 }
12001228 } ;
12011229 let mut pool_info =
0 commit comments