Skip to content

[tx-generator] Add --testnet-config-dir flag to json_highlevel#6529

Open
palas wants to merge 3 commits intomasterfrom
add-testnet-config-dir-to-tx-generator
Open

[tx-generator] Add --testnet-config-dir flag to json_highlevel#6529
palas wants to merge 3 commits intomasterfrom
add-testnet-config-dir-to-tx-generator

Conversation

@palas
Copy link
Copy Markdown
Contributor

@palas palas commented Apr 13, 2026

Description

Adds a --testnet-config-dir flag to tx-generator json_highlevel that auto-discovers infrastructure config (socket path, signing key, node config, target nodes) from a cardano-testnet output directory, using the shared path conventions from Cardano.Node.Testnet.Paths.

Discovered infrastructure always overrides any user-provided values for those fields. All other config fields must be supplied by the user.

Closes #6513 (part 2 of #6510). Depends on #6518 (part 1).

What's new:

  • Cardano.TxGenerator.Setup.TestnetDiscovery module — scans testnet dir for infrastructure config, merges with user config at JSON level (infrastructure always wins)
  • json_highlevel parser now accepts either a full config file (existing behaviour preserved) or --testnet-config-dir with an optional partial config overlay
  • Property-based test verifying infrastructure fields always override user-provided values, and that missing required non-infra fields cause failure

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. These may include:
    • property tests
    • roundtrip tests
      See Running tests for more details
  • Any changes are noted in the CHANGELOG.md for affected package
  • The version bounds in .cabal files are updated
  • CI passes. See note on CI. The following CI checks are required:
    • Code is linted with hlint. See .github/workflows/check-hlint.yml to get the hlint version
    • Code is formatted with stylish-haskell. See .github/workflows/stylish-haskell.yml to get the stylish-haskell version
    • Code builds on Linux, MacOS and Windows for ghc-9.6 and ghc-9.12
  • Self-reviewed the diff

@palas palas requested a review from a team as a code owner April 13, 2026 20:35
@palas palas self-assigned this Apr 13, 2026
@palas palas linked an issue Apr 13, 2026 that may be closed by this pull request
Base automatically changed from move-testnet-paths-to-node to master April 14, 2026 22:51
palas added 2 commits April 24, 2026 03:36
Add a `--testnet-config-dir` flag that auto-discovers the 4 infrastructure
parameters (socket path, signing key, node config file, target nodes) from
a `cardano-testnet` output directory.  Discovered infrastructure always
overrides user-provided values; all other config fields must be supplied
by the user.
@palas palas force-pushed the add-testnet-config-dir-to-tx-generator branch from e8b7377 to ffba8e5 Compare April 24, 2026 01:39
@palas palas force-pushed the add-testnet-config-dir-to-tx-generator branch from ffba8e5 to 0154393 Compare April 24, 2026 02:02
@Jimbo4350 Jimbo4350 requested a review from Copilot April 27, 2026 17:28
Copy link
Copy Markdown
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

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

Minor naming issues.

deriving instance Show SignalSpecificInfo
#endif

data JsonHLSource
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.

Haddocks?


case Aeson.fromJSON merged of
Aeson.Success opts -> pure opts
Aeson.Error err -> die $ "Failed to parse merged config: " ++ err
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.

Prefix the name of the function to the error message.

validateFileExists portPath ("port file for " ++ defaultNodeName idx)
portStr <- readFile portPath
case readMaybe portStr :: Maybe PortNumber of
Nothing -> die $ "Invalid port number in: " ++ portPath
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.

Prefix the function name in the error message.


-- Property test --

-- | Non-infra required field names.
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.

Don't use the infra terminology it is confusing.

-- | Property: infrastructure fields always come from the testnet directory
-- regardless of what the user supplies; non-infra fields come from the user
-- config; missing required non-infra fields cause failure.
prop_infraOverride :: Property
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.

again, don't use infra it is confusing.

Copy link
Copy Markdown

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

Adds a --testnet-config-dir option to tx-generator json_highlevel to auto-discover infrastructure settings from a cardano-testnet output directory (using Cardano.Node.Testnet.Paths), and merges those discovered infrastructure fields over user-provided JSON config.

Changes:

  • Introduces Cardano.TxGenerator.Setup.TestnetDiscovery to discover socket path, signing key, node config, and target nodes from a testnet directory and merge them into user config (infra wins).
  • Extends json_highlevel command parsing/execution to optionally perform testnet discovery before decoding NixServiceOptions.
  • Adds a new test module covering JSON round-tripping and a property test ensuring infra fields override user config.

Reviewed changes

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

Show a summary per file
File Description
bench/tx-generator/tx-generator.cabal Adds new module/deps and wires in new test module/dependencies.
bench/tx-generator/src/Cardano/TxGenerator/Setup/TestnetDiscovery.hs Implements testnet directory discovery + JSON-level merge for infra fields.
bench/tx-generator/src/Cardano/Benchmarking/Command.hs Adds --testnet-config-dir plumbing for json_highlevel.
bench/tx-generator/test/TestnetDiscoveryTest.hs Adds round-trip + property tests for discovery/merge semantics.
bench/tx-generator/test/Main.hs Registers the new test group.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +126 to +130
-- | Validate that a file exists, dying with a clear message if not.
validateFileExists :: FilePath -> String -> IO ()
validateFileExists path description = do
exists <- doesFileExist path
unless exists $ die $ "Required " ++ description ++ " file not found: " ++ path
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

validateFileExists uses doesFileExist for localNodeSocketPath. The node socket is a Unix domain socket (not a regular file), so doesFileExist can return False even when the socket exists, causing discoverTestnetConfig to fail on real testnets. Use an existence check that works for sockets (e.g. doesPathExist/getFileStatus without isRegularFile), or special-case socket validation.

Copilot uses AI. Check for mistakes.
Comment on lines +220 to +224
acquire = do
saved <- hDuplicate stderr
devNull <- openFile "/dev/null" WriteMode
hDuplicateTo devNull stderr
pure (saved, devNull)
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

withSilentStderr redirects stderr to /dev/null, which will fail on Windows (CI builds include Windows). Consider using System.IO.nullDevice (when available) or redirect to a temporary file/handle (you already depend on temporary) to keep the test portable.

Copilot uses AI. Check for mistakes.
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 --testnet-config-dir flag to tx-generator json_highlevel

3 participants