From 61ead641adfe7df32d17c5cd2efb04be4f3fee27 Mon Sep 17 00:00:00 2001 From: BiPhan4 Date: Wed, 15 Mar 2023 21:12:39 -0400 Subject: [PATCH 1/5] added logger --- go.mod | 2 +- jprov/server/proofs.go | 6 ++++++ jprov/testutils/logger.go | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 jprov/testutils/logger.go diff --git a/go.mod b/go.mod index 59073b6..485e7b5 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/cosmos/cosmos-sdk v0.45.11 github.com/cosmos/go-bip39 v1.0.0 github.com/huin/goupnp v1.0.3 - github.com/jackalLabs/canine-chain v1.2.0-beta.6 + github.com/jackalLabs/canine-chain v1.2.0-beta.7 github.com/julienschmidt/httprouter v1.3.0 github.com/rs/cors v1.8.2 github.com/rs/zerolog v1.27.0 diff --git a/jprov/server/proofs.go b/jprov/server/proofs.go index 75a4bf6..be34939 100644 --- a/jprov/server/proofs.go +++ b/jprov/server/proofs.go @@ -13,8 +13,10 @@ import ( "github.com/JackalLabs/jackal-provider/jprov/crypto" "github.com/JackalLabs/jackal-provider/jprov/queue" + "github.com/JackalLabs/jackal-provider/jprov/testutils" "github.com/JackalLabs/jackal-provider/jprov/types" "github.com/JackalLabs/jackal-provider/jprov/utils" + "github.com/wealdtech/go-merkletree/sha3" sdk "github.com/cosmos/cosmos-sdk/types" @@ -127,8 +129,12 @@ func postProof(clientCtx client.Context, cid string, block string, db *leveldb.D q.Append(&u) wg.Wait() + logger, logFile := testutils.CreateLogger() + if u.Err != nil { + logger.Printf("The error is %s\n", u.Err) ctx.Logger.Error(fmt.Sprintf("Posting Error: %s", u.Err.Error())) + logFile.Close() return } diff --git a/jprov/testutils/logger.go b/jprov/testutils/logger.go new file mode 100644 index 0000000..6b8169c --- /dev/null +++ b/jprov/testutils/logger.go @@ -0,0 +1,14 @@ +package testutils + +import ( + "log" + "os" +) + +func CreateLogger() (log.Logger, *os.File) { + f, _ := os.OpenFile("logs.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666) + log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile) + log.SetOutput(f) + + return *log.Default(), f +} From cca501663586b7c5e56db2a9be88cb654d69a7f3 Mon Sep 17 00:00:00 2001 From: BiPhan4 Date: Wed, 15 Mar 2023 23:25:34 -0400 Subject: [PATCH 2/5] CalculateGas() never executes --- jprov/queue/queue.go | 1 + jprov/server/proofs.go | 5 +++-- jprov/testutils/logger.go | 5 +++-- jprov/utils/tx.go | 24 ++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/jprov/queue/queue.go b/jprov/queue/queue.go index 2e7a186..b3da71e 100644 --- a/jprov/queue/queue.go +++ b/jprov/queue/queue.go @@ -6,6 +6,7 @@ import ( "github.com/JackalLabs/jackal-provider/jprov/types" "github.com/JackalLabs/jackal-provider/jprov/utils" + "github.com/cosmos/cosmos-sdk/client" ctypes "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" diff --git a/jprov/server/proofs.go b/jprov/server/proofs.go index be34939..8a7db5a 100644 --- a/jprov/server/proofs.go +++ b/jprov/server/proofs.go @@ -129,10 +129,11 @@ func postProof(clientCtx client.Context, cid string, block string, db *leveldb.D q.Append(&u) wg.Wait() - logger, logFile := testutils.CreateLogger() + logger, logFile := testutils.CreateLogger("proofLogs") if u.Err != nil { - logger.Printf("The error is %s\n", u.Err) + logger.Printf("The error is: %s\n", u.Err) + ctx.Logger.Error(fmt.Sprintf("Posting Error: %s", u.Err.Error())) logFile.Close() return diff --git a/jprov/testutils/logger.go b/jprov/testutils/logger.go index 6b8169c..96f71f5 100644 --- a/jprov/testutils/logger.go +++ b/jprov/testutils/logger.go @@ -1,12 +1,13 @@ package testutils import ( + "fmt" "log" "os" ) -func CreateLogger() (log.Logger, *os.File) { - f, _ := os.OpenFile("logs.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666) +func CreateLogger(filename string) (log.Logger, *os.File) { + f, _ := os.OpenFile(fmt.Sprintf("%s.log", filename), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666) log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile) log.SetOutput(f) diff --git a/jprov/utils/tx.go b/jprov/utils/tx.go index 6a3ca0d..1cd6af3 100644 --- a/jprov/utils/tx.go +++ b/jprov/utils/tx.go @@ -5,6 +5,7 @@ import ( "os" "github.com/JackalLabs/jackal-provider/jprov/crypto" + "github.com/JackalLabs/jackal-provider/jprov/testutils" "github.com/cosmos/cosmos-sdk/client" txns "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" @@ -55,11 +56,18 @@ func SendTx(clientCtx client.Context, flagSet *pflag.FlagSet, msgs ...sdk.Msg) ( if err != nil { return nil, err } + logger, logFile := testutils.CreateLogger("sendTxLogs") + + logger.Printf("The initial estimated gas is %d\n", txf.Gas()) // Prints out 200000 //gas, err := flagSet.GetInt(types.FlagGasCap) //if err != nil { // return nil, err //} + logger.Printf("txf.SimulateAndExecute() is %t\n", txf.SimulateAndExecute()) + logger.Printf("clientCtx.Simulate is %t\n", clientCtx.Simulate) + + // Both these values are false so the if block will not execute and gas will not be simulated if txf.SimulateAndExecute() || clientCtx.Simulate { _, adjusted, err := txns.CalculateGas(clientCtx, txf, msgs...) @@ -70,9 +78,25 @@ func SendTx(clientCtx client.Context, flagSet *pflag.FlagSet, msgs ...sdk.Msg) ( txf = txf.WithGas(adjusted) _, _ = fmt.Fprintf(os.Stderr, "%s\n", txns.GasEstimateResponse{GasEstimate: txf.Gas()}) } + // This if block below never executes if clientCtx.Simulate { return nil, nil } + logger.Printf("The estimated gas after the loop is %d\n", txf.Gas()) // Always prints out 200000 which is the default factory value + + // Attempting to calculate... + + _, adjusted, err := txns.CalculateGas(clientCtx, txf.WithSimulateAndExecute(true), msgs...) + if err != nil { + return nil, err + } + + txf = txf.WithGas(adjusted) + logger.Printf("Did it actually get estimated? %d\n", txf.Gas()) // ????? + + _, _ = fmt.Fprintf(os.Stderr, "%s\n", txns.GasEstimateResponse{GasEstimate: txf.Gas()}) + + logFile.Close() tx, err := txns.BuildUnsignedTx(txf, msgs...) if err != nil { From 89fb5bd523caebcca433957054def94d4677d002 Mon Sep 17 00:00:00 2001 From: BiPhan4 Date: Thu, 16 Mar 2023 15:43:34 -0400 Subject: [PATCH 3/5] gas flag default to auto enables gas calculation. Clean up logging statements --- jprov/jprovd/provider_commands.go | 2 +- jprov/server/proofs.go | 5 ----- jprov/utils/tx.go | 25 +------------------------ 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/jprov/jprovd/provider_commands.go b/jprov/jprovd/provider_commands.go index 5a714cc..d040e1b 100644 --- a/jprov/jprovd/provider_commands.go +++ b/jprov/jprovd/provider_commands.go @@ -183,5 +183,5 @@ func AddTxFlagsToCmd(cmd *cobra.Command) { cmd.Flags().String(flags.FlagChainID, "", "The network chain ID") // --gas can accept integers and "auto" - cmd.Flags().String(flags.FlagGas, "", fmt.Sprintf("gas limit to set per-transaction; set to %q to calculate sufficient gas automatically (default %d)", flags.GasFlagAuto, flags.DefaultGasLimit)) + cmd.Flags().String(flags.FlagGas, "auto", fmt.Sprintf("gas limit to set per-transaction; set to %q to calculate sufficient gas automatically (default %d)", flags.GasFlagAuto, flags.DefaultGasLimit)) } diff --git a/jprov/server/proofs.go b/jprov/server/proofs.go index 8a7db5a..d2ad878 100644 --- a/jprov/server/proofs.go +++ b/jprov/server/proofs.go @@ -13,7 +13,6 @@ import ( "github.com/JackalLabs/jackal-provider/jprov/crypto" "github.com/JackalLabs/jackal-provider/jprov/queue" - "github.com/JackalLabs/jackal-provider/jprov/testutils" "github.com/JackalLabs/jackal-provider/jprov/types" "github.com/JackalLabs/jackal-provider/jprov/utils" @@ -129,13 +128,9 @@ func postProof(clientCtx client.Context, cid string, block string, db *leveldb.D q.Append(&u) wg.Wait() - logger, logFile := testutils.CreateLogger("proofLogs") - if u.Err != nil { - logger.Printf("The error is: %s\n", u.Err) ctx.Logger.Error(fmt.Sprintf("Posting Error: %s", u.Err.Error())) - logFile.Close() return } diff --git a/jprov/utils/tx.go b/jprov/utils/tx.go index 1cd6af3..5348265 100644 --- a/jprov/utils/tx.go +++ b/jprov/utils/tx.go @@ -5,7 +5,6 @@ import ( "os" "github.com/JackalLabs/jackal-provider/jprov/crypto" - "github.com/JackalLabs/jackal-provider/jprov/testutils" "github.com/cosmos/cosmos-sdk/client" txns "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" @@ -56,18 +55,11 @@ func SendTx(clientCtx client.Context, flagSet *pflag.FlagSet, msgs ...sdk.Msg) ( if err != nil { return nil, err } - logger, logFile := testutils.CreateLogger("sendTxLogs") - - logger.Printf("The initial estimated gas is %d\n", txf.Gas()) // Prints out 200000 //gas, err := flagSet.GetInt(types.FlagGasCap) //if err != nil { // return nil, err //} - logger.Printf("txf.SimulateAndExecute() is %t\n", txf.SimulateAndExecute()) - logger.Printf("clientCtx.Simulate is %t\n", clientCtx.Simulate) - - // Both these values are false so the if block will not execute and gas will not be simulated if txf.SimulateAndExecute() || clientCtx.Simulate { _, adjusted, err := txns.CalculateGas(clientCtx, txf, msgs...) @@ -78,25 +70,10 @@ func SendTx(clientCtx client.Context, flagSet *pflag.FlagSet, msgs ...sdk.Msg) ( txf = txf.WithGas(adjusted) _, _ = fmt.Fprintf(os.Stderr, "%s\n", txns.GasEstimateResponse{GasEstimate: txf.Gas()}) } - // This if block below never executes + if clientCtx.Simulate { return nil, nil } - logger.Printf("The estimated gas after the loop is %d\n", txf.Gas()) // Always prints out 200000 which is the default factory value - - // Attempting to calculate... - - _, adjusted, err := txns.CalculateGas(clientCtx, txf.WithSimulateAndExecute(true), msgs...) - if err != nil { - return nil, err - } - - txf = txf.WithGas(adjusted) - logger.Printf("Did it actually get estimated? %d\n", txf.Gas()) // ????? - - _, _ = fmt.Fprintf(os.Stderr, "%s\n", txns.GasEstimateResponse{GasEstimate: txf.Gas()}) - - logFile.Close() tx, err := txns.BuildUnsignedTx(txf, msgs...) if err != nil { From fdd25ac482cb815946d04d23fa8ddd3266aead19 Mon Sep 17 00:00:00 2001 From: BiPhan4 Date: Mon, 20 Mar 2023 17:54:39 -0400 Subject: [PATCH 4/5] logging gas cost for stray claiming and all other transactions --- jprov/strays/hand_process.go | 5 +++++ jprov/utils/tx.go | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/jprov/strays/hand_process.go b/jprov/strays/hand_process.go index 583f37a..414ba7c 100644 --- a/jprov/strays/hand_process.go +++ b/jprov/strays/hand_process.go @@ -7,6 +7,7 @@ import ( "os" "github.com/JackalLabs/jackal-provider/jprov/crypto" + "github.com/JackalLabs/jackal-provider/jprov/testutils" "github.com/JackalLabs/jackal-provider/jprov/utils" "github.com/cosmos/cosmos-sdk/client" txns "github.com/cosmos/cosmos-sdk/client/tx" @@ -191,6 +192,10 @@ func (h *LittleHand) SendTx(clientCtx client.Context, flagSet *pflag.FlagSet, ms return nil, nil } + logger, logFile := testutils.CreateLogger("handProcessSendTx") + logger.Printf("Cost of claiming stray is%d\n", txf.Gas()) + logFile.Close() + tx, err := txns.BuildUnsignedTx(txf, msgs...) if err != nil { return nil, err diff --git a/jprov/utils/tx.go b/jprov/utils/tx.go index 5348265..863506d 100644 --- a/jprov/utils/tx.go +++ b/jprov/utils/tx.go @@ -5,6 +5,8 @@ import ( "os" "github.com/JackalLabs/jackal-provider/jprov/crypto" + "github.com/JackalLabs/jackal-provider/jprov/testutils" + "github.com/cosmos/cosmos-sdk/client" txns "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" @@ -71,6 +73,10 @@ func SendTx(clientCtx client.Context, flagSet *pflag.FlagSet, msgs ...sdk.Msg) ( _, _ = fmt.Fprintf(os.Stderr, "%s\n", txns.GasEstimateResponse{GasEstimate: txf.Gas()}) } + logger, logFile := testutils.CreateLogger("generalSendTxCosts") + logger.Printf("Cost of other transactions is%d\n", txf.Gas()) + logFile.Close() + if clientCtx.Simulate { return nil, nil } From bede67df66d9f6cb29ce968e0da289f5fcc26b1b Mon Sep 17 00:00:00 2001 From: BiPhan4 Date: Mon, 20 Mar 2023 18:55:38 -0400 Subject: [PATCH 5/5] remove logging statements --- jprov/strays/hand_process.go | 5 ----- jprov/utils/tx.go | 5 ----- 2 files changed, 10 deletions(-) diff --git a/jprov/strays/hand_process.go b/jprov/strays/hand_process.go index 414ba7c..583f37a 100644 --- a/jprov/strays/hand_process.go +++ b/jprov/strays/hand_process.go @@ -7,7 +7,6 @@ import ( "os" "github.com/JackalLabs/jackal-provider/jprov/crypto" - "github.com/JackalLabs/jackal-provider/jprov/testutils" "github.com/JackalLabs/jackal-provider/jprov/utils" "github.com/cosmos/cosmos-sdk/client" txns "github.com/cosmos/cosmos-sdk/client/tx" @@ -192,10 +191,6 @@ func (h *LittleHand) SendTx(clientCtx client.Context, flagSet *pflag.FlagSet, ms return nil, nil } - logger, logFile := testutils.CreateLogger("handProcessSendTx") - logger.Printf("Cost of claiming stray is%d\n", txf.Gas()) - logFile.Close() - tx, err := txns.BuildUnsignedTx(txf, msgs...) if err != nil { return nil, err diff --git a/jprov/utils/tx.go b/jprov/utils/tx.go index 863506d..7e6476c 100644 --- a/jprov/utils/tx.go +++ b/jprov/utils/tx.go @@ -5,7 +5,6 @@ import ( "os" "github.com/JackalLabs/jackal-provider/jprov/crypto" - "github.com/JackalLabs/jackal-provider/jprov/testutils" "github.com/cosmos/cosmos-sdk/client" txns "github.com/cosmos/cosmos-sdk/client/tx" @@ -73,10 +72,6 @@ func SendTx(clientCtx client.Context, flagSet *pflag.FlagSet, msgs ...sdk.Msg) ( _, _ = fmt.Fprintf(os.Stderr, "%s\n", txns.GasEstimateResponse{GasEstimate: txf.Gas()}) } - logger, logFile := testutils.CreateLogger("generalSendTxCosts") - logger.Printf("Cost of other transactions is%d\n", txf.Gas()) - logFile.Close() - if clientCtx.Simulate { return nil, nil }