Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
Review response
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenGround0 committed Oct 6, 2020
1 parent 0269804 commit 4d53729
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions actors/migration/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
func init() {
constStrs := []string{
"77669179383316",
"16058975841646949912583456815941211282956743",
"516058975841646949912583456815941211282956743",
}
constBigs := math2.Parse(constStrs)
gTauOverB0 = big.NewFromGo(constBigs[0]) // Q.128
Expand Down Expand Up @@ -94,6 +94,15 @@ func (m *rewardMigrator) MigrateState(ctx context.Context, store cbor.IpldStore,
outCumSumBaseline = big.Mul(outCumSumBaseline, oneOverGTau) // Q.128 * Q.128 => Q.256
outCumSumBaseline = big.Rsh(outCumSumBaseline, 2*math2.Precision128) // Q.256 => Q.0

// Reduce baseline total so that the amount of tokens remaining to be minted is held fixed across the upgrade
preUpgradeTheta := reward2.ComputeRTheta(inState.EffectiveNetworkTime, inState.EffectiveBaselinePower, inState.CumsumRealized, inState.CumsumBaseline) // Q.128
thetaDiff := big.Sub(preUpgradeTheta, postUpgradeTheta)
baselineAdjustmentExp := big.Mul(reward2.Lambda, thetaDiff) // Q.128 * Q.128 => Q.256
baselineAdjustmentExp = big.Rsh(baselineAdjustmentExp, math2.Precision128) // Q.256 => Q.128
baselineAdjustment := big.NewFromGo(math2.ExpNeg(baselineAdjustmentExp.Int))
outBaselineTotal := big.Mul(reward0.BaselineTotal, baselineAdjustment) // Q.0 * Q.128 => Q.128
outBaselineTotal = big.Rsh(outBaselineTotal, math2.Precision128) // Q.128 => Q.0

// Set reward filter postiion and velocity values

// Filter position is set by evaluating the closed form expression for expected
Expand All @@ -114,7 +123,7 @@ func (m *rewardMigrator) MigrateState(ctx context.Context, store cbor.IpldStore,
acc2 = big.NewFromGo(math2.ExpNeg(acc2.Int))
acc1 = big.Mul(acc1, acc2) //Q.128 * Q.128 => Q.256
acc1 = big.Rsh(acc1, math2.Precision128) // Q.256 => Q.128
acc1 = big.Mul(acc1, reward0.BaselineTotal) // Q.128 * Q.0 => Q.128
acc1 = big.Mul(acc1, outBaselineTotal) // Q.128 * Q.0 => Q.128
acc3 := big.Mul(big.NewInt(int64(migInfo.priorEpoch)), reward2.Lambda) // Q.0 * Q.128 => Q.128
acc3 = big.NewFromGo(math2.ExpNeg(acc3.Int))
acc3 = big.Mul(acc3, reward0.SimpleTotal) // Q.128 * Q.0 => Q.128
Expand All @@ -129,15 +138,6 @@ func (m *rewardMigrator) MigrateState(ctx context.Context, store cbor.IpldStore,
) // Q.128
outThisEpochRewardSmoothed := smoothing2.NewEstimate(outRewardSmoothedPosition, outRewardSmoothedVelocity)

// Reduce baseline total so that the amount of tokens remaining to be minted is held fixed across the upgrade
preUpgradeTheta := reward2.ComputeRTheta(inState.EffectiveNetworkTime, inState.EffectiveBaselinePower, inState.CumsumRealized, inState.CumsumBaseline) // Q.128
thetaDiff := big.Sub(preUpgradeTheta, postUpgradeTheta)
baselineAdjustmentExp := big.Mul(reward2.Lambda, thetaDiff) // Q.128 * Q.128 => Q.256
baselineAdjustmentExp = big.Rsh(baselineAdjustmentExp, math2.Precision128) // Q.256 => Q.128
baselineAdjustment := big.NewFromGo(math2.ExpNeg(baselineAdjustmentExp.Int))
outBaselineTotal := big.Mul(reward0.BaselineTotal, baselineAdjustment) // Q.0 * Q.128 => Q.128
outBaselineTotal = big.Rsh(outBaselineTotal, math2.Precision128) // Q.128 => Q.0

outState := reward2.State{
CumsumBaseline: outCumSumBaseline,
CumsumRealized: inState.CumsumRealized,
Expand Down
2 changes: 1 addition & 1 deletion actors/util/math/exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func ExpBySquaring(base big.Int, n int64) big.Int {
// Recurse
if n < 0 {
inverseBase := big.Div(big.Lsh(one, Precision128), base) // Q.256 / Q.128 => Q.128
return ExpBySquaring(inverseBase, n)
return ExpBySquaring(inverseBase, -n)
}
baseSquared := big.Mul(base, base) // Q.128 * Q.128 => Q.256
baseSquared = big.Rsh(baseSquared, Precision128) // Q.256 => Q.128
Expand Down

0 comments on commit 4d53729

Please sign in to comment.