mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-09-13 20:00:10 +00:00

* adjust issuePoPRewards to mint stagedCRDDL * add GetChallengeRange * add resolveStagedClaims on ReissueRDDLResult msg * move claim resolve to distribution result * add StagedDenom and ClaimDenom to config * added the prepare4linting.sh script * renamed PoPEpochs to PopEpochs * renamed DistributionAddressPoP to DistributionAddressPop * added config value ReIssuanceEpochs * detached the re-issuance from the distribution process and schedule them independently * changed logging messages * added an explicit util/kv_serialize.go file to have all KV serialization done * switched to Bigendian serialization of int64 to have the ordered list on the kvstore * added ComputeReIssuanceValue to enable re-issuances once a day or defined by ReIssuanceEpoch * integrated a ReIssuanceValue computation test case * adjusted the challenges test cases to be epoch-dependent * added ReIssuances per ReIssuanceEpoch * extended the Reissue message * checking ReIssuanceProposal in the ante handler * added precision setter for the UINT to RDDL token converter (and test cases) * add e2e test case for pop rewards Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> Co-authored-by: Jürgen Eckel <juergen@riddleandcode.com>
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package dao
|
|
|
|
import (
|
|
"encoding/hex"
|
|
|
|
"github.com/planetmint/planetmint-go/config"
|
|
"github.com/planetmint/planetmint-go/util"
|
|
"github.com/planetmint/planetmint-go/x/dao/keeper"
|
|
|
|
abci "github.com/cometbft/cometbft/abci/types"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
|
|
proposerAddress := req.Header.GetProposerAddress()
|
|
|
|
// Check if node is block proposer
|
|
// take the following actions only once, that's why we filter for the Block Proposer
|
|
if !util.IsValidatorBlockProposer(ctx, proposerAddress) {
|
|
return
|
|
}
|
|
currentBlockHeight := req.Header.GetHeight()
|
|
|
|
hexProposerAddress := hex.EncodeToString(proposerAddress)
|
|
if isPopHeight(req.Header.GetHeight()) {
|
|
// select PoP participants
|
|
challenger := ""
|
|
challengee := ""
|
|
|
|
// Issue PoP
|
|
util.SendInitPoP(ctx, hexProposerAddress, challenger, challengee, currentBlockHeight)
|
|
// TODO send MQTT message to challenger && challengee
|
|
}
|
|
|
|
if isReIssuanceHeight(currentBlockHeight) {
|
|
reIssuance, err := k.CreateNextReIssuanceObject(ctx, currentBlockHeight)
|
|
if err == nil {
|
|
util.SendInitReissuance(ctx, hexProposerAddress, reIssuance.GetRawTx(), currentBlockHeight,
|
|
reIssuance.GetFirstIncludedPop(), reIssuance.GetLastIncludedPop())
|
|
} else {
|
|
util.GetAppLogger().Error(ctx, "error while computing the RDDL re-issuance ", err)
|
|
}
|
|
}
|
|
|
|
if isDistributionHeight(currentBlockHeight) {
|
|
distribution, err := k.GetDistributionForReissuedTokens(ctx, currentBlockHeight)
|
|
if err != nil {
|
|
util.GetAppLogger().Error(ctx, "error while computing the RDDL distribution ", err)
|
|
}
|
|
util.SendDistributionRequest(ctx, distribution)
|
|
}
|
|
}
|
|
|
|
func isPopHeight(height int64) bool {
|
|
cfg := config.GetConfig()
|
|
return height%int64(cfg.PopEpochs) == 0
|
|
}
|
|
|
|
func isReIssuanceHeight(height int64) bool {
|
|
cfg := config.GetConfig()
|
|
return height%int64(cfg.ReIssuanceEpochs) == 0
|
|
}
|
|
|
|
func isDistributionHeight(height int64) bool {
|
|
cfg := config.GetConfig()
|
|
return height%int64(cfg.DistributionEpochs) == 0
|
|
}
|
|
|
|
func EndBlocker(ctx sdk.Context, _ abci.RequestEndBlock, k keeper.Keeper) {
|
|
k.DistributeCollectedFees(ctx)
|
|
}
|