From 6587671e748805a438c4c617e766ce168a38e5e6 Mon Sep 17 00:00:00 2001 From: dylanhuang Date: Mon, 13 Feb 2023 14:13:00 +0800 Subject: [PATCH 1/3] fix: Dockerfile (#1312) --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3010ed36c4..2fc8527ab6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,7 @@ ENV HOME=${BSC_HOME} ENV DATA_DIR=/data ENV PACKAGES ca-certificates~=20220614-r0 jq~=1.6 \ - bash~=5.1.16-r2 bind-tools~=9.16.36 tini~=0.19.0 \ + bash~=5.1.16-r2 bind-tools~=9.16.37 tini~=0.19.0 \ grep~=3.7 curl~=7.83.1 sed~=4.8-r0 RUN apk add --no-cache $PACKAGES \ From fc4303c6c601a697bc1d1f9da17e11c556c6dba1 Mon Sep 17 00:00:00 2001 From: Larry <92799281+brilliant-lx@users.noreply.github.com> Date: Wed, 15 Mar 2023 18:06:00 +0800 Subject: [PATCH 2/3] fix: crash on nil access when TxPool shutdown (#1353) (#1356) --- miner/worker.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 599032c217..d44187f928 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1126,7 +1126,12 @@ LOOP: // subscribe before fillTransactions txsCh := make(chan core.NewTxsEvent, txChanSize) sub := w.eth.TxPool().SubscribeNewTxsEvent(txsCh) - defer sub.Unsubscribe() + // if TxPool has been stopped, `sub` would be nil, it could happen on shutdown. + if sub == nil { + log.Info("commitWork SubscribeNewTxsEvent return nil") + } else { + defer sub.Unsubscribe() + } // Fill pending transactions from the txpool fillStart := time.Now() @@ -1196,7 +1201,9 @@ LOOP: } // if sub's channel if full, it will block other NewTxsEvent subscribers, // so unsubscribe ASAP and Unsubscribe() is re-enterable, safe to call several time. - sub.Unsubscribe() + if sub != nil { + sub.Unsubscribe() + } } // get the most profitable work bestWork := workList[0] From e4381a5d250b177950cdff6855c00ae14b70365c Mon Sep 17 00:00:00 2001 From: dylanhuang Date: Mon, 3 Apr 2023 10:22:49 +0800 Subject: [PATCH 3/3] log: support custom time format configuration (#1401) --- log/format.go | 15 +++++++++++++-- node/config.go | 13 +++++++++---- node/node.go | 24 ++++++++++++++++++------ 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/log/format.go b/log/format.go index 613dc33be7..6c1d5942b3 100644 --- a/log/format.go +++ b/log/format.go @@ -14,9 +14,12 @@ import ( "unicode/utf8" ) +var ( + timeFormat = "2006-01-02T15:04:05-0700" + termTimeFormat = "01-02|15:04:05.000" +) + const ( - timeFormat = "2006-01-02T15:04:05-0700" - termTimeFormat = "01-02|15:04:05.000" floatFormat = 'f' termMsgJust = 40 termCtxMaxPadding = 40 @@ -482,3 +485,11 @@ func escapeString(s string) string { } return strconv.Quote(s) } + +func SetTermTimeFormat(format string) { + termTimeFormat = format +} + +func SetTimeFormat(format string) { + timeFormat = format +} diff --git a/node/config.go b/node/config.go index 2e37c23532..baa7a8f50d 100644 --- a/node/config.go +++ b/node/config.go @@ -502,8 +502,13 @@ func (c *Config) warnOnce(w *bool, format string, args ...interface{}) { } type LogConfig struct { - FileRoot string - FilePath string - MaxBytesSize uint - Level string + FileRoot *string + FilePath *string + MaxBytesSize *uint + Level *string + + // TermTimeFormat is the time format used for console logging. + TermTimeFormat *string + // TimeFormat is the time format used for file logging. + TimeFormat *string } diff --git a/node/node.go b/node/node.go index 48f7b4c4be..ef256f77e7 100644 --- a/node/node.go +++ b/node/node.go @@ -86,13 +86,25 @@ func New(conf *Config) (*Node, error) { conf.DataDir = absdatadir } if conf.LogConfig != nil { - logFilePath := "" - if conf.LogConfig.FileRoot == "" { - logFilePath = path.Join(conf.DataDir, conf.LogConfig.FilePath) - } else { - logFilePath = path.Join(conf.LogConfig.FileRoot, conf.LogConfig.FilePath) + if conf.LogConfig.TermTimeFormat != nil && *conf.LogConfig.TermTimeFormat != "" { + log.SetTermTimeFormat(*conf.LogConfig.TermTimeFormat) + } + + if conf.LogConfig.TimeFormat != nil && *conf.LogConfig.TimeFormat != "" { + log.SetTimeFormat(*conf.LogConfig.TimeFormat) + } + + if conf.LogConfig.FileRoot != nil && conf.LogConfig.FilePath != nil && + conf.LogConfig.MaxBytesSize != nil && conf.LogConfig.Level != nil { + // log to file + logFilePath := "" + if *conf.LogConfig.FileRoot == "" { + logFilePath = path.Join(conf.DataDir, *conf.LogConfig.FilePath) + } else { + logFilePath = path.Join(*conf.LogConfig.FileRoot, *conf.LogConfig.FilePath) + } + log.Root().SetHandler(log.NewFileLvlHandler(logFilePath, *conf.LogConfig.MaxBytesSize, *conf.LogConfig.Level)) } - log.Root().SetHandler(log.NewFileLvlHandler(logFilePath, conf.LogConfig.MaxBytesSize, conf.LogConfig.Level)) } if conf.Logger == nil { conf.Logger = log.New()