feat: add store for challenge initiator reward amount indexed by height

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2024-07-01 20:57:35 +02:00
parent 00c7a6cd37
commit 390aefa002
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
5 changed files with 29 additions and 2 deletions

View File

@ -69,3 +69,19 @@ func (k Keeper) GetChallenges(ctx sdk.Context) (challenges []types.Challenge, er
}
return
}
func (k Keeper) storeChallangeInitiatorReward(ctx sdk.Context, height int64, amount uint64) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PoPInitiatorReward))
appendValue := util.SerializeUint64(amount)
store.Set(util.SerializeInt64(height), appendValue)
}
func (k Keeper) getChallengeInitiatorReward(ctx sdk.Context, height int64) (amount uint64, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PoPInitiatorReward))
amountBytes := store.Get(util.SerializeInt64(height))
if amountBytes == nil {
return 0, false
}
amount = util.DeserializeUint64(amountBytes)
return amount, true
}

View File

@ -45,7 +45,6 @@ func (k msgServer) resolveStagedClaims(ctx sdk.Context, start int64, end int64)
}
popParticipants := make(map[string]uint64)
validatorPopReward := k.GetValidatorPoPReward(ctx)
for _, challenge := range challenges {
// if challenge not finished nobody has claims
@ -61,6 +60,10 @@ func (k msgServer) resolveStagedClaims(ctx sdk.Context, start int64, end int64)
if err != nil {
util.GetAppLogger().Error(ctx, "error converting initiator address")
}
validatorPopReward, found := k.getChallengeInitiatorReward(ctx, challenge.GetHeight())
if !found {
util.GetAppLogger().Error(ctx, "No PoP initiator reward found for height %v", challenge.GetHeight())
}
popParticipants[initiatorAddr.String()] += validatorPopReward
}

View File

@ -24,6 +24,9 @@ func (k msgServer) InitPop(goCtx context.Context, msg *types.MsgInitPop) (*types
k.StoreChallenge(ctx, challenge)
amount := k.GetValidatorPoPReward(ctx)
k.storeChallangeInitiatorReward(ctx, msg.GetHeight(), amount)
validatorIdentity, err := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
if err != nil {
util.GetAppLogger().Error(ctx, initPopTag+errormsg.CouldNotGetValidatorIdentity+": "+err.Error())

View File

@ -80,7 +80,10 @@ func (k msgServer) issuePoPRewards(ctx sdk.Context, challenge types.Challenge) (
stagedCRDDL = stagedCRDDL.AddAmount(sdk.NewIntFromUint64(challengerAmt))
}
validatorPoPreward := k.GetValidatorPoPReward(ctx)
validatorPoPreward, found := k.getChallengeInitiatorReward(ctx, challenge.GetHeight())
if !found {
util.GetAppLogger().Error(ctx, "No PoP initiator reward found for height %v", challenge.GetHeight())
}
stagedCRDDL = stagedCRDDL.AddAmount(sdk.NewIntFromUint64(validatorPoPreward))
err = k.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(stagedCRDDL))

View File

@ -25,6 +25,8 @@ const (
PoPDistributionKey = "Dao/PoPDistribution"
PoPInitiatorReward = "Dao/PoPInitiatorReward"
ParamsKey = "Dao/Params"
)