Skip to content

Commit 42bd2a1

Browse files
authored
Merge pull request #25 from base-org/version-api
Add version handler for api
2 parents ccdfbf9 + 1ddba73 commit 42bd2a1

File tree

8 files changed

+119
-72
lines changed

8 files changed

+119
-72
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM golang:1.21.6-alpine3.19 as builder
22

3-
RUN apk add --no-cache make gcc musl-dev linux-headers jq bash
3+
RUN apk add --no-cache make gcc musl-dev linux-headers jq bash git
44

55
WORKDIR /app
66

api/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
GITCOMMIT ?= $(shell git rev-parse HEAD)
2+
LDFLAGS := -ldflags "-X github.com/base-org/blob-archiver/api/version.GitCommit=$(GITCOMMIT)"
3+
14
blob-api:
25
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/blob-api ./cmd/main.go
36

api/service/api.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/attestantio/go-eth2-client/api"
1616
"github.com/attestantio/go-eth2-client/spec/deneb"
1717
m "github.com/base-org/blob-archiver/api/metrics"
18+
"github.com/base-org/blob-archiver/api/version"
1819
"github.com/base-org/blob-archiver/common/storage"
1920
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
2021
"github.com/ethereum/go-ethereum/common"
@@ -106,6 +107,7 @@ func NewAPI(dataStoreClient storage.DataStoreReader, beaconClient client.BeaconB
106107
})
107108

108109
r.Get("/eth/v1/beacon/blob_sidecars/{id}", result.blobSidecarHandler)
110+
r.Get("/eth/v1/node/version", result.versionHandler)
109111

110112
return result
111113
}
@@ -128,6 +130,17 @@ func isKnownIdentifier(id string) bool {
128130
return slices.Contains([]string{"genesis", "finalized", "head"}, id)
129131
}
130132

133+
// versionHandler implements the /eth/v1/node/version endpoint.
134+
func (a *API) versionHandler(w http.ResponseWriter, _ *http.Request) {
135+
w.Header().Set("Content-Type", jsonAcceptType)
136+
w.WriteHeader(http.StatusOK)
137+
err := json.NewEncoder(w).Encode(version.APIVersion)
138+
if err != nil {
139+
a.logger.Error("unable to encode version to JSON", "err", err)
140+
errServerError.write(w)
141+
}
142+
}
143+
131144
// toBeaconBlockHash converts a string that can be a slot, hash or identifier to a beacon block hash.
132145
func (a *API) toBeaconBlockHash(id string) (common.Hash, *httpError) {
133146
if isHash(id) {

api/service/api_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/base-org/blob-archiver/common/beacon/beacontest"
1919
"github.com/base-org/blob-archiver/common/blobtest"
2020
"github.com/base-org/blob-archiver/common/storage"
21+
"github.com/ethereum-optimism/optimism/op-service/eth"
2122
"github.com/ethereum-optimism/optimism/op-service/testlog"
2223
"github.com/ethereum/go-ethereum/common"
2324
"github.com/ethereum/go-ethereum/log"
@@ -303,6 +304,23 @@ func TestAPIService(t *testing.T) {
303304
}
304305
}
305306

307+
func TestVersionHandler(t *testing.T) {
308+
a, _, _, cleanup := setup(t)
309+
defer cleanup()
310+
311+
request := httptest.NewRequest("GET", "/eth/v1/node/version", nil)
312+
response := httptest.NewRecorder()
313+
314+
a.router.ServeHTTP(response, request)
315+
316+
require.Equal(t, 200, response.Code)
317+
require.Equal(t, "application/json", response.Header().Get("Content-Type"))
318+
var v eth.APIVersionResponse
319+
err := json.Unmarshal(response.Body.Bytes(), &v)
320+
require.NoError(t, err)
321+
require.Equal(t, "Blob Archiver API/unknown", v.Data.Version)
322+
}
323+
306324
func TestHealthHandler(t *testing.T) {
307325
a, _, _, cleanup := setup(t)
308326
defer cleanup()

api/version/version.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package version
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/ethereum-optimism/optimism/op-service/eth"
7+
)
8+
9+
var (
10+
GitCommit = ""
11+
APIVersion eth.APIVersionResponse
12+
)
13+
14+
func init() {
15+
commit := GitCommit
16+
if commit == "" {
17+
commit = "unknown"
18+
}
19+
20+
APIVersion = eth.APIVersionResponse{
21+
Data: eth.VersionInformation{
22+
Version: fmt.Sprintf("Blob Archiver API/%s", commit),
23+
},
24+
}
25+
}

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ services:
77
dockerfile: Dockerfile
88
env_file:
99
- .env
10+
ports:
11+
- "8000:8000"
1012
command:
1113
- "blob-api"
1214
depends_on:

go.mod

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ go 1.21.6
44

55
require (
66
github.com/attestantio/go-eth2-client v0.21.1
7-
github.com/ethereum-optimism/optimism v1.7.2
8-
github.com/ethereum/go-ethereum v1.13.8
7+
github.com/ethereum-optimism/optimism v1.7.6
8+
github.com/ethereum/go-ethereum v1.101315.1
99
github.com/go-chi/chi/v5 v5.0.12
10-
github.com/minio/minio-go/v7 v7.0.66
10+
github.com/minio/minio-go/v7 v7.0.70
1111
github.com/prometheus/client_golang v1.19.0
1212
github.com/rs/zerolog v1.32.0
1313
github.com/stretchr/testify v1.9.0
@@ -17,7 +17,6 @@ require (
1717
require (
1818
github.com/DataDog/zstd v1.5.2 // indirect
1919
github.com/Microsoft/go-winio v0.6.1 // indirect
20-
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
2120
github.com/beorn7/perks v1.0.1 // indirect
2221
github.com/bits-and-blooms/bitset v1.10.0 // indirect
2322
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
@@ -34,9 +33,9 @@ require (
3433
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
3534
github.com/davecgh/go-spew v1.1.1 // indirect
3635
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
37-
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
36+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
3837
github.com/dustin/go-humanize v1.0.1 // indirect
39-
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240318114348-52d3dbd1605d // indirect
38+
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240522134500-19555bdbdc95 // indirect
4039
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
4140
github.com/fatih/color v1.16.0 // indirect
4241
github.com/ferranbt/fastssz v0.1.3 // indirect
@@ -45,16 +44,16 @@ require (
4544
github.com/go-logr/logr v1.2.4 // indirect
4645
github.com/go-logr/stdr v1.2.2 // indirect
4746
github.com/go-ole/go-ole v1.3.0 // indirect
47+
github.com/goccy/go-json v0.10.2 // indirect
4848
github.com/goccy/go-yaml v1.9.2 // indirect
4949
github.com/gofrs/flock v0.8.1 // indirect
5050
github.com/gogo/protobuf v1.3.2 // indirect
5151
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
5252
github.com/google/uuid v1.6.0 // indirect
53-
github.com/gorilla/websocket v1.5.0 // indirect
53+
github.com/gorilla/websocket v1.5.1 // indirect
5454
github.com/holiman/uint256 v1.2.4 // indirect
5555
github.com/huandu/go-clone v1.6.0 // indirect
56-
github.com/json-iterator/go v1.1.12 // indirect
57-
github.com/klauspost/compress v1.17.4 // indirect
56+
github.com/klauspost/compress v1.17.6 // indirect
5857
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
5958
github.com/kr/pretty v0.3.1 // indirect
6059
github.com/kr/text v0.2.0 // indirect
@@ -65,8 +64,6 @@ require (
6564
github.com/minio/sha256-simd v1.0.1 // indirect
6665
github.com/mitchellh/mapstructure v1.5.0 // indirect
6766
github.com/mmcloughlin/addchain v0.4.0 // indirect
68-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
69-
github.com/modern-go/reflect2 v1.0.2 // indirect
7067
github.com/olekukonko/tablewriter v0.0.5 // indirect
7168
github.com/pkg/errors v0.9.1 // indirect
7269
github.com/pmezard/go-difflib v1.0.0 // indirect
@@ -80,25 +77,24 @@ require (
8077
github.com/rs/xid v1.5.0 // indirect
8178
github.com/russross/blackfriday/v2 v2.1.0 // indirect
8279
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
83-
github.com/sirupsen/logrus v1.9.3 // indirect
8480
github.com/supranational/blst v0.3.11 // indirect
8581
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
8682
github.com/tklauser/go-sysconf v0.3.12 // indirect
8783
github.com/tklauser/numcpus v0.6.1 // indirect
8884
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
89-
github.com/yusufpapurcu/wmi v1.2.2 // indirect
85+
github.com/yusufpapurcu/wmi v1.2.3 // indirect
9086
go.opentelemetry.io/otel v1.16.0 // indirect
9187
go.opentelemetry.io/otel/metric v1.16.0 // indirect
9288
go.opentelemetry.io/otel/trace v1.16.0 // indirect
93-
golang.org/x/crypto v0.21.0 // indirect
94-
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
89+
golang.org/x/crypto v0.23.0 // indirect
90+
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
9591
golang.org/x/mod v0.14.0 // indirect
96-
golang.org/x/net v0.21.0 // indirect
92+
golang.org/x/net v0.23.0 // indirect
9793
golang.org/x/sync v0.6.0 // indirect
98-
golang.org/x/sys v0.18.0 // indirect
99-
golang.org/x/term v0.18.0 // indirect
100-
golang.org/x/text v0.14.0 // indirect
101-
golang.org/x/tools v0.16.1 // indirect
94+
golang.org/x/sys v0.20.0 // indirect
95+
golang.org/x/term v0.20.0 // indirect
96+
golang.org/x/text v0.15.0 // indirect
97+
golang.org/x/tools v0.17.0 // indirect
10298
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
10399
google.golang.org/protobuf v1.32.0 // indirect
104100
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
@@ -108,4 +104,4 @@ require (
108104
rsc.io/tmplfunc v0.0.3 // indirect
109105
)
110106

111-
replace github.com/ethereum/go-ethereum v1.13.8 => github.com/ethereum-optimism/op-geth v1.101308.3-rc.1
107+
replace github.com/ethereum/go-ethereum v1.101315.1 => github.com/ethereum-optimism/op-geth v1.101315.1

0 commit comments

Comments
 (0)