Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/Qb-1323,Qb-1320: Pot module account issue & move distribution to endblock #174

Merged
merged 3 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ var (
registertypes.TotalSlashedPoolName: {authtypes.Minter, authtypes.Burner},

pottypes.FoundationAccount: {authtypes.Minter, authtypes.Burner},
pottypes.MiningRewardPool: nil,
pottypes.TrafficRewardPool: nil,
pottypes.TotalRewardPool: nil,
//pottypes.TotalMinedTokens: {authtypes.Minter, authtypes.Burner},

Expand Down
2 changes: 1 addition & 1 deletion x/evm/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (k *Keeper) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {

k.SetBaseFeeParam(ctx, baseFee)

if !ctx.IsCheckTx() {
if !ctx.IsCheckTx() && len(ctx.HeaderHash()) > 0 {
overriddenTxHashes = make(map[string]struct{}, 0)
block, err := core.BlockByHash(&rpctypes.Context{}, ctx.HeaderHash().Bytes())
rawTxs := block.Block.Txs
Expand Down
27 changes: 25 additions & 2 deletions x/pot/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper)
}

// EndBlocker called every block, process inflation, update validator set.
func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
// TODO: fill out if your application requires endblock, if not you can delete this function
func EndBlocker(ctx sdk.Context, req abci.RequestEndBlock, k keeper.Keeper) []abci.ValidatorUpdate {

// Do not distribute rewards until the next block
if !k.GetIsReadyToDistributeReward(ctx) && k.GetUnhandledEpoch(ctx).GT(sdk.ZeroInt()) {
k.SetIsReadyToDistributeReward(ctx, true)
return []abci.ValidatorUpdate{}
}

walletVolumes, found := k.GetUnhandledReport(ctx)
if !found {
return []abci.ValidatorUpdate{}
}
epoch := k.GetUnhandledEpoch(ctx)
logger := k.Logger(ctx)

//distribute POT reward
_, err := k.DistributePotReward(ctx, walletVolumes, epoch)
if err != nil {
logger.Error("An error occurred while distributing the reward. ", err)
}

k.SetUnhandledReport(ctx, nil)
k.SetUnhandledEpoch(ctx, sdk.ZeroInt())

return []abci.ValidatorUpdate{}
}
15 changes: 12 additions & 3 deletions x/pot/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ func TestPotVolumeReportMsgs(t *testing.T) {
println("S=" + S.String() + "\nPt=" + Pt.String() + "\nY=" + Y.String() + "\nLt=" + Lt.String() + "\nR=" + R.String() + "\n")

println("---------------------------")
potKeeper.InitVariable(ctx)
distributeGoal := types.InitDistributeGoal()
distributeGoal, err := potKeeper.CalcTrafficRewardInTotal(ctx, distributeGoal, totalConsumedUoz)
require.NoError(t, err)
Expand All @@ -304,10 +305,9 @@ func TestPotVolumeReportMsgs(t *testing.T) {

println("---------------------------")
println("distribute detail:")
distributeGoalBalance := distributeGoal
rewardDetailMap := make(map[string]types.Reward)
rewardDetailMap, distributeGoalBalance = potKeeper.CalcRewardForResourceNode(ctx, totalConsumedUoz, volumeReportMsg.WalletVolumes, distributeGoalBalance, rewardDetailMap)
rewardDetailMap, distributeGoalBalance = potKeeper.CalcRewardForMetaNode(ctx, distributeGoalBalance, rewardDetailMap)
rewardDetailMap = potKeeper.CalcRewardForResourceNode(ctx, totalConsumedUoz, volumeReportMsg.WalletVolumes, distributeGoal, rewardDetailMap)
rewardDetailMap = potKeeper.CalcRewardForMetaNode(ctx, distributeGoal, rewardDetailMap)

println("resource_wallet1: address = " + resOwner1.String())
println(" miningReward = " + rewardDetailMap[resOwner1.String()].RewardFromMiningPool.String())
Expand Down Expand Up @@ -356,6 +356,11 @@ func TestPotVolumeReportMsgs(t *testing.T) {
require.NoError(t, err)

/********************* commit & check result *********************/
// reward distribution start at height = height + 1 where volume report tx executed
header = tmproto.Header{Height: stApp.LastBlockHeight() + 1, ChainID: chainID}
stApp.BeginBlock(abci.RequestBeginBlock{Header: header})
stApp.EndBlock(abci.RequestEndBlock{Height: header.Height})
stApp.Commit()
header = tmproto.Header{Height: stApp.LastBlockHeight() + 1, ChainID: chainID}
stApp.BeginBlock(abci.RequestBeginBlock{Header: header})
ctx = stApp.BaseApp.NewContext(true, header)
Expand Down Expand Up @@ -466,6 +471,10 @@ func checkResult(t *testing.T, ctx sdk.Context,
}
println("matureTotalOfResNode1Change = " + matureTotalOfResNode1Change.String())
require.Equal(t, matureTotalOfResNode1Change.String(), upcomingMaturedIndividual.String())

totalRewardPoolAddr := accountKeeper.GetModuleAddress(types.TotalRewardPool)
totalRewardPoolBalance := bankKeeper.GetAllBalances(ctx, totalRewardPoolAddr)
println("totalRewardPoolBalance = " + totalRewardPoolBalance.String())
}

func checkValidator(t *testing.T, app *app.NewApp, addr sdk.ValAddress, expFound bool) stakingtypes.Validator {
Expand Down
Loading