Skip to content

Conversation

@tuhalf
Copy link
Collaborator

@tuhalf tuhalf commented Dec 29, 2025

No description provided.

…encies.

migrate: use Oasis SDK for join, clean secp256k1, fix RPC hangs

Move join contract reads to the Oasis SDK (Sapphire) and update Go module
dependencies accordingly. Drop the vendored libsecp256k1 tree and its
submodule metadata, relying on the geth secp256k1 wrapper instead.
Add bounded RPC response waiting and ensure client initialization only
starts after a successful connection to avoid indefinite startup hangs.
@gemini-code-assist
Copy link
Contributor

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 marks a significant architectural shift by integrating the Oasis SDK into the project. The primary goal is to modernize and streamline interactions with the Oasis network, moving away from a custom JSON-RPC implementation and a C-based cryptographic library. This change impacts how smart contract data is fetched and how elliptic curve operations are handled, leading to a more cohesive Go-native codebase.

Highlights

  • Oasis SDK Integration: The project has been migrated to utilize the Oasis SDK for interacting with the Oasis network. This involves replacing manual JSON-RPC calls with the SDK's client functionalities.
  • Removal of libsecp256k1 Submodule: The entire libsecp256k1 C submodule, along with its build scripts, tests, and related CGO bindings, has been removed from the repository. This significantly streamlines the project's cryptographic dependencies.
  • Refactored Smart Contract Interaction: The getPropertyValues function in cmd/diode/join.go has been updated to leverage the new OasisClient for confidential EVM calls, replacing the previous HTTP-based JSON-RPC requests.
  • Updated Elliptic Curve Operations: The Go-based secp256k1 curve implementation has been refined to handle edge cases for points at infinity and scalar multiplication, ensuring robust cryptographic operations without relying on the removed C library.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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
Contributor

@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

The pull request primarily integrates the Oasis SDK for client-side interactions, replacing a custom JSON-RPC implementation. This involves adding new Oasis SDK imports, removing old HTTP-related imports, and refactoring the joinHandler and getPropertyValues functions in cmd/diode/join.go to use the new OasisClient struct and its methods. The rpcURL variable has been removed, and contract address handling now uses contractAddrBytes and oasisClient. Concurrently, the crypto/secp256k1 submodule has been removed, and its related Cgo bindings and ScalarMult function in curve.go have been eliminated, with corresponding adjustments to ext.h and the Add method in curve.go to handle points at infinity. A review comment suggests making OASIS_LOCAL_SAPPHIRE_ID a required environment variable for local network setups to improve explicitness, and another points out the magic number 20 for contract address length, recommending a named constant for better readability.

}
sapphireID := strings.TrimSpace(os.Getenv(oasisLocalSapphireIDEnv))
if sapphireID == "" {
sapphireID = defaultSapphireID()
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The defaultSapphireID function falls back to using the 'testnet' configuration to get a default Sapphire ID for the 'local' network. This dependency on testnet configuration for a local setup might be confusing for developers and makes the local environment not self-contained.

Consider making OASIS_LOCAL_SAPPHIRE_ID a required environment variable when network=local. This would make the configuration more explicit and less surprising.

return fmt.Errorf("invalid network: %s", network)
var err error
contractAddrBytes, err = hex.DecodeString(strings.TrimPrefix(contractAddress, "0x"))
if err != nil || len(contractAddrBytes) != 20 {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The number 20 is used here to check the length of the contract address. This is a magic number. To improve readability and maintainability, consider defining a constant for this value, for example const expectedAddressLength = 20, and using that constant here.

@tuhalf
Copy link
Collaborator Author

tuhalf commented Dec 29, 2025

I sometimes get this runtime error:
[tuhalf@tuhalf diode_client]$ ./diode -update=false -debug -diodeaddrs=us2.prenet.diode.io:41046 join 0xCf20FaDA36e07A03C90871a6E976813b7d04407A
INFO Diode Client version : v1.16.7-dirty 28 Ara 2025
WARN join command is still BETA, parameters may change
INFO Contract Address : 0xCf20FaDA36e07A03C90871a6E976813b7d04407A
INFO Client address : 0x83257a218dbee967439b888f619819390c17ae2e
INFO Fleet address : 0x6000000000000000000000000000000000000000
DEBUG Adding relay#0 [] @ us2.prenet.diode.io:41046
DEBUG received blockrange: [10212213 10212214 10212215 10212216 10212217 10212218 10212219 10212220 10212221 10212222 10212223 10212224 10212225 10212226 10212227 10212228 10212229 10212230 10212231 10212232 10212233 10212234 10212235 10212236 10212237 10212238 10212239 10212240 10212241 10212242 10212243 10212244 10212245 10212246 10212247 10212248 10212249 10212250 10212251 10212252 10212253 10212254 10212255 10212256 10212257 10212258 10212259 10212260 10212261 10212262 10212263 10212264 10212265 10212266 10212267 10212268 10212269 10212270 10212271 10212272 10212273 10212274 10212275 10212276 10212277 10212278 10212279 10212280 10212281 10212282 10212283 10212284 10212285 10212286 10212287 10212288 10212289 10212290 10212291 10212292 10212293 10212294 10212295 10212296 10212297 10212298 10212299 10212300 10212301 10212302 10212303 10212304 10212305 10212306 10212307 10212308 10212309 10212310 10212311 10212312 10212313 10212314 10212315 10212316 10212317 10212318 10212319 10212320 10212321 10212322 10212323 10212324] (112) server=us2.prenet.diode.io:41046
DEBUG Added relay#0 [0x7e4cd38d266902444dc9c8f7c0aa716a32497d0b] @ us2.prenet.diode.io:41046
INFO Network is validated, last valid block: 10212320 0x000008dd30466e84ab180b285184b0f5fd647fa2929d9ef66d1887460ff549e9
DEBUG Fetching join contract (device=0x83257a218dbee967439b888f619819390c17ae2e, contract=0xCf20FaDA36e07A03C90871a6E976813b7d04407A, network=mainnet, rpc=grpc.oasis.io:443, keys=[public private protected wireguard socksd bind debug diodeaddrs fleet extra_config])
DEBUG Join contract fetch success (device=0x83257a218dbee967439b888f619819390c17ae2e): public(len=4), private(empty), protected(empty), wireguard(empty), socksd(empty), bind(empty), debug(empty), diodeaddrs(empty), fleet(empty), extra_config(empty)
DEBUG Public Ports: 8080
DEBUG Private Ports:
DEBUG Protected Ports:
INFO Updated port configurations from contract
INFO HTTP Gateway Enabled : https://0x83257a218dbee967439b888f619819390c17ae2e.diode.link:8080/
INFO Port :
INFO Port localhost:8080 : 8080 public any
DEBUG Fetching join contract (device=0x83257a218dbee967439b888f619819390c17ae2e, contract=0xCf20FaDA36e07A03C90871a6E976813b7d04407A, network=mainnet, rpc=grpc.oasis.io:443, keys=[public private protected wireguard socksd bind debug diodeaddrs fleet extra_config])
DEBUG Join contract fetch success (device=0x83257a218dbee967439b888f619819390c17ae2e): public(len=4), private(empty), protected(empty), wireguard(empty), socksd(empty), bind(empty), debug(empty), diodeaddrs(empty), fleet(empty), extra_config(empty)
INFO Client connection closed unexpectedly: EOF server=us2.prenet.diode.io:41046
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x9d7f4d]

goroutine 52 [running]:
sync/atomic.(*Int32).Add(...)
/home/tuhalf/.asdf/installs/golang/1.25.3/go/src/sync/atomic/type.go:94
sync.(*RWMutex).RLock(...)
/home/tuhalf/.asdf/installs/golang/1.25.3/go/src/sync/rwmutex.go:72
github.com/diodechain/diode_client/rpc.(*SSL).TotalConnections(0x846e4630dd080000?)
/home/tuhalf/Documents/GitHub/diode_client/rpc/ssl.go:85 +0x2d
github.com/diodechain/diode_client/rpc.(*Client).newTicket(0xc0002211d0)
/home/tuhalf/Documents/GitHub/diode_client/rpc/client.go:656 +0x114
github.com/diodechain/diode_client/rpc.(*Client).greet.(*Client).SubmitNewTicket.func1()
/home/tuhalf/Documents/GitHub/diode_client/rpc/client.go:612 +0x4f
github.com/dominicletz/genserver.(*GenServer).loop(0xc00055e780)
/home/tuhalf/.asdf/installs/golang/1.25.3/packages/pkg/mod/github.com/dominicletz/genserver@v1.3.1/genserver.go:78 +0x26
created by github.com/dominicletz/genserver.New in goroutine 1
/home/tuhalf/.asdf/installs/golang/1.25.3/packages/pkg/mod/github.com/dominicletz/genserver@v1.3.1/genserver.go:49 +0x15c

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