diff --git a/go.mod b/go.mod index bcd0b4e..a9383d1 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ethpandaops/beacon go 1.19 require ( - github.com/attestantio/go-eth2-client v0.19.5 + github.com/attestantio/go-eth2-client v0.19.9 github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9 github.com/ethpandaops/ethwallclock v0.2.0 github.com/go-co-op/gocron v1.16.2 @@ -16,19 +16,19 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/fatih/color v1.13.0 // indirect + github.com/fatih/color v1.16.0 // indirect github.com/ferranbt/fastssz v0.1.3 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/goccy/go-yaml v1.9.5 // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/holiman/uint256 v1.2.2 // indirect + github.com/holiman/uint256 v1.2.4 // indirect github.com/huandu/go-clone v1.6.0 // indirect - github.com/klauspost/cpuid/v2 v2.1.2 // indirect + github.com/klauspost/cpuid/v2 v2.2.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.16 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/minio/sha256-simd v1.0.0 // indirect + github.com/minio/sha256-simd v1.0.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_model v0.3.0 // indirect @@ -40,11 +40,11 @@ require ( go.opentelemetry.io/otel v1.16.0 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect go.opentelemetry.io/otel/trace v1.16.0 // indirect - golang.org/x/crypto v0.10.0 // indirect + golang.org/x/crypto v0.18.0 // indirect golang.org/x/net v0.10.0 // indirect golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.9.0 // indirect - golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect + golang.org/x/sys v0.16.0 // indirect + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index d234a41..075e4b7 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/attestantio/go-eth2-client v0.19.5 h1:4V+vhXsCYji5jWrlONbr03GV7qoLRdzq96dLgXaqmek= -github.com/attestantio/go-eth2-client v0.19.5/go.mod h1:mZve1kV9Ctj0I1HH9gdg+MnI8lZ+Cb2EktEtOYrBlsM= +github.com/attestantio/go-eth2-client v0.19.9 h1:g5LLX3X7cLC0KS0oai/MtxBOZz3U3QPIX5qryYMxgVE= +github.com/attestantio/go-eth2-client v0.19.9/go.mod h1:TTz7YF6w4z6ahvxKiHuGPn6DbQn7gH6HPuWm/DEQeGE= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= @@ -13,8 +13,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/ethpandaops/ethwallclock v0.2.0 h1:EeFKtZ7v6TAdn/oAh0xaPujD7N4amjBxrWIByraUfLM= github.com/ethpandaops/ethwallclock v0.2.0/go.mod h1:y0Cu+mhGLlem19vnAV2x0hpFS5KZ7oOi2SWYayv9l24= 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/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/ferranbt/fastssz v0.1.3 h1:ZI+z3JH05h4kgmFXdHuR1aWYsgrg7o+Fw7/NCzM16Mo= github.com/ferranbt/fastssz v0.1.3/go.mod h1:0Y9TEd/9XuFlh7mskMPfXiI2Dkw4Ddg9EyXt1W7MRvE= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= @@ -43,33 +43,32 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/holiman/uint256 v1.2.2 h1:TXKcSGc2WaxPD2+bmzAsVthL4+pEN0YwXcL5qED83vk= -github.com/holiman/uint256 v1.2.2/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= +github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU= +github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c= github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U= github.com/huandu/go-clone v1.6.0 h1:HMo5uvg4wgfiy5FoGOqlFLQED/VGRm2D9Pi8g1FXPGc= github.com/huandu/go-clone v1.6.0/go.mod h1:ReGivhG6op3GYr+UY3lS6mxjKp7MIGTknuU5TbTVaXE= github.com/huandu/go-clone/generic v1.6.0 h1:Wgmt/fUZ28r16F2Y3APotFD59sHk1p78K0XLdbUYN5U= -github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.1.2 h1:XhdX4fqAJUA0yj+kUwMavO0hHrSPAecYdYf1ZmxHvak= -github.com/klauspost/cpuid/v2 v2.1.2/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= +github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 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/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/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/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= -github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= -github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= +github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= +github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= 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/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -111,8 +110,8 @@ go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZE go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= -golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= +golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= +golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= @@ -126,18 +125,19 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/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-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= -golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 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-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= diff --git a/pkg/beacon/beacon_block.go b/pkg/beacon/beacon_block.go index 9972f45..3d4fc15 100644 --- a/pkg/beacon/beacon_block.go +++ b/pkg/beacon/beacon_block.go @@ -6,48 +6,30 @@ import ( // GetDepositCountsFromBeaconBlock returns the number of deposits in a beacon block func GetDepositCountsFromBeaconBlock(block *spec.VersionedSignedBeaconBlock) int { - switch block.Version { - case spec.DataVersionPhase0: - return len(block.Phase0.Message.Body.Deposits) - case spec.DataVersionAltair: - return len(block.Altair.Message.Body.Deposits) - case spec.DataVersionBellatrix: - return len(block.Bellatrix.Message.Body.Deposits) - case spec.DataVersionCapella: - return len(block.Capella.Message.Body.Deposits) - default: - return 0 + deposits, err := block.Deposits() + if err == nil { + return len(deposits) } + + return 0 } // GetVoluntaryExitsFromBeaconBlock returns the number of voluntary exits in a beacon block func GetVoluntaryExitsFromBeaconBlock(block *spec.VersionedSignedBeaconBlock) int { - switch block.Version { - case spec.DataVersionPhase0: - return len(block.Phase0.Message.Body.VoluntaryExits) - case spec.DataVersionAltair: - return len(block.Altair.Message.Body.VoluntaryExits) - case spec.DataVersionBellatrix: - return len(block.Bellatrix.Message.Body.VoluntaryExits) - case spec.DataVersionCapella: - return len(block.Capella.Message.Body.VoluntaryExits) - default: - return 0 + exits, err := block.VoluntaryExits() + if err == nil { + return len(exits) } + + return 0 } // GetTransactionsCountFromBeaconBlock returns the number of transactions in a beacon block func GetTransactionsCountFromBeaconBlock(block *spec.VersionedSignedBeaconBlock) int { - switch block.Version { - case spec.DataVersionPhase0: - return 0 - case spec.DataVersionAltair: - return 0 - case spec.DataVersionBellatrix: - return len(block.Bellatrix.Message.Body.ExecutionPayload.Transactions) - case spec.DataVersionCapella: - return len(block.Capella.Message.Body.ExecutionPayload.Transactions) - default: - return 0 + transactions, err := block.ExecutionTransactions() + if err == nil { + return len(transactions) } + + return 0 } diff --git a/pkg/beacon/metrics_beacon.go b/pkg/beacon/metrics_beacon.go index efbc32c..99e5a48 100644 --- a/pkg/beacon/metrics_beacon.go +++ b/pkg/beacon/metrics_beacon.go @@ -33,6 +33,7 @@ type BeaconMetrics struct { WithdrawalsAmount prometheus.GaugeVec WithdrawalsIndexMax prometheus.GaugeVec WithdrawalsIndexMin prometheus.GaugeVec + BlobKZGCommitments prometheus.GaugeVec currentVersionHead string currentVersionFinalized string @@ -219,6 +220,18 @@ func NewBeaconMetrics(beac Node, log logrus.FieldLogger, namespace string, const "version", }, ), + BlobKZGCommitments: *prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: namespace, + Name: "blob_kzg_commitments", + Help: "The amount of blob kzg commitments in the block.", + ConstLabels: constLabels, + }, + []string{ + "block_id", + "version", + }, + ), } prometheus.MustRegister(b.Attestations) @@ -236,6 +249,7 @@ func NewBeaconMetrics(beac Node, log logrus.FieldLogger, namespace string, const prometheus.MustRegister(b.WithdrawalsAmount) prometheus.MustRegister(b.WithdrawalsIndexMax) prometheus.MustRegister(b.WithdrawalsIndexMin) + prometheus.MustRegister(b.BlobKZGCommitments) return b } @@ -469,12 +483,13 @@ func (b *BeaconMetrics) recordNewBeaconBlock(blockID string, block *spec.Version transactions := GetTransactionsCountFromBeaconBlock(block) b.Transactions.WithLabelValues(blockID, version).Set(float64(transactions)) - if block.Version == spec.DataVersionCapella { + withdrawals, err := block.Withdrawals() + if err == nil { gwei := int64(0) indexMax := int64(0) indexMin := int64(math.MaxInt64) - for _, withdrawal := range block.Capella.Message.Body.ExecutionPayload.Withdrawals { + for _, withdrawal := range withdrawals { gwei += int64(withdrawal.Amount) index := int64(withdrawal.Index) @@ -488,7 +503,7 @@ func (b *BeaconMetrics) recordNewBeaconBlock(blockID string, block *spec.Version } b.WithdrawalsAmount.WithLabelValues(blockID, version).Set(float64(gwei)) - b.Withdrawals.WithLabelValues(blockID, version).Set(float64(len(block.Capella.Message.Body.ExecutionPayload.Withdrawals))) + b.Withdrawals.WithLabelValues(blockID, version).Set(float64(len(withdrawals))) if indexMax > 0 { b.WithdrawalsIndexMax.WithLabelValues(blockID, version).Set(float64(indexMax)) @@ -498,4 +513,9 @@ func (b *BeaconMetrics) recordNewBeaconBlock(blockID string, block *spec.Version b.WithdrawalsIndexMin.WithLabelValues(blockID, version).Set(float64(indexMin)) } } + + blobs, err := block.BlobKZGCommitments() + if err == nil { + b.BlobKZGCommitments.WithLabelValues(blockID, version).Set(float64(len(blobs))) + } } diff --git a/pkg/beacon/metrics_fork.go b/pkg/beacon/metrics_fork.go index 1dbd668..09a1d68 100644 --- a/pkg/beacon/metrics_fork.go +++ b/pkg/beacon/metrics_fork.go @@ -3,8 +3,8 @@ package beacon import ( "context" - v1 "github.com/attestantio/go-eth2-client/api/v1" "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/ethpandaops/ethwallclock" "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" ) @@ -81,8 +81,8 @@ func (f *ForkMetrics) Name() string { // Start starts the job. func (f *ForkMetrics) Start(ctx context.Context) error { // TODO(sam.calder-mason): Update this to use the wall clock instead. - f.beacon.OnBlock(ctx, func(ctx context.Context, event *v1.BlockEvent) error { - return f.calculateCurrent(ctx, event.Slot) + f.beacon.Wallclock().OnEpochChanged(func(epoch ethwallclock.Epoch) { + f.calculateCurrent(ctx) }) return nil @@ -93,7 +93,9 @@ func (f *ForkMetrics) Stop() error { return nil } -func (f *ForkMetrics) calculateCurrent(ctx context.Context, slot phase0.Slot) error { +func (f *ForkMetrics) calculateCurrent(ctx context.Context) error { + slot := f.beacon.Wallclock().Slots().Current() + spec, err := f.beacon.Spec() if err != nil { return err @@ -107,14 +109,14 @@ func (f *ForkMetrics) calculateCurrent(ctx context.Context, slot phase0.Slot) er for _, fork := range spec.ForkEpochs { f.Epochs.WithLabelValues(fork.Name).Set(float64(fork.Epoch)) - if fork.Active(slot, slotsPerEpoch) { + if fork.Active(phase0.Slot(slot.Number()), slotsPerEpoch) { f.Activated.WithLabelValues(fork.Name).Set(1) } else { f.Activated.WithLabelValues(fork.Name).Set(0) } } - current, err := spec.ForkEpochs.CurrentFork(slot, slotsPerEpoch) + current, err := spec.ForkEpochs.CurrentFork(phase0.Slot(slot.Number()), slotsPerEpoch) if err != nil { f.log.WithError(err).Error("Failed to set current fork") } else {