Improve "synced block.." log (#9760)

This commit is contained in:
terence tsao 2021-10-09 06:27:34 -07:00 committed by GitHub
parent 65d2df4609
commit f114a47b5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 1 deletions

View File

@ -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,

View File

@ -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"],
)

View File

@ -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"
}
}

View File

@ -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)
}
})
}
}