-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Custom Fallback TOML Config #15617
base: develop
Are you sure you want to change the base?
Custom Fallback TOML Config #15617
Conversation
// fallback.toml(defaults dir) <- fallback.toml(env CL_CHAIN_FALLBACK) <- ChainSpecific.toml(env CL_CHAIN_DEFAULTS) | ||
// | ||
// the custom fallback gets processed and overrides the default fallback | ||
if path := env.CustomFallback.Get(); path != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we lock this in with a testscripts test like in https://github.com/smartcontractkit/chainlink/pull/14090/files#diff-ea10429fdb1fbc100e3d8082e39e6d40a12f82b48c1f37ab9158b6c3c0e44d81 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I'll add that
AER Report: CI Coreaer_workflow , commit , Detect Changes , Scheduled Run Frequency , Clean Go Tidy & Generate , Flakeguard Root Project / Get Tests To Run , Flakeguard Deployment Project , Core Tests (go_core_tests) , lint , Core Tests (go_core_tests_integration) , Core Tests (go_core_ccip_deployment_tests) , Core Tests (go_core_race_tests) , Core Tests (go_core_fuzz) , Flakeguard Root Project / Run Tests , Flakeguard Root Project / Report , Flakey Test Detection , SonarQube Scan 1. TestRPCClient_SubscribeFilterLogs failed: [go_core_tests]Source of Error:
Why: The test Suggested fix: Ensure the test setup correctly simulates the expected JSON-RPC messages. Verify the mock server sends the correct "eth_subscribe" and "logs" messages and fix any JSON formatting issues in the test or mock server. AER Report: Operator UI CI ran successfully ✅ |
1d753ac
to
436023c
Compare
id := config.ChainID.String() | ||
|
||
// add ChainID to set of default IDs | ||
DefaultIDs = append(DefaultIDs, chainID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is important not to separate these global var assignments (defaults
and defaultNames
too) from their declarations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to use helpers, then how about returning values to set from init()
?
a449414
to
f57243d
Compare
This commit provides using an existing env var `CL_CHAIN_DEFAULTS` as a path to a custom `fallback.toml`. This allows plugins to define their own set of fallback options apart from the core node which override the default fallback options.
f57243d
to
4515f8a
Compare
ba58f5c
to
2a8f287
Compare
func readConfig(path string, reader func(name string) ([]byte, error), fallback bool) (*big.Big, Chain, error) { | ||
bts, err := reader(path) | ||
if err != nil { | ||
return nil, Chain{}, fmt.Errorf("%w: %s", errRead, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, Chain{}, fmt.Errorf("%w: %s", errRead, err.Error()) | |
return nil, Chain{}, fmt.Errorf("%w: %w", errRead, err) |
continue | ||
} | ||
|
||
log.Fatalf("custom defaults override failure (%s): %s", entry.Name(), err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Fatalf("custom defaults override failure (%s): %s", entry.Name(), err.Error()) | |
log.Fatalf("custom defaults override failure (%s): %s", entry.Name(), err) |
id := config.ChainID.String() | ||
// decode from toml to a chain config | ||
if err := cconfig.DecodeTOML(bytes.NewReader(bts), &config); err != nil { | ||
return nil, Chain{}, fmt.Errorf("%w %s: %s", errDecode, path, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, Chain{}, fmt.Errorf("%w %s: %s", errDecode, path, err.Error()) | |
return nil, Chain{}, fmt.Errorf("%w %s: %w", errDecode, path, err) |
// read all default configs | ||
initReadDefaults() | ||
|
||
// check for and apply any overrides | ||
initApplyEVMOverrides() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this indirection is adding value. Please consider setting the global vars from this func, one way or another.
https://github.com/smartcontractkit/chainlink/pull/15617/files#r1883872492
errRead = errors.New("error reading file") | ||
errDecode = errors.New("error in TOML decoding") | ||
errMissingChainID = errors.New("missing ChainID") | ||
errNonNilChainID = errors.New("fallback ChainID must be nil") | ||
errFallbackConfig = errors.New("fallback config") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these all single use? I think the indirection makes it harder to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I guess errFallbackConfig
is actually checked for
if fallback { | ||
if config.ChainID != nil { | ||
return nil, Chain{}, fmt.Errorf("%w: found: %s", errNonNilChainID, config.ChainID) | ||
} | ||
customDefaults[id] = config.Chain | ||
|
||
return nil, config.Chain, errFallbackConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not be using a custom error to communicate back to the caller when there is not an error, and it seems unnecessary in this case since they passed it in to us in the first place.
if err != nil { | ||
log.Fatalf("error opening file (name: %v) in custom defaults override directory: %v", entry.Name(), err) | ||
if errors.Is(err, errFallbackConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already know when it is a fallback config, because we just passed the boolean arg to readConfig
. Let's use that logic directly instead of hacking errors.
This commit provides using an existing env var
CL_CHAIN_DEFAULTS
as a path to a customfallback.toml
. This allows plugins to define their own set of fallback options apart from the core node which override the default fallback options.CCIP-4395