Skip to content

Commit 803bafa

Browse files
authored
Merge pull request #123 from ethpandaops/release/attnets-support
release(contributoor): attnets support
2 parents 9a1f88b + e547017 commit 803bafa

30 files changed

+3730
-203
lines changed

.github/typos.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[files]
2+
extend-exclude = ["pkg/ethereum/node_identity_test.go"]

.github/workflows/alpha-release.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@ jobs:
2323
RELEASE_SUFFIX=${GITHUB_REF#refs/heads/release/}
2424
2525
# Fetch all tags and get the latest that matches the pattern
26-
# Using the refs/tags API
27-
LATEST_VERSION=$(curl --silent "https://api.github.com/repos/$GITHUB_REPOSITORY/git/refs/tags" \
28-
| jq -r --arg suffix "$RELEASE_SUFFIX" '.[] | select(.ref | test("refs/tags/v?[0-9]+\\.[0-9]+\\.[0-9]+-" + $suffix + "$")) | .ref' \
26+
# Using the refs/tags API with authentication
27+
LATEST_VERSION=$(curl --silent -H "Authorization: token $GITHUB_TOKEN" \
28+
"https://api.github.com/repos/$GITHUB_REPOSITORY/git/refs/tags" \
29+
| jq -r --arg suffix "$RELEASE_SUFFIX" \
30+
'if type == "array" then .[] | select(.ref | test("refs/tags/v?[0-9]+\\.[0-9]+\\.[0-9]+-" + $suffix + "$")) | .ref else empty end' \
2931
| sed 's|refs/tags/||' | sort -V | tail -n 1)
32+
33+
# Alternative: Use git commands directly which is more reliable
34+
if [[ -z "$LATEST_VERSION" ]]; then
35+
echo "API call failed or returned no results, trying git command..."
36+
LATEST_VERSION=$(git tag -l "*-${RELEASE_SUFFIX}" | grep -E "^v?[0-9]+\.[0-9]+\.[0-9]+-${RELEASE_SUFFIX}$" | sort -V | tail -n 1)
37+
fi
38+
3039
echo "Found latest $RELEASE_SUFFIX version: $LATEST_VERSION"
3140
3241
# Default to 0.0.0 if no matching release was found

.github/workflows/check-typos.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ jobs:
1313
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1414

1515
- name: Check for typos
16-
uses: crate-ci/typos@392b78fe18a52790c53f42456e46124f77346842 # v1.34.0
16+
uses: crate-ci/typos@392b78fe18a52790c53f42456e46124f77346842 # v1.34.0
17+
with:
18+
config: .github/typos.toml

cmd/sentry/config.go

Lines changed: 271 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,35 @@ import (
1313

1414
// applyConfigOverridesFromFlags applies CLI flags to the config if they are set.
1515
func applyConfigOverridesFromFlags(cfg *config.Config, c *cli.Context) error {
16-
// Apply environment variables first, then override with CLI flags if set
16+
// Apply network configuration
17+
if err := applyNetworkConfig(cfg, c); err != nil {
18+
return err
19+
}
20+
21+
// Apply service addresses
22+
applyServiceAddresses(cfg, c)
23+
24+
// Apply logging configuration
25+
applyLoggingConfig(cfg, c)
26+
27+
// Apply output server configuration
28+
if err := applyOutputServerConfig(cfg, c); err != nil {
29+
return err
30+
}
31+
32+
// Apply contributoor directory
33+
applyContributoorDirectory(cfg, c)
34+
35+
// Apply attestation subnet configuration
36+
if err := applyAttestationSubnetConfig(cfg, c); err != nil {
37+
return err
38+
}
39+
40+
return nil
41+
}
42+
43+
// applyNetworkConfig applies network configuration from env and CLI.
44+
func applyNetworkConfig(cfg *config.Config, c *cli.Context) error {
1745
if network := os.Getenv("CONTRIBUTOOR_NETWORK"); network != "" {
1846
log.Infof("Setting network from env to %s", network)
1947

@@ -30,6 +58,12 @@ func applyConfigOverridesFromFlags(cfg *config.Config, c *cli.Context) error {
3058
}
3159
}
3260

61+
return nil
62+
}
63+
64+
// applyServiceAddresses applies service address configurations.
65+
func applyServiceAddresses(cfg *config.Config, c *cli.Context) {
66+
// Beacon node address
3367
if addr := os.Getenv("CONTRIBUTOOR_BEACON_NODE_ADDRESS"); addr != "" {
3468
log.Infof("Setting beacon node address from env")
3569
cfg.SetBeaconNodeAddress(addr)
@@ -40,6 +74,7 @@ func applyConfigOverridesFromFlags(cfg *config.Config, c *cli.Context) error {
4074
cfg.SetBeaconNodeAddress(c.String("beacon-node-address"))
4175
}
4276

77+
// Metrics address
4378
if addr := os.Getenv("CONTRIBUTOOR_METRICS_ADDRESS"); addr != "" {
4479
log.Infof("Setting metrics address from env to %s", addr)
4580
cfg.SetMetricsAddress(addr)
@@ -50,6 +85,7 @@ func applyConfigOverridesFromFlags(cfg *config.Config, c *cli.Context) error {
5085
cfg.SetMetricsAddress(c.String("metrics-address"))
5186
}
5287

88+
// Health check address
5389
if addr := os.Getenv("CONTRIBUTOOR_HEALTH_CHECK_ADDRESS"); addr != "" {
5490
log.Infof("Setting health check address from env to %s", addr)
5591
cfg.SetHealthCheckAddress(addr)
@@ -59,7 +95,10 @@ func applyConfigOverridesFromFlags(cfg *config.Config, c *cli.Context) error {
5995
log.Infof("Overriding health check address from CLI to %s", c.String("health-check-address"))
6096
cfg.SetHealthCheckAddress(c.String("health-check-address"))
6197
}
98+
}
6299

100+
// applyLoggingConfig applies logging configuration.
101+
func applyLoggingConfig(cfg *config.Config, c *cli.Context) {
63102
if level := os.Getenv("CONTRIBUTOOR_LOG_LEVEL"); level != "" {
64103
log.Infof("Setting log level from env to %s", level)
65104
cfg.SetLogLevel(level)
@@ -69,7 +108,11 @@ func applyConfigOverridesFromFlags(cfg *config.Config, c *cli.Context) error {
69108
log.Infof("Overriding log level from CLI to %s", c.String("log-level"))
70109
cfg.SetLogLevel(c.String("log-level"))
71110
}
111+
}
72112

113+
// applyOutputServerConfig applies output server configuration.
114+
func applyOutputServerConfig(cfg *config.Config, c *cli.Context) error {
115+
// Address
73116
if addr := os.Getenv("CONTRIBUTOOR_OUTPUT_SERVER_ADDRESS"); addr != "" {
74117
log.Infof("Setting output server address from env")
75118
cfg.SetOutputServerAddress(addr)
@@ -80,7 +123,17 @@ func applyConfigOverridesFromFlags(cfg *config.Config, c *cli.Context) error {
80123
cfg.SetOutputServerAddress(c.String("output-server-address"))
81124
}
82125

83-
// Handle credentials from env
126+
// Credentials
127+
if err := applyOutputServerCredentials(cfg, c); err != nil {
128+
return err
129+
}
130+
131+
// TLS
132+
return applyOutputServerTLS(cfg, c)
133+
}
134+
135+
// applyOutputServerCredentials applies output server credentials.
136+
func applyOutputServerCredentials(cfg *config.Config, c *cli.Context) error {
84137
var (
85138
username = os.Getenv("CONTRIBUTOOR_USERNAME")
86139
password = os.Getenv("CONTRIBUTOOR_PASSWORD")
@@ -105,6 +158,11 @@ func applyConfigOverridesFromFlags(cfg *config.Config, c *cli.Context) error {
105158
)
106159
}
107160

161+
return nil
162+
}
163+
164+
// applyOutputServerTLS applies output server TLS configuration.
165+
func applyOutputServerTLS(cfg *config.Config, c *cli.Context) error {
108166
if tls := os.Getenv("CONTRIBUTOOR_OUTPUT_SERVER_TLS"); tls != "" {
109167
log.Infof("Setting output server tls from env to %s", tls)
110168

@@ -127,17 +185,226 @@ func applyConfigOverridesFromFlags(cfg *config.Config, c *cli.Context) error {
127185
cfg.SetOutputServerTLS(tls)
128186
}
129187

130-
// Handle contributoor directory from env
188+
return nil
189+
}
190+
191+
// applyContributoorDirectory applies contributoor directory configuration.
192+
func applyContributoorDirectory(cfg *config.Config, c *cli.Context) {
131193
if dir := os.Getenv("CONTRIBUTOOR_DIRECTORY"); dir != "" {
132194
log.Infof("Setting contributoor directory from env to %s", dir)
133195
cfg.ContributoorDirectory = dir
134196
}
135197

136-
// CLI flag overrides env var
137198
if c.String("contributoor-directory") != "" {
138199
log.Infof("Overriding contributoor directory from CLI to %s", c.String("contributoor-directory"))
139200
cfg.ContributoorDirectory = c.String("contributoor-directory")
140201
}
202+
}
203+
204+
// applyAttestationSubnetConfig applies attestation subnet configuration.
205+
func applyAttestationSubnetConfig(cfg *config.Config, c *cli.Context) error {
206+
// Handle enabled flag from env
207+
if enabled := os.Getenv("CONTRIBUTOOR_ATTESTATION_SUBNET_CHECK_ENABLED"); enabled != "" {
208+
log.Infof("Setting attestation subnet check enabled from env to %s", enabled)
209+
210+
enabledBool, err := strconv.ParseBool(enabled)
211+
if err != nil {
212+
return errors.Wrap(err, "failed to parse attestation subnet check enabled env var")
213+
}
214+
215+
if cfg.AttestationSubnetCheck == nil {
216+
cfg.AttestationSubnetCheck = &config.AttestationSubnetCheck{}
217+
}
218+
219+
cfg.AttestationSubnetCheck.Enabled = enabledBool
220+
cfg.AttestationSubnetCheck.MaxSubnets = 2
221+
}
222+
223+
// Handle max subnets from env
224+
if maxSubnets := os.Getenv("CONTRIBUTOOR_ATTESTATION_SUBNET_MAX_SUBNETS"); maxSubnets != "" {
225+
log.Infof("Setting attestation subnet max subnets from env to %s", maxSubnets)
226+
227+
maxSubnetsInt, err := strconv.ParseUint(maxSubnets, 10, 32)
228+
if err != nil {
229+
return errors.Wrap(err, "failed to parse attestation subnet max subnets env var")
230+
}
231+
232+
if cfg.AttestationSubnetCheck == nil {
233+
cfg.AttestationSubnetCheck = &config.AttestationSubnetCheck{}
234+
}
235+
236+
cfg.AttestationSubnetCheck.MaxSubnets = uint32(maxSubnetsInt)
237+
}
238+
239+
// CLI flag overrides env var for enabled
240+
if c.Bool("attestation-subnet-check-enabled") {
241+
log.Infof("Setting attestation subnet check enabled from CLI to true")
242+
243+
if cfg.AttestationSubnetCheck == nil {
244+
cfg.AttestationSubnetCheck = &config.AttestationSubnetCheck{}
245+
}
246+
247+
cfg.AttestationSubnetCheck.Enabled = true
248+
}
249+
250+
// CLI flag overrides env var for max subnets
251+
if c.Int("attestation-subnet-max-subnets") >= 0 { // -1 means not set
252+
log.Infof("Setting attestation subnet max subnets from CLI to %d", c.Int("attestation-subnet-max-subnets"))
253+
254+
if cfg.AttestationSubnetCheck == nil {
255+
cfg.AttestationSubnetCheck = &config.AttestationSubnetCheck{}
256+
}
257+
258+
cfg.AttestationSubnetCheck.MaxSubnets = uint32(c.Int("attestation-subnet-max-subnets")) //nolint:gosec // conversion fine.
259+
}
260+
261+
// Handle mismatch detection window
262+
if err := applyMismatchDetectionWindow(cfg, c); err != nil {
263+
return err
264+
}
265+
266+
// Handle mismatch threshold
267+
if err := applyMismatchThreshold(cfg, c); err != nil {
268+
return err
269+
}
270+
271+
// Handle mismatch cooldown
272+
if err := applyMismatchCooldown(cfg, c); err != nil {
273+
return err
274+
}
275+
276+
// Handle subnet high water mark
277+
if err := applySubnetHighWaterMark(cfg, c); err != nil {
278+
return err
279+
}
280+
281+
return nil
282+
}
283+
284+
// applyMismatchDetectionWindow applies mismatch detection window configuration.
285+
func applyMismatchDetectionWindow(cfg *config.Config, c *cli.Context) error {
286+
// Handle env var
287+
if window := os.Getenv("CONTRIBUTOOR_ATTESTATION_SUBNET_MISMATCH_DETECTION_WINDOW"); window != "" {
288+
log.Infof("Setting attestation subnet mismatch detection window from env to %s", window)
289+
290+
windowInt, err := strconv.ParseUint(window, 10, 32)
291+
if err != nil {
292+
return errors.Wrap(err, "failed to parse attestation subnet mismatch detection window env var")
293+
}
294+
295+
if cfg.AttestationSubnetCheck == nil {
296+
cfg.AttestationSubnetCheck = &config.AttestationSubnetCheck{}
297+
}
298+
299+
cfg.AttestationSubnetCheck.MismatchDetectionWindow = uint32(windowInt)
300+
}
301+
302+
// CLI flag overrides env var
303+
if c.Int("attestation-subnet-mismatch-detection-window") >= 0 { // -1 means not set
304+
log.Infof("Setting attestation subnet mismatch detection window from CLI to %d", c.Int("attestation-subnet-mismatch-detection-window"))
305+
306+
if cfg.AttestationSubnetCheck == nil {
307+
cfg.AttestationSubnetCheck = &config.AttestationSubnetCheck{}
308+
}
309+
310+
cfg.AttestationSubnetCheck.MismatchDetectionWindow = uint32(c.Int("attestation-subnet-mismatch-detection-window")) //nolint:gosec // conversion fine.
311+
}
312+
313+
return nil
314+
}
315+
316+
// applyMismatchThreshold applies mismatch threshold configuration.
317+
func applyMismatchThreshold(cfg *config.Config, c *cli.Context) error {
318+
// Handle env var
319+
if threshold := os.Getenv("CONTRIBUTOOR_ATTESTATION_SUBNET_MISMATCH_THRESHOLD"); threshold != "" {
320+
log.Infof("Setting attestation subnet mismatch threshold from env to %s", threshold)
321+
322+
thresholdInt, err := strconv.ParseUint(threshold, 10, 32)
323+
if err != nil {
324+
return errors.Wrap(err, "failed to parse attestation subnet mismatch threshold env var")
325+
}
326+
327+
if cfg.AttestationSubnetCheck == nil {
328+
cfg.AttestationSubnetCheck = &config.AttestationSubnetCheck{}
329+
}
330+
331+
cfg.AttestationSubnetCheck.MismatchThreshold = uint32(thresholdInt)
332+
}
333+
334+
// CLI flag overrides env var
335+
if c.Int("attestation-subnet-mismatch-threshold") >= 0 { // -1 means not set
336+
log.Infof("Setting attestation subnet mismatch threshold from CLI to %d", c.Int("attestation-subnet-mismatch-threshold"))
337+
338+
if cfg.AttestationSubnetCheck == nil {
339+
cfg.AttestationSubnetCheck = &config.AttestationSubnetCheck{}
340+
}
341+
342+
cfg.AttestationSubnetCheck.MismatchThreshold = uint32(c.Int("attestation-subnet-mismatch-threshold")) //nolint:gosec // conversion fine.
343+
}
344+
345+
return nil
346+
}
347+
348+
// applyMismatchCooldown applies mismatch cooldown configuration.
349+
func applyMismatchCooldown(cfg *config.Config, c *cli.Context) error {
350+
// Handle env var
351+
if cooldown := os.Getenv("CONTRIBUTOOR_ATTESTATION_SUBNET_MISMATCH_COOLDOWN_SECONDS"); cooldown != "" {
352+
log.Infof("Setting attestation subnet mismatch cooldown from env to %s seconds", cooldown)
353+
354+
cooldownInt, err := strconv.ParseUint(cooldown, 10, 32)
355+
if err != nil {
356+
return errors.Wrap(err, "failed to parse attestation subnet mismatch cooldown env var")
357+
}
358+
359+
if cfg.AttestationSubnetCheck == nil {
360+
cfg.AttestationSubnetCheck = &config.AttestationSubnetCheck{}
361+
}
362+
363+
cfg.AttestationSubnetCheck.MismatchCooldownSeconds = uint32(cooldownInt)
364+
}
365+
366+
// CLI flag overrides env var
367+
if c.Int("attestation-subnet-mismatch-cooldown-seconds") >= 0 { // -1 means not set
368+
log.Infof("Setting attestation subnet mismatch cooldown from CLI to %d seconds", c.Int("attestation-subnet-mismatch-cooldown-seconds"))
369+
370+
if cfg.AttestationSubnetCheck == nil {
371+
cfg.AttestationSubnetCheck = &config.AttestationSubnetCheck{}
372+
}
373+
374+
cfg.AttestationSubnetCheck.MismatchCooldownSeconds = uint32(c.Int("attestation-subnet-mismatch-cooldown-seconds")) //nolint:gosec // conversion fine.
375+
}
376+
377+
return nil
378+
}
379+
380+
// applySubnetHighWaterMark applies subnet high water mark configuration.
381+
func applySubnetHighWaterMark(cfg *config.Config, c *cli.Context) error {
382+
// Handle env var
383+
if watermark := os.Getenv("CONTRIBUTOOR_ATTESTATION_SUBNET_HIGH_WATER_MARK"); watermark != "" {
384+
log.Infof("Setting attestation subnet high water mark from env to %s", watermark)
385+
386+
watermarkInt, err := strconv.ParseUint(watermark, 10, 32)
387+
if err != nil {
388+
return errors.Wrap(err, "failed to parse attestation subnet high water mark env var")
389+
}
390+
391+
if cfg.AttestationSubnetCheck == nil {
392+
cfg.AttestationSubnetCheck = &config.AttestationSubnetCheck{}
393+
}
394+
395+
cfg.AttestationSubnetCheck.SubnetHighWaterMark = uint32(watermarkInt)
396+
}
397+
398+
// CLI flag overrides env var
399+
if c.Int("attestation-subnet-high-water-mark") >= 0 { // -1 means not set
400+
log.Infof("Setting attestation subnet high water mark from CLI to %d", c.Int("attestation-subnet-high-water-mark"))
401+
402+
if cfg.AttestationSubnetCheck == nil {
403+
cfg.AttestationSubnetCheck = &config.AttestationSubnetCheck{}
404+
}
405+
406+
cfg.AttestationSubnetCheck.SubnetHighWaterMark = uint32(c.Int("attestation-subnet-high-water-mark")) //nolint:gosec // conversion fine.
407+
}
141408

142409
return nil
143410
}

0 commit comments

Comments
 (0)