Skip to content
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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

EasterTheBunny
Copy link
Contributor

@EasterTheBunny EasterTheBunny commented Dec 10, 2024

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.

CCIP-4395

// 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 != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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

Copy link
Contributor

github-actions bot commented Dec 10, 2024

AER Report: CI Core

aer_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:
Run tests	2024-12-13T17:10:38.8426705Z --- FAIL: TestRPCClient_SubscribeFilterLogs (0.62s)
Run tests	2024-12-13T17:10:38.8428877Z logger.go:146: 17:10:16.290625237	DEBUG	Client.RPC	RPC dial: evmclient.Client#dial	{"clientTier": "primary", "clientName": "rpc", "client": "(primary)rpc:ws://127.0.0.1:42499", "evmChainID": "123456", "wsuri": "ws://127.0.0.1:42499"}
Run tests	2024-12-13T17:10:38.8432849Z logger.go:146: 17:10:16.290689781	DEBUG	Client.RPC	RPC call: evmclient.Client#SubscribeFilterLogs	{"clientTier": "primary", "clientName": "rpc", "client": "(primary)rpc:ws://127.0.0.1:42499", "evmChainID": "123456", "requestID": "c9ff6506-8671-4115-97fd-91d08b355080", "q": {"BlockHash":null,"FromBlock":null,"ToBlock":null,"Addresses":null,"Topics":null}}
Run tests	2024-12-13T17:10:38.8435543Z --- FAIL: TestRPCClient_SubscribeFilterLogs/Subscription_error_is_properly_wrapper (0.34s)
Run tests	2024-12-13T17:10:38.8437577Z client.go:159: Received message {"jsonrpc":"2.0","id":1,"method":"eth_subscribe","params":["logs",{"address":null,"fromBlock":"0x0","toBlock":"latest","topics":null}]}
Run tests	2024-12-13T17:10:38.8438766Z 
Run tests	2024-12-13T17:10:38.8439710Z client.go:233: Sending message: {"jsonrpc":"2.0","id":1,"result":"0x00"}
Run tests	2024-12-13T17:10:38.8441405Z client.go:233: Sending message: {"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":"0x00","result":{}}}
Run tests	2024-12-13T17:10:38.8443298Z client.go:159: Received message {"jsonrpc":"2.0","id":2,"method":"eth_unsubscribe","params":["0x00"]}
Run tests	2024-12-13T17:10:38.8444332Z 
Run tests	2024-12-13T17:10:38.8444955Z rpc_client_test.go:364: 
Run tests	2024-12-13T17:10:40.9018396Z 	 				/home/runner/work/chainlink/chainlink/core/chains/evm/testutils/client.go:216
Run tests	2024-12-13T17:10:40.9020438Z 	 				/home/runner/work/chainlink/chainlink/core/chains/evm/testutils/client.go:178
Run tests	2024-12-13T17:10:40.9082895Z 	 				/home/runner/work/chainlink/chainlink/core/chains/evm/testutils/client.go:140
Run tests	2024-12-13T17:10:40.9084659Z 	 				/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.linux-amd64/src/net/http/server.go:2220
Run tests	2024-12-13T17:10:40.9086367Z 	 				/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.linux-amd64/src/net/http/server.go:3210
Run tests	2024-12-13T17:10:40.9088042Z 	 				/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.linux-amd64/src/net/http/server.go:2092
Run tests	2024-12-13T17:10:40.9089649Z 	 				/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.linux-amd64/src/runtime/asm_amd64.s:1700
Run tests	2024-12-13T17:10:40.9090307Z 	Error: 	Not equal: 
Run tests	2024-12-13T17:10:40.9090873Z 	 	expected: "eth_subscribe"
Run tests	2024-12-13T17:10:40.9091479Z 	 	actual : "eth_unsubscribe"
Run tests	2024-12-13T17:10:40.9091869Z 	 	
Run tests	2024-12-13T17:10:40.9092254Z 	 	Diff:
Run tests	2024-12-13T17:10:40.9092745Z 	 	--- Expected
Run tests	2024-12-13T17:10:40.9093187Z 	 	+++ Actual
Run tests	2024-12-13T17:10:40.9093985Z 	 	@@ -1 +1 @@
Run tests	2024-12-13T17:10:40.9094438Z 	 	-eth_subscribe
Run tests	2024-12-13T17:10:40.9094905Z 	 	+eth_unsubscribe
Run tests	2024-12-13T17:10:40.9095643Z 	Test: 	TestRPCClient_SubscribeFilterLogs/Subscription_error_is_properly_wrapper
Run tests	2024-12-13T17:10:40.9096162Z rpc_client_test.go:365: 
Run tests	2024-12-13T17:10:40.9097014Z 	Error Trace:	/home/runner/work/chainlink/chainlink/core/chains/evm/client/rpc_client_test.go:365
Run tests	2024-12-13T17:10:40.9098588Z 	 				/home/runner/work/chainlink/chainlink/core/chains/evm/testutils/client.go:216
Run tests	2024-12-13T17:10:40.9099826Z 	 				/home/runner/work/chainlink/chainlink/core/chains/evm/testutils/client.go:178
Run tests	2024-12-13T17:10:40.9101032Z 	 				/home/runner/work/chainlink/chainlink/core/chains/evm/testutils/client.go:140
Run tests	2024-12-13T17:10:40.9102501Z 	 				/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.linux-amd64/src/net/http/server.go:2220
Run tests	2024-12-13T17:10:40.9104033Z 	 				/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.linux-amd64/src/net/http/server.go:3210
Run tests	2024-12-13T17:10:40.9105549Z 	 				/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.linux-amd64/src/net/http/server.go:2092
Run tests	2024-12-13T17:10:40.9107001Z 	 				/home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.linux-amd64/src/runtime/asm_amd64.s:1700
Run tests	2024-12-13T17:10:40.9107597Z 	Error: 	Not equal: 
Run tests	2024-12-13T17:10:40.9108046Z 	 	expected: "logs"
Run tests	2024-12-13T17:10:40.9108503Z 	 	actual : "0x00"
Run tests	2024-12-13T17:10:40.9108838Z 	 	
Run tests	2024-12-13T17:10:40.9109177Z 	 	Diff:
Run tests	2024-12-13T17:10:40.9109580Z 	 	--- Expected
Run tests	2024-12-13T17:10:40.9109990Z 	 	+++ Actual
Run tests	2024-12-13T17:10:40.9110399Z 	 	@@ -1 +1 @@
Run tests	2024-12-13T17:10:40.9110768Z 	 	-logs
Run tests	2024-12-13T17:10:40.9111126Z 	 	+0x00
Run tests	2024-12-13T17:10:40.9111814Z 	Test: 	TestRPCClient_SubscribeFilterLogs/Subscription_error_is_properly_wrapper
Run tests	2024-12-13T17:10:40.9112487Z client.go:233: Sending message: {"jsonrpc":"2.0","id":2,"result":}
Run tests	2024-12-13T17:10:40.9113483Z client.go:159: Received message {"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"invalid character '}' looking for beginning of value"}}
Run tests	2024-12-13T17:10:40.9114047Z 
Run tests	2024-12-13T17:10:40.9114793Z client.go:200: Received jsonrpc error: {"code":-32700,"message":"invalid character '}' looking for beginning of value"}
Run tests	2024-12-13T17:10:40.9115758Z client.go:146: Failed to read message: read tcp 127.0.0.1:42499->127.0.0.1:36348: read: connection reset by peer
Run tests	2024-12-13T17:10:40.9116309Z rpc_client_test.go:382: 
Run tests	2024-12-13T17:10:40.9117149Z 	Error Trace:	/home/runner/work/chainlink/chainlink/core/chains/evm/client/rpc_client_test.go:382
Run tests	2024-12-13T17:10:40.9118535Z 	Error: 	Error "RPCClient returned error (rpc): missing required field 'address' for Log" does not contain "RPCClient returned error (rpc): invalid character"
Run tests	2024-12-13T17:10:40.9119603Z 	Test: 	TestRPCClient_SubscribeFilterLogs/Subscription_error_is_properly_wrapper

Why: The test TestRPCClient_SubscribeFilterLogs failed due to mismatched expected and actual JSON-RPC messages. The test expected "eth_subscribe" and "logs" but received "eth_unsubscribe" and "0x00". Additionally, there was an invalid JSON character error.

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 ✅

aer_workflow , commit

@EasterTheBunny EasterTheBunny force-pushed the etb/toml-custom-fallback branch from 1d753ac to 436023c Compare December 11, 2024 16:59
id := config.ChainID.String()

// add ChainID to set of default IDs
DefaultIDs = append(DefaultIDs, chainID)
Copy link
Contributor

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.

Copy link
Contributor

@jmank88 jmank88 Dec 13, 2024

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()?

@EasterTheBunny EasterTheBunny force-pushed the etb/toml-custom-fallback branch 2 times, most recently from a449414 to f57243d Compare December 13, 2024 16:20
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.
@EasterTheBunny EasterTheBunny force-pushed the etb/toml-custom-fallback branch from f57243d to 4515f8a Compare December 13, 2024 16:21
@EasterTheBunny EasterTheBunny force-pushed the etb/toml-custom-fallback branch from ba58f5c to 2a8f287 Compare December 13, 2024 17:05
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())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, Chain{}, fmt.Errorf("%w %s: %s", errDecode, path, err.Error())
return nil, Chain{}, fmt.Errorf("%w %s: %w", errDecode, path, err)

Comment on lines +35 to +39
// read all default configs
initReadDefaults()

// check for and apply any overrides
initApplyEVMOverrides()
Copy link
Contributor

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

Comment on lines +43 to +47
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")
Copy link
Contributor

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.

Copy link
Contributor

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

Comment on lines +160 to +165
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
Copy link
Contributor

@jmank88 jmank88 Dec 13, 2024

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) {
Copy link
Contributor

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.

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.

4 participants