From f114a47b5b008fd0de411ec8f5b7e19d19fb33eb Mon Sep 17 00:00:00 2001 From: terence tsao Date: Sat, 9 Oct 2021 06:27:34 -0700 Subject: [PATCH] Improve "synced block.." log (#9760) --- beacon-chain/blockchain/log.go | 2 ++ runtime/version/BUILD.bazel | 8 +++++++- runtime/version/fork.go | 11 +++++++++++ runtime/version/fork_test.go | 29 +++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 runtime/version/fork_test.go diff --git a/beacon-chain/blockchain/log.go b/beacon-chain/blockchain/log.go index 34ded537b..38d5a89a6 100644 --- a/beacon-chain/blockchain/log.go +++ b/beacon-chain/blockchain/log.go @@ -55,6 +55,8 @@ func logBlockSyncStatus(block block.BeaconBlock, blockRoot [32]byte, finalized * "epoch": slots.ToEpoch(block.Slot()), "finalizedEpoch": finalized.Epoch, "finalizedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(finalized.Root)[:8]), + "parentRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(block.ParentRoot())[:8]), + "version": version.String(block.Version()), }).Info("Synced new block") log.WithFields(logrus.Fields{ "slot": block.Slot, diff --git a/runtime/version/BUILD.bazel b/runtime/version/BUILD.bazel index f702b90be..f0653c2f2 100644 --- a/runtime/version/BUILD.bazel +++ b/runtime/version/BUILD.bazel @@ -1,4 +1,4 @@ -load("@prysm//tools/go:def.bzl", "go_library") +load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", @@ -20,3 +20,9 @@ go_library( "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", ], ) + +go_test( + name = "go_default_test", + srcs = ["fork_test.go"], + embed = [":go_default_library"], +) diff --git a/runtime/version/fork.go b/runtime/version/fork.go index 9b7e0ba81..7a15f1032 100644 --- a/runtime/version/fork.go +++ b/runtime/version/fork.go @@ -4,3 +4,14 @@ const ( Phase0 = iota Altair ) + +func String(version int) string { + switch version { + case Phase0: + return "phase0" + case Altair: + return "altair" + default: + return "unknown version" + } +} diff --git a/runtime/version/fork_test.go b/runtime/version/fork_test.go new file mode 100644 index 000000000..84ecff61c --- /dev/null +++ b/runtime/version/fork_test.go @@ -0,0 +1,29 @@ +package version + +import "testing" + +func TestVersionString(t *testing.T) { + tests := []struct { + name string + version int + want string + }{ + { + name: "phase0", + version: Phase0, + want: "phase0", + }, + { + name: "altair", + version: Altair, + want: "altair", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := String(tt.version); got != tt.want { + t.Errorf("String() = %v, want %v", got, tt.want) + } + }) + } +}