@@ -927,19 +927,39 @@ func (es *ExtensionStateImpl) regulateIssue(iScore *big.Int) error {
927927 return err
928928 }
929929 reward := new (big.Int ).Set (iScore )
930- if prevGlobal != nil && icstate .IISSVersion3 == prevGlobal .GetIISSVersion () {
931- pg := prevGlobal .GetV2 ()
932- multiplier := big .NewInt (int64 (prevGlobal .GetTermPeriod () * icmodule .IScoreICXRatio ))
933- divider := big .NewInt (icmodule .MonthBlock * icmodule .DenomInRate )
934- rewardCPS := new (big.Int ).Mul (pg .GetIGlobal (), pg .GetICps ().NumBigInt ())
935- rewardCPS .Mul (rewardCPS , multiplier )
936- rewardCPS .Div (rewardCPS , divider )
937- reward .Add (reward , rewardCPS )
938- rewardRelay := new (big.Int ).Mul (pg .GetIGlobal (), pg .GetIRelay ().NumBigInt ())
939- rewardRelay .Mul (rewardRelay , multiplier )
940- rewardRelay .Div (rewardRelay , divider )
941- reward .Add (reward , rewardRelay )
942- es .logger .Tracef ("regulateIssue with cps: %d, relay: %d" , rewardCPS , rewardRelay )
930+ if prevGlobal != nil {
931+ switch prevGlobal .GetIISSVersion () {
932+ case icstate .IISSVersion2 :
933+ case icstate .IISSVersion3 :
934+ pg := prevGlobal .GetV2 ()
935+ multiplier := big .NewInt (int64 (prevGlobal .GetTermPeriod () * icmodule .IScoreICXRatio ))
936+ divider := big .NewInt (icmodule .MonthBlock * icmodule .DenomInRate )
937+ rewardCPS := new (big.Int ).Mul (pg .GetIGlobal (), pg .GetICps ().NumBigInt ())
938+ rewardCPS .Mul (rewardCPS , multiplier )
939+ rewardCPS .Div (rewardCPS , divider )
940+ reward .Add (reward , rewardCPS )
941+ rewardRelay := new (big.Int ).Mul (pg .GetIGlobal (), pg .GetIRelay ().NumBigInt ())
942+ rewardRelay .Mul (rewardRelay , multiplier )
943+ rewardRelay .Div (rewardRelay , divider )
944+ reward .Add (reward , rewardRelay )
945+ es .logger .Tracef ("regulateIssue with cps: %d, relay: %d" , rewardCPS , rewardRelay )
946+ case icstate .IISSVersion4 :
947+ if term .Revision () >= icmodule .RevisionFixIssueRegulator {
948+ pg := prevGlobal .GetV3 ()
949+ multiplier := big .NewInt (int64 (pg .GetTermPeriod () * icmodule .IScoreICXRatio ))
950+
951+ keys := []icstate.RFundKey {icstate .KeyIcps , icstate .KeyIrelay }
952+ for _ , key := range keys {
953+ amount := pg .GetRewardFundAmountByKey (key )
954+ amount .Mul (amount , multiplier )
955+ amount .Div (amount , big .NewInt (icmodule .MonthBlock ))
956+ reward .Add (reward , amount )
957+ es .logger .Tracef ("regulateIssue with %s: %s" , key , amount )
958+ }
959+ }
960+ default :
961+ panic ("regulateIssue: unknown IISS version" )
962+ }
943963 }
944964
945965 is , err := es .State .GetIssue ()
@@ -1703,9 +1723,10 @@ func (es *ExtensionStateImpl) transferRewardFund(cc icmodule.CallContext) error
17031723 amount .Div (amount , div )
17041724 if ok {
17051725 if err := cc .Transfer (from , to , amount , module .Reward ); err != nil {
1706- return err
1726+ EmitRewardFundTransferFailedEvent (cc , k .key , from , to , amount )
1727+ } else {
1728+ EmitRewardFundTransferredEvent (cc , k .key , from , to , amount )
17071729 }
1708- EmitRewardFundTransferredEvent (cc , k .key , from , to , amount )
17091730 } else {
17101731 if cc .Revision ().Value () >= icmodule .RevisionFixTransferRewardFund {
17111732 if err := cc .Withdraw (from , amount , module .Burn ); err != nil {
0 commit comments