Skip to content

fix(pkg/p2p): replace persistent gater with no-op gater#3273

Open
auricom wants to merge 6 commits intomainfrom
fix/p2p-no-op-gater
Open

fix(pkg/p2p): replace persistent gater with no-op gater#3273
auricom wants to merge 6 commits intomainfrom
fix/p2p-no-op-gater

Conversation

@auricom
Copy link
Copy Markdown
Contributor

@auricom auricom commented Apr 21, 2026

Summary

  • Replaces the persistent BasicConnectionGater (backed by Badger) with a no-op variant that never persists or blocks any peer
  • Removes libp2p.ConnectionGater registration from the host — no connection-level filtering at all
  • Removes setupBlockedPeers / setupAllowedPeers — nothing ever blocks
  • Keeps the gater instance solely to satisfy goheaderp2p.NewExchange's concrete type requirement

Fixes the root cause of the edennet-2 incident (#3267): stale blocklist entries in Badger were causing fullnodes to reject every binary builder peer, preventing header sync from initializing and forcing DA-only sync.

Test plan

  • go test ./pkg/p2p/... passes
  • No-op confirmed working on edennet-2

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added new p2p.disable_connection_gater configuration flag (enabled by default) to manage P2P connection filtering behavior. Users can disable it to restore peer filtering when experiencing P2P network flooding issues.
  • Bug Fixes

    • Fixed issue where stale blocklist entries from previous sessions blocked legitimate peer connections after system restart.

auricom and others added 3 commits April 20, 2026 17:02
Defines the full TTLConnectionGater feature: TTL-based peer blocklist
with config/dynamic block sources, startup reconciliation, background
sweep, and Prometheus metrics for blocklist observability.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Stale blocklist entries in the Badger datastore were causing the
edennet-2 incident (#3267): fullnodes rejected every
binary builder peer, header sync never initialized, and nodes fell back
to DA-only sync.

Replace the persistent BasicConnectionGater with a no-op variant:
- Nil datastore → purely in-memory, nothing survives restart
- Removed from libp2p host → no connection-level filtering
- Removed setupBlockedPeers / setupAllowedPeers → nothing ever blocks
- Instance kept only to satisfy go-header's Exchange API requirement

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The no-op gater implementation resolves the edennet-2 incident
(#3267) without the TTL wrapper described in the ADR.
The ADR is no longer relevant.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 21, 2026

Claude encountered an error —— View job


I'll analyze this and get back to you.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 21, 2026

📝 Walkthrough

Walkthrough

A new P2P configuration flag p2p.disable_connection_gater (default true) was added to control connection gater behavior. The implementation conditionally disables gater setup and registration based on this flag, allowing users to prevent stale blocklist entries from persisting across restarts when the feature is disabled.

Changes

Cohort / File(s) Summary
Configuration & Documentation
CHANGELOG.md, pkg/config/config.go, pkg/config/config_test.go, pkg/config/defaults.go
Added new P2P configuration flag disable_connection_gater (default true), extended P2PConfig struct with DisableConnectionGater boolean field, registered flag in CLI/viper, updated test assertions to verify flag presence and default value, and set default to true in DefaultConfig().
P2P Client Implementation
pkg/p2p/client.go
Modified NewClient to conditionally create datastore (nil when gater disabled), updated startWithHost to skip peer blocking/allowlisting setup when disabled, and changed listen to only register connection gater with libp2p host when not disabled.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Poem

🐰 A gater with memory causes such strife,
Blocklists that linger through restarts of life,
But now we can toggle—set it to true,
A fresh start awaits, with peers shiny and new! ✨
Hops forward with joy, our P2P will sing! 🎵

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: replacing a persistent connection gater with a no-op variant to fix the stale blocklist issue.
Description check ✅ Passed The description provides a comprehensive summary of changes, the rationale (edennet-2 incident fix), and test validation, though it could explicitly reference the issue number in the template format.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/p2p-no-op-gater

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 21, 2026

The latest Buf updates on your PR. Results from workflow CI / buf-check (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped✅ passed✅ passedApr 21, 2026, 4:11 PM

@auricom auricom enabled auto-merge April 21, 2026 14:27
auricom and others added 2 commits April 21, 2026 16:27
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 21, 2026

Codecov Report

❌ Patch coverage is 78.94737% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.59%. Comparing base (c1d4996) to head (1649719).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/p2p/client.go 73.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3273      +/-   ##
==========================================
- Coverage   62.60%   62.59%   -0.01%     
==========================================
  Files         122      122              
  Lines       13020    13029       +9     
==========================================
+ Hits         8151     8156       +5     
- Misses       3984     3987       +3     
- Partials      885      886       +1     
Flag Coverage Δ
combined 62.59% <78.94%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this behind a evnode.p2p flag?
Like --evnode.p2p.disable_blacklist so we can get why they get blacklisted

Adds p2p.disable_connection_gater (default: true) so operators can
re-enable peer-level connection filtering without redeploying a patched
binary. When set to false, the connection gater is registered with the
libp2p host and blocked_peers / allowed_peers config entries are
enforced — useful when experiencing P2P flooding.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/p2p/client.go`:
- Around line 169-178: If DisableConnectionGater is true but conf.BlockedPeers
or conf.AllowedPeers are non-empty, add a warning log so operators know their
settings are ignored; in the method containing the shown block (the code that
currently checks c.conf.DisableConnectionGater and calls
setupBlockedPeers/setupAllowedPeers), detect when c.conf.DisableConnectionGater
== true and (len(c.conf.BlockedPeers) > 0 || len(c.conf.AllowedPeers) > 0) and
emit a clear warning via c.logger.Warn() referencing the fields (e.g.,
"BlockedPeers configured but connection gater disabled") before
returning/continuing, rather than silently dropping the values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7dceaf50-9e0c-43bd-bff6-124290699e7b

📥 Commits

Reviewing files that changed from the base of the PR and between c1d4996 and 1649719.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • pkg/config/config.go
  • pkg/config/config_test.go
  • pkg/config/defaults.go
  • pkg/p2p/client.go

Comment thread pkg/p2p/client.go
Comment on lines +169 to 178
if !c.conf.DisableConnectionGater {
c.logger.Debug().Str("blacklist", c.conf.BlockedPeers).Msg("blocking blacklisted peers")
if err := c.setupBlockedPeers(c.parseAddrInfoList(c.conf.BlockedPeers)); err != nil {
return err
}
c.logger.Debug().Str("whitelist", c.conf.AllowedPeers).Msg("allowing whitelisted peers")
if err := c.setupAllowedPeers(c.parseAddrInfoList(c.conf.AllowedPeers)); err != nil {
return err
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Warn when BlockedPeers/AllowedPeers are configured but ignored.

When DisableConnectionGater is true (the default), any values set in conf.BlockedPeers or conf.AllowedPeers are silently dropped — the flags remain wired in AddFlags and the struct fields still exist, so operators can easily set them without realizing they have no effect. Consider emitting a warning log here (or at startup) if either list is non-empty while the gater is disabled, so misconfiguration is surfaced instead of hidden.

Proposed fix
 	if !c.conf.DisableConnectionGater {
 		c.logger.Debug().Str("blacklist", c.conf.BlockedPeers).Msg("blocking blacklisted peers")
 		if err := c.setupBlockedPeers(c.parseAddrInfoList(c.conf.BlockedPeers)); err != nil {
 			return err
 		}
 		c.logger.Debug().Str("whitelist", c.conf.AllowedPeers).Msg("allowing whitelisted peers")
 		if err := c.setupAllowedPeers(c.parseAddrInfoList(c.conf.AllowedPeers)); err != nil {
 			return err
 		}
+	} else if c.conf.BlockedPeers != "" || c.conf.AllowedPeers != "" {
+		c.logger.Warn().
+			Str("blocked_peers", c.conf.BlockedPeers).
+			Str("allowed_peers", c.conf.AllowedPeers).
+			Msg("p2p.blocked_peers / p2p.allowed_peers are set but ignored because p2p.disable_connection_gater=true")
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if !c.conf.DisableConnectionGater {
c.logger.Debug().Str("blacklist", c.conf.BlockedPeers).Msg("blocking blacklisted peers")
if err := c.setupBlockedPeers(c.parseAddrInfoList(c.conf.BlockedPeers)); err != nil {
return err
}
c.logger.Debug().Str("whitelist", c.conf.AllowedPeers).Msg("allowing whitelisted peers")
if err := c.setupAllowedPeers(c.parseAddrInfoList(c.conf.AllowedPeers)); err != nil {
return err
}
}
if !c.conf.DisableConnectionGater {
c.logger.Debug().Str("blacklist", c.conf.BlockedPeers).Msg("blocking blacklisted peers")
if err := c.setupBlockedPeers(c.parseAddrInfoList(c.conf.BlockedPeers)); err != nil {
return err
}
c.logger.Debug().Str("whitelist", c.conf.AllowedPeers).Msg("allowing whitelisted peers")
if err := c.setupAllowedPeers(c.parseAddrInfoList(c.conf.AllowedPeers)); err != nil {
return err
}
} else if c.conf.BlockedPeers != "" || c.conf.AllowedPeers != "" {
c.logger.Warn().
Str("blocked_peers", c.conf.BlockedPeers).
Str("allowed_peers", c.conf.AllowedPeers).
Msg("p2p.blocked_peers / p2p.allowed_peers are set but ignored because p2p.disable_connection_gater=true")
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/p2p/client.go` around lines 169 - 178, If DisableConnectionGater is true
but conf.BlockedPeers or conf.AllowedPeers are non-empty, add a warning log so
operators know their settings are ignored; in the method containing the shown
block (the code that currently checks c.conf.DisableConnectionGater and calls
setupBlockedPeers/setupAllowedPeers), detect when c.conf.DisableConnectionGater
== true and (len(c.conf.BlockedPeers) > 0 || len(c.conf.AllowedPeers) > 0) and
emit a clear warning via c.logger.Warn() referencing the fields (e.g.,
"BlockedPeers configured but connection gater disabled") before
returning/continuing, rather than silently dropping the values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants