Replace fmt.PrintX calls by proper logging (#159)

// Closes #137

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
Julian Strobl 2023-10-20 12:57:42 +02:00 committed by GitHub
parent 6aaa5399ef
commit 45504f4670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 26 deletions

View File

@ -1,8 +1,6 @@
package ante package ante
import ( import (
"fmt"
errorsmod "cosmossdk.io/errors" errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/config" "github.com/planetmint/planetmint-go/config"
@ -17,15 +15,16 @@ func NewCheckReissuanceDecorator() CheckReissuanceDecorator {
} }
func (cmad CheckReissuanceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { func (cmad CheckReissuanceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
logger := ctx.Logger()
for _, msg := range tx.GetMsgs() { for _, msg := range tx.GetMsgs() {
if sdk.MsgTypeURL(msg) == "/planetmintgo.dao.MsgReissueRDDLProposal" { if sdk.MsgTypeURL(msg) == "/planetmintgo.dao.MsgReissueRDDLProposal" {
MsgProposal, ok := msg.(*daotypes.MsgReissueRDDLProposal) MsgProposal, ok := msg.(*daotypes.MsgReissueRDDLProposal)
if ok { if ok {
fmt.Println("REISSUE: receive Proposal") logger.Debug("REISSUE: receive Proposal")
conf := config.GetConfig() conf := config.GetConfig()
isValid := dao.IsValidReissuanceCommand(MsgProposal.GetTx(), conf.ReissuanceAsset, MsgProposal.GetBlockheight()) isValid := dao.IsValidReissuanceCommand(MsgProposal.GetTx(), conf.ReissuanceAsset, MsgProposal.GetBlockheight())
if !isValid { if !isValid {
fmt.Println("REISSUE: Invalid Proposal") logger.Debug("REISSUE: Invalid Proposal")
return ctx, errorsmod.Wrapf(daotypes.ErrReissuanceProposal, "error during CheckTx or ReCheckTx") return ctx, errorsmod.Wrapf(daotypes.ErrReissuanceProposal, "error during CheckTx or ReCheckTx")
} }
} }

View File

@ -179,7 +179,7 @@ func TestAppStateDeterminism(t *testing.T) {
baseapp.SetChainID(chainID), baseapp.SetChainID(chainID),
) )
fmt.Printf( logger.Info(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed, config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed,
) )
@ -283,12 +283,12 @@ func TestAppImportExport(t *testing.T) {
simtestutil.PrintStats(db) simtestutil.PrintStats(db)
} }
fmt.Printf("exporting genesis...\n") logger.Info("exporting genesis...\n")
exported, err := bApp.ExportAppStateAndValidators(false, []string{}, []string{}) exported, err := bApp.ExportAppStateAndValidators(false, []string{}, []string{})
require.NoError(t, err) require.NoError(t, err)
fmt.Printf("importing genesis...\n") logger.Info("importing genesis...\n")
newDB, newDir, _, _, err := simtestutil.SetupSimulation( newDB, newDir, _, _, err := simtestutil.SetupSimulation(
config, config,
@ -338,7 +338,7 @@ func TestAppImportExport(t *testing.T) {
newApp.ModuleManager().InitGenesis(ctxB, bApp.AppCodec(), genesisState) newApp.ModuleManager().InitGenesis(ctxB, bApp.AppCodec(), genesisState)
newApp.StoreConsensusParams(ctxB, exported.ConsensusParams) newApp.StoreConsensusParams(ctxB, exported.ConsensusParams)
fmt.Printf("comparing stores...\n") logger.Info("comparing stores...\n")
storeKeysPrefixes := []storeKeysPrefixes{ storeKeysPrefixes := []storeKeysPrefixes{
{bApp.GetKey(authtypes.StoreKey), newApp.GetKey(authtypes.StoreKey), [][]byte{}}, {bApp.GetKey(authtypes.StoreKey), newApp.GetKey(authtypes.StoreKey), [][]byte{}},
@ -367,7 +367,7 @@ func TestAppImportExport(t *testing.T) {
failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.Prefixes) failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.Prefixes)
require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare") require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare")
fmt.Printf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B) logger.Info("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B)
require.Equal(t, 0, len(failedKVAs), simtestutil.GetSimulationLog(skp.A.Name(), bApp.SimulationManager().StoreDecoders, failedKVAs, failedKVBs)) require.Equal(t, 0, len(failedKVAs), simtestutil.GetSimulationLog(skp.A.Name(), bApp.SimulationManager().StoreDecoders, failedKVAs, failedKVBs))
} }
} }
@ -439,16 +439,16 @@ func TestAppSimulationAfterImport(t *testing.T) {
} }
if stopEarly { if stopEarly {
fmt.Println("can't export or import a zero-validator genesis, exiting test...") logger.Info("can't export or import a zero-validator genesis, exiting test...")
return return
} }
fmt.Printf("exporting genesis...\n") logger.Info("exporting genesis...\n")
exported, err := bApp.ExportAppStateAndValidators(true, []string{}, []string{}) exported, err := bApp.ExportAppStateAndValidators(true, []string{}, []string{})
require.NoError(t, err) require.NoError(t, err)
fmt.Printf("importing genesis...\n") logger.Info("importing genesis...\n")
newDB, newDir, _, _, err := simtestutil.SetupSimulation( newDB, newDir, _, _, err := simtestutil.SetupSimulation(
config, config,

View File

@ -3,7 +3,6 @@ package util
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt"
"os/exec" "os/exec"
"strconv" "strconv"
@ -13,9 +12,10 @@ import (
func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, tx_unsigned string, blk_height int64) error { func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, tx_unsigned string, blk_height int64) error {
//get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store //get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store
logger := ctx.Logger()
// Construct the command // Construct the command
sending_validator_address := config.GetConfig().ValidatorAddress sending_validator_address := config.GetConfig().ValidatorAddress
fmt.Println("REISSUE: create Proposal") logger.Debug("REISSUE: create Proposal")
cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-proposal", cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-proposal",
"--from", sending_validator_address, "-y", "--from", sending_validator_address, "-y",
proposerAddress, tx_unsigned, strconv.FormatInt(blk_height, 10)) proposerAddress, tx_unsigned, strconv.FormatInt(blk_height, 10))
@ -36,9 +36,10 @@ func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, tx_unsig
} }
func SendRDDLReissuanceResult(ctx sdk.Context, proposerAddress string, txID string, blk_height uint64) error { func SendRDDLReissuanceResult(ctx sdk.Context, proposerAddress string, txID string, blk_height uint64) error {
logger := ctx.Logger()
// Construct the command // Construct the command
sending_validator_address := config.GetConfig().ValidatorAddress sending_validator_address := config.GetConfig().ValidatorAddress
fmt.Println("REISSUE: create Result") logger.Debug("REISSUE: create Result")
cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-result", cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-result",
"--from", sending_validator_address, "-y", "--from", sending_validator_address, "-y",
proposerAddress, txID, strconv.FormatUint(blk_height, 10)) proposerAddress, txID, strconv.FormatUint(blk_height, 10))

View File

@ -2,7 +2,6 @@ package dao
import ( import (
"encoding/hex" "encoding/hex"
"fmt"
"github.com/planetmint/planetmint-go/config" "github.com/planetmint/planetmint-go/config"
"github.com/planetmint/planetmint-go/util" "github.com/planetmint/planetmint-go/util"
@ -21,7 +20,7 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper)
if isPoPHeight(req.Header.GetHeight()) && util.IsValidatorBlockProposer(ctx, proposerAddress) { if isPoPHeight(req.Header.GetHeight()) && util.IsValidatorBlockProposer(ctx, proposerAddress) {
blockHeight := req.Header.GetHeight() blockHeight := req.Header.GetHeight()
// TODO: implement PoP trigger // TODO: implement PoP trigger
fmt.Println("TODO: implement PoP trigger") logger.Info("TODO: implement PoP trigger")
hexProposerAddress := hex.EncodeToString(proposerAddress) hexProposerAddress := hex.EncodeToString(proposerAddress)
conf := config.GetConfig() conf := config.GetConfig()
tx_unsigned := GetReissuanceCommand(conf.ReissuanceAsset, blockHeight) tx_unsigned := GetReissuanceCommand(conf.ReissuanceAsset, blockHeight)

View File

@ -2,7 +2,6 @@ package keeper
import ( import (
"context" "context"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/util" "github.com/planetmint/planetmint-go/util"
@ -11,19 +10,20 @@ import (
func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReissueRDDLProposal) (*types.MsgReissueRDDLProposalResponse, error) { func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReissueRDDLProposal) (*types.MsgReissueRDDLProposalResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx) ctx := sdk.UnwrapSDKContext(goCtx)
logger := ctx.Logger()
validator_identity, valid_result := util.GetValidatorCometBFTIdentity(ctx) validator_identity, valid_result := util.GetValidatorCometBFTIdentity(ctx)
if valid_result && msg.Proposer == validator_identity { if valid_result && msg.Proposer == validator_identity {
// 1. sign tx // 1. sign tx
// 2. broadcast tx // 2. broadcast tx
fmt.Println("REISSUE: Asset") logger.Debug("REISSUE: Asset")
txID, err := util.ReissueAsset(msg.Tx) txID, err := util.ReissueAsset(msg.Tx)
if err == nil { if err == nil {
// 3. notarize result by notarizing the liquid tx-id // 3. notarize result by notarizing the liquid tx-id
_ = util.SendRDDLReissuanceResult(ctx, msg.GetProposer(), txID, msg.GetBlockheight()) _ = util.SendRDDLReissuanceResult(ctx, msg.GetProposer(), txID, msg.GetBlockheight())
//TODO verify and resolve error //TODO verify and resolve error
} else { } else {
fmt.Println("REISSUE: Asset reissuance failure") logger.Debug("REISSUE: Asset reissuance failure")
} }
//TODO: reissuance need to be initiated otherwise //TODO: reissuance need to be initiated otherwise
} }

View File

@ -3,7 +3,6 @@ package keeper
import ( import (
"bytes" "bytes"
"context" "context"
"log"
"os/exec" "os/exec"
"strings" "strings"
@ -46,7 +45,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
} }
if k.isNFTCreationRequest(msg.Machine) && util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress) { if k.isNFTCreationRequest(msg.Machine) && util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress) {
_ = k.issueMachineNFT(msg.Machine) _ = k.issueMachineNFT(ctx, msg.Machine)
//TODO create NFTCreationMessage to be stored by all nodes //TODO create NFTCreationMessage to be stored by all nodes
// if err != nil { // if err != nil {
// return nil, types.ErrNFTIssuanceFailed // return nil, types.ErrNFTIssuanceFailed
@ -75,8 +74,9 @@ func validateExtendedPublicKey(issuer string, cfg chaincfg.Params) bool {
return isValidExtendedPublicKey return isValidExtendedPublicKey
} }
func (k msgServer) issueNFTAsset(name string, machine_address string) (asset_id string, contract string, err error) { func (k msgServer) issueNFTAsset(ctx sdk.Context, name string, machine_address string) (asset_id string, contract string, err error) {
conf := config.GetConfig() conf := config.GetConfig()
logger := ctx.Logger()
cmdName := "poetry" cmdName := "poetry"
cmdArgs := []string{"run", "python", "issuer_service/issue2liquid.py", name, machine_address} cmdArgs := []string{"run", "python", "issuer_service/issue2liquid.py", name, machine_address}
@ -95,7 +95,7 @@ func (k msgServer) issueNFTAsset(name string, machine_address string) (asset_id
// Execute the command // Execute the command
err = cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
log.Printf("cmd.Run() failed with %s\n", err) logger.Error("cmd.Run() failed with %s\n", err)
err = errorsmod.Wrap(types.ErrMachineNFTIssuance, stderr.String()) err = errorsmod.Wrap(types.ErrMachineNFTIssuance, stderr.String())
} else { } else {
lines := strings.Split(stdout.String(), "\n") lines := strings.Split(stdout.String(), "\n")
@ -109,8 +109,8 @@ func (k msgServer) issueNFTAsset(name string, machine_address string) (asset_id
return asset_id, contract, err return asset_id, contract, err
} }
func (k msgServer) issueMachineNFT(machine *types.Machine) error { func (k msgServer) issueMachineNFT(ctx sdk.Context, machine *types.Machine) error {
_, _, err := k.issueNFTAsset(machine.Name, machine.Address) _, _, err := k.issueNFTAsset(ctx, machine.Name, machine.Address)
return err return err
// asset registration is not performed in case of NFT issuance for machines // asset registration is not performed in case of NFT issuance for machines
//asset_id, contract, err := k.issueNFTAsset(machine.Name, machine.Address) //asset_id, contract, err := k.issueNFTAsset(machine.Name, machine.Address)