Fix distribution bugs (#228)

* fixed missing-proposer bug for asset distribution

* improved logging

reduced type conversions and potential errors

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-12-12 11:09:33 +01:00 committed by GitHub
parent 73b0d1b4c8
commit 2b19b8194b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 15 deletions

View File

@ -2,7 +2,6 @@ package util
import (
"context"
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/config"
@ -63,16 +62,11 @@ func SendDistributionRequest(goCtx context.Context, distribution daotypes.Distri
buildSignBroadcastTx(goCtx, "sending the distribution request", sendingValidatorAddress, msg)
}
func SendDistributionResult(goCtx context.Context, lastPoP string, daoTxID string, invTxID string, popTxID string) {
func SendDistributionResult(goCtx context.Context, lastPoP int64, daoTxID string, invTxID string, popTxID string) {
ctx := sdk.UnwrapSDKContext(goCtx)
sendingValidatorAddress := config.GetConfig().ValidatorAddress
GetAppLogger().Info(ctx, "create Distribution Result")
iLastPoP, err := strconv.ParseInt(lastPoP, 10, 64)
if err != nil {
ctx.Logger().Error("Distribution Result: preparation failed ", err.Error())
return
}
msg := daotypes.NewMsgDistributionResult(sendingValidatorAddress, iLastPoP, daoTxID, invTxID, popTxID)
msg := daotypes.NewMsgDistributionResult(sendingValidatorAddress, lastPoP, daoTxID, invTxID, popTxID)
buildSignBroadcastTx(goCtx, "send distribution result", sendingValidatorAddress, msg)
}

View File

@ -47,6 +47,7 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper)
if err != nil {
util.GetAppLogger().Error(ctx, "error while computing the RDDL distribution ", err)
}
distribution.Proposer = hexProposerAddress
util.SendDistributionRequest(ctx, distribution)
}
}

View File

@ -2,7 +2,6 @@ package keeper
import (
"context"
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/util"
@ -14,26 +13,27 @@ func (k msgServer) DistributionRequest(goCtx context.Context, msg *types.MsgDist
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx)
if validResult && msg.Distribution.GetProposer() == validatorIdentity {
util.GetAppLogger().Info(ctx, "distribution request: Entering Asset Distribution Mode")
// issue three distributions:
investorTx, err := util.DistributeAsset(msg.Distribution.InvestorAddr, msg.Distribution.InvestorAmount)
if err != nil {
ctx.Logger().Error("Distribution Request: could not distribute asset to Investors: ", err.Error())
util.GetAppLogger().Error(ctx, "Distribution Request: could not distribute asset to Investors: ", err.Error())
}
popTx, err := util.DistributeAsset(msg.Distribution.PopAddr, msg.Distribution.PopAmount)
if err != nil {
ctx.Logger().Error("Distribution Request: could not distribute asset to PoP: ", err.Error())
util.GetAppLogger().Error(ctx, "Distribution Request: could not distribute asset to PoP: ", err.Error())
}
daoTx, err := util.DistributeAsset(msg.Distribution.DaoAddr, msg.Distribution.DaoAmount)
if err != nil {
ctx.Logger().Error("Distribution Request: could not distribute asset to DAO: ", err.Error())
util.GetAppLogger().Error(ctx, "Distribution Request: could not distribute asset to DAO: ", err.Error())
}
msg.Distribution.InvestorTxID = investorTx
msg.Distribution.PopTxID = popTx
msg.Distribution.DaoTxID = daoTx
lastPopString := strconv.FormatInt(msg.Distribution.LastPop, 10)
util.SendDistributionResult(goCtx, lastPopString, daoTx, investorTx, popTx)
util.SendDistributionResult(goCtx, msg.Distribution.LastPop, daoTx, investorTx, popTx)
}
util.GetAppLogger().Info(ctx, "distribution request: storing distribution")
k.StoreDistributionOrder(ctx, *msg.GetDistribution())
return &types.MsgDistributionRequestResponse{}, nil

View File

@ -21,7 +21,7 @@ func (k msgServer) DistributionResult(goCtx context.Context, msg *types.MsgDistr
distribution.InvestorTxID = msg.InvestorTxID
err := k.resolveStagedClaims(ctx, distribution.FirstPop, distribution.LastPop)
if err != nil {
return nil, errorsmod.Wrapf(types.ErrResolvingStagedClaims, " for provieded PoP heights: %d %d", distribution.FirstPop, distribution.LastPop)
return nil, errorsmod.Wrapf(types.ErrResolvingStagedClaims, " for provided PoP heights: %d %d", distribution.FirstPop, distribution.LastPop)
}
k.StoreDistributionOrder(ctx, distribution)
} else {