Skip to content

Conversation

JonathanOppenheimer
Copy link
Member

@JonathanOppenheimer JonathanOppenheimer commented Sep 26, 2025

Why this should be merged

This PR closes #3934 and adds deterministic randomization to genesis configuration and network parameters for Antithesis testing. The randomization is controlled by the ANTITHESIS_RANDOM_SEED environment variable. I assume this makes testing more rigorous or something. I actually have no idea why this feature is desired. 🤷

Randomized Parameters

Below are the ranges in which variables are randomized - if different ranges for any of these are desired, let me know.

P-Chain Parameters

Parameter Range Purpose
Dynamic Fee Min Gas Price 1 to 1,000 nAVAX Primary goal - P-chain minimum gas price
Gas Max Capacity 500K to 2M Maximum gas storage for future use
Gas Max Per Second 50K to 200K Maximum gas consumption rate
Gas Target Per Second 25% to 75% of max Target gas consumption for stable fees

Transaction Fees

Parameter Range Purpose
Base Transaction Fee 0.1 to 10 milliAVAX Standard transaction cost
Create Asset Fee 0.5 to 50 milliAVAX Fee for creating new assets

Validator & Staking Parameters

Parameter Range Purpose
Validator Fee Min Price 1 to 1,000 nAVAX Minimum price for validator operations
Validator Fee Capacity 10K to 50K Validator fee system capacity
Validator Fee Target 25% to 75% of capacity Target validator fee usage
Min Validator Stake 1 to 5 KiloAVAX Minimum stake to become validator
Max Validator Stake 2 to 10 MegaAVAX Maximum stake per validator
Min Delegator Stake 5 to 100 AVAX Minimum delegation amount
Min Delegation Fee 1% to 10% Minimum fee validators can charge

Genesis Timing

Parameter Range Purpose
Initial Stake Duration 12 to 48 hours How long initial validators stake
Stake Duration Offset 30 minutes to 3 hours Offset for stake timing
C-Chain Gas Limit 50M to 200M Block gas limit on C-Chain

How this works

  • ANTITHESIS_RANDOM_SEED environment variable enables randomization
  • If not set -> uses standard/default genesis configuration
    • This means this should be backwards compatible with other prior tests? I think?
  • If set -> applies deterministic randomization using the read in seed value

How this was tested

I created a few unit tests

  • TestNewRandomizedTestGenesis
  • TestRandomizedParams
  • TestRandomizedParamsValidation
  • TestRandomizedGenesisWithDifferentSeeds

that verify accordingly

  • Randomization works with valid seeds
  • Default behavior without environment variable
  • Deterministic output for same seeds

Additionally, I ran the antithesis tests locally with a randomized seed that has been set.

# Enable randomization with a specific seed
export ANTITHESIS_RANDOM_SEED=123456789

./scripts/run_task.sh test-build-antithesis-images-avalanchego
./scripts/run_task.sh test-build-antithesis-images-xsvm

I also modified the CI to set ANTITHESIS_RANDOM_SEED: ${{ github.run_id }}, which seemed like a reasonable value, and I also made it manually configurable.

In these two text files you an see the successful run.

Critically:

[09-26|13:33:32.165] INFO tmpnet/network.go:1189 applied randomized network parameters {"seed": "123456789", "minGasPrice": 885, "validatorMinPrice": 223, "txFee": 2700000, "createAssetTxFee": 22200000, "minValidatorStake": 2000000000000, "maxValidatorStake": 7000000000000000, "minDelegatorStake": 15000000000, "minDelegationFee": 60000}

You can also check the CI on this PR, to see a similar message, with randomized parameters being set.

Need to be documented in RELEASES.md?

No

@JonathanOppenheimer JonathanOppenheimer self-assigned this Sep 26, 2025
@Copilot Copilot AI review requested due to automatic review settings September 26, 2025 18:00
@JonathanOppenheimer JonathanOppenheimer added the testing This primarily focuses on testing label Sep 26, 2025
Copy link
Contributor

@Copilot 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 adds deterministic randomization to genesis configuration and network parameters for Antithesis testing. When the ANTITHESIS_RANDOM_SEED environment variable is set, it applies random values to various network parameters including fees, staking amounts, and timing configurations to enable more comprehensive testing scenarios.

  • Implements randomized genesis configuration controlled by ANTITHESIS_RANDOM_SEED environment variable
  • Adds randomization of network parameters including gas prices, transaction fees, and staking limits
  • Updates CI workflows to automatically set random seeds using GitHub run IDs

Reviewed Changes

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

Show a summary per file
File Description
tests/fixture/tmpnet/network.go Adds logic to apply randomized network flags when environment variable is set
tests/fixture/tmpnet/genesis.go Implements randomized genesis creation and parameter generation functions
tests/fixture/tmpnet/genesis_randomized_test.go Adds comprehensive test suite for randomization functionality
.github/workflows/trigger-antithesis-xsvm.yml Adds optional random seed input parameter for manual workflow triggers
.github/workflows/trigger-antithesis-avalanchego.yml Adds optional random seed input parameter for manual workflow triggers
.github/workflows/publish_antithesis_images.yml Sets automatic random seed using GitHub run ID
.github/workflows/ci.yml Sets automatic random seed for CI antithesis image builds

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

}

// Create a deterministic random source
rng := rand.New(rand.NewSource(seed)) // #nosec G404
Copy link
Preview

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

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

Using math/rand for cryptographic purposes is not secure. Consider using crypto/rand for security-sensitive randomization, especially for network parameters that could affect consensus.

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we care about this?

return baseParams
}

rng := rand.New(rand.NewSource(seed)) // #nosec G404
Copy link
Preview

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

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

Using math/rand for cryptographic purposes is not secure. Consider using crypto/rand for security-sensitive randomization, especially for network parameters that could affect consensus.

Copilot uses AI. Check for mistakes.

@JonathanOppenheimer JonathanOppenheimer marked this pull request as draft September 26, 2025 18:01
return
}

// TODO(jonathanoppenheimer): is there a better way to apply these values?
Copy link
Member Author

Choose a reason for hiding this comment

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

This seemed like a bad way to apply the randomizedParams Is there a more concise way of doing so?

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Jonathan Oppenheimer <[email protected]>
@JonathanOppenheimer JonathanOppenheimer marked this pull request as ready for review September 26, 2025 18:17
@JonathanOppenheimer JonathanOppenheimer moved this to In Review 🔎 in avalanchego Sep 26, 2025
@maru-ava maru-ava marked this pull request as draft September 29, 2025 15:21
@maru-ava
Copy link
Contributor

Converting to draft to avoid accidental review while this PR is in a research phase.

@StephenButtolph StephenButtolph moved this from In Review 🔎 to Backlog 🧊 in avalanchego Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing This primarily focuses on testing
Projects
Status: Backlog 🧊
Development

Successfully merging this pull request may close these issues.

Utilize ${ANTITHESIS_RANDOM_SEED} to randomize genesis config
2 participants