Skip to content

feat:impl tools-cli and adding enrgen command#132

Merged
g11tech merged 8 commits intoblockblaz:mainfrom
GrapeBaBa:cli_util
Sep 9, 2025
Merged

feat:impl tools-cli and adding enrgen command#132
g11tech merged 8 commits intoblockblaz:mainfrom
GrapeBaBa:cli_util

Conversation

@GrapeBaBa
Copy link
Copy Markdown
Member

@GrapeBaBa GrapeBaBa commented Aug 31, 2025

Motivation

Currently we need a CLI command to generate ENR. Since discussed before, it need a new CLI which separates from zeam CLI. This PR introduces a new CLI which named zeam-tools and adds a sub-command enrgen.

Implementation

 USAGE:
     ./zig-out/bin/zeam-tools [OPTIONS] [COMMANDS]

 COMMANDS:
  enrgen     Generate a new ENR (Ethereum Node Record)

 OPTIONS:
  -h, --help                       Show help information
  -v, --version                    Show version information
 USAGE:
     ./zig-out/bin/zeam-tools enrgen [OPTIONS] 

 OPTIONS:
  -s, --sk STRING                  Secret key (hex string with or without 0x prefix)(required)
  -i, --ip STRING                  IPv4 address for the ENR(required)
  -u, --udp INTEGER                UDP port for discovery(required)
  -o, --out STRING                 Output file path (prints to stdout if not specified)(default: null)
  -h, --help                       Show help information for the enrgen command

Fix #130

Copilot AI review requested due to automatic review settings August 31, 2025 10:31
@gemini-code-assist
Copy link
Copy Markdown

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new CLI tool called zeam-tools with an enrgen command for generating Ethereum Node Records (ENR). The implementation separates this functionality from the main zeam CLI as previously discussed.

  • Adds a new zeam-tools CLI executable with structured argument parsing
  • Implements enrgen subcommand to generate ENR from secret key, IP address, and UDP port
  • Includes comprehensive error handling and test coverage for ENR generation functionality

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
pkgs/tools-cli/src/main.zig Main implementation of the tools CLI with ENR generation functionality
build.zig.zon Adds zig-enr dependency for ENR generation capabilities
build.zig Configures build for the new tools CLI executable and its tests

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

return error.ENRSetIPFailed;
};

var udp_bytes: [2]u8 = undefined;
Copy link

Copilot AI Aug 31, 2025

Choose a reason for hiding this comment

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

The choice of big-endian byte order for the UDP port should be documented, as this is a specific requirement for ENR encoding that may not be obvious to future maintainers.

Suggested change
var udp_bytes: [2]u8 = undefined;
var udp_bytes: [2]u8 = undefined;
// ENR specification requires the UDP port to be encoded in big-endian byte order.

Copilot uses AI. Check for mistakes.
@GrapeBaBa
Copy link
Copy Markdown
Member Author

@gballet @g11tech can't request reviewer, ping you here.

const ENRGenCmd = struct {
sk: []const u8,
ip: []const u8,
udp: u16,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, it seems the spec is not good here, it doesn't need a quic field. there is already a standard udp field there. Combine secp256k1, ip, udp, it can generate a ipv4 multiaddr. This is already used in beacon chain, i think we need change the spec here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

There will presumably be more than one tool, so it should have another directory, e.g. pkgs/tools/enrgen/src/main.zig. I don't think we need -cli, tools are typically CLIs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Current tools CLI design assume that multiple tools will be sub commands, So that we have only one CLI binary. Suggested dir seems not match this assumption. What is your opinion?

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.

my opinion is that, unless I'm mistaken, this is not part of the main client. If it is, then this needs to be a subcommand and if that is the case, it needs to be in pkgs/cli and not aside.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree this is a new CLI, but I don't think we should have a directory like pkgs/tools/enrgen/src/main.zig. What I thought is pkgs/tools/src/main.zig, the enrgen is a subcommand of this CLI. When we add new tools, we don't need add new main.zig and just add another subcommand in pkgs/tools/src/main.zig.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think for now we can go for all cli tools in in pkgs/tools with zeam-tools exe target as per this PR, if we feel that we need to change this to something better/more convenient, we can figure it out later

Copy link
Copy Markdown
Contributor

@gballet gballet left a comment

Choose a reason for hiding this comment

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

Looks like you need to add a dependency for this to compile in docker. My suggestion is to not build this executable in docker, unless it's necessary for daily operations. If you disagree, fine, just add the dependency and call that build-all thing that I suggested.

@GrapeBaBa
Copy link
Copy Markdown
Member Author

Looks like you need to add a dependency for this to compile in docker. My suggestion is to not build this executable in docker, unless it's necessary for daily operations. If you disagree, fine, just add the dependency and call that build-all thing that I suggested.

Yes, I prefer to not build executable in docker, let me look how to make a separate build for this.

else \
GIT_VERSION=$(echo "$GIT_VERSION" | head -c 7); \
fi && \
zig build -Doptimize=ReleaseFast -Dgit_version="$GIT_VERSION"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@gballet Currently, I used zig build all to tested on CI to see if it works on 0.14.1. It is really works https://github.com/blockblaz/zeam/actions/runs/17393132752. I'll change it to zig build to avoid including the zeam-tools in docker image.

@g11tech
Copy link
Copy Markdown
Member

g11tech commented Sep 3, 2025

actually we do need this in docker because all the tools to be used by genesis genertor need to be in docker, although we can build a separate docker image for this

g11tech
g11tech previously approved these changes Sep 3, 2025
Copy link
Copy Markdown
Member

@g11tech g11tech left a comment

Choose a reason for hiding this comment

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

lgtm but check it with @gballet as well

@GrapeBaBa GrapeBaBa requested a review from gballet September 8, 2025 15:22
Copy link
Copy Markdown
Contributor

@gballet gballet left a comment

Choose a reason for hiding this comment

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

Left a few more comments. I think the tool part is ready, but the build needs to have some changes.

Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
tools bin in the Docker build

Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
@GrapeBaBa GrapeBaBa requested review from g11tech and gballet September 9, 2025 06:05
@g11tech g11tech merged commit a984662 into blockblaz:main Sep 9, 2025
5 checks 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.

Add a command in CLI to generate ENR

4 participants