mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 06:25:47 +00:00
feat: add store for challenge initiator reward amount indexed by height
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
00c7a6cd37
commit
390aefa002
@ -69,3 +69,19 @@ func (k Keeper) GetChallenges(ctx sdk.Context) (challenges []types.Challenge, er
|
|||||||
}
|
}
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
|||||||
@ -45,7 +45,6 @@ func (k msgServer) resolveStagedClaims(ctx sdk.Context, start int64, end int64)
|
|||||||
}
|
}
|
||||||
|
|
||||||
popParticipants := make(map[string]uint64)
|
popParticipants := make(map[string]uint64)
|
||||||
validatorPopReward := k.GetValidatorPoPReward(ctx)
|
|
||||||
|
|
||||||
for _, challenge := range challenges {
|
for _, challenge := range challenges {
|
||||||
// if challenge not finished nobody has claims
|
// 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 {
|
if err != nil {
|
||||||
util.GetAppLogger().Error(ctx, "error converting initiator address")
|
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
|
popParticipants[initiatorAddr.String()] += validatorPopReward
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,9 @@ func (k msgServer) InitPop(goCtx context.Context, msg *types.MsgInitPop) (*types
|
|||||||
|
|
||||||
k.StoreChallenge(ctx, challenge)
|
k.StoreChallenge(ctx, challenge)
|
||||||
|
|
||||||
|
amount := k.GetValidatorPoPReward(ctx)
|
||||||
|
k.storeChallangeInitiatorReward(ctx, msg.GetHeight(), amount)
|
||||||
|
|
||||||
validatorIdentity, err := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
|
validatorIdentity, err := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetAppLogger().Error(ctx, initPopTag+errormsg.CouldNotGetValidatorIdentity+": "+err.Error())
|
util.GetAppLogger().Error(ctx, initPopTag+errormsg.CouldNotGetValidatorIdentity+": "+err.Error())
|
||||||
|
|||||||
@ -80,7 +80,10 @@ func (k msgServer) issuePoPRewards(ctx sdk.Context, challenge types.Challenge) (
|
|||||||
stagedCRDDL = stagedCRDDL.AddAmount(sdk.NewIntFromUint64(challengerAmt))
|
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))
|
stagedCRDDL = stagedCRDDL.AddAmount(sdk.NewIntFromUint64(validatorPoPreward))
|
||||||
|
|
||||||
err = k.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(stagedCRDDL))
|
err = k.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(stagedCRDDL))
|
||||||
|
|||||||
@ -25,6 +25,8 @@ const (
|
|||||||
|
|
||||||
PoPDistributionKey = "Dao/PoPDistribution"
|
PoPDistributionKey = "Dao/PoPDistribution"
|
||||||
|
|
||||||
|
PoPInitiatorReward = "Dao/PoPInitiatorReward"
|
||||||
|
|
||||||
ParamsKey = "Dao/Params"
|
ParamsKey = "Dao/Params"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user