Skip to content

Commit 9bad342

Browse files
auricomclaude
andauthored
P1: verifier scalability, DA cache, client reuse, log format, security bumps (#58)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent eeb8416 commit 9bad342

17 files changed

Lines changed: 1255 additions & 240 deletions

File tree

‎Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# build stage
2-
FROM golang:1.25-alpine AS builder
2+
FROM golang:1.26-alpine AS builder
33

44
WORKDIR /build
55

‎README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Metrics will be available at `http://localhost:2112/metrics`
7777
- `--balance.scrape-interval`: Balance check scrape interval in seconds (default: 30)
7878
- `--verifier.workers`: Number of concurrent workers for block verification (default: 50)
7979
- `--verbose`: Enable verbose (debug level) logging (default: false)
80+
- `--log-format`: Log output format, `console` (human-readable) or `json` (one JSON object per line, for Loki/ELK ingestion) (default: `console`)
8081

8182
### Example with Custom Endpoints
8283

@@ -119,6 +120,8 @@ Monitor native token balances for one or more Celestia addresses:
119120

120121
This will query account balances every 30 seconds with automatic failover between RPC endpoints.
121122

123+
`https://` consensus endpoints are dialed over TLS (port 443 if none is given); `http://` and bare `host:port` endpoints use plaintext gRPC.
124+
122125
## Prometheus Metrics
123126

124127
The following metrics are exposed:
@@ -276,7 +279,7 @@ When `--balance.addresses` and `--balance.consensus-rpc-urls` are provided:
276279

277280
There are two independent debug logging mechanisms:
278281

279-
- `--verbose` flag: sets the application log level to debug.
282+
- `--verbose` flag: sets the application log level to debug. Per-block and per-poll success messages (block verification, drift polls, balance checks, JSON-RPC health checks) are logged at debug level, so use `--verbose` to see them. Warnings and errors are always logged.
280283
- `EVMETRICS_DEBUG=true` environment variable: logs DA submission details from the metrics package.
281284

282285
**Use cases**: Troubleshoot submission failures, verify submission flow.

‎cmd/monitor.go‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"io"
78
"os"
89
"os/signal"
910
"strings"
@@ -33,6 +34,7 @@ const (
3334
flagDataNS = "data-namespace"
3435
flagDuration = "duration"
3536
flagVerbose = "verbose"
37+
flagLogFormat = "log-format"
3638
flagPort = "port"
3739
flagChain = "chain-id"
3840
flagReferenceNode = "reference-node"
@@ -59,6 +61,7 @@ type flagValues struct {
5961
dataNS string
6062
duration int
6163
verbose bool
64+
logFormat string
6265
port int
6366
chainID string
6467
referenceNode string
@@ -92,6 +95,7 @@ func NewMonitorCmd() *cobra.Command {
9295
cmd.Flags().StringVar(&flags.dataNS, flagDataNS, "", "Data namespace (my_app_data_namespace)")
9396
cmd.Flags().IntVar(&flags.duration, flagDuration, 0, "Duration in seconds to stream (0 = infinite)")
9497
cmd.Flags().BoolVar(&flags.verbose, flagVerbose, false, "Enable verbose logging")
98+
cmd.Flags().StringVar(&flags.logFormat, flagLogFormat, "console", "Log output format: console or json")
9599
cmd.Flags().IntVar(&flags.port, flagPort, 2112, "HTTP server port for metrics")
96100
cmd.Flags().StringVar(&flags.chainID, flagChain, "testnet", "chainID identifier for metrics labels")
97101
cmd.Flags().StringVar(&flags.referenceNode, flagReferenceNode, "", "Reference node RPC endpoint URL (sequencer) for drift monitoring")
@@ -159,17 +163,27 @@ func newClients(ctx context.Context, flags flagValues, logger zerolog.Logger) (*
159163
return evnodeClient, evmClient, celestiaClient, nil
160164
}
161165

162-
func monitorAndExportMetrics(_ *cobra.Command, _ []string) error {
163-
// Setup logger
166+
func newLogger(format string, verbose bool, w io.Writer) (zerolog.Logger, error) {
167+
switch format {
168+
case "console":
169+
w = zerolog.ConsoleWriter{Out: w, TimeFormat: time.RFC3339}
170+
case "json":
171+
default:
172+
return zerolog.Logger{}, fmt.Errorf("invalid --%s %q: must be console or json", flagLogFormat, format)
173+
}
174+
164175
logLevel := zerolog.InfoLevel
165-
if flags.verbose {
176+
if verbose {
166177
logLevel = zerolog.DebugLevel
167178
}
168-
logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}).
169-
Level(logLevel).
170-
With().
171-
Timestamp().
172-
Logger()
179+
return zerolog.New(w).Level(logLevel).With().Timestamp().Logger(), nil
180+
}
181+
182+
func monitorAndExportMetrics(_ *cobra.Command, _ []string) error {
183+
logger, err := newLogger(flags.logFormat, flags.verbose, os.Stdout)
184+
if err != nil {
185+
return err
186+
}
173187

174188
// setup context with signal handling for graceful shutdown
175189
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)

‎cmd/monitor_test.go‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package cmd
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestNewLogger(t *testing.T) {
12+
t.Run("json", func(t *testing.T) {
13+
var buf bytes.Buffer
14+
logger, err := newLogger("json", false, &buf)
15+
require.NoError(t, err)
16+
17+
logger.Info().Msg("hello")
18+
19+
var entry map[string]any
20+
require.NoError(t, json.Unmarshal(buf.Bytes(), &entry))
21+
require.Equal(t, "info", entry["level"])
22+
require.Equal(t, "hello", entry["message"])
23+
require.Contains(t, entry, "time")
24+
})
25+
26+
t.Run("console", func(t *testing.T) {
27+
var buf bytes.Buffer
28+
logger, err := newLogger("console", false, &buf)
29+
require.NoError(t, err)
30+
31+
logger.Info().Msg("hello")
32+
33+
require.Contains(t, buf.String(), "hello")
34+
require.False(t, json.Valid(buf.Bytes()))
35+
})
36+
37+
t.Run("invalid format", func(t *testing.T) {
38+
_, err := newLogger("xml", false, &bytes.Buffer{})
39+
require.Error(t, err)
40+
})
41+
42+
t.Run("verbose enables debug", func(t *testing.T) {
43+
var buf bytes.Buffer
44+
logger, err := newLogger("json", false, &buf)
45+
require.NoError(t, err)
46+
logger.Debug().Msg("hidden")
47+
require.Empty(t, buf.String())
48+
49+
logger, err = newLogger("json", true, &buf)
50+
require.NoError(t, err)
51+
logger.Debug().Msg("shown")
52+
require.Contains(t, buf.String(), `"message":"shown"`)
53+
})
54+
}

‎go.mod‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
module github.com/evstack/ev-metrics
22

3-
go 1.25.6
3+
go 1.26.0
44

55
require (
66
connectrpc.com/connect v1.19.1
77
github.com/celestiaorg/go-square/v3 v3.0.2
88
github.com/cosmos/cosmos-sdk v0.50.14
9-
github.com/ethereum/go-ethereum v1.16.5
9+
github.com/ethereum/go-ethereum v1.17.0
1010
github.com/evstack/ev-node v1.0.0
1111
github.com/prometheus/client_golang v1.23.2
1212
github.com/rs/zerolog v1.34.0
1313
github.com/spf13/cobra v1.10.2
1414
github.com/stretchr/testify v1.11.1
15-
golang.org/x/sync v0.20.0
16-
google.golang.org/grpc v1.79.2
15+
golang.org/x/sync v0.23.0
16+
google.golang.org/grpc v1.83.1
1717
google.golang.org/protobuf v1.36.11
1818
)
1919

@@ -33,6 +33,7 @@ require (
3333
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
3434
github.com/DataDog/zstd v1.5.5 // indirect
3535
github.com/Microsoft/go-winio v0.6.2 // indirect
36+
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251001021608-1fe7b43fc4d6 // indirect
3637
github.com/StackExchange/wmi v1.2.1 // indirect
3738
github.com/beorn7/perks v1.0.1 // indirect
3839
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
@@ -47,7 +48,7 @@ require (
4748
github.com/cockroachdb/pebble v1.1.5 // indirect
4849
github.com/cockroachdb/redact v1.1.5 // indirect
4950
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
50-
github.com/cometbft/cometbft v0.38.19 // indirect
51+
github.com/cometbft/cometbft v0.38.21 // indirect
5152
github.com/cometbft/cometbft-db v0.14.1 // indirect
5253
github.com/consensys/gnark-crypto v0.18.1 // indirect
5354
github.com/cosmos/btcutil v1.0.5 // indirect
@@ -60,7 +61,6 @@ require (
6061
github.com/cosmos/ics23/go v0.11.0 // indirect
6162
github.com/cosmos/ledger-cosmos-go v0.15.0 // indirect
6263
github.com/crate-crypto/go-eth-kzg v1.4.0 // indirect
63-
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
6464
github.com/danieljoos/wincred v1.1.2 // indirect
6565
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
6666
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
@@ -71,8 +71,7 @@ require (
7171
github.com/dustin/go-humanize v1.0.1 // indirect
7272
github.com/dvsekhvalnov/jose2go v1.7.0 // indirect
7373
github.com/emicklei/dot v1.6.2 // indirect
74-
github.com/ethereum/c-kzg-4844/v2 v2.1.3 // indirect
75-
github.com/ethereum/go-verkle v0.2.2 // indirect
74+
github.com/ethereum/c-kzg-4844/v2 v2.1.5 // indirect
7675
github.com/fatih/color v1.18.0 // indirect
7776
github.com/felixge/httpsnoop v1.0.4 // indirect
7877
github.com/filecoin-project/go-jsonrpc v0.10.1 // indirect
@@ -81,6 +80,8 @@ require (
8180
github.com/go-kit/kit v0.13.0 // indirect
8281
github.com/go-kit/log v0.2.1 // indirect
8382
github.com/go-logfmt/logfmt v0.6.0 // indirect
83+
github.com/go-logr/logr v1.4.3 // indirect
84+
github.com/go-logr/stdr v1.2.2 // indirect
8485
github.com/go-ole/go-ole v1.3.0 // indirect
8586
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
8687
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
@@ -153,20 +154,24 @@ require (
153154
github.com/zondax/ledger-go v1.0.0 // indirect
154155
go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect
155156
go.opencensus.io v0.24.0 // indirect
157+
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
158+
go.opentelemetry.io/otel v1.44.0 // indirect
159+
go.opentelemetry.io/otel/metric v1.44.0 // indirect
160+
go.opentelemetry.io/otel/trace v1.44.0 // indirect
156161
go.uber.org/multierr v1.11.0 // indirect
157162
go.uber.org/zap v1.27.1 // indirect
158163
go.yaml.in/yaml/v2 v2.4.3 // indirect
159164
go.yaml.in/yaml/v3 v3.0.4 // indirect
160-
golang.org/x/crypto v0.48.0 // indirect
165+
golang.org/x/crypto v0.57.0 // indirect
161166
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect
162-
golang.org/x/net v0.51.0 // indirect
163-
golang.org/x/sys v0.41.0 // indirect
164-
golang.org/x/term v0.40.0 // indirect
165-
golang.org/x/text v0.34.0 // indirect
167+
golang.org/x/net v0.60.0 // indirect
168+
golang.org/x/sys v0.48.0 // indirect
169+
golang.org/x/term v0.46.0 // indirect
170+
golang.org/x/text v0.42.0 // indirect
166171
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
167172
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
168-
google.golang.org/genproto/googleapis/api v0.0.0-20260209200024-4cfbd4190f57 // indirect
169-
google.golang.org/genproto/googleapis/rpc v0.0.0-20260209200024-4cfbd4190f57 // indirect
173+
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect
174+
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
170175
gopkg.in/yaml.v3 v3.0.1 // indirect
171176
gotest.tools/v3 v3.5.2 // indirect
172177
nhooyr.io/websocket v1.8.6 // indirect

0 commit comments

Comments
 (0)