From e7e40776c4e16bd3685bbb9462ec5ead6d73c931 Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Mon, 6 Jan 2025 23:40:21 +0530 Subject: [PATCH 01/10] Fix logging --- core/logger/logger.go | 38 ++++++++++++++++++++++++++++++++++++++ core/transaction/entity.go | 8 +++++++- zboxcore/logger/logger.go | 8 +------- zcncore/wallet_base.go | 11 ++++++----- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/core/logger/logger.go b/core/logger/logger.go index fbe517017..4af6e8692 100644 --- a/core/logger/logger.go +++ b/core/logger/logger.go @@ -3,6 +3,8 @@ package logger import ( "fmt" + "github.com/0chain/gosdk/core/version" + "gopkg.in/natefinch/lumberjack.v2" "io" "log" "os" @@ -142,3 +144,39 @@ func (l *Logger) Close() { } } } + +// Initialize common logger +var logging Logger + +func GetLogger() *Logger { + return &logging +} + +func CloseLog() { + logging.Close() +} + +func init() { + logging.Init(DEBUG, "0chain-core-sdk") +} + +// SetLogLevel set the log level. +// lvl - 0 disabled; higher number (upto 4) more verbosity +func SetLogLevel(lvl int) { + logging.SetLevel(lvl) +} + +// SetLogFile - sets file path to write log +// verbose - true - console output; false - no console output +func SetLogFile(logFile string, verbose bool) { + ioWriter := &lumberjack.Logger{ + Filename: logFile, + MaxSize: 100, // MB + MaxBackups: 5, // number of backups + MaxAge: 28, //days + LocalTime: false, + Compress: false, // disabled by default + } + logging.SetLogFile(ioWriter, verbose) + logging.Info("******* Wallet SDK Version:", version.VERSIONSTR, " ******* (SetLogFile)") +} diff --git a/core/transaction/entity.go b/core/transaction/entity.go index eee839b5a..57565f64e 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -23,7 +23,7 @@ import ( lru "github.com/hashicorp/golang-lru" ) -var Logger logger.Logger +var Logger = logger.GetLogger() const STORAGE_SCADDRESS = "6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d7" const MINERSC_SCADDRESS = "6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d9" @@ -535,6 +535,8 @@ func SmartContractTxnValueFeeWithRetry(scAddress string, sn SmartContractTxnData func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, value, fee uint64, verifyTxn bool, clients ...string) (hash, out string, nonce int64, t *Transaction, err error) { + Logger.Info("SmartContractTxnValueFee", zap.Any("scAddress", scAddress), zap.Any("sn", sn), zap.Any("value", value), zap.Any("fee", fee), zap.Any("verifyTxn", verifyTxn), zap.Any("clients", clients), zap.Any("time", time.Now())) + clientId := client.Id() if len(clients) > 0 && clients[0] != "" { clientId = clients[0] @@ -613,6 +615,8 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, Logger.Info(msg) Logger.Info("estimated txn fee: ", txn.TransactionFee) + Logger.Info("sending transaction to the network", zap.Any("txn", txn), zap.Any("time", time.Now())) + err = SendTransactionSync(txn, nodeClient.GetStableMiners()) if err != nil { Logger.Info("transaction submission failed", zap.Error(err)) @@ -621,6 +625,8 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, return } + Logger.Info("transaction submitted successfully", zap.Any("txn", txn), zap.Any("time", time.Now())) + if verifyTxn { var ( querySleepTime = time.Duration(cfg.QuerySleepTime) * time.Second diff --git a/zboxcore/logger/logger.go b/zboxcore/logger/logger.go index 37a89ee44..64134eb35 100644 --- a/zboxcore/logger/logger.go +++ b/zboxcore/logger/logger.go @@ -3,11 +3,5 @@ package logger import "github.com/0chain/gosdk/core/logger" -var defaultLogLevel = logger.DEBUG - // Logger global logger instance -var Logger logger.Logger - -func init() { - Logger.Init(defaultLogLevel, "0box-sdk") -} +var Logger = logger.GetLogger() diff --git a/zcncore/wallet_base.go b/zcncore/wallet_base.go index f4ead5968..28c87ab97 100644 --- a/zcncore/wallet_base.go +++ b/zcncore/wallet_base.go @@ -4,6 +4,9 @@ import ( "crypto/ed25519" "encoding/hex" "fmt" + "github.com/0chain/gosdk/core/logger" + "github.com/0chain/gosdk/core/version" + "gopkg.in/natefinch/lumberjack.v2" "net/http" "strings" "time" @@ -16,15 +19,14 @@ import ( "github.com/0chain/gosdk/core/client" rawencryption "github.com/0chain/gosdk/core/encryption" - "github.com/0chain/gosdk/core/logger" - "github.com/0chain/gosdk/core/version" "github.com/0chain/gosdk/core/zcncrypto" "github.com/0chain/gosdk/zboxcore/encryption" "github.com/0chain/gosdk/zboxcore/zboxutil" openssl "github.com/Luzifer/go-openssl/v3" - "gopkg.in/natefinch/lumberjack.v2" ) +var logging = logger.GetLogger() + const ( GET_CLIENT = `/v1/client/get` PUT_TRANSACTION = `/v1/transaction/put` @@ -79,11 +81,10 @@ const ( ) var defaultLogLevel = logger.DEBUG -var logging logger.Logger // GetLogger returns the logger instance func GetLogger() *logger.Logger { - return &logging + return logging } // CloseLog closes log file From 84f0fc634d92b4d006ce2601be53876c63f4570e Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Mon, 6 Jan 2025 23:59:57 +0530 Subject: [PATCH 02/10] Fix logging --- zboxcore/sdk/sdk.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index 260cd57cc..adb6eddbe 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -97,7 +97,7 @@ func SetLogFile(logFile string, verbose bool) { // GetLogger retrieves logger instance func GetLogger() *logger.Logger { - return &l.Logger + return l.Logger } type BackPool struct { From 5282742f3ce404d49feebd920f7ea28aa420c944 Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 7 Jan 2025 00:22:33 +0530 Subject: [PATCH 03/10] Debug --- core/transaction/entity.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 57565f64e..6c772717d 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -535,7 +535,8 @@ func SmartContractTxnValueFeeWithRetry(scAddress string, sn SmartContractTxnData func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, value, fee uint64, verifyTxn bool, clients ...string) (hash, out string, nonce int64, t *Transaction, err error) { - Logger.Info("SmartContractTxnValueFee", zap.Any("scAddress", scAddress), zap.Any("sn", sn), zap.Any("value", value), zap.Any("fee", fee), zap.Any("verifyTxn", verifyTxn), zap.Any("clients", clients), zap.Any("time", time.Now())) + now := time.Now() + Logger.Info("SmartContractTxnValueFee", zap.Any("scAddress", scAddress), zap.Any("sn", sn), zap.Any("value", value), zap.Any("fee", fee), zap.Any("verifyTxn", verifyTxn), zap.Any("clients", clients), zap.Any("time", now)) clientId := client.Id() if len(clients) > 0 && clients[0] != "" { @@ -615,7 +616,7 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, Logger.Info(msg) Logger.Info("estimated txn fee: ", txn.TransactionFee) - Logger.Info("sending transaction to the network", zap.Any("txn", txn), zap.Any("time", time.Now())) + Logger.Info("sending transaction to the network", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) err = SendTransactionSync(txn, nodeClient.GetStableMiners()) if err != nil { @@ -625,7 +626,7 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, return } - Logger.Info("transaction submitted successfully", zap.Any("txn", txn), zap.Any("time", time.Now())) + Logger.Info("transaction submitted successfully", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) if verifyTxn { var ( @@ -638,6 +639,7 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, var confirmationResponse string for retries < cfg.MaxTxnQuery { + Logger.Info("verifying transaction", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds()), zap.Any("retry", retries)) t, confirmationResponse, err = VerifyTransactionWithRes(txn.Hash) if err == nil { break @@ -669,8 +671,12 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, t.TransactionOutput = confirmationResponse } + Logger.Info("transaction verified successfully", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) + return t.Hash, t.TransactionOutput, t.TransactionNonce, t, nil } + Logger.Info("1transaction submitted successfully", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) + return txn.Hash, "", txn.TransactionNonce, txn, nil } From b9c11adf1df27ead5e99bcb7240fb8eaff91d2c3 Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 7 Jan 2025 00:53:31 +0530 Subject: [PATCH 04/10] Debug --- core/logger/logger.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/logger/logger.go b/core/logger/logger.go index 4af6e8692..b9e0e1131 100644 --- a/core/logger/logger.go +++ b/core/logger/logger.go @@ -105,8 +105,26 @@ func (l *Logger) Debug(v ...interface{}) { } } +func formatAnyValue(v interface{}) string { + switch v := v.(type) { + case string: + return v + case fmt.Stringer: + return v.String() + case error: + return v.Error() + default: + return fmt.Sprintf("%+v", v) // Default format for all types (including structs) + } +} + func (l *Logger) Info(v ...interface{}) { if l.lvl >= INFO { + // Format each argument to be readable + for i, arg := range v { + v[i] = formatAnyValue(arg) + } + err := l.logInfo.Output(2, fmt.Sprint(v...)) if err != nil { fmt.Printf("Error logging info message: %v", err) From e448eef6f3d85f76df6ec613e385b4886088c062 Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 7 Jan 2025 01:17:53 +0530 Subject: [PATCH 05/10] Debug --- core/transaction/entity.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 6c772717d..fd92f7102 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/0chain/common/core/logging" "net/http" "strings" "sync" @@ -538,6 +539,8 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, now := time.Now() Logger.Info("SmartContractTxnValueFee", zap.Any("scAddress", scAddress), zap.Any("sn", sn), zap.Any("value", value), zap.Any("fee", fee), zap.Any("verifyTxn", verifyTxn), zap.Any("clients", clients), zap.Any("time", now)) + logging.Logger.Info("Jayash SmartContractTxnValueFee", zap.Any("scAddress", scAddress), zap.Any("sn", sn), zap.Any("value", value), zap.Any("fee", fee), zap.Any("verifyTxn", verifyTxn), zap.Any("clients", clients), zap.Any("time", now)) + clientId := client.Id() if len(clients) > 0 && clients[0] != "" { clientId = clients[0] From b4ca9662a8c8492a0b97f13f34d0df0c619ac8e3 Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 7 Jan 2025 01:23:14 +0530 Subject: [PATCH 06/10] Debug --- core/transaction/entity.go | 43 +++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index fd92f7102..6a4cbcdfc 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -539,6 +539,8 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, now := time.Now() Logger.Info("SmartContractTxnValueFee", zap.Any("scAddress", scAddress), zap.Any("sn", sn), zap.Any("value", value), zap.Any("fee", fee), zap.Any("verifyTxn", verifyTxn), zap.Any("clients", clients), zap.Any("time", now)) + Logger.Info("1Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + logging.Logger.Info("Jayash SmartContractTxnValueFee", zap.Any("scAddress", scAddress), zap.Any("sn", sn), zap.Any("value", value), zap.Any("fee", fee), zap.Any("verifyTxn", verifyTxn), zap.Any("clients", clients), zap.Any("time", now)) clientId := client.Id() @@ -546,21 +548,29 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, clientId = clients[0] } + Logger.Info("2Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + var requestBytes []byte if requestBytes, err = json.Marshal(sn); err != nil { return } + Logger.Info("3Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + cfg, err := conf.GetClientConfig() if err != nil { return } + Logger.Info("4Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + nodeClient, err := client.GetNode() if err != nil { return } + Logger.Info("5Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + txn := NewTransactionEntity(client.Id(clientId), cfg.ChainID, client.PublicKey(clientId), nonce) @@ -576,6 +586,8 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, txn.TransactionType = TxnTypeSend } + Logger.Info("6Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + // adjust fees if not set if fee == 0 { fee, err = EstimateFee(txn, nodeClient.Network().Miners, 0.2) @@ -588,6 +600,8 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, txn.TransactionFee = fee } + Logger.Info("7Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + if txn.TransactionNonce == 0 { txn.TransactionNonce = client.Cache.GetNextNonce(txn.ClientID) } @@ -597,6 +611,8 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, return } + Logger.Info("8Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + if client.GetClient().IsSplit { txn.Signature, err = txn.getAuthorize() if err != nil { @@ -604,6 +620,8 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, } } + Logger.Info("9Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + ok, err := txn.VerifySigWith(txn.PublicKey, sys.VerifyWith) if err != nil { err = errors.New("", "verification failed for auth response") @@ -615,10 +633,14 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, return } + Logger.Info("10Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + msg := fmt.Sprintf("executing transaction '%s' with hash %s ", sn.Name, txn.Hash) Logger.Info(msg) Logger.Info("estimated txn fee: ", txn.TransactionFee) + Logger.Info("11Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("sending transaction to the network", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) err = SendTransactionSync(txn, nodeClient.GetStableMiners()) @@ -629,6 +651,8 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, return } + Logger.Info("12Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("transaction submitted successfully", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) if verifyTxn { @@ -637,11 +661,16 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, retries = 0 ) + Logger.Info("13Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + sys.Sleep(querySleepTime) + Logger.Info("14Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + var confirmationResponse string for retries < cfg.MaxTxnQuery { + Logger.Info("15Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds()), zap.Any("retries", retries)) Logger.Info("verifying transaction", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds()), zap.Any("retry", retries)) t, confirmationResponse, err = VerifyTransactionWithRes(txn.Hash) if err == nil { @@ -651,30 +680,42 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, sys.Sleep(querySleepTime) } + Logger.Info("16Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + if err != nil { Logger.Error("Error verifying the transaction", err.Error(), txn.Hash) client.Cache.Evict(txn.ClientID) return } + Logger.Info("17Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + if t == nil { return "", "", 0, txn, errors.New("transaction_validation_failed", "Failed to get the transaction confirmation : "+txn.Hash) } + Logger.Info("18Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + if t.Status == TxnFail { return t.Hash, t.TransactionOutput, 0, t, errors.New("", t.TransactionOutput) } + Logger.Info("19Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + if t.Status == TxnChargeableError { return t.Hash, t.TransactionOutput, t.TransactionNonce, t, errors.New("", t.TransactionOutput) } + Logger.Info("20Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + if t.TransactionType == TxnTypeSend { t.TransactionOutput = confirmationResponse } - Logger.Info("transaction verified successfully", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("21Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + + Logger.Info("Jayash transaction verified successfully", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) return t.Hash, t.TransactionOutput, t.TransactionNonce, t, nil } From 49b75f507a6fe81189d9875ed70e453d27c09fff Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 7 Jan 2025 01:24:47 +0530 Subject: [PATCH 07/10] Debug --- core/logger/logger.go | 18 ----------------- core/transaction/entity.go | 40 +++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/core/logger/logger.go b/core/logger/logger.go index b9e0e1131..4af6e8692 100644 --- a/core/logger/logger.go +++ b/core/logger/logger.go @@ -105,26 +105,8 @@ func (l *Logger) Debug(v ...interface{}) { } } -func formatAnyValue(v interface{}) string { - switch v := v.(type) { - case string: - return v - case fmt.Stringer: - return v.String() - case error: - return v.Error() - default: - return fmt.Sprintf("%+v", v) // Default format for all types (including structs) - } -} - func (l *Logger) Info(v ...interface{}) { if l.lvl >= INFO { - // Format each argument to be readable - for i, arg := range v { - v[i] = formatAnyValue(arg) - } - err := l.logInfo.Output(2, fmt.Sprint(v...)) if err != nil { fmt.Printf("Error logging info message: %v", err) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 6a4cbcdfc..7e1e7595d 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -539,7 +539,7 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, now := time.Now() Logger.Info("SmartContractTxnValueFee", zap.Any("scAddress", scAddress), zap.Any("sn", sn), zap.Any("value", value), zap.Any("fee", fee), zap.Any("verifyTxn", verifyTxn), zap.Any("clients", clients), zap.Any("time", now)) - Logger.Info("1Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("1Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) logging.Logger.Info("Jayash SmartContractTxnValueFee", zap.Any("scAddress", scAddress), zap.Any("sn", sn), zap.Any("value", value), zap.Any("fee", fee), zap.Any("verifyTxn", verifyTxn), zap.Any("clients", clients), zap.Any("time", now)) @@ -548,28 +548,28 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, clientId = clients[0] } - Logger.Info("2Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("2Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) var requestBytes []byte if requestBytes, err = json.Marshal(sn); err != nil { return } - Logger.Info("3Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("3Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) cfg, err := conf.GetClientConfig() if err != nil { return } - Logger.Info("4Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("4Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) nodeClient, err := client.GetNode() if err != nil { return } - Logger.Info("5Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("5Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) txn := NewTransactionEntity(client.Id(clientId), cfg.ChainID, client.PublicKey(clientId), nonce) @@ -586,7 +586,7 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, txn.TransactionType = TxnTypeSend } - Logger.Info("6Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("6Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) // adjust fees if not set if fee == 0 { @@ -600,7 +600,7 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, txn.TransactionFee = fee } - Logger.Info("7Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("7Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) if txn.TransactionNonce == 0 { txn.TransactionNonce = client.Cache.GetNextNonce(txn.ClientID) @@ -611,7 +611,7 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, return } - Logger.Info("8Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("8Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) if client.GetClient().IsSplit { txn.Signature, err = txn.getAuthorize() @@ -620,7 +620,7 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, } } - Logger.Info("9Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("9Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) ok, err := txn.VerifySigWith(txn.PublicKey, sys.VerifyWith) if err != nil { @@ -633,13 +633,13 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, return } - Logger.Info("10Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("10Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) msg := fmt.Sprintf("executing transaction '%s' with hash %s ", sn.Name, txn.Hash) Logger.Info(msg) Logger.Info("estimated txn fee: ", txn.TransactionFee) - Logger.Info("11Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("11Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) Logger.Info("sending transaction to the network", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) @@ -651,7 +651,7 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, return } - Logger.Info("12Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("12Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) Logger.Info("transaction submitted successfully", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) @@ -661,11 +661,11 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, retries = 0 ) - Logger.Info("13Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("13Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) sys.Sleep(querySleepTime) - Logger.Info("14Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("14Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) var confirmationResponse string @@ -680,7 +680,7 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, sys.Sleep(querySleepTime) } - Logger.Info("16Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("16Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) if err != nil { Logger.Error("Error verifying the transaction", err.Error(), txn.Hash) @@ -688,32 +688,32 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, return } - Logger.Info("17Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("17Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) if t == nil { return "", "", 0, txn, errors.New("transaction_validation_failed", "Failed to get the transaction confirmation : "+txn.Hash) } - Logger.Info("18Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("18Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) if t.Status == TxnFail { return t.Hash, t.TransactionOutput, 0, t, errors.New("", t.TransactionOutput) } - Logger.Info("19Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("19Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) if t.Status == TxnChargeableError { return t.Hash, t.TransactionOutput, t.TransactionNonce, t, errors.New("", t.TransactionOutput) } - Logger.Info("20Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("20Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) if t.TransactionType == TxnTypeSend { t.TransactionOutput = confirmationResponse } - Logger.Info("21Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds())) + Logger.Info("21Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) Logger.Info("Jayash transaction verified successfully", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) From c7f8c80baf0e354ab55f8b3edab0bf845a571376 Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 7 Jan 2025 01:34:34 +0530 Subject: [PATCH 08/10] Debug --- core/transaction/entity.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 7e1e7595d..68944449f 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -5,7 +5,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/0chain/common/core/logging" "net/http" "strings" "sync" @@ -541,8 +540,6 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, Logger.Info("1Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - logging.Logger.Info("Jayash SmartContractTxnValueFee", zap.Any("scAddress", scAddress), zap.Any("sn", sn), zap.Any("value", value), zap.Any("fee", fee), zap.Any("verifyTxn", verifyTxn), zap.Any("clients", clients), zap.Any("time", now)) - clientId := client.Id() if len(clients) > 0 && clients[0] != "" { clientId = clients[0] From 851f4f9ead8f21f74927bd81d34e44d12475be85 Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 7 Jan 2025 02:06:43 +0530 Subject: [PATCH 09/10] Fix timeout --- core/transaction/entity.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 68944449f..d0bdc4716 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -270,7 +270,7 @@ func (t *Transaction) VerifySigWith(pubkey string, verifyHandler VerifyFunc) (bo } func SendTransactionSync(txn *Transaction, miners []string) error { - const requestTimeout = 30 * time.Second // Timeout for each request + const requestTimeout = 3 * time.Second // Timeout for each request fails := make(chan error, len(miners)) var wg sync.WaitGroup From 9d68c980753b98bbd46b0fc2fe8266eee3125848 Mon Sep 17 00:00:00 2001 From: Jayash Satolia Date: Tue, 7 Jan 2025 02:08:13 +0530 Subject: [PATCH 10/10] Remove logging --- core/transaction/entity.go | 53 -------------------------------------- 1 file changed, 53 deletions(-) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index d0bdc4716..995a45954 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -535,39 +535,26 @@ func SmartContractTxnValueFeeWithRetry(scAddress string, sn SmartContractTxnData func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, value, fee uint64, verifyTxn bool, clients ...string) (hash, out string, nonce int64, t *Transaction, err error) { - now := time.Now() - Logger.Info("SmartContractTxnValueFee", zap.Any("scAddress", scAddress), zap.Any("sn", sn), zap.Any("value", value), zap.Any("fee", fee), zap.Any("verifyTxn", verifyTxn), zap.Any("clients", clients), zap.Any("time", now)) - - Logger.Info("1Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - clientId := client.Id() if len(clients) > 0 && clients[0] != "" { clientId = clients[0] } - Logger.Info("2Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - var requestBytes []byte if requestBytes, err = json.Marshal(sn); err != nil { return } - Logger.Info("3Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - cfg, err := conf.GetClientConfig() if err != nil { return } - Logger.Info("4Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - nodeClient, err := client.GetNode() if err != nil { return } - Logger.Info("5Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - txn := NewTransactionEntity(client.Id(clientId), cfg.ChainID, client.PublicKey(clientId), nonce) @@ -583,8 +570,6 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, txn.TransactionType = TxnTypeSend } - Logger.Info("6Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - // adjust fees if not set if fee == 0 { fee, err = EstimateFee(txn, nodeClient.Network().Miners, 0.2) @@ -597,8 +582,6 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, txn.TransactionFee = fee } - Logger.Info("7Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - if txn.TransactionNonce == 0 { txn.TransactionNonce = client.Cache.GetNextNonce(txn.ClientID) } @@ -608,8 +591,6 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, return } - Logger.Info("8Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - if client.GetClient().IsSplit { txn.Signature, err = txn.getAuthorize() if err != nil { @@ -617,8 +598,6 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, } } - Logger.Info("9Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - ok, err := txn.VerifySigWith(txn.PublicKey, sys.VerifyWith) if err != nil { err = errors.New("", "verification failed for auth response") @@ -630,16 +609,10 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, return } - Logger.Info("10Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - msg := fmt.Sprintf("executing transaction '%s' with hash %s ", sn.Name, txn.Hash) Logger.Info(msg) Logger.Info("estimated txn fee: ", txn.TransactionFee) - Logger.Info("11Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - - Logger.Info("sending transaction to the network", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) - err = SendTransactionSync(txn, nodeClient.GetStableMiners()) if err != nil { Logger.Info("transaction submission failed", zap.Error(err)) @@ -648,27 +621,17 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, return } - Logger.Info("12Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - - Logger.Info("transaction submitted successfully", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) - if verifyTxn { var ( querySleepTime = time.Duration(cfg.QuerySleepTime) * time.Second retries = 0 ) - Logger.Info("13Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - sys.Sleep(querySleepTime) - Logger.Info("14Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - var confirmationResponse string for retries < cfg.MaxTxnQuery { - Logger.Info("15Jayash SmartContractTxnValueFee", zap.Any("time", time.Since(now).Milliseconds()), zap.Any("retries", retries)) - Logger.Info("verifying transaction", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds()), zap.Any("retry", retries)) t, confirmationResponse, err = VerifyTransactionWithRes(txn.Hash) if err == nil { break @@ -677,47 +640,31 @@ func SmartContractTxnValueFee(scAddress string, sn SmartContractTxnData, sys.Sleep(querySleepTime) } - Logger.Info("16Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - if err != nil { Logger.Error("Error verifying the transaction", err.Error(), txn.Hash) client.Cache.Evict(txn.ClientID) return } - Logger.Info("17Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - if t == nil { return "", "", 0, txn, errors.New("transaction_validation_failed", "Failed to get the transaction confirmation : "+txn.Hash) } - Logger.Info("18Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - if t.Status == TxnFail { return t.Hash, t.TransactionOutput, 0, t, errors.New("", t.TransactionOutput) } - Logger.Info("19Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - if t.Status == TxnChargeableError { return t.Hash, t.TransactionOutput, t.TransactionNonce, t, errors.New("", t.TransactionOutput) } - Logger.Info("20Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - if t.TransactionType == TxnTypeSend { t.TransactionOutput = confirmationResponse } - Logger.Info("21Jayash SmartContractTxnValueFee", " : Time : ", time.Since(now).Milliseconds()) - - Logger.Info("Jayash transaction verified successfully", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) - return t.Hash, t.TransactionOutput, t.TransactionNonce, t, nil } - Logger.Info("1transaction submitted successfully", zap.Any("txn", txn), zap.Any("time", time.Since(now).Milliseconds())) - return txn.Hash, "", txn.TransactionNonce, txn, nil }