diff --git a/app/ante/check_reissuance_decorator.go b/app/ante/check_reissuance_decorator.go index 9359baa..7c2a326 100644 --- a/app/ante/check_reissuance_decorator.go +++ b/app/ante/check_reissuance_decorator.go @@ -7,6 +7,10 @@ import ( daotypes "github.com/planetmint/planetmint-go/x/dao/types" ) +var ( + anteHandlerTag = "ante handler: " +) + type CheckReissuanceDecorator struct { dk DaoKeeper } @@ -22,13 +26,13 @@ func (cmad CheckReissuanceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu if sdk.MsgTypeURL(msg) == "/planetmintgo.dao.MsgReissueRDDLProposal" { MsgProposal, ok := msg.(*daotypes.MsgReissueRDDLProposal) if ok { - util.GetAppLogger().Debug(ctx, "ante handler - received re-issuance proposal") + util.GetAppLogger().Debug(ctx, anteHandlerTag+"received re-issuance proposal: "+MsgProposal.String()) isValid := cmad.dk.IsValidReIssuanceProposal(ctx, MsgProposal) if !isValid { - util.GetAppLogger().Info(ctx, "ante handler - rejected re-issuance proposal") + util.GetAppLogger().Info(ctx, anteHandlerTag+"rejected re-issuance proposal") return ctx, errorsmod.Wrapf(daotypes.ErrReissuanceProposal, "error during CheckTx or ReCheckTx") } - util.GetAppLogger().Debug(ctx, "ante handler - accepted re-issuance proposal") + util.GetAppLogger().Debug(ctx, anteHandlerTag+"accepted re-issuance proposal: "+MsgProposal.String()) } } } diff --git a/util/issue_commands.go b/util/issue_commands.go index 7117053..e227a8e 100644 --- a/util/issue_commands.go +++ b/util/issue_commands.go @@ -12,6 +12,8 @@ import ( ) func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingValidatorAddress string, msg sdk.Msg) { + ctx := sdk.UnwrapSDKContext(goCtx) + GetAppLogger().Info(ctx, loggingContext+": "+msg.String()) go func() { ctx := sdk.UnwrapSDKContext(goCtx) addr := sdk.MustAccAddressFromBech32(sendingValidatorAddress) @@ -42,51 +44,45 @@ func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingV func SendInitReissuance(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64, firstIncludedPop int64, lastIncludedPop int64) { - ctx := sdk.UnwrapSDKContext(goCtx) // get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store sendingValidatorAddress := config.GetConfig().ValidatorAddress - GetAppLogger().Info(ctx, "create re-issuance proposal") msg := daotypes.NewMsgReissueRDDLProposal(sendingValidatorAddress, proposerAddress, txUnsigned, blockHeight, firstIncludedPop, lastIncludedPop) - buildSignBroadcastTx(goCtx, "initializing RDDL re-issuance", sendingValidatorAddress, msg) + loggingContext := "reissuance proposal" + buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg) } func SendReissuanceResult(goCtx context.Context, proposerAddress string, txID string, blockHeight int64) { - ctx := sdk.UnwrapSDKContext(goCtx) sendingValidatorAddress := config.GetConfig().ValidatorAddress - GetAppLogger().Info(ctx, "create re-issuance result") msg := daotypes.NewMsgReissueRDDLResult(sendingValidatorAddress, proposerAddress, txID, blockHeight) - buildSignBroadcastTx(goCtx, "sending the re-issuance result", sendingValidatorAddress, msg) + loggingContext := "reissuance result" + buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg) } func SendDistributionRequest(goCtx context.Context, distribution daotypes.DistributionOrder) { - ctx := sdk.UnwrapSDKContext(goCtx) sendingValidatorAddress := config.GetConfig().ValidatorAddress - GetAppLogger().Info(ctx, "create Distribution Request") msg := daotypes.NewMsgDistributionRequest(sendingValidatorAddress, &distribution) - buildSignBroadcastTx(goCtx, "sending the distribution request", sendingValidatorAddress, msg) + loggingContext := "distribution request" + buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg) } 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") msg := daotypes.NewMsgDistributionResult(sendingValidatorAddress, lastPoP, daoTxID, invTxID, popTxID) - buildSignBroadcastTx(goCtx, "send distribution result", sendingValidatorAddress, msg) + loggingContext := "distribution result" + buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg) } func SendLiquidAssetRegistration(goCtx context.Context, notarizedAsset machinetypes.LiquidAsset) { - ctx := sdk.UnwrapSDKContext(goCtx) sendingValidatorAddress := config.GetConfig().ValidatorAddress - GetAppLogger().Info(ctx, "create Liquid Asset Registration") msg := machinetypes.NewMsgNotarizeLiquidAsset(sendingValidatorAddress, ¬arizedAsset) - buildSignBroadcastTx(goCtx, "Liquid Asset Registration:", sendingValidatorAddress, msg) + loggingContext := "notarize liquid asset" + buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg) } func SendInitPoP(goCtx context.Context, proposer string, challenger string, challengee string, blockHeight int64) { - ctx := sdk.UnwrapSDKContext(goCtx) sendingValidatorAddress := config.GetConfig().ValidatorAddress - GetAppLogger().Info(ctx, "create Init PoP message") msg := daotypes.NewMsgInitPop(sendingValidatorAddress, proposer, challenger, challengee, blockHeight) - buildSignBroadcastTx(goCtx, "Init PoP:", sendingValidatorAddress, msg) + loggingContext := "init PoP" + buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg) } diff --git a/util/logger.go b/util/logger.go index 7e3bae5..cfa12b5 100644 --- a/util/logger.go +++ b/util/logger.go @@ -44,7 +44,7 @@ func (logger *AppLogger) testingLog(msg string, keyvals ...interface{}) { logger.testingLogger.Log(msg) return } - logger.testingLogger.Log(msg, keyvals) + logger.testingLogger.Logf(msg, keyvals...) } func (logger *AppLogger) Info(ctx sdk.Context, msg string, keyvals ...interface{}) { diff --git a/x/dao/keeper/msg_server_distribution_request.go b/x/dao/keeper/msg_server_distribution_request.go index 476f5c3..2cc312f 100644 --- a/x/dao/keeper/msg_server_distribution_request.go +++ b/x/dao/keeper/msg_server_distribution_request.go @@ -9,6 +9,10 @@ import ( "github.com/planetmint/planetmint-go/x/dao/types" ) +var ( + distributionRequestTag = "distribution request: " +) + func (k msgServer) DistributionRequest(goCtx context.Context, msg *types.MsgDistributionRequest) (*types.MsgDistributionRequestResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -21,30 +25,32 @@ func (k msgServer) DistributionRequest(goCtx context.Context, msg *types.MsgDist return nil, errorsmod.Wrap(types.ErrReissuanceTxIDMissing, "for last reissuance height") } - util.GetAppLogger().Info(ctx, "distribution request: storing distribution") + util.GetAppLogger().Info(ctx, distributionRequestTag+"storing distribution: "+msg.GetDistribution().String()) k.StoreDistributionOrder(ctx, *msg.GetDistribution()) validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx) if validResult && msg.Distribution.GetProposer() == validatorIdentity { - util.GetAppLogger().Info(ctx, "distribution request: Entering Asset Distribution Mode") + util.GetAppLogger().Info(ctx, distributionRequestTag+"entering asset distribution mode") // issue three distributions: investorTx, err := util.DistributeAsset(msg.Distribution.InvestorAddr, msg.Distribution.InvestorAmount) if err != nil { - util.GetAppLogger().Error(ctx, "Distribution Request: could not distribute asset to Investors: ", err.Error()) + util.GetAppLogger().Error(ctx, distributionRequestTag+"could not distribute asset to Investors: ", err.Error()) } popTx, err := util.DistributeAsset(msg.Distribution.PopAddr, msg.Distribution.PopAmount) if err != nil { - util.GetAppLogger().Error(ctx, "Distribution Request: could not distribute asset to PoP: ", err.Error()) + util.GetAppLogger().Error(ctx, distributionRequestTag+"could not distribute asset to PoP: ", err.Error()) } daoTx, err := util.DistributeAsset(msg.Distribution.DaoAddr, msg.Distribution.DaoAmount) if err != nil { - util.GetAppLogger().Error(ctx, "Distribution Request: could not distribute asset to DAO: ", err.Error()) + util.GetAppLogger().Error(ctx, distributionRequestTag+"could not distribute asset to DAO: ", err.Error()) } msg.Distribution.InvestorTxID = investorTx msg.Distribution.PopTxID = popTx msg.Distribution.DaoTxID = daoTx util.SendDistributionResult(goCtx, msg.Distribution.LastPop, daoTx, investorTx, popTx) + } else { + util.GetAppLogger().Error(ctx, distributionRequestTag+"failed. valid result: %v proposer: %s validator identity: %s", validResult, msg.Distribution.GetProposer(), validatorIdentity) } return &types.MsgDistributionRequestResponse{}, nil diff --git a/x/dao/keeper/msg_server_reissue_rddl_proposal.go b/x/dao/keeper/msg_server_reissue_rddl_proposal.go index 6a28cf0..09f7284 100644 --- a/x/dao/keeper/msg_server_reissue_rddl_proposal.go +++ b/x/dao/keeper/msg_server_reissue_rddl_proposal.go @@ -8,17 +8,23 @@ import ( "github.com/planetmint/planetmint-go/x/dao/types" ) +var ( + reissueTag = "reissue: " +) + func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReissueRDDLProposal) (*types.MsgReissueRDDLProposalResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx) if validResult && msg.Proposer == validatorIdentity { - util.GetAppLogger().Info(ctx, "reissue: Asset: "+msg.GetTx()) + util.GetAppLogger().Info(ctx, reissueTag+"asset: "+msg.GetTx()) txID, err := util.ReissueAsset(msg.Tx) if err != nil { - util.GetAppLogger().Error(ctx, "reissue: Asset reissuance failed: "+err.Error()) + util.GetAppLogger().Error(ctx, reissueTag+"asset reissuance failed: "+err.Error()) } // 3. notarize result by notarizing the liquid tx-id util.SendReissuanceResult(goCtx, msg.GetProposer(), txID, msg.GetBlockHeight()) + } else { + util.GetAppLogger().Error(ctx, reissueTag+"failed. valid result: %v proposer: %s validator identity: %s", validResult, msg.Proposer, validatorIdentity) } var reissuance types.Reissuance diff --git a/x/dao/keeper/reissuance.go b/x/dao/keeper/reissuance.go index 6ec57d4..662592b 100644 --- a/x/dao/keeper/reissuance.go +++ b/x/dao/keeper/reissuance.go @@ -136,23 +136,23 @@ func (k Keeper) ComputeReIssuanceValue(ctx sdk.Context, startHeight int64, endHe var overallAmount uint64 popEpochs := int64(config.GetConfig().PopEpochs) for _, obj := range challenges { + popString := fmt.Sprintf("firstPoP: %d, PoP height: %d, current height %d", startHeight, obj.GetHeight(), endHeight) // if (index == 0 && startHeight == 0 && obj.BlockHeight == 0) || // corner case (beginning of the chain) if startHeight < obj.GetHeight() && obj.GetHeight()+2*popEpochs <= endHeight { popReIssuanceString := GetReissuanceAsStringValue(obj.GetHeight()) amount, err := util.RDDLTokenStringToUint(popReIssuanceString) if err != nil { - util.GetAppLogger().Error(ctx, fmt.Sprintf("unable to compute PoP re-issuance value (firstPop %d, Pop height %d, current height %d)", - startHeight, obj.GetHeight(), endHeight)) + util.GetAppLogger().Error(ctx, "unable to compute PoP re-issuance value: "+popString) continue } + util.GetAppLogger().Info(ctx, "PoP is part of the reissuance: "+popString) if firstIncludedPop == 0 { firstIncludedPop = obj.GetHeight() } lastIncludedPop = obj.GetHeight() overallAmount += amount } else { - util.GetAppLogger().Debug(ctx, fmt.Sprintf("the PoP is not part of the reissuance (firstPop %d, Pop height %d, current height %d)", - startHeight, obj.GetHeight(), endHeight)) + util.GetAppLogger().Debug(ctx, "PoP is not part of the reissuance: "+popString) if obj.GetHeight()+2*popEpochs > endHeight { break } diff --git a/x/machine/keeper/msg_server_attest_machine.go b/x/machine/keeper/msg_server_attest_machine.go index 116d5d9..7ef9e76 100644 --- a/x/machine/keeper/msg_server_attest_machine.go +++ b/x/machine/keeper/msg_server_attest_machine.go @@ -56,12 +56,12 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach } if k.isNFTCreationRequest(msg.Machine) && util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress) { - util.GetAppLogger().Info(ctx, "Issuing Machine NFT") + util.GetAppLogger().Info(ctx, "Issuing Machine NFT: "+msg.Machine.String()) err := k.issueMachineNFT(goCtx, msg.Machine) if err != nil { util.GetAppLogger().Error(ctx, "Machine NFT issuance failed : "+err.Error()) } else { - util.GetAppLogger().Info(ctx, "Machine NFT issuance successful") + util.GetAppLogger().Info(ctx, "Machine NFT issuance successful: "+msg.Machine.String()) } } else { util.GetAppLogger().Info(ctx, "skipping Machine NFT issuance")