From e58e27acbca902b79e2d37e0f9eaca78adcc9fd4 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Sat, 1 Oct 2022 14:45:03 +0100 Subject: [PATCH 1/3] Do not send results when syncing. If a node is syncing it can present events that are very out of date. As such, ignore results if they come from an unsynced node. --- go.mod | 14 ++++++------ go.sum | 36 +++++++++++++++++-------------- main.go | 2 +- services/blocks/events/service.go | 11 ++++++++++ services/heads/events/service.go | 11 ++++++++++ 5 files changed, 50 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index 9a3aca2..9b04b0a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/wealdtech/probec go 1.18 require ( - github.com/attestantio/go-eth2-client v0.11.5 + github.com/attestantio/go-eth2-client v0.13.6 github.com/mitchellh/go-homedir v1.1.0 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.12.2 @@ -19,15 +19,15 @@ require ( github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.13.0 // indirect - github.com/ferranbt/fastssz v0.1.0 // indirect + github.com/ferranbt/fastssz v0.1.2 // indirect github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/goccy/go-yaml v1.9.5 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/klauspost/cpuid/v2 v2.0.13 // indirect + github.com/klauspost/cpuid/v2 v2.1.1 // indirect github.com/magiconair/properties v1.8.6 // indirect - github.com/mattn/go-colorable v0.1.12 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/minio/sha256-simd v1.0.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect @@ -44,9 +44,9 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.4.0 // indirect golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect - golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d // indirect + golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect golang.org/x/text v0.3.7 // indirect - golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect + golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/protobuf v1.28.0 // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect gopkg.in/ini.v1 v1.66.6 // indirect diff --git a/go.sum b/go.sum index b11a597..a58d3ec 100644 --- a/go.sum +++ b/go.sum @@ -43,8 +43,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/attestantio/go-eth2-client v0.11.5 h1:wyos1nc7+/hI4WBOXRcY3jXQgAKDhhr+TiwR2u60++o= -github.com/attestantio/go-eth2-client v0.11.5/go.mod h1:zXL/BxC0cBBhxj+tP7QG7t9Ufoa8GwQLdlbvZRd9+dM= +github.com/attestantio/go-eth2-client v0.13.6 h1:KivmTvEdW5Ah3wSsfb8u/8cZZh/BtaRwNJuPpLqhQdg= +github.com/attestantio/go-eth2-client v0.13.6/go.mod h1:bcg5gfjVcm+MtcaZfzv/uSWNHU4i8hGamVG+9JCZnC0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -74,9 +74,9 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= -github.com/ferranbt/fastssz v0.0.0-20220103083642-bc5fefefa28b/go.mod h1:S8yiDeAXy8f88W4Ul+0dBMPx49S05byYbmZD6Uv94K4= -github.com/ferranbt/fastssz v0.1.0 h1:IXYgeThN82mYwjuSfGj6sYNpJol4wNnyeeQLjlmW8i8= -github.com/ferranbt/fastssz v0.1.0/go.mod h1:S8yiDeAXy8f88W4Ul+0dBMPx49S05byYbmZD6Uv94K4= +github.com/ferranbt/fastssz v0.1.1/go.mod h1:U2ZsxlYyvGeQGmadhz8PlEqwkBzDIhHwd3xuKrg2JIs= +github.com/ferranbt/fastssz v0.1.2 h1:Dky6dXlngF6Qjc+EfDipAkE83N5I5DE68bY6O0VLNPk= +github.com/ferranbt/fastssz v0.1.2/go.mod h1:X5UPrE2u1UJjxHA8X54u04SBwdAQjG2sFtWs39YxyWs= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= @@ -183,9 +183,9 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.0.11/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= -github.com/klauspost/cpuid/v2 v2.0.13 h1:1XxvOiqXZ8SULZUKim/wncr3wZ38H4yCuVDvKdK9OGs= -github.com/klauspost/cpuid/v2 v2.0.13/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= +github.com/klauspost/cpuid/v2 v2.1.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/klauspost/cpuid/v2 v2.1.1 h1:t0wUqjowdm8ezddV5k0tLWVklVuvLJpoHeb4WBdydm0= +github.com/klauspost/cpuid/v2 v2.1.1/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= @@ -202,11 +202,13 @@ github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamh github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= @@ -215,7 +217,6 @@ github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -262,6 +263,7 @@ github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0 github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7 h1:0tVE4tdWQK9ZpYygoV7+vS6QkDvQVySboMVEIxBJmXw= github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7/go.mod h1:wmuf/mdK4VMD+jA9ThwcUKjg3a2XWM9cVfFYjDyY4j4= +github.com/prysmaticlabs/gohashtree v0.0.1-alpha.0.20220714111606-acbb2962fb48 h1:cSo6/vk8YpvkLbk9v3FO97cakNmUoxwi2KMP8hd5WIw= github.com/r3labs/sse/v2 v2.7.4/go.mod h1:hUrYMKfu9WquG9MyI0r6TKiNH+6Sw/QPKm2YbNbU5g8= github.com/r3labs/sse/v2 v2.8.0 h1:El87DStHljKBTTsbDAdng3PLBej64+9wPafaYIkcV5A= github.com/r3labs/sse/v2 v2.8.0/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I= @@ -463,10 +465,12 @@ golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d h1:Zu/JngovGLVi6t2J3nmAf3AoTDwuzw85YZ3b9o4yU7s= -golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI= +golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -533,8 +537,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f h1:uF6paiQQebLeSXkrTqHqz0MXhXXS1KgF41eUdBNvxK0= -golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= diff --git a/main.go b/main.go index 85bc567..71bbfad 100644 --- a/main.go +++ b/main.go @@ -41,7 +41,7 @@ import ( ) // ReleaseVersion is the release version for the code. -var ReleaseVersion = "0.2.2" +var ReleaseVersion = "0.2.3" func main() { os.Exit(main2()) diff --git a/services/blocks/events/service.go b/services/blocks/events/service.go index b142b12..585cf8e 100644 --- a/services/blocks/events/service.go +++ b/services/blocks/events/service.go @@ -74,6 +74,17 @@ func (s *Service) monitorEvents(ctx context.Context, if err := eventsProvider.Events(ctx, []string{"block"}, func(event *apiv1.Event) { data := event.Data.(*apiv1.BlockEvent) delay := time.Since(s.chainTime.StartOfSlot(data.Slot)) + + // Ensure the node is synced. + syncing, err := eventsProvider.(consensusclient.NodeSyncingProvider).NodeSyncing(ctx) + if err != nil { + log.Error().Err(err).Msg("Failed to ascertain if node is syncing") + return + } + if syncing.IsSyncing { + log.Debug().Msg("Node is syncing, not sending information") + } + monitorEventProcessed(delay) // Build and send the data. diff --git a/services/heads/events/service.go b/services/heads/events/service.go index cf1c478..25497cb 100644 --- a/services/heads/events/service.go +++ b/services/heads/events/service.go @@ -74,6 +74,17 @@ func (s *Service) monitorEvents(ctx context.Context, if err := eventsProvider.Events(ctx, []string{"head"}, func(event *apiv1.Event) { data := event.Data.(*apiv1.HeadEvent) delay := time.Since(s.chainTime.StartOfSlot(data.Slot)) + + // Ensure the node is synced. + syncing, err := eventsProvider.(consensusclient.NodeSyncingProvider).NodeSyncing(ctx) + if err != nil { + log.Error().Err(err).Msg("Failed to ascertain if node is syncing") + return + } + if syncing.IsSyncing { + log.Debug().Msg("Node is syncing, not sending information") + } + monitorEventProcessed(delay) // Build and send the data. From 77f4ed88bc7e956de16b0efe28c2f777ab2f9c81 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Sat, 1 Oct 2022 14:46:53 +0100 Subject: [PATCH 2/3] Add test to workflow. --- .github/workflows/test.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c38ba0e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,15 @@ +name: test +on: + push: + branches: + - master + pull_request: +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: 1.17 + - uses: actions/checkout@v3 + - uses: n8maninger/action-golang-test@v1 From 1f08ff2a4a33b04446771c39e39f739adbfc062e Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Sat, 1 Oct 2022 14:53:19 +0100 Subject: [PATCH 3/3] Fix tests. --- services/blocks/events/service_test.go | 18 ++++ services/heads/events/service_test.go | 18 ++++ services/submitter/immediate/service_test.go | 99 -------------------- services/submitter/mock/service.go | 38 ++++++++ 4 files changed, 74 insertions(+), 99 deletions(-) delete mode 100644 services/submitter/immediate/service_test.go create mode 100644 services/submitter/mock/service.go diff --git a/services/blocks/events/service_test.go b/services/blocks/events/service_test.go index 17fcd3c..6e01e86 100644 --- a/services/blocks/events/service_test.go +++ b/services/blocks/events/service_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/require" standardchaintime "github.com/wealdtech/chaind/services/chaintime/standard" "github.com/wealdtech/probec/services/blocks/events" + mocksubmitter "github.com/wealdtech/probec/services/submitter/mock" ) func TestService(t *testing.T) { @@ -38,6 +39,8 @@ func TestService(t *testing.T) { ) require.NoError(t, err) + submitter := mocksubmitter.New() + tests := []struct { name string params []events.Parameter @@ -52,6 +55,7 @@ func TestService(t *testing.T) { events.WithEventsProviders(map[string]consensusclient.EventsProvider{ "test": mockClient, }), + events.WithSubmitter(submitter), }, err: "problem with parameters: monitor not supplied", }, @@ -62,6 +66,7 @@ func TestService(t *testing.T) { events.WithEventsProviders(map[string]consensusclient.EventsProvider{ "test": mockClient, }), + events.WithSubmitter(submitter), }, err: "problem with parameters: chain time service not supplied", }, @@ -71,9 +76,21 @@ func TestService(t *testing.T) { events.WithLogLevel(zerolog.Disabled), events.WithChainTime(chainTime), events.WithEventsProviders(map[string]consensusclient.EventsProvider{}), + events.WithSubmitter(submitter), }, err: "problem with parameters: events providers not supplied", }, + { + name: "SubmitterMissing", + params: []events.Parameter{ + events.WithLogLevel(zerolog.Disabled), + events.WithChainTime(chainTime), + events.WithEventsProviders(map[string]consensusclient.EventsProvider{ + "test": mockClient, + }), + }, + err: "problem with parameters: submitter not supplied", + }, { name: "Good", params: []events.Parameter{ @@ -82,6 +99,7 @@ func TestService(t *testing.T) { events.WithEventsProviders(map[string]consensusclient.EventsProvider{ "test": mockClient, }), + events.WithSubmitter(submitter), }, }, } diff --git a/services/heads/events/service_test.go b/services/heads/events/service_test.go index 17fcd3c..6e01e86 100644 --- a/services/heads/events/service_test.go +++ b/services/heads/events/service_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/require" standardchaintime "github.com/wealdtech/chaind/services/chaintime/standard" "github.com/wealdtech/probec/services/blocks/events" + mocksubmitter "github.com/wealdtech/probec/services/submitter/mock" ) func TestService(t *testing.T) { @@ -38,6 +39,8 @@ func TestService(t *testing.T) { ) require.NoError(t, err) + submitter := mocksubmitter.New() + tests := []struct { name string params []events.Parameter @@ -52,6 +55,7 @@ func TestService(t *testing.T) { events.WithEventsProviders(map[string]consensusclient.EventsProvider{ "test": mockClient, }), + events.WithSubmitter(submitter), }, err: "problem with parameters: monitor not supplied", }, @@ -62,6 +66,7 @@ func TestService(t *testing.T) { events.WithEventsProviders(map[string]consensusclient.EventsProvider{ "test": mockClient, }), + events.WithSubmitter(submitter), }, err: "problem with parameters: chain time service not supplied", }, @@ -71,9 +76,21 @@ func TestService(t *testing.T) { events.WithLogLevel(zerolog.Disabled), events.WithChainTime(chainTime), events.WithEventsProviders(map[string]consensusclient.EventsProvider{}), + events.WithSubmitter(submitter), }, err: "problem with parameters: events providers not supplied", }, + { + name: "SubmitterMissing", + params: []events.Parameter{ + events.WithLogLevel(zerolog.Disabled), + events.WithChainTime(chainTime), + events.WithEventsProviders(map[string]consensusclient.EventsProvider{ + "test": mockClient, + }), + }, + err: "problem with parameters: submitter not supplied", + }, { name: "Good", params: []events.Parameter{ @@ -82,6 +99,7 @@ func TestService(t *testing.T) { events.WithEventsProviders(map[string]consensusclient.EventsProvider{ "test": mockClient, }), + events.WithSubmitter(submitter), }, }, } diff --git a/services/submitter/immediate/service_test.go b/services/submitter/immediate/service_test.go deleted file mode 100644 index ff8e19c..0000000 --- a/services/submitter/immediate/service_test.go +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright © 2022 Weald Technology Trading. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package immediate_test - -import ( - "context" - "testing" - - consensusclient "github.com/attestantio/go-eth2-client" - "github.com/attestantio/go-eth2-client/mock" - "github.com/rs/zerolog" - "github.com/stretchr/testify/require" - standardchaintime "github.com/wealdtech/chaind/services/chaintime/standard" - "github.com/wealdtech/probec/services/blocks/events" -) - -func TestService(t *testing.T) { - ctx := context.Background() - - mockClient, err := mock.New(ctx) - require.NoError(t, err) - - chainTime, err := standardchaintime.New(ctx, - standardchaintime.WithGenesisTimeProvider(mockClient), - standardchaintime.WithSpecProvider(mockClient), - standardchaintime.WithForkScheduleProvider(mockClient), - ) - require.NoError(t, err) - - tests := []struct { - name string - params []events.Parameter - err string - }{ - { - name: "MonitorMissing", - params: []events.Parameter{ - events.WithLogLevel(zerolog.Disabled), - events.WithMonitor(nil), - events.WithChainTime(chainTime), - events.WithEventsProviders(map[string]consensusclient.EventsProvider{ - "test": mockClient, - }), - }, - err: "problem with parameters: monitor not supplied", - }, - { - name: "ChainTimeMissing", - params: []events.Parameter{ - events.WithLogLevel(zerolog.Disabled), - events.WithEventsProviders(map[string]consensusclient.EventsProvider{ - "test": mockClient, - }), - }, - err: "problem with parameters: chain time service not supplied", - }, - { - name: "EventsProvidersEmpty", - params: []events.Parameter{ - events.WithLogLevel(zerolog.Disabled), - events.WithChainTime(chainTime), - events.WithEventsProviders(map[string]consensusclient.EventsProvider{}), - }, - err: "problem with parameters: events providers not supplied", - }, - { - name: "Good", - params: []events.Parameter{ - events.WithLogLevel(zerolog.Disabled), - events.WithChainTime(chainTime), - events.WithEventsProviders(map[string]consensusclient.EventsProvider{ - "test": mockClient, - }), - }, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - _, err := events.New(context.Background(), test.params...) - if test.err != "" { - require.EqualError(t, err, test.err) - } else { - require.NoError(t, err) - } - }) - } -} diff --git a/services/submitter/mock/service.go b/services/submitter/mock/service.go new file mode 100644 index 0000000..4289948 --- /dev/null +++ b/services/submitter/mock/service.go @@ -0,0 +1,38 @@ +// Copyright © 2022 Weald Technology Trading. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package mock + +import ( + "context" + + submitter "github.com/wealdtech/probec/services/submitter" +) + +// Service is a mock submitter. +type service struct{} + +// New creates a new mock submitter. +func New() submitter.Service { + return &service{} +} + +// SubmitBlockDelay submits a block delay data point. +func (s *service) SubmitBlockDelay(ctx context.Context, body string) error { + return nil +} + +// SubmitHeadDelay submits a head delay data point. +func (s *service) SubmitHeadDelay(ctx context.Context, body string) error { + return nil +}