diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index be3622d..f93a4db 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -18,12 +18,13 @@ jobs: - uses: 'actions/setup-go@v5' with: cache: false - go-version: '1.22' + go-version: '1.26' - uses: 'actions/checkout@v4' - name: 'golangci-lint' uses: 'golangci/golangci-lint-action@v6' with: - version: 'latest' + version: 'v1.64.8' + install-mode: 'goinstall' args: '--timeout=60m' only-new-issues: true skip-cache: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e09a13..b4c078c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/setup-go@v5 with: cache: false - go-version: '1.22' + go-version: '1.26' - uses: actions/checkout@v4 - uses: n8maninger/action-golang-test@v2 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 841f879..bdc01f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +0.11.0: + - support gloas: store execution payload bids, and execution payloads from envelopes once a child block confirms them + 0.10.2: - added `blocks.blobs.enable` configuration flag (default: true) to control whether blobs for blocks should be fetched and saved diff --git a/Dockerfile b/Dockerfile index 50e140d..c4b5159 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.22-bookworm as builder +FROM golang:1.26-bookworm as builder WORKDIR /app diff --git a/go.mod b/go.mod index 747f2d8..9fd4d89 100644 --- a/go.mod +++ b/go.mod @@ -1,25 +1,24 @@ module github.com/wealdtech/chaind -go 1.22.7 - -toolchain go1.23.2 +go 1.26.0 require ( - github.com/attestantio/go-eth2-client v0.27.1 + github.com/OffchainLabs/go-bitfield v0.0.0-20251031151322-f427d04d8506 + github.com/attestantio/go-eth2-client v0.30.2 github.com/aws/aws-sdk-go v1.55.6 + github.com/holiman/uint256 v1.3.2 github.com/jackc/pgx-shopspring-decimal v0.0.0-20220624020537-1d36b5a1853e github.com/jackc/pgx-zerolog v0.0.0-20230315001418-f978528409eb github.com/jackc/pgx/v5 v5.7.2 github.com/mitchellh/go-homedir v1.1.0 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.20.5 - github.com/prysmaticlabs/go-bitfield v0.0.0-20240618144021-706c95b2dd15 github.com/rs/zerolog v1.33.0 github.com/sasha-s/go-deadlock v0.3.5 github.com/shopspring/decimal v1.4.0 github.com/spf13/pflag v1.0.6 github.com/spf13/viper v1.19.0 - github.com/stretchr/testify v1.10.0 + github.com/stretchr/testify v1.11.1 github.com/wealdtech/go-majordomo v1.1.1 go.opentelemetry.io/otel v1.34.0 go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.34.0 @@ -27,7 +26,7 @@ require ( go.opentelemetry.io/otel/sdk v1.34.0 go.opentelemetry.io/otel/trace v1.34.0 go.uber.org/atomic v1.11.0 - golang.org/x/sync v0.11.0 + golang.org/x/sync v0.17.0 google.golang.org/grpc v1.70.0 ) @@ -41,10 +40,8 @@ require ( github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/emicklei/dot v1.6.4 // indirect github.com/fatih/color v1.18.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect - github.com/ferranbt/fastssz v0.1.4 // indirect github.com/fsnotify/fsnotify v1.8.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect @@ -56,23 +53,22 @@ require ( github.com/googleapis/gax-go/v2 v2.14.1 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/holiman/uint256 v1.3.2 // indirect github.com/huandu/go-clone v1.7.2 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/klauspost/compress v1.17.11 // indirect - github.com/klauspost/cpuid/v2 v2.2.9 // indirect + github.com/klauspost/cpuid/v2 v2.3.0 // indirect github.com/magiconair/properties v1.8.9 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/minio/sha256-simd v1.0.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect - github.com/petermattis/goid v0.0.0-20250121172306-05bcfb9a85dc // indirect - github.com/pk910/dynamic-ssz v0.0.5 // indirect + github.com/petermattis/goid v0.0.0-20260918085751-abfca077860b // 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.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.62.0 // indirect @@ -90,12 +86,12 @@ require ( go.opentelemetry.io/otel/metric v1.34.0 // indirect go.opentelemetry.io/proto/otlp v1.5.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.33.0 // indirect + golang.org/x/crypto v0.42.0 // indirect golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect - golang.org/x/net v0.34.0 // indirect + golang.org/x/net v0.43.0 // indirect golang.org/x/oauth2 v0.26.0 // indirect - golang.org/x/sys v0.30.0 // indirect - golang.org/x/text v0.22.0 // indirect + golang.org/x/sys v0.36.0 // indirect + golang.org/x/text v0.29.0 // indirect golang.org/x/time v0.10.0 // indirect golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect google.golang.org/api v0.220.0 // indirect @@ -103,9 +99,7 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20250204164813-702378808489 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250204164813-702378808489 // indirect google.golang.org/protobuf v1.36.4 // indirect - gopkg.in/Knetic/govaluate.v3 v3.0.0 // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 8336c0c..c3e7352 100644 --- a/go.sum +++ b/go.sum @@ -72,10 +72,12 @@ cloud.google.com/go/storage v1.23.0/go.mod h1:vOEEDNFnciUMhBeT6hsJIn3ieU5cFRmzeL dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +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/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -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/aws/aws-sdk-go v1.44.81/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= github.com/aws/aws-sdk-go v1.55.6 h1:cSg4pvZ3m8dgYcgqB97MrcdjUmZ1BeMYKUxMMB89IPk= github.com/aws/aws-sdk-go v1.55.6/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= @@ -107,8 +109,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/emicklei/dot v1.6.4 h1:cG9ycT67d9Yw22G+mAb4XiuUz6E6H1S0zePp/5Cwe/c= -github.com/emicklei/dot v1.6.4/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -124,8 +124,6 @@ github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/ferranbt/fastssz v0.1.4 h1:OCDB+dYDEQDvAgtAGnTSidK1Pe2tW3nFV40XyMkTeDY= -github.com/ferranbt/fastssz v0.1.4/go.mod h1:Ea3+oeoRGGLGm5shYAeDgu6PGUlcvQhE2fILyD9+tGg= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= @@ -281,8 +279,8 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= -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.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -307,8 +305,6 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 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/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= -github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= 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.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -318,10 +314,12 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= -github.com/petermattis/goid v0.0.0-20250121172306-05bcfb9a85dc h1:Xz/LkK9AJRY5QTkA1uE1faB8yeqRFjeKgwDtI13ogcY= -github.com/petermattis/goid v0.0.0-20250121172306-05bcfb9a85dc/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= -github.com/pk910/dynamic-ssz v0.0.5 h1:VP9heGYUwzlpyhk28P2nCAzhvGsePJOOOO5vQMDh2qQ= -github.com/pk910/dynamic-ssz v0.0.5/go.mod h1:b6CrLaB2X7pYA+OSEEbkgXDEcRnjLOZIxZTsMuO/Y9c= +github.com/petermattis/goid v0.0.0-20260918085751-abfca077860b h1:OzNsuVdSWGwXvWKTtChx9ve89k4cFJ6NxYM4Aw4/f+E= +github.com/petermattis/goid v0.0.0-20260918085751-abfca077860b/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= +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/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -336,10 +334,6 @@ github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -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= github.com/r3labs/sse/v2 v2.10.0/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= @@ -379,8 +373,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -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/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/wealdtech/go-majordomo v1.1.1 h1:o+vS/akiT7zuufU7H+A6Cp52qbkjzaaMZlgwm/rciDk= @@ -433,8 +427,8 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= -golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= +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-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -516,8 +510,8 @@ golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220617184016-355a448f1bc9/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= -golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= +golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= +golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -553,8 +547,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -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/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= +golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -621,8 +615,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220818161305-2296e01440c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.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/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= @@ -634,8 +628,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 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.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -892,8 +886,6 @@ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM= google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= -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/main.go b/main.go index c2e4856..99716ec 100644 --- a/main.go +++ b/main.go @@ -64,7 +64,7 @@ import ( ) // ReleaseVersion is the release version for the code. -var ReleaseVersion = "0.10.2" +var ReleaseVersion = "0.11.0" func main() { os.Exit(main2()) diff --git a/services/blocks/standard/handler.go b/services/blocks/standard/handler.go index 7434c44..c2eaaa3 100644 --- a/services/blocks/standard/handler.go +++ b/services/blocks/standard/handler.go @@ -20,6 +20,7 @@ import ( "math/big" "net/http" + "github.com/OffchainLabs/go-bitfield" eth2client "github.com/attestantio/go-eth2-client" "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/spec" @@ -28,9 +29,10 @@ import ( "github.com/attestantio/go-eth2-client/spec/capella" "github.com/attestantio/go-eth2-client/spec/deneb" "github.com/attestantio/go-eth2-client/spec/electra" + "github.com/attestantio/go-eth2-client/spec/gloas" "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/jackc/pgx/v5" "github.com/pkg/errors" - "github.com/prysmaticlabs/go-bitfield" "github.com/wealdtech/chaind/services/chaindb" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" @@ -195,6 +197,8 @@ func (s *Service) OnBlock(ctx context.Context, signedBlock *spec.VersionedSigned return s.onBlockElectra(ctx, signedBlock.Electra, dbBlock) case spec.DataVersionFulu: return s.onBlockElectra(ctx, signedBlock.Fulu, dbBlock) + case spec.DataVersionGloas: + return s.onBlockGloas(ctx, signedBlock.Gloas, dbBlock) case spec.DataVersionUnknown: return errors.New("unknown block version") default: @@ -475,6 +479,132 @@ func (s *Service) onBlockElectra(ctx context.Context, signedBlock *electra.Signe return nil } +// onBlockGloas handles a Gloas block. +// Gloas attestations and attester slashings have the same fields as their Electra +// equivalents, so are converted and handled as such. +func (s *Service) onBlockGloas(ctx context.Context, signedBlock *gloas.SignedBeaconBlock, dbBlock *chaindb.Block) error { + ctx, span := otel.Tracer("wealdtech.chaind.services.blocks.standard").Start(ctx, "OnBlockGloas") + defer span.End() + + attestations := make([]*electra.Attestation, len(signedBlock.Message.Body.Attestations)) + for i, attestation := range signedBlock.Message.Body.Attestations { + electraAttestation := electra.Attestation(*attestation) + attestations[i] = &electraAttestation + } + if err := s.updateElectraAttestationsForBlock(ctx, + signedBlock.Message.Slot, + dbBlock.Root, + attestations); err != nil { + return errors.Wrap(err, "failed to update attestations") + } + if err := s.updateProposerSlashingsForBlock(ctx, + signedBlock.Message.Slot, + dbBlock.Root, + signedBlock.Message.Body.ProposerSlashings); err != nil { + return errors.Wrap(err, "failed to update proposer slashings") + } + attesterSlashings := make([]*electra.AttesterSlashing, len(signedBlock.Message.Body.AttesterSlashings)) + for i, attesterSlashing := range signedBlock.Message.Body.AttesterSlashings { + attestation1 := electra.IndexedAttestation(*attesterSlashing.Attestation1) + attestation2 := electra.IndexedAttestation(*attesterSlashing.Attestation2) + attesterSlashings[i] = &electra.AttesterSlashing{ + Attestation1: &attestation1, + Attestation2: &attestation2, + } + } + if err := s.updateElectraAttesterSlashingsForBlock(ctx, + signedBlock.Message.Slot, + dbBlock.Root, + attesterSlashings); err != nil { + return errors.Wrap(err, "failed to update attester slashings") + } + if err := s.updateDepositsForBlock(ctx, + signedBlock.Message.Slot, + dbBlock.Root, + signedBlock.Message.Body.Deposits); err != nil { + return errors.Wrap(err, "failed to update deposits") + } + if err := s.updateVoluntaryExitsForBlock(ctx, + signedBlock.Message.Slot, + dbBlock.Root, + signedBlock.Message.Body.VoluntaryExits); err != nil { + return errors.Wrap(err, "failed to update voluntary exits") + } + if err := s.updateSyncAggregateForBlock(ctx, + signedBlock.Message.Slot, + dbBlock.Root, + signedBlock.Message.Body.SyncAggregate); err != nil { + return errors.Wrap(err, "failed to update sync aggregate") + } + + if err := s.updateDepositRequestsForBlock(ctx, dbBlock.DepositRequests); err != nil { + return errors.Wrap(err, "failed to update deposit requests") + } + if err := s.updateWithdrawalRequestsForBlock(ctx, dbBlock.WithdrawalRequests); err != nil { + return errors.Wrap(err, "failed to update withdrawal requests") + } + if err := s.updateConsolidationRequestsForBlock(ctx, dbBlock.ConsolidationRequests); err != nil { + return errors.Wrap(err, "failed to update consolidation requests") + } + + if err := s.updateParentExecutionPayload(ctx, dbBlock); err != nil { + return errors.Wrap(err, "failed to update parent execution payload") + } + + return nil +} + +// parentPayloadIsFull returns true if the child's bid builds on the parent's payload. +func parentPayloadIsFull(parent *chaindb.Block, child *chaindb.Block) bool { + if parent.ExecutionPayloadBid == nil || child.ExecutionPayloadBid == nil { + return false + } + + return child.ExecutionPayloadBid.ParentBlockHash == parent.ExecutionPayloadBid.BlockHash +} + +// updateParentExecutionPayload stores the execution payload and blob sidecars of the block's parent. +// The payload and blobs for a Gloas block arrive in a separate envelope after the block, and +// may never arrive; the child's bid states if the parent payload is canonical, so +// they are stored when the child is processed. +func (s *Service) updateParentExecutionPayload(ctx context.Context, block *chaindb.Block) error { + parent, err := s.chainDB.(chaindb.BlocksProvider).BlockByRoot(ctx, block.ParentRoot) + if err != nil { + if errors.Is(err, pgx.ErrNoRows) { + log.Debug().Uint64("slot", uint64(block.Slot)).Msg("Parent block not in database; cannot update its execution payload") + return nil + } + return errors.Wrap(err, "failed to obtain parent block") + } + if parent.ExecutionPayload != nil || !parentPayloadIsFull(parent, block) { + // Already stored, pre-Gloas, or empty. + return nil + } + + response, err := s.eth2Client.(eth2client.ExecutionPayloadProvider).SignedExecutionPayloadEnvelope(ctx, &api.SignedExecutionPayloadEnvelopeOpts{ + Block: parent.Root.String(), + }) + if err != nil { + return errors.Wrap(err, "failed to obtain parent execution payload envelope") + } + if response.Data == nil || response.Data.Gloas == nil || response.Data.Gloas.Message == nil || response.Data.Gloas.Message.Payload == nil { + return errors.New("parent execution payload envelope missing payload") + } + + parent.ExecutionPayload = dbExecutionPayloadGloas(parent.Root, parent.Slot, response.Data.Gloas.Message.Payload) + if err := s.blocksSetter.SetBlock(ctx, parent); err != nil { + return errors.Wrap(err, "failed to set parent block") + } + + if len(parent.BlobKZGCommitments) > 0 { + if err := s.updateBlobSidecarsForBlock(ctx, parent.Root); err != nil { + return errors.Wrap(err, "failed to update parent blob sidecars") + } + } + + return nil +} + func (s *Service) updateDepositRequestsForBlock(ctx context.Context, requests []*chaindb.DepositRequest, ) error { @@ -764,6 +894,8 @@ func (s *Service) dbBlock( return s.dbBlockElectra(ctx, block.Electra.Message) case spec.DataVersionFulu: return s.dbBlockElectra(ctx, block.Fulu.Message) + case spec.DataVersionGloas: + return s.dbBlockGloas(ctx, block.Gloas.Message) case spec.DataVersionUnknown: return nil, errors.New("unknown block version") default: @@ -1212,6 +1344,168 @@ func (*Service) dbBlockElectra( return dbBlock, nil } +// dbBlockGloas converts a Gloas block to its database equivalent. +// Gloas blocks carry only a bid for the execution payload; the payload itself arrives +// in a separate envelope, so the block is stored without an execution payload. +func (*Service) dbBlockGloas( + _ context.Context, + block *gloas.BeaconBlock, +) (*chaindb.Block, error) { + bodyRoot, err := block.Body.HashTreeRoot() + if err != nil { + return nil, errors.Wrap(err, "failed to calculate body root") + } + + header := &phase0.BeaconBlockHeader{ + Slot: block.Slot, + ProposerIndex: block.ProposerIndex, + ParentRoot: block.ParentRoot, + StateRoot: block.StateRoot, + BodyRoot: bodyRoot, + } + root, err := header.HashTreeRoot() + if err != nil { + return nil, errors.Wrap(err, "failed to calculate block root") + } + + blsToExecutionChanges := make([]*chaindb.BLSToExecutionChange, len(block.Body.BLSToExecutionChanges)) + for i := range block.Body.BLSToExecutionChanges { + blsToExecutionChanges[i] = &chaindb.BLSToExecutionChange{ + InclusionBlockRoot: root, + InclusionSlot: block.Slot, + InclusionIndex: uint(i), + ValidatorIndex: block.Body.BLSToExecutionChanges[i].Message.ValidatorIndex, + } + copy(blsToExecutionChanges[i].FromBLSPubKey[:], block.Body.BLSToExecutionChanges[i].Message.FromBLSPubkey[:]) + copy(blsToExecutionChanges[i].ToExecutionAddress[:], block.Body.BLSToExecutionChanges[i].Message.ToExecutionAddress[:]) + } + + // Gloas blocks contain the execution requests of their parent's payload. + depositRequests := make([]*chaindb.DepositRequest, 0) + if block.Body.ParentExecutionRequests != nil { + for i, request := range block.Body.ParentExecutionRequests.Deposits { + depositRequest := &chaindb.DepositRequest{ + InclusionBlockRoot: root, + InclusionSlot: block.Slot, + InclusionIndex: uint(i), + Pubkey: request.Pubkey, + WithdrawalCredentials: [32]byte(request.WithdrawalCredentials), + Amount: request.Amount, + Signature: request.Signature, + Index: request.Index, + } + depositRequests = append(depositRequests, depositRequest) + } + } + + withdrawalRequests := make([]*chaindb.WithdrawalRequest, 0) + if block.Body.ParentExecutionRequests != nil { + for i, request := range block.Body.ParentExecutionRequests.Withdrawals { + withdrawalRequest := &chaindb.WithdrawalRequest{ + InclusionBlockRoot: root, + InclusionSlot: block.Slot, + InclusionIndex: uint(i), + SourceAddress: request.SourceAddress, + ValidatorPubkey: request.ValidatorPubkey, + Amount: request.Amount, + } + withdrawalRequests = append(withdrawalRequests, withdrawalRequest) + } + } + + consolidationRequests := make([]*chaindb.ConsolidationRequest, 0) + if block.Body.ParentExecutionRequests != nil { + for i, request := range block.Body.ParentExecutionRequests.Consolidations { + consolidationRequest := &chaindb.ConsolidationRequest{ + InclusionBlockRoot: root, + InclusionSlot: block.Slot, + InclusionIndex: uint(i), + SourceAddress: request.SourceAddress, + SourcePubkey: request.SourcePubkey, + TargetPubkey: request.TargetPubkey, + } + consolidationRequests = append(consolidationRequests, consolidationRequest) + } + } + + var blobKZGCommitments []deneb.KZGCommitment + var executionPayloadBid *chaindb.ExecutionPayloadBid + if block.Body.SignedExecutionPayloadBid != nil && block.Body.SignedExecutionPayloadBid.Message != nil { + bid := block.Body.SignedExecutionPayloadBid.Message + blobKZGCommitments = bid.BlobKZGCommitments + executionPayloadBid = &chaindb.ExecutionPayloadBid{ + ParentBlockHash: bid.ParentBlockHash, + BlockHash: bid.BlockHash, + FeeRecipient: bid.FeeRecipient, + GasLimit: bid.GasLimit, + BuilderIndex: uint64(bid.BuilderIndex), + Value: bid.Value, + ExecutionPayment: bid.ExecutionPayment, + } + } + + dbBlock := &chaindb.Block{ + Slot: block.Slot, + ProposerIndex: block.ProposerIndex, + Root: root, + Graffiti: block.Body.Graffiti[:], + RANDAOReveal: block.Body.RANDAOReveal, + BodyRoot: bodyRoot, + ParentRoot: block.ParentRoot, + StateRoot: block.StateRoot, + ETH1BlockHash: block.Body.ETH1Data.BlockHash, + ETH1DepositCount: block.Body.ETH1Data.DepositCount, + ETH1DepositRoot: block.Body.ETH1Data.DepositRoot, + BLSToExecutionChanges: blsToExecutionChanges, + BlobKZGCommitments: blobKZGCommitments, + DepositRequests: depositRequests, + WithdrawalRequests: withdrawalRequests, + ConsolidationRequests: consolidationRequests, + ExecutionPayloadBid: executionPayloadBid, + } + + return dbBlock, nil +} + +// dbExecutionPayloadGloas converts a Gloas execution payload, delivered in an envelope +// for the block with the given root and slot, to its database equivalent. +func dbExecutionPayloadGloas(root phase0.Root, + slot phase0.Slot, + payload *gloas.ExecutionPayload, +) *chaindb.ExecutionPayload { + withdrawals := make([]*chaindb.Withdrawal, len(payload.Withdrawals)) + for i := range payload.Withdrawals { + withdrawals[i] = &chaindb.Withdrawal{ + InclusionBlockRoot: root, + InclusionSlot: slot, + InclusionIndex: uint(i), + Index: payload.Withdrawals[i].Index, + ValidatorIndex: payload.Withdrawals[i].ValidatorIndex, + Amount: payload.Withdrawals[i].Amount, + } + copy(withdrawals[i].Address[:], payload.Withdrawals[i].Address[:]) + } + + return &chaindb.ExecutionPayload{ + ParentHash: payload.ParentHash, + FeeRecipient: payload.FeeRecipient, + StateRoot: payload.StateRoot, + ReceiptsRoot: payload.ReceiptsRoot, + LogsBloom: payload.LogsBloom, + PrevRandao: payload.PrevRandao, + BlockNumber: payload.BlockNumber, + GasLimit: payload.GasLimit, + GasUsed: payload.GasUsed, + Timestamp: payload.Timestamp, + ExtraData: payload.ExtraData, + BaseFeePerGas: payload.BaseFeePerGas.ToBig(), + BlockHash: payload.BlockHash, + Withdrawals: withdrawals, + BlobGasUsed: payload.BlobGasUsed, + ExcessBlobGas: payload.ExcessBlobGas, + } +} + func (s *Service) dbAttestation( ctx context.Context, inclusionSlot phase0.Slot, diff --git a/services/blocks/standard/handler_test.go b/services/blocks/standard/handler_test.go new file mode 100644 index 0000000..2da06bf --- /dev/null +++ b/services/blocks/standard/handler_test.go @@ -0,0 +1,137 @@ +// Copyright © 2026 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 standard + +import ( + "context" + "testing" + + "github.com/OffchainLabs/go-bitfield" + "github.com/attestantio/go-eth2-client/spec/altair" + "github.com/attestantio/go-eth2-client/spec/capella" + "github.com/attestantio/go-eth2-client/spec/deneb" + "github.com/attestantio/go-eth2-client/spec/electra" + "github.com/attestantio/go-eth2-client/spec/gloas" + "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/holiman/uint256" + "github.com/stretchr/testify/require" + "github.com/wealdtech/chaind/services/chaindb" +) + +func TestDBBlockGloas(t *testing.T) { + block := &gloas.BeaconBlock{ + Slot: 100, + Body: &gloas.BeaconBlockBody{ + ETH1Data: &phase0.ETH1Data{BlockHash: make([]byte, 32)}, + SyncAggregate: &altair.SyncAggregate{ + SyncCommitteeBits: bitfield.NewBitvector512(), + }, + SignedExecutionPayloadBid: &gloas.SignedExecutionPayloadBid{ + Message: &gloas.ExecutionPayloadBid{ + BlockHash: phase0.Hash32{0x02}, + FeeRecipient: [20]byte{0x03}, + BuilderIndex: 4, + Value: 5, + ExecutionPayment: 6, + BlobKZGCommitments: []deneb.KZGCommitment{{0x01}}, + }, + }, + ParentExecutionRequests: &gloas.ExecutionRequests{ + Deposits: []*electra.DepositRequest{{WithdrawalCredentials: make([]byte, 32), Index: 7}}, + Withdrawals: []*electra.WithdrawalRequest{{Amount: 5}}, + Consolidations: []*electra.ConsolidationRequest{{}}, + }, + }, + } + + dbBlock, err := (&Service{}).dbBlockGloas(context.Background(), block) + require.NoError(t, err) + require.Nil(t, dbBlock.ExecutionPayload) + require.Equal(t, phase0.Slot(100), dbBlock.Slot) + require.Len(t, dbBlock.BlobKZGCommitments, 1) + require.Len(t, dbBlock.DepositRequests, 1) + require.Equal(t, uint64(7), dbBlock.DepositRequests[0].Index) + require.Equal(t, dbBlock.Root, dbBlock.DepositRequests[0].InclusionBlockRoot) + require.Len(t, dbBlock.WithdrawalRequests, 1) + require.Len(t, dbBlock.ConsolidationRequests, 1) + require.Equal(t, &chaindb.ExecutionPayloadBid{ + BlockHash: [32]byte{0x02}, + FeeRecipient: [20]byte{0x03}, + BuilderIndex: 4, + Value: 5, + ExecutionPayment: 6, + }, dbBlock.ExecutionPayloadBid) +} + +func TestDBExecutionPayloadGloas(t *testing.T) { + root := phase0.Root{0x01} + payload := &gloas.ExecutionPayload{ + FeeRecipient: [20]byte{0x02}, + BlockNumber: 123, + BaseFeePerGas: uint256.NewInt(7), + Withdrawals: []*capella.Withdrawal{ + {Index: 1, ValidatorIndex: 10, Address: [20]byte{0x03}, Amount: 32}, + // Builder payment. + {Index: 2, ValidatorIndex: phase0.ValidatorIndex(4 | 1<<40), Address: [20]byte{0x02}, Amount: 5}, + }, + } + + res := dbExecutionPayloadGloas(root, 100, payload) + require.Equal(t, uint64(123), res.BlockNumber) + require.Equal(t, [20]byte{0x02}, res.FeeRecipient) + require.Equal(t, int64(7), res.BaseFeePerGas.Int64()) + require.Len(t, res.Withdrawals, 2) + require.Equal(t, &chaindb.Withdrawal{ + InclusionBlockRoot: root, + InclusionSlot: 100, + InclusionIndex: 1, + Index: 2, + ValidatorIndex: phase0.ValidatorIndex(4 | 1<<40), + Address: [20]byte{0x02}, + Amount: 5, + }, res.Withdrawals[1]) +} + +func TestParentPayloadIsFull(t *testing.T) { + parent := &chaindb.Block{ExecutionPayloadBid: &chaindb.ExecutionPayloadBid{BlockHash: [32]byte{0x01}}} + tests := []struct { + name string + parent *chaindb.Block + child *chaindb.Block + full bool + }{ + { + name: "PreGloasParent", + parent: &chaindb.Block{}, + child: &chaindb.Block{ExecutionPayloadBid: &chaindb.ExecutionPayloadBid{ParentBlockHash: [32]byte{0x01}}}, + }, + { + name: "Full", + parent: parent, + child: &chaindb.Block{ExecutionPayloadBid: &chaindb.ExecutionPayloadBid{ParentBlockHash: [32]byte{0x01}}}, + full: true, + }, + { + name: "Empty", + parent: parent, + child: &chaindb.Block{ExecutionPayloadBid: &chaindb.ExecutionPayloadBid{ParentBlockHash: [32]byte{0x09}}}, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + require.Equal(t, test.full, parentPayloadIsFull(test.parent, test.child)) + }) + } +} diff --git a/services/chaindb/postgresql/attestations.go b/services/chaindb/postgresql/attestations.go index eb5e222..e7b26a2 100644 --- a/services/chaindb/postgresql/attestations.go +++ b/services/chaindb/postgresql/attestations.go @@ -81,9 +81,9 @@ func (s *Service) SetAttestation(ctx context.Context, attestation *chaindb.Attes ,f_source_root = excluded.f_source_root ,f_target_epoch = excluded.f_target_epoch ,f_target_root = excluded.f_target_root - ,f_canonical = excluded.f_canonical - ,f_target_correct = excluded.f_target_correct - ,f_head_correct = excluded.f_head_correct + ,f_canonical = COALESCE(excluded.f_canonical, t_attestations.f_canonical) + ,f_target_correct = COALESCE(excluded.f_target_correct, t_attestations.f_target_correct) + ,f_head_correct = COALESCE(excluded.f_head_correct, t_attestations.f_head_correct) `, attestation.InclusionSlot, attestation.InclusionBlockRoot[:], @@ -115,7 +115,13 @@ func (s *Service) SetAttestations(ctx context.Context, attestations []*chaindb.A return ErrNoTransaction } - _, err := tx.CopyFrom(ctx, + // Create a savepoint in case the copy fails, so that the caller can fall back to setting individually. + nestedTx, err := tx.Begin(ctx) + if err != nil { + return errors.Wrap(err, "failed to create nested transaction") + } + + _, err = nestedTx.CopyFrom(ctx, pgx.Identifier{"t_attestations"}, []string{ "f_inclusion_slot", @@ -168,7 +174,15 @@ func (s *Service) SetAttestations(ctx context.Context, attestations []*chaindb.A headCorrect, }, nil })) - return err + if err != nil { + if rollbackErr := nestedTx.Rollback(ctx); rollbackErr != nil { + return errors.Wrapf(err, "failed to copy attestations, and failed to roll back nested transaction: %v", rollbackErr) + } + + return err + } + + return nestedTx.Commit(ctx) } // AttestationsForBlock fetches all attestations made for the given block. diff --git a/services/chaindb/postgresql/blocks.go b/services/chaindb/postgresql/blocks.go index 3927b95..de840d8 100644 --- a/services/chaindb/postgresql/blocks.go +++ b/services/chaindb/postgresql/blocks.go @@ -76,7 +76,7 @@ func (s *Service) SetBlock(ctx context.Context, block *chaindb.Block) error { ,f_body_root = excluded.f_body_root ,f_parent_root = excluded.f_parent_root ,f_state_root = excluded.f_state_root - ,f_canonical = excluded.f_canonical + ,f_canonical = COALESCE(excluded.f_canonical, t_blocks.f_canonical) ,f_eth1_block_hash = excluded.f_eth1_block_hash ,f_eth1_deposit_count = excluded.f_eth1_deposit_count ,f_eth1_deposit_root = excluded.f_eth1_deposit_root @@ -104,6 +104,11 @@ func (s *Service) SetBlock(ctx context.Context, block *chaindb.Block) error { return errors.Wrap(err, "failed to set execution payload") } + // Set execution payload bid (will return without error if bid is not present). + if err := s.setExecutionPayloadBid(ctx, block); err != nil { + return errors.Wrap(err, "failed to set execution payload bid") + } + // Set BLS to execution changes (will return without error if changes are not present). if err := s.setBLSToExecutionChanges(ctx, block); err != nil { return errors.Wrap(err, "failed to set BLS to execution changes") @@ -264,6 +269,9 @@ LIMIT $%d`, len(queryVals))) block.ExecutionPayload = payload } } + if err := s.addExecutionPayloadBids(ctx, tx, blocks); err != nil { + return nil, err + } // Always return order of slot then root. sort.Slice(blocks, func(i int, j int) bool { @@ -372,6 +380,9 @@ func (s *Service) BlocksBySlot(ctx context.Context, slot phase0.Slot) ([]*chaind return nil, err } } + if err := s.addExecutionPayloadBids(ctx, tx, blocks); err != nil { + return nil, err + } return blocks, nil } @@ -476,6 +487,9 @@ func (s *Service) BlocksForSlotRange(ctx context.Context, startSlot phase0.Slot, return nil, err } } + if err := s.addExecutionPayloadBids(ctx, tx, blocks); err != nil { + return nil, err + } return blocks, nil } @@ -564,6 +578,10 @@ func (s *Service) BlockByRoot(ctx context.Context, root phase0.Root) (*chaindb.B if err != nil { return nil, err } + block.ExecutionPayloadBid, err = s.executionPayloadBid(ctx, tx, block.Root) + if err != nil { + return nil, err + } return block, nil } @@ -713,6 +731,9 @@ func (s *Service) BlocksByParentRoot(ctx context.Context, parentRoot phase0.Root return nil, err } } + if err := s.addExecutionPayloadBids(ctx, tx, blocks); err != nil { + return nil, err + } return blocks, nil } @@ -905,6 +926,9 @@ func (s *Service) LatestBlocks(ctx context.Context) ([]*chaindb.Block, error) { return nil, err } } + if err := s.addExecutionPayloadBids(ctx, tx, blocks); err != nil { + return nil, err + } return blocks, nil } diff --git a/services/chaindb/postgresql/executionpayloadbid.go b/services/chaindb/postgresql/executionpayloadbid.go new file mode 100644 index 0000000..021e5f1 --- /dev/null +++ b/services/chaindb/postgresql/executionpayloadbid.go @@ -0,0 +1,189 @@ +// Copyright © 2026 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 postgresql + +import ( + "context" + "math/big" + + "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/jackc/pgx/v5" + "github.com/pkg/errors" + "github.com/shopspring/decimal" + "github.com/wealdtech/chaind/services/chaindb" + "go.opentelemetry.io/otel" +) + +// setExecutionPayloadBid sets the execution payload bid of a block. +func (s *Service) setExecutionPayloadBid(ctx context.Context, block *chaindb.Block) error { + ctx, span := otel.Tracer("wealdtech.chaind.services.chaindb.postgresql").Start(ctx, "setExecutionPayloadBid") + defer span.End() + + tx := s.tx(ctx) + if tx == nil { + return ErrNoTransaction + } + + if block == nil { + return errors.New("block missing") + } + if block.ExecutionPayloadBid == nil { + // Do not treat this as an error, as pre-Gloas blocks will not have a bid. + return nil + } + + bid := block.ExecutionPayloadBid + _, err := tx.Exec(ctx, ` +INSERT INTO t_block_execution_payload_bids(f_block_root + ,f_parent_block_hash + ,f_block_hash + ,f_fee_recipient + ,f_gas_limit + ,f_builder_index + ,f_value + ,f_execution_payment + ) +VALUES($1,$2,$3,$4,$5,$6,$7,$8) +ON CONFLICT (f_block_root) DO +UPDATE +SET f_parent_block_hash = excluded.f_parent_block_hash + ,f_block_hash = excluded.f_block_hash + ,f_fee_recipient = excluded.f_fee_recipient + ,f_gas_limit = excluded.f_gas_limit + ,f_builder_index = excluded.f_builder_index + ,f_value = excluded.f_value + ,f_execution_payment = excluded.f_execution_payment +`, + block.Root[:], + bid.ParentBlockHash[:], + bid.BlockHash[:], + bid.FeeRecipient[:], + bid.GasLimit, + decimal.NewFromBigInt(new(big.Int).SetUint64(bid.BuilderIndex), 0), + bid.Value, + bid.ExecutionPayment, + ) + + return err +} + +// executionPayloadBid fetches the execution payload bid of a block. +func (s *Service) executionPayloadBid(ctx context.Context, + tx pgx.Tx, + root phase0.Root, +) ( + *chaindb.ExecutionPayloadBid, + error, +) { + bids, err := s.executionPayloadBids(ctx, tx, []phase0.Root{root}) + if err != nil { + return nil, err + } + + return bids[root], nil +} + +// executionPayloadBids fetches the execution payload bids of multiple blocks. +func (s *Service) executionPayloadBids(ctx context.Context, + tx pgx.Tx, + roots []phase0.Root, +) ( + map[phase0.Root]*chaindb.ExecutionPayloadBid, + error, +) { + ctx, span := otel.Tracer("wealdtech.chaind.services.chaindb.postgresql").Start(ctx, "executionPayloadBids") + defer span.End() + + broots := make([][]byte, len(roots)) + for i := range roots { + broots[i] = roots[i][:] + } + + rows, err := tx.Query(ctx, ` +SELECT f_block_root + ,f_parent_block_hash + ,f_block_hash + ,f_fee_recipient + ,f_gas_limit + ,f_builder_index + ,f_value + ,f_execution_payment +FROM t_block_execution_payload_bids +WHERE f_block_root = ANY($1)`, + broots, + ) + if err != nil { + return nil, err + } + defer rows.Close() + + res := make(map[phase0.Root]*chaindb.ExecutionPayloadBid) + for rows.Next() { + bid := &chaindb.ExecutionPayloadBid{} + var blockRoot []byte + var parentBlockHash []byte + var blockHash []byte + var feeRecipient []byte + var builderIndex decimal.Decimal + err := rows.Scan(&blockRoot, + &parentBlockHash, + &blockHash, + &feeRecipient, + &bid.GasLimit, + &builderIndex, + &bid.Value, + &bid.ExecutionPayment, + ) + if err != nil { + return nil, errors.Wrap(err, "failed to scan row") + } + copy(bid.ParentBlockHash[:], parentBlockHash) + copy(bid.BlockHash[:], blockHash) + copy(bid.FeeRecipient[:], feeRecipient) + bid.BuilderIndex = builderIndex.BigInt().Uint64() + + var key phase0.Root + copy(key[:], blockRoot) + res[key] = bid + } + if err := rows.Err(); err != nil { + return nil, errors.Wrap(err, "failed to read rows") + } + + return res, nil +} + +// addExecutionPayloadBids adds execution payload bids to the given blocks. +func (s *Service) addExecutionPayloadBids(ctx context.Context, + tx pgx.Tx, + blocks []*chaindb.Block, +) error { + if len(blocks) == 0 { + return nil + } + + roots := make([]phase0.Root, len(blocks)) + for i := range blocks { + roots[i] = blocks[i].Root + } + bids, err := s.executionPayloadBids(ctx, tx, roots) + if err != nil { + return err + } + for _, block := range blocks { + block.ExecutionPayloadBid = bids[block.Root] + } + + return nil +} diff --git a/services/chaindb/postgresql/executionpayloadbid_test.go b/services/chaindb/postgresql/executionpayloadbid_test.go new file mode 100644 index 0000000..62fe1ac --- /dev/null +++ b/services/chaindb/postgresql/executionpayloadbid_test.go @@ -0,0 +1,83 @@ +// Copyright © 2026 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 postgresql_test + +import ( + "context" + "math" + "os" + "testing" + + "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/rs/zerolog" + "github.com/stretchr/testify/require" + "github.com/wealdtech/chaind/services/chaindb" + "github.com/wealdtech/chaind/services/chaindb/postgresql" +) + +func TestExecutionPayloadBid(t *testing.T) { + ctx := context.Background() + s, err := postgresql.New(ctx, + postgresql.WithLogLevel(zerolog.Disabled), + postgresql.WithConnectionURL(os.Getenv("CHAINDB_URL")), + ) + require.NoError(t, err) + + bid := &chaindb.ExecutionPayloadBid{ + ParentBlockHash: [32]byte{0x01}, + BlockHash: [32]byte{0x02}, + FeeRecipient: [20]byte{0x03}, + GasLimit: 60000000, + BuilderIndex: math.MaxUint64, // Self-build. + Value: 5, + ExecutionPayment: 6, + } + block := &chaindb.Block{ + Slot: 1, + Root: phase0.Root{0xb1, 0xd0}, + Graffiti: make([]byte, 32), + ETH1BlockHash: make([]byte, 32), + ExecutionPayloadBid: bid, + } + + ctx, cancel, err := s.BeginTx(ctx) + require.NoError(t, err) + defer cancel() + + require.NoError(t, s.SetBlock(ctx, block)) + + res, err := s.BlockByRoot(ctx, block.Root) + require.NoError(t, err) + require.Equal(t, bid, res.ExecutionPayloadBid) + + blocks, err := s.Blocks(ctx, &chaindb.BlockFilter{From: &block.Slot, To: &block.Slot}) + require.NoError(t, err) + require.Len(t, blocks, 1) + require.Equal(t, bid, blocks[0].ExecutionPayloadBid) + + blocks, err = s.BlocksBySlot(ctx, block.Slot) + require.NoError(t, err) + require.Len(t, blocks, 1) + require.Equal(t, bid, blocks[0].ExecutionPayloadBid) + + blocks, err = s.BlocksForSlotRange(ctx, block.Slot, block.Slot+1) + require.NoError(t, err) + require.Len(t, blocks, 1) + require.Equal(t, bid, blocks[0].ExecutionPayloadBid) + + blocks, err = s.BlocksByParentRoot(ctx, block.ParentRoot) + require.NoError(t, err) + require.Len(t, blocks, 1) + require.Equal(t, bid, blocks[0].ExecutionPayloadBid) +} diff --git a/services/chaindb/postgresql/refetch_test.go b/services/chaindb/postgresql/refetch_test.go new file mode 100644 index 0000000..c66711a --- /dev/null +++ b/services/chaindb/postgresql/refetch_test.go @@ -0,0 +1,92 @@ +// Copyright © 2026 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 postgresql_test + +import ( + "context" + "os" + "testing" + + "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/rs/zerolog" + "github.com/stretchr/testify/require" + "github.com/wealdtech/chaind/services/chaindb" + "github.com/wealdtech/chaind/services/chaindb/postgresql" +) + +// TestRefetchKeepsCanonical ensures that re-setting blocks and attestations without +// canonical information, as a refetch does, keeps the existing canonical information. +func TestRefetchKeepsCanonical(t *testing.T) { + ctx := context.Background() + s, err := postgresql.New(ctx, + postgresql.WithLogLevel(zerolog.Disabled), + postgresql.WithConnectionURL(os.Getenv("CHAINDB_URL")), + ) + require.NoError(t, err) + + ctx, cancel, err := s.BeginTx(ctx) + require.NoError(t, err) + defer cancel() + + trueVal := true + falseVal := false + newBlock := func(canonical *bool) *chaindb.Block { + return &chaindb.Block{ + Slot: 9999999, + Root: phase0.Root{0xfe, 0x01}, + Graffiti: make([]byte, 32), + ETH1BlockHash: make([]byte, 32), + Canonical: canonical, + } + } + + require.NoError(t, s.SetBlock(ctx, newBlock(&trueVal))) + require.NoError(t, s.SetBlock(ctx, newBlock(nil))) + block, err := s.BlockByRoot(ctx, phase0.Root{0xfe, 0x01}) + require.NoError(t, err) + require.NotNil(t, block.Canonical) + require.True(t, *block.Canonical) + + // An explicit status, as set by the finalizer, still applies. + require.NoError(t, s.SetBlock(ctx, newBlock(&falseVal))) + block, err = s.BlockByRoot(ctx, phase0.Root{0xfe, 0x01}) + require.NoError(t, err) + require.False(t, *block.Canonical) + + newAttestation := func(canonical *bool) *chaindb.Attestation { + return &chaindb.Attestation{ + InclusionSlot: 9999999, + InclusionBlockRoot: phase0.Root{0xfe, 0x01}, + Slot: 9999998, + CommitteeIndices: []phase0.CommitteeIndex{0}, + AggregationBits: []byte{0x01}, + AggregationIndices: []phase0.ValidatorIndex{1}, + BeaconBlockRoot: phase0.Root{0xfe, 0x02}, + Canonical: canonical, + TargetCorrect: canonical, + HeadCorrect: canonical, + } + } + + require.NoError(t, s.SetAttestations(ctx, []*chaindb.Attestation{newAttestation(&trueVal)})) + // The bulk set fails for existing attestations, but must leave the transaction usable for the fallback. + require.Error(t, s.SetAttestations(ctx, []*chaindb.Attestation{newAttestation(nil)})) + require.NoError(t, s.SetAttestation(ctx, newAttestation(nil))) + attestations, err := s.AttestationsForBlock(ctx, phase0.Root{0xfe, 0x02}) + require.NoError(t, err) + require.Len(t, attestations, 1) + require.True(t, *attestations[0].Canonical) + require.True(t, *attestations[0].TargetCorrect) + require.True(t, *attestations[0].HeadCorrect) +} diff --git a/services/chaindb/postgresql/upgrader.go b/services/chaindb/postgresql/upgrader.go index 17f6600..2542b8e 100644 --- a/services/chaindb/postgresql/upgrader.go +++ b/services/chaindb/postgresql/upgrader.go @@ -27,7 +27,7 @@ type schemaMetadata struct { Version uint64 `json:"version"` } -var currentVersion = uint64(16) +var currentVersion = uint64(17) type upgrade struct { requiresRefetch bool @@ -140,6 +140,11 @@ var upgrades = map[uint64]*upgrade{ addBlockConsolidationRequests, }, }, + 17: { + funcs: []func(context.Context, *Service) error{ + addBlockExecutionPayloadBids, + }, + }, } // Upgrade upgrades the database. @@ -1256,6 +1261,19 @@ CREATE INDEX i_block_consolidation_requests_2 ON t_block_consolidation_requests( CREATE INDEX i_block_consolidation_requests_3 ON t_block_consolidation_requests(f_source_address); CREATE INDEX i_block_consolidation_requests_4 ON t_block_consolidation_requests(f_source_pubkey); CREATE INDEX i_block_consolidation_requests_5 ON t_block_consolidation_requests(f_target_pubkey); + +CREATE TABLE t_block_execution_payload_bids( + f_block_root BYTEA NOT NULL PRIMARY KEY REFERENCES t_blocks(f_root) ON DELETE CASCADE + ,f_parent_block_hash BYTEA NOT NULL + ,f_block_hash BYTEA NOT NULL + ,f_fee_recipient BYTEA NOT NULL + ,f_gas_limit BIGINT NOT NULL + ,f_builder_index NUMERIC NOT NULL + ,f_value BIGINT NOT NULL + ,f_execution_payment BIGINT NOT NULL +); +CREATE INDEX i_block_execution_payload_bids_1 ON t_block_execution_payload_bids(f_fee_recipient); +CREATE INDEX i_block_execution_payload_bids_2 ON t_block_execution_payload_bids(f_builder_index); `); err != nil { cancel() return errors.Wrap(err, "failed to create initial tables") @@ -2102,3 +2120,38 @@ CREATE INDEX i_block_consolidation_requests_5 ON t_block_consolidation_requests( return nil } + +// addBlockExecutionPayloadBids adds the execution payload bids table. +func addBlockExecutionPayloadBids(ctx context.Context, s *Service) error { + tx := s.tx(ctx) + if tx == nil { + return ErrNoTransaction + } + + tableExists, err := s.tableExists(ctx, "t_block_execution_payload_bids") + if err != nil { + return errors.Wrap(err, "failed to check presence of t_block_execution_payload_bids") + } + if tableExists { + return nil + } + + if _, err := tx.Exec(ctx, ` +CREATE TABLE t_block_execution_payload_bids( + f_block_root BYTEA NOT NULL PRIMARY KEY REFERENCES t_blocks(f_root) ON DELETE CASCADE + ,f_parent_block_hash BYTEA NOT NULL + ,f_block_hash BYTEA NOT NULL + ,f_fee_recipient BYTEA NOT NULL + ,f_gas_limit BIGINT NOT NULL + ,f_builder_index NUMERIC NOT NULL + ,f_value BIGINT NOT NULL + ,f_execution_payment BIGINT NOT NULL +); +CREATE INDEX i_block_execution_payload_bids_1 ON t_block_execution_payload_bids(f_fee_recipient); +CREATE INDEX i_block_execution_payload_bids_2 ON t_block_execution_payload_bids(f_builder_index); +`); err != nil { + return errors.Wrap(err, "failed to create t_block_execution_payload_bids") + } + + return nil +} diff --git a/services/chaindb/types.go b/services/chaindb/types.go index 2c5efc4..2137831 100644 --- a/services/chaindb/types.go +++ b/services/chaindb/types.go @@ -47,6 +47,8 @@ type Block struct { DepositRequests []*DepositRequest WithdrawalRequests []*WithdrawalRequest ConsolidationRequests []*ConsolidationRequest + // Information only available from Gloas onwards. + ExecutionPayloadBid *ExecutionPayloadBid } // Validator holds information about a validator. @@ -309,6 +311,17 @@ type ExecutionPayload struct { ExcessBlobGas uint64 } +// ExecutionPayloadBid holds information about a block's execution payload bid. +type ExecutionPayloadBid struct { + ParentBlockHash [32]byte + BlockHash [32]byte + FeeRecipient [20]byte + GasLimit uint64 + BuilderIndex uint64 + Value phase0.Gwei + ExecutionPayment phase0.Gwei +} + // BLSToExecutionChange holds information about credentials change operations. type BLSToExecutionChange struct { InclusionBlockRoot phase0.Root diff --git a/services/summarizer/standard/block.go b/services/summarizer/standard/block.go index 51dd18e..5a5ad5c 100644 --- a/services/summarizer/standard/block.go +++ b/services/summarizer/standard/block.go @@ -17,10 +17,10 @@ import ( "context" "fmt" + "github.com/OffchainLabs/go-bitfield" "github.com/attestantio/go-eth2-client/spec/electra" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/pkg/errors" - "github.com/prysmaticlabs/go-bitfield" "github.com/wealdtech/chaind/services/chaindb" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" diff --git a/services/summarizer/standard/epoch.go b/services/summarizer/standard/epoch.go index 48f15f4..5d03a1b 100644 --- a/services/summarizer/standard/epoch.go +++ b/services/summarizer/standard/epoch.go @@ -19,10 +19,10 @@ import ( "sort" "time" + "github.com/OffchainLabs/go-bitfield" "github.com/attestantio/go-eth2-client/spec/electra" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/pkg/errors" - "github.com/prysmaticlabs/go-bitfield" "github.com/wealdtech/chaind/services/chaindb" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" @@ -243,12 +243,19 @@ func (s *Service) withdrawalStatsForEpoch(ctx context.Context, } for _, withdrawal := range withdrawals { + if withdrawal.ValidatorIndex&builderIndexFlag != 0 { + // Builder payment to a proposer from Gloas onwards, not a validator withdrawal. + continue + } summary.Withdrawals += withdrawal.Amount } return nil } +// builderIndexFlag is set on the validator index of withdrawals made by builders. +const builderIndexFlag = phase0.ValidatorIndex(1 << 40) + func (s *Service) attestationStatsForEpoch(ctx context.Context, epoch phase0.Epoch, balances []*chaindb.ValidatorBalance, diff --git a/services/summarizer/standard/validatorday.go b/services/summarizer/standard/validatorday.go index 4e792be..fe53983 100644 --- a/services/summarizer/standard/validatorday.go +++ b/services/summarizer/standard/validatorday.go @@ -17,9 +17,9 @@ import ( "context" "time" + "github.com/OffchainLabs/go-bitfield" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/pkg/errors" - "github.com/prysmaticlabs/go-bitfield" "github.com/wealdtech/chaind/services/chaindb" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute"