Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slow transactions #1725

Open
wants to merge 10 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions core/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package logger

import (
"fmt"
"github.com/0chain/gosdk/core/version"
"gopkg.in/natefinch/lumberjack.v2"
"io"
"log"
"os"
Expand Down Expand Up @@ -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)")
}
4 changes: 2 additions & 2 deletions core/transaction/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions zboxcore/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion zboxcore/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions zcncore/wallet_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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`
Expand Down Expand Up @@ -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
Expand Down
Loading