Repository navigation
[CRE-7120]core/config: deep-copy in Core.SetFrom to avoid aliasing source config - #24059
Draft
pavel-raykov wants to merge 3 commits into
Draft
pavel-raykov wants to merge 3 commits into
pavel-raykov wants to merge 3 commits into
Conversation
Core.SetFrom copied pointers, slices and maps from its source, so the result aliased it: writing through the effective config (e.g. test overrides like *c.Insecure.DevWebServer = true) mutated the shared package-level defaults and the user input config, and raced under parallel tests. SetFrom now deep-copies its argument first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
I see you updated files related to
|
Contributor
|
✅ No conflicts with other open PRs targeting |
mchain0
reviewed
Oct 23, 2026
| // Values are deep-copied, so c never aliases f: later writes through either one | ||
| // do not affect the other. | ||
| func (c *Core) SetFrom(f *Core) { | ||
| fc := deepCopy(*f) |
Contributor
There was a problem hiding this comment.
concerns as expressed earlier for the deep copy approach comment here: #24052 (comment)
Replace the hand-rolled reflection helper with go-clone, already used for the same purpose in chainlink-common x/config. It also copies private fields (e.g. the *big.Int inside decimal.Decimal), which the reflection helper had to copy by value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Slowly also handles cyclic and shared pointers, matching how chainlink-common x/config clones its config defaults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Alternative to #24052 that fixes the root cause in
SetFrominstead of re-decoding defaults on every call.Problem
toml.Core.SetFrom(and every nestedsetFrom) copies pointers, slices and maps from its source. Its result therefore shares memory with the source:CoreDefaults()shares with the package-level decoded defaults. In-place test overrides such as*c.Insecure.DevWebServer = truechange the defaults for every later config, and race under parallel tests.setDefaults(core.SetFrom(&c.Core)) makes the effective config share with the user input config, andConfig.SetFromdoes the same when merging config strings.Fix
Core.SetFromdeep-copies its argument withhuandu/go-clone(clone.Slowly) before merging. The same library is already used for copying config defaults in chainlink-commonx/config. It is a new direct dependency here (indirect in the other modules, viamake gomodtidy).CoreDefaults()still decodes the embeddedcore.tomlonce at init. That keeps fail-fast startup and avoids a TOML decode per call.Tests
TestCoreDefaults_distinctInstances: writes through oneCoreDefaults()result and checks that another is unaffected.TestCoreDefaults_noSharedReferences: reflection check that twoCoreDefaults()results share no pointer, slice or map.TestGeneralConfigOpts_ConcurrentOverrideAndNew: concurrent in-place overrides andNew(); reports races under-racewithout the fix.With the deep copy removed, the first two tests fail and the third reports data races.
Not covered
configtoml.Defaultsin chainlink-evm) still share pointers with package-level state and need a matching change there.Config.SetFrommerges the other chains (EVM, Solana, etc.) through their ownSetFrom, which this PR does not change.🤖 Generated with Claude Code