Skip to content

Conversation

@tuhalf
Copy link
Collaborator

@tuhalf tuhalf commented Nov 26, 2025

PR Summary (refs #171 )

Centralized contract perimeter handling into a single controller (contractSync / runContractController*) that batch-fetches all properties once and applies them to control-plane config, ports, and WireGuard. cmd/diode/join.go
Simplified helpers to consume provided property maps only (no internal fetches) and tightened join flow to run an initial sync before starting services. cmd/diode/join.go
Kept service startup consistent while removing redundant fetch paths and the old loops. cmd/diode/join.go

@gemini-code-assist
Copy link

Summary of Changes

Hello @tuhalf, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the contract handling logic within the join command. The primary goal is to centralize and optimize how contract-based configurations are retrieved and applied to the control plane, ports, and WireGuard. By introducing batch fetching and a dedicated synchronization controller, the changes aim to improve performance, simplify the codebase, and enhance the reliability of configuration updates during the daemon's startup and operation.

Highlights

  • Centralized Contract Handling: Introduced contractSync and runContractController to centralize the fetching and application of contract properties, streamlining the configuration process.
  • Batch Property Fetching: Implemented getPropertyValues to fetch multiple contract properties in a single JSON-RPC batch call, significantly improving efficiency compared to individual fetches.
  • Simplified Helper Functions: Refactored updatePortsFromContract and updateWireGuardFromContract to consume pre-fetched property maps, removing redundant internal fetch logic.
  • Improved Error Handling: Enhanced error handling during contract property fetching, allowing for partial property application and logging warnings for failed fetches.
  • Streamlined Join Flow: Modified the joinHandler to perform an initial contract synchronization before starting services, ensuring that all necessary configurations are applied upfront.
  • New Utility Functions: Added several utility functions (normalizeList, stringFromValue, stringSliceFromValue, boolFromValue, durationFromValue, intFromValue) for robust type conversion and list processing of contract values.
  • Dynamic Configuration Application: Developed applyConfigKey and applyControlPlaneConfig to dynamically apply various control plane configurations from contract properties, including support for extra_config.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly refactors the contract property handling in the join command. It introduces batch fetching of properties from the smart contract, which is a great performance improvement. The logic is now centralized in a contractSync controller, and the startup flow is more robust, applying configuration before starting services. The code is cleaner and more modular.

I've left a few comments:

  • A high-severity issue regarding an unseeded random number generator which would make address shuffling predictable.
  • A medium-severity issue to improve error message clarity when parsing RPC responses.
  • A medium-severity issue about an inconsistency and inefficiency in how blocklists are applied compared to allowlists, suggesting a future refactoring.

Overall, this is a solid improvement to the codebase.

Comment on lines +496 to +510
func applyBlocklist(cfg *config.Config, blocklists []string) {
cfg.SBlocklists = config.StringValues(blocklists)
blocklistMap := cfg.Blocklists()
for addr := range blocklistMap {
delete(blocklistMap, addr)
}
for _, entry := range blocklists {
addr, err := util.DecodeAddress(entry)
if err != nil {
cfg.Logger.Warn("Skipping invalid blocklist address %q: %v", entry, err)
continue
}
blocklistMap[addr] = true
}
}

Choose a reason for hiding this comment

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

medium

This function is inconsistent with applyAllowlist and is inefficient. applyAllowlist can directly create a new map and assign it to cfg.Allowlists because it's a public field. Here, because cfg.blocklists is private, you have to use cfg.Blocklists() which might populate a new map from SBlocklists, which you then clear and repopulate. This is redundant.

For better consistency and efficiency, consider making cfg.blocklists public in config.Config (like Allowlists) and then adopting the same implementation pattern as applyAllowlist:

func applyBlocklist(cfg *config.Config, blocklists []string) {
	cfg.SBlocklists = config.StringValues(blocklists)
	cfg.blocklists = nil // if made public
	if len(blocklists) == 0 {
		return
	}
	newBlocklistMap := make(map[util.Address]bool, len(blocklists))
	for _, entry := range blocklists {
		addr, err := util.DecodeAddress(entry)
		if err != nil {
			cfg.Logger.Warn("Skipping invalid blocklist address %q: %v", entry, err)
			continue
		}
		newBlocklistMap[addr] = true
	}
    cfg.blocklists = newBlocklistMap
}

Since changing config.Config is outside this file's scope, I'm pointing this out as a medium-severity issue for future refactoring. The current implementation is functionally correct but could be improved.

tuhalf and others added 5 commits November 27, 2025 02:08
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@dominicletz
Copy link
Member

@tuhalf please ensure the commands are all tested at least once for configuration.

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.

3 participants