From 453012ff165428cfedffe65c8caf71e1c9e412d6 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 7 Apr 2021 15:32:46 +0300 Subject: [PATCH 1/2] runtime: tune runtime.Log messages Add transaction hash, print contract hash in LE (as all user-facing functions do) and don't double-quote the message, zap already does quoting of its own. --- pkg/core/interop/runtime/engine.go | 10 +++++++--- pkg/core/interop/runtime/engine_test.go | 6 ++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/core/interop/runtime/engine.go b/pkg/core/interop/runtime/engine.go index 4735a3056..abd071678 100644 --- a/pkg/core/interop/runtime/engine.go +++ b/pkg/core/interop/runtime/engine.go @@ -82,10 +82,14 @@ func Log(ic *interop.Context) error { if len(state) > MaxNotificationSize { return fmt.Errorf("message length shouldn't exceed %v", MaxNotificationSize) } - msg := fmt.Sprintf("%q", state) + var txHash string + if ic.Tx != nil { + txHash = ic.Tx.Hash().StringLE() + } ic.Log.Info("runtime log", - zap.Stringer("script", ic.VM.GetCurrentScriptHash()), - zap.String("logs", msg)) + zap.String("tx", txHash), + zap.String("script", ic.VM.GetCurrentScriptHash().StringLE()), + zap.String("msg", state)) return nil } diff --git a/pkg/core/interop/runtime/engine_test.go b/pkg/core/interop/runtime/engine_test.go index 27a2e98f9..41b1c2dc9 100644 --- a/pkg/core/interop/runtime/engine_test.go +++ b/pkg/core/interop/runtime/engine_test.go @@ -125,10 +125,8 @@ func TestLog(t *testing.T) { var logMsg map[string]interface{} require.NoError(t, json.Unmarshal([]byte(ls[0]), &logMsg)) require.Equal(t, "info", logMsg["level"]) - require.Equal(t, "runtime log", logMsg["msg"]) - require.Equal(t, h.StringBE(), logMsg["script"]) - require.Equal(t, `"hello"`, logMsg["logs"]) - + require.Equal(t, "hello", logMsg["msg"]) + require.Equal(t, h.StringLE(), logMsg["script"]) }) } From 1785a333d2ce85407c6dcd9a457d7221a5eb7134 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 7 Apr 2021 15:36:42 +0300 Subject: [PATCH 2/2] core: tune "blockchain persist completed" message It's misleading, we're writing it on disk-level persistence, it's not the same as block "persistence" in C#, so we better write it clear. --- pkg/core/blockchain.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index f6cd03577..fe354677b 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1092,9 +1092,9 @@ func (bc *Blockchain) persist() error { if err != nil { return err } - bc.log.Info("blockchain persist completed", - zap.Uint32("persistedBlocks", diff), - zap.Int("persistedKeys", persisted), + bc.log.Info("persisted to disk", + zap.Uint32("blocks", diff), + zap.Int("keys", persisted), zap.Uint32("headerHeight", storedHeaderHeight), zap.Uint32("blockHeight", bHeight), zap.Duration("took", time.Since(start)))