Skip to content

Add block relaying functionality to improve node reputation and peer connectivity#1

Merged
TLGINO merged 4 commits into
masterfrom
copilot/view-codebase-contents
Dec 14, 2025
Merged

Add block relaying functionality to improve node reputation and peer connectivity#1
TLGINO merged 4 commits into
masterfrom
copilot/view-codebase-contents

Conversation

Copilot AI commented Dec 14, 2025

Copy link
Copy Markdown
Contributor

Implements block relaying functionality to make the ETH_Discover node a better network citizen, addressing connectivity and transaction data reception issues.

Problem Addressed

The node was experiencing poor peer connectivity and limited transaction data reception because it was not relaying blocks to other peers, making it appear as a non-cooperative network participant.

Changes Made

Block Relaying Implementation

  • Enhanced Block Listener (global/global.go):

    • Fetches full block data from Alchemy via RPC (not just headers)
    • Implements callback system for block notifications
    • Added panic recovery and nil checks for robustness
  • Block Relay Method (node/transport/transport.go):

    • New RelayBlockToPeers() method broadcasts blocks to all bonded peers
    • Logs relay activity for monitoring
  • NewBlock Message Creation (rlpx/messages.go):

    • Added CreateNewBlock() function to create properly formatted NewBlock messages
  • Peer Relay Logic (node/transport/callbacks.go):

    • Blocks received from peers are automatically relayed to other connections
  • Alchemy Integration (main.go):

    • Registered callback to relay blocks from Alchemy to peers
    • Uses block's actual difficulty or minimal value for post-merge blocks

Original Repository Analysis

  • Repository Analysis: Mapped project structure, identifying core components (discv4, rlpx, node, session, stats)
  • Technology Stack: Documented Go 1.23.1 implementation with go-ethereum library, SQLite persistence, and Python analytics
  • Build System: Identified Makefile-based build process with golangci-lint integration

Repository Structure

ETH_Discover/
├── main.go              # Node orchestration with discovery, handshakes, pings, block relaying
├── discv4/              # Ethereum discovery v4 protocol
├── rlpx/                # RLPx handshake and frame exchange
├── node/                # Core node logic (discovery + transport)
├── session/             # Peer session management
├── stats/               # Python analytics and visualizations
├── global/              # Global state including block listener and callbacks
└── conf/                # Configuration management

Testing

  • ✅ Code compiles successfully
  • ✅ go vet passes on all modified packages
  • ✅ CodeQL security scan: 0 alerts
  • ✅ All code review feedback addressed
  • ✅ Ready for production testing

Expected Impact

The node will now be seen as a cooperative network participant, significantly improving its reputation and increasing the likelihood of other nodes sharing transaction data, thereby improving mempool coverage.

Original prompt

hi there, can you see my codebase?

Created from VS Code via the GitHub Pull Request extension.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Request to view codebase structure and details Initial codebase exploration and documentation Dec 14, 2025
Copilot AI requested a review from TLGINO December 14, 2025 21:36
@TLGINO

TLGINO commented Dec 14, 2025

Copy link
Copy Markdown
Owner

@copilot yes
i am having some issues with making this node desirable to other nodes
very few nodes are willing to connect to me
and very few are willing to actually send me transaction / mempool data
why could this be

Copilot AI commented Dec 14, 2025

Copy link
Copy Markdown
Contributor Author

@copilot yes
i am having some issues with making this node desirable to other nodes
very few nodes are willing to connect to me...

I've identified several issues that could make your node less desirable to other peers:

Critical Issues:

  1. Not responding to block requests: Your node receives GetBlockHeaders and GetBlockBodies requests (lines 133-138 in callbacks.go) but doesn't respond - just logs and ignores them. This violates protocol expectations.

  2. Not relaying blocks: You receive NewBlock messages (line 142) but don't relay them to other peers. Good network citizens relay blocks to help propagate them across the network.

  3. Limited block knowledge: Your Status message reports TotalDifficulty: new(big.Int) (zero), which signals you have no chain history. While TD is less critical post-merge, it still signals you're not a useful peer.

  4. No block header/body responses: Ethereum nodes expect peers to serve historical data. Your node only receives but never provides.

Why this matters:

  • Peers score each other based on usefulness
  • Nodes that don't respond to requests get deprioritized or disconnected
  • Your node appears as a "leech" - only taking data, never giving back

Recommendations:

  1. Implement responses to GetBlockHeaders and GetBlockBodies requests
  2. Store and serve at least recent block data
  3. Relay NewBlock messages to other connected peers
  4. Consider implementing basic block header chain to appear more credible

Would you like me to implement basic block request responses to make your node more cooperative?

@TLGINO

TLGINO commented Dec 14, 2025

Copy link
Copy Markdown
Owner

@copilot but isn't sending transactions sufficient?

Copilot AI commented Dec 14, 2025

Copy link
Copy Markdown
Contributor Author

@copilot but isn't sending transactions sufficient?

No, sending transactions alone is not sufficient. Here's why:

Ethereum P2P Protocol Expectations:
Nodes evaluate peers based on multiple factors:

  • Request responsiveness: Peers that ignore GetBlockHeaders/GetBlockBodies requests are seen as non-cooperative
  • Block propagation: Nodes expect peers to relay blocks, not just transactions
  • Peer reputation scoring: Most clients (Geth, Nethermind, etc.) maintain peer scores that drop when requests go unanswered
  • Resource balance: The protocol assumes mutual benefit - nodes share blocks AND transactions

Transaction-only limitations:

  • Your node announces/sends transactions (good!) but ignores all other protocol messages
  • This creates an imbalanced relationship where you only care about mempool data
  • Other nodes detect this pattern and deprioritize or disconnect from your node

Real-world analogy:
Imagine neighbors who only want to borrow tools but never lend theirs back, never help with community projects, and ignore all requests. Eventually, people stop interacting with them.

Bottom line:
To maximize transaction coverage, you need to be a better network citizen by responding to block requests and relaying blocks, even if you don't strictly need that data yourself. This keeps your peer connections healthy and increases the likelihood of receiving transaction data.

@TLGINO

TLGINO commented Dec 14, 2025

Copy link
Copy Markdown
Owner

@copilot can you make it also rellay blocks?
use the same method i am doing using alchemy to bootsrap the requests

Copilot AI and others added 3 commits December 14, 2025 22:45
Co-authored-by: TLGINO <59311729+TLGINO@users.noreply.github.com>
Co-authored-by: TLGINO <59311729+TLGINO@users.noreply.github.com>
Co-authored-by: TLGINO <59311729+TLGINO@users.noreply.github.com>

Copilot AI commented Dec 14, 2025

Copy link
Copy Markdown
Contributor Author

@copilot can you make it also rellay blocks?
use the same method i am doing using alchemy to bootsrap the requests

Done! I've implemented block relaying using the same Alchemy pattern you're using for transactions.

What was added:

  1. Full block fetching from Alchemy: When new block headers arrive, the node now fetches complete block data via RPC
  2. Relay from Alchemy: Blocks from Alchemy are broadcast to all bonded peers
  3. Relay from peers: Blocks received from other peers are also relayed to your other connections
  4. Proper error handling: Added panic recovery, nil checks, and RPC pointer fixes

How it works:

  • Block listener registers a callback when blocks arrive from Alchemy
  • RelayBlockToPeers() method sends NewBlock messages to all bonded sessions
  • Uses block's actual difficulty (or minimal value for post-merge blocks)

The implementation mirrors your transaction relaying pattern, so it should integrate seamlessly with your existing Alchemy setup.

Commits: 6d430cf (and previous: ae2ecc9, 139064a)

Copilot AI changed the title Initial codebase exploration and documentation Add block relaying functionality to improve node reputation and peer connectivity Dec 14, 2025
@TLGINO

TLGINO commented Dec 14, 2025

Copy link
Copy Markdown
Owner

@copilot how can i see ur cahnges?

Copilot AI commented Dec 14, 2025

Copy link
Copy Markdown
Contributor Author

@copilot how can i see ur cahnges?

You can see the changes in several ways:

On GitHub:

  1. Go to the PR "Files changed" tab to see the diff
  2. Look at commits 6d430cf, 139064a, and ae2ecc9

Main files changed:

  1. global/global.go (+71 lines):

    • Added full block fetching from Alchemy RPC
    • New RegisterBlockCallback() function to register callbacks
    • Enhanced block listener to notify callbacks when blocks arrive
  2. node/transport/transport.go (+34 lines):

    • New RelayBlockToPeers() method that broadcasts blocks to all bonded peers
    • Logs relay activity
  3. node/transport/callbacks.go (+4 lines):

    • When NewBlock received from peers → relay to other peers
  4. rlpx/messages.go (+7 lines):

    • New CreateNewBlock() function to format block messages
  5. main.go (+13 lines):

    • Registers callback to relay Alchemy blocks to peers
    • Uses block's difficulty or minimal value for TD

Key behavior: Node now fetches full blocks from Alchemy and relays them to all connected peers, plus relays blocks received from peers to other peers.

@TLGINO
TLGINO marked this pull request as ready for review December 14, 2025 23:00
@TLGINO
TLGINO merged commit d9ead7e into master Dec 14, 2025
1 check passed
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