Skip to content

Return new instances of big int for DefaultConfig#804

Merged
facuMH merged 5 commits intomainfrom
facundo/fix_race_config
Apr 3, 2026
Merged

Return new instances of big int for DefaultConfig#804
facuMH merged 5 commits intomainfrom
facundo/fix_race_config

Conversation

@facuMH
Copy link
Copy Markdown
Contributor

@facuMH facuMH commented Apr 3, 2026

This PR fixes https://github.com/0xsoniclabs/sonic-admin/issues/687

The Problem:
A data race was detected in integration tests when multiple nodes attempted to load or save their configurations concurrently. This occurred during the TOML marshaling/unmarshaling process.

To reproduce, checkout commit c89694f and run the following command:

go test ./tests/ -race -count 1 -run TestIntegrationTestNet_CanDefineValidatorsStakes

The resulting race detector log points to UnmarshalTOML for both the read and write operations.

The Root of the issue:
The DefaultMaxGasPrice global variable was defined as a *big.Int. When the default configuration was copied to load/save the node config, only the pointer address was copied, not the underlying value.

When an integration test spins up multiple nodes simultaneously:

  • Both nodes reference the same memory address for their max gas price.
  • During UnmarshalTOML, the *big.Int value is modified in place.
  • Concurrent read/write access to this shared pointer without synchronization triggers the data race.

The Solution
Convert the global variable DefaultMaxGasPrice into a function that returns a new *big.Int instance on every call.

@facuMH facuMH requested review from LuisPH3 and Copilot April 3, 2026 08:37
@facuMH facuMH self-assigned this Apr 3, 2026
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

Fixes a race condition during concurrent TOML marshal/unmarshal of node configuration by ensuring the default max gas price is not shared via a global *big.Int pointer.

Changes:

  • Replaced the exported DefaultMaxGasPrice global *big.Int with a function that returns a new *big.Int per call.
  • Updated default config/oracle initialization to call DefaultMaxGasPrice() instead of referencing a shared pointer.

Reviewed changes

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

File Description
gossip/gasprice/gasprice.go Converts default max gas price from shared global pointer to per-call allocation; updates oracle initialization accordingly.
gossip/config.go Updates default gossip config to use gasprice.DefaultMaxGasPrice() when setting GPO.MaxGasPrice.

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

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
gossip/config.go 88.80% <100.00%> (ø)
gossip/gasprice/gasprice.go 83.82% <100.00%> (+0.49%) ⬆️

... and 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@facuMH facuMH changed the title Return new instances of big int for Return new instances of big int for DefaultConfig Apr 3, 2026
Copy link
Copy Markdown
Contributor

@LuisPH3 LuisPH3 left a comment

Choose a reason for hiding this comment

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

The PR identifies the source of races during testing, this issue cannot happen in production, but shadows mechanism to detect other race conditions.

  • The cause was rather old. Weird that it did not happen before.
  • The change introduces regression testing

@facuMH facuMH force-pushed the facundo/fix_race_config branch from 6461a1c to 130e243 Compare April 3, 2026 11:24
@facuMH facuMH merged commit e7be321 into main Apr 3, 2026
2 checks passed
@facuMH facuMH deleted the facundo/fix_race_config branch April 3, 2026 11:39
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