-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refuse to start if binary network doesn't match chain node network #340
Comments
I would love to contribute and resolve this issue, please assign it to me. |
Please feel free to ask any questions you have. |
Hi @LexLuthr , I've implemented this by:
+ const (
+ NetworkMainnet = "mainnet"
+ NetworkCalibnet = "calibnet"
+ NetworkTestnet = "testnet"
+ )
+
+ func CurrentNetwork() string {
+ switch BuildType {
+ case BuildMainnet:
+ return NetworkMainnet
+ case BuildCalibnet:
+ return NetworkCalibnet
+ case Build2k:
+ return NetworkTestnet
+ default:
+ return "unknown"
+ }
+ }
+ func validateNetworkMatch(ctx context.Context, api v0api.FullNode) error {
+ // Get network name from the chain node
+ networkName, err := api.StateNetworkName(ctx)
+ if err != nil {
+ return xerrors.Errorf("failed to get network name from chain node: %w", err)
+ }
+
+ // Get binary's network
+ binaryNetwork := build.CurrentNetwork()
+
+ // Compare networks
+ if string(networkName) != binaryNetwork {
+ return xerrors.Errorf("network mismatch: binary built for %s but chain node is on %s",
+ binaryNetwork, networkName)
+ }
+
+ return nil
+ }
// I have added some validation check in run command
+ api, closer, err := lcli.GetFullNodeAPI(cctx)
+ if err != nil {
+ return err
+ }
+ defer closer()
+
+ if err := validateNetworkMatch(ctx, api); err != nil {
+ return xerrors.Errorf("network validation failed: %w", err)
+ } The validation happens early in the startup process and will prevent Curio from starting if there's a network mismatch. The error message indicates which network the binary was built for and which network the chain node is on. The validation happens early in the startup process before any services are started. The error message will indicate the mismatch (e.g., "network mismatch: binary built for mainnet but chain node is on calibnet"). Could you please review this approach and let me know if:
Thank you! |
|
I've implemented the feedback :
The validation now happens early in the connection process, providing better error handling and reporting when network mismatches occur. Could you lemme know if there's any adjustments required |
Basically on startup detect if the curio binary is e.g. calib and the chain node is mainnet - will prevent from deploying the wrong binary to a wrong environment (like I may have just done 😅)
The text was updated successfully, but these errors were encountered: