mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00
refactor: improve logging (#257)
* refactor: improve logging - Introduce logger tags - Log variable contents - Fix testing logger to support string formatting * refactor: set logging context And move logging into function. Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
parent
6bff8e835d
commit
4599bc2c78
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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{}) {
|
||||
|
@ -40,7 +40,7 @@ func SendMqttMessagesToServer(ctx sdk.Context, challenge types.Challenge) {
|
||||
GetAppLogger().Error(ctx, "MQTT error: "+err.Error())
|
||||
return
|
||||
}
|
||||
GetAppLogger().Info(ctx, "MQTT message successfully sent")
|
||||
GetAppLogger().Info(ctx, "MQTT message successfully sent: "+challenge.String())
|
||||
}
|
||||
|
||||
func sendMqttMessages(challenge types.Challenge) (err error) {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user