From 360e8d52a8bf6f4ec7c225443cbb986c6004ce6b Mon Sep 17 00:00:00 2001 From: Marketen Date: Thu, 22 Oct 2026 17:44:50 +0200 Subject: [PATCH 1/4] Bump go-eth2-client to v0.30.2 for Gloas support Glamsterdam's consensus fork (Gloas) moves the execution payload out of the beacon block. v0.30.2 is the first go-eth2-client release that can decode Gloas beacon blocks and fetch execution payload envelopes; with v0.27.1 the oracle stops at the first Gloas slot because the block can't be decoded. v0.30 requires Go 1.25, so the Dockerfile and CI move to it as well. go-bitfield moved from prysmaticlabs to OffchainLabs upstream, which only affects one test import. No behaviour changes. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/tests.yml | 2 +- Dockerfile | 4 ++-- go.mod | 25 ++++++++++----------- go.sum | 44 ++++++++++++++++++------------------- oracle/block_test.go | 2 +- 5 files changed, 37 insertions(+), 40 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c960974..9fddaec 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - go-version: [1.24.x] + go-version: [1.25.x] #macos-latest, windows-latest os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} diff --git a/Dockerfile b/Dockerfile index 23ed4e8..b97407a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.24-alpine AS build +FROM golang:1.25-alpine AS build ARG BUILD_VERSION WORKDIR /app @@ -9,7 +9,7 @@ RUN apk add --update gcc g++ RUN go mod download RUN go build -o /mev-sp-oracle -ldflags "-X github.com/dappnode/mev-sp-oracle/config.ReleaseVersion=$BUILD_VERSION" . -FROM golang:1.24-alpine +FROM golang:1.25-alpine WORKDIR / diff --git a/go.mod b/go.mod index aa9d297..59efe68 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,9 @@ module github.com/dappnode/mev-sp-oracle -go 1.23.0 - -toolchain go1.24.2 +go 1.25.0 require ( + github.com/OffchainLabs/go-bitfield v0.0.0-20251031151322-f427d04d8506 github.com/attestantio/go-builder-client v0.4.3 github.com/avast/retry-go/v4 v4.5.0 github.com/gorilla/mux v1.8.0 @@ -12,12 +11,11 @@ require ( github.com/miguelmota/go-solidity-sha3 v0.1.1 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.17.0 - github.com/prysmaticlabs/go-bitfield v0.0.0-20240618144021-706c95b2dd15 github.com/rs/zerolog v1.32.0 github.com/sirupsen/logrus v1.9.3 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 github.com/txaty/go-merkletree v0.1.15 - golang.org/x/crypto v0.35.0 + golang.org/x/crypto v0.42.0 golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa ) @@ -44,19 +42,19 @@ require ( github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-playground/validator/v10 v10.11.1 // indirect github.com/goccy/go-yaml v1.11.2 // indirect - github.com/google/go-cmp v0.6.0 // indirect github.com/google/uuid v1.3.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/holiman/uint256 v1.3.2 // indirect github.com/huandu/go-clone v1.6.0 // indirect - github.com/klauspost/cpuid/v2 v2.2.9 // indirect + github.com/klauspost/cpuid/v2 v2.3.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect github.com/minio/sha256-simd v1.0.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect - github.com/pk910/dynamic-ssz v0.0.4 // indirect + github.com/pk910/dynamic-ssz v1.4.0 // indirect + github.com/pk910/hashtree-bindings v0.2.6 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect @@ -71,11 +69,10 @@ require ( go.opentelemetry.io/otel v1.19.0 // indirect go.opentelemetry.io/otel/metric v1.19.0 // indirect go.opentelemetry.io/otel/trace v1.19.0 // indirect - golang.org/x/net v0.36.0 // indirect - golang.org/x/sync v0.11.0 // indirect + golang.org/x/net v0.43.0 // indirect + golang.org/x/sync v0.17.0 // indirect golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect google.golang.org/protobuf v1.34.2 // indirect - gopkg.in/Knetic/govaluate.v3 v3.0.0 // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect @@ -83,7 +80,7 @@ require ( ) require ( - github.com/attestantio/go-eth2-client v0.27.1 + github.com/attestantio/go-eth2-client v0.30.2 github.com/ethereum/go-ethereum v1.15.7 - golang.org/x/sys v0.30.0 // indirect + golang.org/x/sys v0.36.0 // indirect ) diff --git a/go.sum b/go.sum index 2a419bf..de85f74 100644 --- a/go.sum +++ b/go.sum @@ -2,14 +2,16 @@ github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/OffchainLabs/go-bitfield v0.0.0-20251031151322-f427d04d8506 h1:d/SJkN8/9Ca+1YmuDiUJxAiV4w/a9S8NcsG7GMQSrVI= +github.com/OffchainLabs/go-bitfield v0.0.0-20251031151322-f427d04d8506/go.mod h1:6TZI4FU6zT8x6ZfWa1J8YQ2NgW0wLV/W3fHRca8ISBo= github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI= github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI= github.com/agiledragon/gomonkey/v2 v2.9.0 h1:PDiKKybR596O6FHW+RVSG0Z7uGCBNbmbUXh3uCNQ7Hc= github.com/agiledragon/gomonkey/v2 v2.9.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY= github.com/attestantio/go-builder-client v0.4.3 h1:K1m/PTqY01mfAPc0h+9iR2OivY3LOevbxHxEfvI4M8M= github.com/attestantio/go-builder-client v0.4.3/go.mod h1:yeJANU1O5P3b/4+iwShz9JMcgUnZABCh5RJBtZnLiDo= -github.com/attestantio/go-eth2-client v0.27.1 h1:g7bm+gG/p+gfzYdEuxuAepVWYb8EO+2KojV5/Lo2BxM= -github.com/attestantio/go-eth2-client v0.27.1/go.mod h1:fvULSL9WtNskkOB4i+Yyr6BKpNHXvmpGZj9969fCrfY= +github.com/attestantio/go-eth2-client v0.30.2 h1:8LWN86Dh5PjXTwcrRR+SXcatcocFw7j08KO7NFqEcNo= +github.com/attestantio/go-eth2-client v0.30.2/go.mod h1:IcbypY5iD/c/T5OLWVuZyWS8kM8HXkGc0ZW12uikfys= github.com/avast/retry-go/v4 v4.5.0 h1:QoRAZZ90cj5oni2Lsgl2GW8mNTnUCnmpx/iKpwVisHg= github.com/avast/retry-go/v4 v4.5.0/go.mod h1:7hLEXp0oku2Nir2xBAsg0PTphp9z71bN5Aq1fboC3+I= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -140,8 +142,8 @@ github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7Bd github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4= github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY= -github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8= +github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y= +github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= @@ -195,8 +197,10 @@ github.com/pion/transport/v2 v2.2.1 h1:7qYnCBlpgSJNYMbLCKuSY9KbQdBFoETvPNETv0y4N github.com/pion/transport/v2 v2.2.1/go.mod h1:cXXWavvCnFF6McHTft3DWS9iic2Mftcz1Aq29pGcU5g= github.com/pion/transport/v3 v3.0.1 h1:gDTlPJwROfSfz6QfSi0ZmeCSkFcnWWiiR9ES0ouANiM= github.com/pion/transport/v3 v3.0.1/go.mod h1:UY7kiITrlMv7/IKgd5eTUcaahZx5oUN3l9SzK5f5xE0= -github.com/pk910/dynamic-ssz v0.0.4 h1:DT29+1055tCEPCaR4V/ez+MOKW7BzBsmjyFvBRqx0ME= -github.com/pk910/dynamic-ssz v0.0.4/go.mod h1:b6CrLaB2X7pYA+OSEEbkgXDEcRnjLOZIxZTsMuO/Y9c= +github.com/pk910/dynamic-ssz v1.4.0 h1:uwDOiBR/gmbC08gGo1TA/SLD17ArJyLKi0PHaQmuZEM= +github.com/pk910/dynamic-ssz v1.4.0/go.mod h1:mnRbhjX+4YMyP4jYMncTUA3aDpMzBLqAbjcvfCyOyRI= +github.com/pk910/hashtree-bindings v0.2.6 h1:BjRQho04nWzGrXwBCLVTyQRNV30O59iPcvQRcidFt2o= +github.com/pk910/hashtree-bindings v0.2.6/go.mod h1:zrWt88783JmhBfcgni6kkIMYRdXTZi/FL//OyI5T/l4= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -210,8 +214,6 @@ github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lne github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= -github.com/prysmaticlabs/go-bitfield v0.0.0-20240618144021-706c95b2dd15 h1:lC8kiphgdOBTcbTvo8MwkvpKjO0SlAgjv4xIK5FGJ94= -github.com/prysmaticlabs/go-bitfield v0.0.0-20240618144021-706c95b2dd15/go.mod h1:8svFBIKKu31YriBG/pNizo9N0Jr9i5PQ+dFkxWg3x5k= github.com/prysmaticlabs/gohashtree v0.0.4-beta h1:H/EbCuXPeTV3lpKeXGPpEV9gsUpkqOOVnWapUyeWro4= github.com/prysmaticlabs/gohashtree v0.0.4-beta/go.mod h1:BFdtALS+Ffhg3lGQIHv9HDWuHS8cTvHZzrHWxwOtGOs= github.com/r3labs/sse/v2 v2.10.0 h1:hFEkLLFY4LDifoHdiCN/LlGBAdVJYsANaLqNYa1l/v0= @@ -237,8 +239,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/supranational/blst v0.3.14 h1:xNMoHRJOTwMn63ip6qoWJ2Ymgvj7E2b9jY2FAwY+qRo= github.com/supranational/blst v0.3.14/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= @@ -265,16 +267,16 @@ go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1 go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs= -golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ= +golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI= +golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8= golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA= -golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I= -golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= -golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= +golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= +golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= +golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -289,14 +291,14 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= -golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= +golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= -golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= +golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= +golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY= golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -304,8 +306,6 @@ golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSm golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= -gopkg.in/Knetic/govaluate.v3 v3.0.0 h1:18mUyIt4ZlRlFZAAfVetz4/rzlJs9yhN+U02F4u1AOc= -gopkg.in/Knetic/govaluate.v3 v3.0.0/go.mod h1:csKLBORsPbafmSCGTEh3U7Ozmsuq8ZSIlKk1bcqph0E= gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y= gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/oracle/block_test.go b/oracle/block_test.go index e1bcd0d..f19daef 100644 --- a/oracle/block_test.go +++ b/oracle/block_test.go @@ -9,6 +9,7 @@ import ( "path/filepath" "testing" + "github.com/OffchainLabs/go-bitfield" v1 "github.com/attestantio/go-eth2-client/api/v1" "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/altair" @@ -19,7 +20,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/pkg/errors" - "github.com/prysmaticlabs/go-bitfield" "github.com/stretchr/testify/require" ) From a6d7b47e4abb2c67e72ecfdb54209ff889d8ad9e Mon Sep 17 00:00:00 2001 From: Marketen Date: Thu, 22 Oct 2026 17:47:02 +0200 Subject: [PATCH 2/4] Compute the vanilla reward from each tx's priority fee The vanilla reward was calculated as every fee paid minus the block gas_used times the base fee. That relies on the block gas_used being the sum of the gas charged to each tx, which Glamsterdam breaks: EIP-7778 stops subtracting refunds from it, and EIP-8037 makes it the largest of two gas dimensions. The pool would have been credited less than it received, and the onchain reconciliation would refuse to freeze the checkpoint. Sum each tx's priority fee instead, using the gas its receipt charged. Until Glamsterdam both calculations are equal, which the new tests check for every supported tx type, so no published reward changes and the change needs no activation slot. It also fixes a tx/receipt hash mismatch silently returning a nil reward with a nil error, as the error was wrapped from a nil one. Co-Authored-By: Claude Opus 5.5 --- go.mod | 2 +- oracle/block.go | 67 ++++++------ oracle/proposer_tip_test.go | 207 ++++++++++++++++++++++++++++++++++++ 3 files changed, 244 insertions(+), 32 deletions(-) create mode 100644 oracle/proposer_tip_test.go diff --git a/go.mod b/go.mod index 59efe68..1988270 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/avast/retry-go/v4 v4.5.0 github.com/gorilla/mux v1.8.0 github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b + github.com/holiman/uint256 v1.3.2 github.com/miguelmota/go-solidity-sha3 v0.1.1 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.17.0 @@ -44,7 +45,6 @@ require ( github.com/goccy/go-yaml v1.11.2 // indirect github.com/google/uuid v1.3.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect - github.com/holiman/uint256 v1.3.2 // indirect github.com/huandu/go-clone v1.6.0 // indirect github.com/klauspost/cpuid/v2 v2.3.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect diff --git a/oracle/block.go b/oracle/block.go index b886476..6460396 100644 --- a/oracle/block.go +++ b/oracle/block.go @@ -671,9 +671,15 @@ func (b *FullBlock) isAddressRewarded(address string) bool { return false } -// The reward for vanila block has to be calculated by iterating all -// txs and getting the individual tips as per EIP1559. Note that to -// calculate this we need the execution header and receipts +// The reward for vanila block is the sum of the priority fee of every tx: what +// it paid per unit of gas above the base fee, times the gas it was charged for. +// The receipts are needed since only they hold the gas each tx was charged for. +// +// This used to be calculated as all the fees paid minus gas_used * base fee, +// which relies on the block gas_used being the sum of the gas charged to each +// tx. Glamsterdam breaks that: EIP-7778 no longer subtracts refunds from the +// block gas_used and EIP-8037 makes it the largest of two gas dimensions. Before +// Glamsterdam both calculations give the same result, so past rewards hold. func (b *FullBlock) GetProposerTip() (*big.Int, error) { // Ensure non nil @@ -681,23 +687,13 @@ func (b *FullBlock) GetProposerTip() (*big.Int, error) { return nil, errors.New("receipts of full block are nil, cant calculate tip") } - if b.ExecutionHeader == nil { - return nil, errors.New("header of full block are nil, cant calculate tip") - } - // Ensure tx and their receipts have the same size if len(b.GetBlockTransactions()) != len(b.ExecutionReceipts) { return nil, errors.New(fmt.Sprintf("txs and receipts not the same length. txs: %d, receipts: %d", len(b.GetBlockTransactions()), len(b.ExecutionReceipts))) } - // little-endian to big-endian - var baseFeePerGasBEBytes [32]byte - for i := 0; i < 32; i++ { - baseFeePerGasBEBytes[i] = b.GetBaseFeePerGas()[32-1-i] - } - baseFeePerGas := new(big.Int).SetBytes(baseFeePerGasBEBytes[:]) - + baseFeePerGas := b.GetBaseFeePerGasBigInt() tips := big.NewInt(0) for i, rawTx := range b.GetBlockTransactions() { @@ -706,31 +702,29 @@ func (b *FullBlock) GetProposerTip() (*big.Int, error) { return nil, errors.Wrap(err, "could not decode tx") } if tx.Hash() != b.ExecutionReceipts[i].TxHash { - return nil, errors.Wrap(err, "tx hash does not match receipt hash") + return nil, errors.New(fmt.Sprintf("tx hash does not match receipt hash. tx: %s, receipt: %s", + tx.Hash().String(), b.ExecutionReceipts[i].TxHash.String())) } - tipFee := new(big.Int) - gasPrice := tx.GasPrice() - gasUsed := big.NewInt(int64(b.ExecutionReceipts[i].GasUsed)) - + // A new tx type could pay its fees differently, so better to stop than + // to credit a wrong reward switch tx.Type() { - case 0: - tipFee.Mul(gasPrice, gasUsed) - case 1: - tipFee.Mul(gasPrice, gasUsed) - case 2, 3, 4: - // Sum gastipcap and basefee or saturate to gasfeecap - usedGasPrice := utils.SumAndSaturate(tx.GasTipCap(), b.ExecutionHeader.BaseFee, tx.GasFeeCap()) - tipFee = new(big.Int).Mul(usedGasPrice, gasUsed) + case types.LegacyTxType, types.AccessListTxType, types.DynamicFeeTxType, types.BlobTxType, types.SetCodeTxType: default: return nil, errors.New(fmt.Sprintf("unknown tx type: %d, hash: %s", tx.Type(), tx.Hash().String())) } - tips = tips.Add(tips, tipFee) + + // As per EIP-1559: min(tip cap, fee cap - base fee). Legacy txs have both + // caps set to their gas price + tipPerGas, err := tx.EffectiveGasTip(baseFeePerGas) + if err != nil { + return nil, errors.Wrap(err, "could not get effective tip of tx "+tx.Hash().String()) + } + gasUsed := new(big.Int).SetUint64(b.ExecutionReceipts[i].GasUsed) + tips.Add(tips, new(big.Int).Mul(tipPerGas, gasUsed)) } - burnt := new(big.Int).Mul(big.NewInt(int64(b.GetGasUsed())), baseFeePerGas) - proposerReward := new(big.Int).Sub(tips, burnt) - return proposerReward, nil + return tips, nil } // Returns the donations sent to the pool. There are two types of donations: @@ -1055,3 +1049,14 @@ func (b *FullBlock) GetBaseFeePerGas() [32]byte { } return baseFeePerGas } + +// Returns the base fee per gas of the block as a number, in wei +func (b *FullBlock) GetBaseFeePerGasBigInt() *big.Int { + // GetBaseFeePerGas is little-endian, big.Int expects big-endian + littleEndian := b.GetBaseFeePerGas() + var bigEndian [32]byte + for i := 0; i < 32; i++ { + bigEndian[i] = littleEndian[32-1-i] + } + return new(big.Int).SetBytes(bigEndian[:]) +} diff --git a/oracle/proposer_tip_test.go b/oracle/proposer_tip_test.go new file mode 100644 index 0000000..e96239a --- /dev/null +++ b/oracle/proposer_tip_test.go @@ -0,0 +1,207 @@ +package oracle + +import ( + "crypto/ecdsa" + "math/big" + "testing" + + v1 "github.com/attestantio/go-eth2-client/api/v1" + "github.com/attestantio/go-eth2-client/spec" + "github.com/attestantio/go-eth2-client/spec/bellatrix" + "github.com/attestantio/go-eth2-client/spec/deneb" + "github.com/attestantio/go-eth2-client/spec/electra" + "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/holiman/uint256" + "github.com/stretchr/testify/require" +) + +const gwei = int64(1_000_000_000) + +// A tx of the block together with the gas its receipt says it was charged for +type chargedTx struct { + tx *types.Transaction + gasUsed uint64 +} + +// Signs one tx of every type the oracle supports. Fee caps are chosen so that +// some txs pay their full tip and others are capped by the fee cap +func txsOfEveryType(t *testing.T, key *ecdsa.PrivateKey) []chargedTx { + t.Helper() + chainId := new(big.Int).SetUint64(MainnetChainId) + signer := types.LatestSignerForChainID(chainId) + to := common.HexToAddress("0x5555555555555555555555555555555555555555") + + sign := func(data types.TxData) *types.Transaction { + tx, err := types.SignNewTx(key, signer, data) + require.NoError(t, err) + return tx + } + txs := []*types.Transaction{ + sign(&types.LegacyTx{Nonce: 0, GasPrice: big.NewInt(13 * gwei), Gas: 21000, To: &to}), + sign(&types.AccessListTx{ChainID: chainId, Nonce: 1, GasPrice: big.NewInt(11 * gwei), Gas: 30000, To: &to}), + // Full tip paid: base fee + tip is below the fee cap + sign(&types.DynamicFeeTx{ChainID: chainId, Nonce: 2, GasTipCap: big.NewInt(2 * gwei), GasFeeCap: big.NewInt(50 * gwei), Gas: 90000, To: &to}), + // Tip capped by the fee cap + sign(&types.DynamicFeeTx{ChainID: chainId, Nonce: 3, GasTipCap: big.NewInt(9 * gwei), GasFeeCap: big.NewInt(12 * gwei), Gas: 50000, To: &to}), + sign(&types.BlobTx{ChainID: uint256.NewInt(MainnetChainId), Nonce: 4, GasTipCap: uint256.NewInt(uint64(3 * gwei)), + GasFeeCap: uint256.NewInt(uint64(40 * gwei)), Gas: 21000, To: to, BlobFeeCap: uint256.NewInt(1), + BlobHashes: []common.Hash{{0x01}}}), + sign(&types.SetCodeTx{ChainID: uint256.NewInt(MainnetChainId), Nonce: 5, GasTipCap: uint256.NewInt(uint64(1 * gwei)), + GasFeeCap: uint256.NewInt(uint64(30 * gwei)), Gas: 60000, To: to}), + } + gasUsed := []uint64{21000, 25400, 61234, 50000, 21000, 47311} + + charged := make([]chargedTx, len(txs)) + for i := range txs { + charged[i] = chargedTx{tx: txs[i], gasUsed: gasUsed[i]} + } + return charged +} + +// Builds a Fulu block containing the given txs and their receipts. blockGasUsed +// is what the block header says, which since Glamsterdam can differ from the +// sum of the receipts +func blockWithReceipts(t *testing.T, txs []chargedTx, baseFeeWei int64, blockGasUsed uint64) *FullBlock { + t.Helper() + rawTxs := make([]bellatrix.Transaction, len(txs)) + receipts := make([]*types.Receipt, len(txs)) + for i, charged := range txs { + raw, err := charged.tx.MarshalBinary() + require.NoError(t, err) + rawTxs[i] = raw + receipts[i] = &types.Receipt{TxHash: charged.tx.Hash(), GasUsed: charged.gasUsed} + } + + fullBlock := NewFullBlock(&v1.ProposerDuty{Slot: 100, ValidatorIndex: 7}, + &v1.Validator{Index: 7, Validator: &phase0.Validator{}}, MainnetChainId) + fullBlock.SetConsensusBlock(&spec.VersionedSignedBeaconBlock{ + Version: spec.DataVersionFulu, + Fulu: &electra.SignedBeaconBlock{Message: &electra.BeaconBlock{ + Slot: 100, ProposerIndex: 7, + Body: &electra.BeaconBlockBody{ExecutionPayload: &deneb.ExecutionPayload{ + BlockNumber: 1000, + GasUsed: blockGasUsed, + BaseFeePerGas: uint256.NewInt(uint64(baseFeeWei)), + Transactions: rawTxs, + }}, + }}, + }) + fullBlock.ExecutionHeader = &types.Header{Number: big.NewInt(1000), BaseFee: big.NewInt(baseFeeWei), GasUsed: blockGasUsed} + fullBlock.ExecutionReceipts = receipts + return fullBlock +} + +func sumGasUsed(txs []chargedTx) uint64 { + total := uint64(0) + for _, charged := range txs { + total += charged.gasUsed + } + return total +} + +// The calculation used until Glamsterdam: every fee paid minus what the block +// burnt, using the block gas_used. Kept here to prove the new one matches it +func formerProposerTip(txs []chargedTx, baseFee *big.Int, blockGasUsed uint64) *big.Int { + fees := big.NewInt(0) + for _, charged := range txs { + pricePerGas := new(big.Int).Add(charged.tx.GasTipCap(), baseFee) + if pricePerGas.Cmp(charged.tx.GasFeeCap()) > 0 { + pricePerGas = charged.tx.GasFeeCap() + } + fees.Add(fees, new(big.Int).Mul(pricePerGas, new(big.Int).SetUint64(charged.gasUsed))) + } + burnt := new(big.Int).Mul(new(big.Int).SetUint64(blockGasUsed), baseFee) + return fees.Sub(fees, burnt) +} + +// Before Glamsterdam the block gas_used is the sum of the receipts, and the new +// calculation must give exactly the old result so past rewards don't change +func Test_GetProposerTip_MatchesFormerCalculationBeforeGlamsterdam(t *testing.T) { + key, err := crypto.GenerateKey() + require.NoError(t, err) + txs := txsOfEveryType(t, key) + + for _, baseFeeGwei := range []int64{1, 7, 10} { + baseFee := big.NewInt(baseFeeGwei * gwei) + fullBlock := blockWithReceipts(t, txs, baseFee.Int64(), sumGasUsed(txs)) + + tip, err := fullBlock.GetProposerTip() + require.NoError(t, err) + require.Equal(t, formerProposerTip(txs, baseFee, sumGasUsed(txs)), tip, "base fee %d gwei", baseFeeGwei) + } +} + +// EIP-7778 stops subtracting refunds from the block gas_used, so it can exceed +// what the txs were charged. The tip must only count what was actually charged +func Test_GetProposerTip_BlockGasUsedIncludesRefunds(t *testing.T) { + key, err := crypto.GenerateKey() + require.NoError(t, err) + txs := txsOfEveryType(t, key) + baseFee := big.NewInt(7 * gwei) + refunds := uint64(19_800) + fullBlock := blockWithReceipts(t, txs, baseFee.Int64(), sumGasUsed(txs)+refunds) + + tip, err := fullBlock.GetProposerTip() + require.NoError(t, err) + + // Worked out by hand at a 7 gwei base fee: legacy 6 gwei, access list + // 4 gwei, dynamic fee 2 gwei (full tip) and 5 gwei (capped by its 12 gwei + // fee cap), blob 3 gwei and set code 1 gwei per unit of gas + expected := big.NewInt(0) + for i, tipGwei := range []int64{6, 4, 2, 5, 3, 1} { + perTx := new(big.Int).Mul(big.NewInt(tipGwei*gwei), new(big.Int).SetUint64(txs[i].gasUsed)) + expected.Add(expected, perTx) + } + require.Equal(t, expected, tip) + + // The former calculation would have burnt the refunds out of the proposer's + // reward, leaving the pool with more ETH than the oracle accounts for + under := new(big.Int).Sub(expected, formerProposerTip(txs, baseFee, sumGasUsed(txs)+refunds)) + require.Equal(t, new(big.Int).Mul(new(big.Int).SetUint64(refunds), baseFee), under) +} + +func Test_GetProposerTip_Errors(t *testing.T) { + key, err := crypto.GenerateKey() + require.NoError(t, err) + txs := txsOfEveryType(t, key) + + t.Run("no receipts", func(t *testing.T) { + fullBlock := blockWithReceipts(t, txs, 7*gwei, sumGasUsed(txs)) + fullBlock.ExecutionReceipts = nil + _, err := fullBlock.GetProposerTip() + require.ErrorContains(t, err, "receipts of full block are nil") + }) + + t.Run("missing receipt", func(t *testing.T) { + fullBlock := blockWithReceipts(t, txs, 7*gwei, sumGasUsed(txs)) + fullBlock.ExecutionReceipts = fullBlock.ExecutionReceipts[1:] + _, err := fullBlock.GetProposerTip() + require.ErrorContains(t, err, "not the same length") + }) + + // Used to return a nil error and a nil tip + t.Run("receipt of another tx", func(t *testing.T) { + fullBlock := blockWithReceipts(t, txs, 7*gwei, sumGasUsed(txs)) + fullBlock.ExecutionReceipts[0].TxHash = common.Hash{0x42} + tip, err := fullBlock.GetProposerTip() + require.ErrorContains(t, err, "tx hash does not match receipt hash") + require.Nil(t, tip) + }) + + t.Run("fee cap below base fee", func(t *testing.T) { + // The capped dynamic fee tx pays at most 12 gwei + fullBlock := blockWithReceipts(t, txs, 20*gwei, sumGasUsed(txs)) + _, err := fullBlock.GetProposerTip() + require.ErrorContains(t, err, "could not get effective tip") + }) +} + +func Test_GetBaseFeePerGasBigInt(t *testing.T) { + key, err := crypto.GenerateKey() + require.NoError(t, err) + fullBlock := blockWithReceipts(t, txsOfEveryType(t, key), 1_234_567_891, 0) + require.Equal(t, big.NewInt(1_234_567_891), fullBlock.GetBaseFeePerGasBigInt()) +} From dfe60805a9977ecad145be5230ddd7268124ebeb Mon Sep 17 00:00:00 2001 From: Marketen Date: Tue, 1 Dec 2026 12:20:41 +0100 Subject: [PATCH 3/4] Detect missed slots from the HTTP status, not the error text A beacon block request failing with an error whose text contained "404" was taken as a missed slot. Any slot number with 404 in it, like 4540412, shows up in the error of a request for it, so a server error or timeout at such a slot would have counted as a missed proposal: a yellow or red card for a validator that did nothing wrong. The status code is now read from go-eth2-client's api.Error, and only a 404 counts as missed. Any other error is retried and then stops the oracle, as before. Co-Authored-By: Claude Fable 5.2 --- oracle/onchain.go | 12 +++++++++++- oracle/onchain_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/oracle/onchain.go b/oracle/onchain.go index 0283473..8f60989 100644 --- a/oracle/onchain.go +++ b/oracle/onchain.go @@ -227,7 +227,7 @@ func (o *Onchain) GetConsensusBlockAtSlot(slot uint64, opts ...retry.Option) (*s // Its not possible to detect if the block was missed or if the block doesn't exist in the chain // GET failed with status 404: {"code":404,"message":"NOT_FOUND: beacon block at slot 7408169","stacktraces":[]} // To keep compatibility after go-eth2-client changes, we consider that a missed block is nil - if strings.Contains(err.Error(), "404") { + if isNotFoundError(err) { signedBeaconBlock = &api.Response[*spec.VersionedSignedBeaconBlock]{ Data: nil, } @@ -245,6 +245,16 @@ func (o *Onchain) GetConsensusBlockAtSlot(slot uint64, opts ...retry.Option) (*s return signedBeaconBlock.Data, err } +// Whether the beacon node answered with HTTP status 404, which for a block +// means there is none at that slot. The status is read from the error itself, +// not from its text: a slot number like 4540412 or an unrelated error body can +// contain "404", and taking those for a missed slot would count a missed +// proposal that never happened +func isNotFoundError(err error) bool { + var apiErr *api.Error + return errors.As(err, &apiErr) && apiErr.StatusCode == normalHttp.StatusNotFound +} + // Gets active validators by asking the chain. It does not get current Onchain object validators func (o *Onchain) GetFinalizedValidators(opts ...retry.Option) (map[phase0.ValidatorIndex]*v1.Validator, error) { var validators *api.Response[map[phase0.ValidatorIndex]*v1.Validator] diff --git a/oracle/onchain_test.go b/oracle/onchain_test.go index 31079f3..05aeaa0 100644 --- a/oracle/onchain_test.go +++ b/oracle/onchain_test.go @@ -14,6 +14,7 @@ import ( "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/dappnode/mev-sp-oracle/config" "github.com/ethereum/go-ethereum/common" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" ) @@ -544,3 +545,43 @@ func isInSlice(element uint64, slice []uint64) bool { } return false } + +func Test_IsNotFoundError(t *testing.T) { + tests := []struct { + name string + err error + notFound bool + }{ + { + name: "block not found", + err: ð2.Error{Method: "GET", StatusCode: 404, Endpoint: "/eth/v2/beacon/blocks/7408169", Data: []byte(`{"code":404,"message":"NOT_FOUND: beacon block at slot 7408169"}`)}, + notFound: true, + }, + { + name: "block not found, wrapped", + err: fmt.Errorf("fetch block: %w", ð2.Error{Method: "GET", StatusCode: 404}), + notFound: true, + }, + { + // The slot number contains "404", which the status check must not be fooled by + name: "server error at a slot whose number contains 404", + err: ð2.Error{Method: "GET", StatusCode: 500, Endpoint: "/eth/v2/beacon/blocks/4540412", Data: []byte(`{"code":500,"message":"Internal error at slot 4540412"}`)}, + notFound: false, + }, + { + name: "unrelated error whose text contains 404", + err: errors.New("dial tcp 10.0.0.1:4040: connection refused, request id 404"), + notFound: false, + }, + { + name: "timeout", + err: context.DeadlineExceeded, + notFound: false, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + require.Equal(t, test.notFound, isNotFoundError(test.err)) + }) + } +} From 67ed2738b8bd4ed0a45e7127bdeb526b67e0f633 Mon Sep 17 00:00:00 2001 From: Marketen Date: Tue, 1 Dec 2026 12:38:27 +0100 Subject: [PATCH 4/4] Call the configured consensus endpoint with a timeout for pending consolidations GetPendingConsolidations built its URL from ConsensusClient.Address(), which go-eth2-client masks for logging: a path is replaced by xxxxx and query values and passwords too. With an endpoint like https://node/beacon?apikey=... every call went to the wrong place. It also used http.DefaultClient, which has no timeout, so a node that stopped answering mid response would hang the oracle forever. The URL is now built from the configured endpoint, keeping its path, query and credentials as go-eth2-client does, and sent with a client that times out after 120 seconds, the timeout already given to go-eth2-client. Failures are reported without the URL, so a key in the query does not end up in the logs. Co-Authored-By: Claude Fable 5.2 --- oracle/onchain.go | 52 ++++++++++++++++++++++++++++++++---- oracle/onchain_test.go | 60 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 5 deletions(-) diff --git a/oracle/onchain.go b/oracle/onchain.go index 8f60989..f9ac10b 100644 --- a/oracle/onchain.go +++ b/oracle/onchain.go @@ -9,6 +9,7 @@ import ( "io" "math/big" normalHttp "net/http" + "net/url" "strconv" "strings" "time" @@ -63,6 +64,12 @@ type EpochDuties struct { // Note that the cache is meant to store only one epoch's duties var ProposalDutyCache EpochDuties +// How long a request to the consensus client may take +const consensusRequestTimeout = 120 * time.Second + +// For the beacon API endpoints go-eth2-client has no call for +var consensusHttpClient = &normalHttp.Client{Timeout: consensusRequestTimeout} + type Onchain struct { ConsensusClient *http.Service ExecutionClient *ethclient.Client @@ -73,6 +80,10 @@ type Onchain struct { PoolAddress string ChainId uint64 validators map[phase0.ValidatorIndex]*v1.Validator + + // As configured. ConsensusClient.Address() masks its path, query and + // password for logging, so it can't be used to call the node + consensusEndpoint string } func NewOnchain(cliCfg *config.CliConfig, updaterKey *ecdsa.PrivateKey) (*Onchain, error) { @@ -92,7 +103,7 @@ func NewOnchain(cliCfg *config.CliConfig, updaterKey *ecdsa.PrivateKey) (*Onchai // Dial the consensus client client, err := http.New(context.Background(), - http.WithTimeout(120*time.Second), + http.WithTimeout(consensusRequestTimeout), http.WithAddress(cliCfg.ConsensusEndpoint), http.WithLogLevel(zerolog.WarnLevel), ) @@ -163,9 +174,37 @@ func NewOnchain(cliCfg *config.CliConfig, updaterKey *ecdsa.PrivateKey) (*Onchai ChainId: uint64(chainId.Int64()), updaterKey: updaterKey, UpdaterAddress: updaterAddress, + + consensusEndpoint: cliCfg.ConsensusEndpoint, }, nil } +// Returns the URL of the given beacon API path on the configured consensus +// endpoint, keeping its own path, query and credentials, as go-eth2-client does +func consensusApiUrl(consensusEndpoint string, path string) (string, error) { + if !strings.HasPrefix(consensusEndpoint, "http") { + consensusEndpoint = "http://" + consensusEndpoint + } + base, err := url.Parse(consensusEndpoint) + if err != nil { + // The parse error would print the endpoint, credentials included + return "", errors.New("invalid consensus endpoint") + } + base.Path = strings.TrimSuffix(base.Path, "/") + path + return base.String(), nil +} + +// Sends a request built from consensusApiUrl. A failure is returned without +// the URL, which may hold credentials in its query +func doConsensusRequest(req *normalHttp.Request) (*normalHttp.Response, error) { + resp, err := consensusHttpClient.Do(req) + var urlErr *url.Error + if errors.As(err, &urlErr) { + return nil, fmt.Errorf("%s %s: %w", urlErr.Op, req.URL.Path, urlErr.Err) + } + return resp, err +} + func (o *Onchain) AreNodesInSync(opts ...retry.Option) (bool, error) { var err error var execSync *ethereum.SyncProgress @@ -2076,16 +2115,19 @@ func (o *Onchain) GetPendingConsolidations(stateID string, opts ...retry.Option) err error ) - err = retry.Do(func() error { - url := fmt.Sprintf("%s/eth/v1/beacon/states/%s/pending_consolidations", o.ConsensusClient.Address(), stateID) + endpoint, err := consensusApiUrl(o.consensusEndpoint, fmt.Sprintf("/eth/v1/beacon/states/%s/pending_consolidations", stateID)) + if err != nil { + return nil, err + } - req, reqErr := normalHttp.NewRequest(normalHttp.MethodGet, url, nil) + err = retry.Do(func() error { + req, reqErr := normalHttp.NewRequest(normalHttp.MethodGet, endpoint, nil) if reqErr != nil { return fmt.Errorf("creating request failed: %w", reqErr) } req.Header.Set("Accept", "application/json") - resp, httpErr := normalHttp.DefaultClient.Do(req) + resp, httpErr := doConsensusRequest(req) if httpErr != nil { log.Warn("Failed attempt to call pending consolidations endpoint: ", httpErr.Error(), " Retrying...") return fmt.Errorf("HTTP request failed: %w", httpErr) diff --git a/oracle/onchain_test.go b/oracle/onchain_test.go index 05aeaa0..fe313c9 100644 --- a/oracle/onchain_test.go +++ b/oracle/onchain_test.go @@ -7,11 +7,15 @@ import ( "fmt" "io/ioutil" "math/big" + normalHttp "net/http" + "net/http/httptest" "path/filepath" "testing" + "time" eth2 "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/avast/retry-go/v4" "github.com/dappnode/mev-sp-oracle/config" "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" @@ -585,3 +589,59 @@ func Test_IsNotFoundError(t *testing.T) { }) } } + +func Test_ConsensusApiUrl(t *testing.T) { + tests := []struct { + endpoint string + url string + }{ + {"http://127.0.0.1:3500", "http://127.0.0.1:3500/eth/v1/beacon/states/10/pending_consolidations"}, + {"http://127.0.0.1:3500/", "http://127.0.0.1:3500/eth/v1/beacon/states/10/pending_consolidations"}, + {"127.0.0.1:3500", "http://127.0.0.1:3500/eth/v1/beacon/states/10/pending_consolidations"}, + {"https://user:pass@node.example/beacon/?apikey=secret", + "https://user:pass@node.example/beacon/eth/v1/beacon/states/10/pending_consolidations?apikey=secret"}, + } + for _, test := range tests { + url, err := consensusApiUrl(test.endpoint, "/eth/v1/beacon/states/10/pending_consolidations") + require.NoError(t, err) + require.Equal(t, test.url, url) + } +} + +// The request goes to the configured endpoint, path and query included, not +// to the masked address go-eth2-client keeps for logging +func Test_GetPendingConsolidations_UsesConfiguredEndpoint(t *testing.T) { + server := httptest.NewServer(normalHttp.HandlerFunc(func(w normalHttp.ResponseWriter, r *normalHttp.Request) { + if r.URL.Path != "/beacon/eth/v1/beacon/states/10/pending_consolidations" || r.URL.Query().Get("apikey") != "secret" { + normalHttp.Error(w, "wrong url "+r.URL.String(), normalHttp.StatusNotFound) + return + } + _, _ = w.Write([]byte(`{"version":"electra","execution_optimistic":false,"finalized":true,"data":[]}`)) + })) + defer server.Close() + + onchain := &Onchain{consensusEndpoint: server.URL + "/beacon?apikey=secret"} + consolidations, err := onchain.GetPendingConsolidations("10", retry.Attempts(1)) + require.NoError(t, err) + require.True(t, consolidations.Finalized) +} + +// A node that stops answering fails the request instead of hanging the oracle, +// and the error does not print the endpoint's credentials +func Test_GetPendingConsolidations_TimesOut(t *testing.T) { + stall := make(chan struct{}) + server := httptest.NewServer(normalHttp.HandlerFunc(func(w normalHttp.ResponseWriter, r *normalHttp.Request) { + <-stall + })) + defer server.Close() + defer close(stall) + + previous := consensusHttpClient + consensusHttpClient = &normalHttp.Client{Timeout: 100 * time.Millisecond} + defer func() { consensusHttpClient = previous }() + + onchain := &Onchain{consensusEndpoint: server.URL + "?apikey=secret"} + _, err := onchain.GetPendingConsolidations("10", retry.Attempts(1)) + require.Error(t, err) + require.NotContains(t, err.Error(), "secret") +}