Fix backward-compatiblity of GraphQL queries for pre-0.48.0 versions#3258
Fix backward-compatiblity of GraphQL queries for pre-0.48.0 versions#3258
Conversation
PR SummaryMedium Risk Overview Introduces legacy GraphQL fragments/queries for Reviewed by Cursor Bugbot for commit df92d81. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7c2136c. Configure here.
| *lock = Some(version.clone()); | ||
| } | ||
| Ok(version) | ||
| } |
There was a problem hiding this comment.
Stale cached node version after failover breaks compatibility
Medium Severity
The node_version cache in ensure_node_version is written once and never refreshed, unlike current_stf_version and current_consensus_parameters_version which are updated on every response via update_chain_state_info. If FailoverTransport switches to a node with a different version, the stale cached version causes the wrong query variant to be sent. Failing over from a 0.48.0+ node to a pre-0.48.0 node would reproduce the exact "Unknown field" error this PR intends to fix.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 7c2136c. Configure here.
| .into(), | ||
| ) | ||
| } | ||
| } |
There was a problem hiding this comment.
Legacy ScriptParameters conversion skips version validation
Low Severity
TryFrom<ScriptParametersLegacy> unconditionally creates ScriptParametersV1 without checking params.version, unlike every other TryFrom in this file (TxParameters, PredicateParameters, ContractParameters, FeeParameters, ConsensusParametersLegacy, GasCostsLegacy) which all validate the version and return ConversionError::UnknownVariant on mismatch. This inconsistency means an unexpected version value is silently accepted instead of producing a clear error.
Reviewed by Cursor Bugbot for commit 7c2136c. Configure here.


Description
Connecting
FuelClientto a node running v0.47.x causes an error since the GraphQL query parameters mismatch. Again I'd like to mention that this is caused by the way we abuse GraphQL: it really should be only used to query the fields we actually need andFuelClientis an abomination.This PR adds a mechanism to query node version first and then performs old versions of queries when needed. We cache
node_versioninChainStateInfo.Note that this PR only does this for pre-0.48.0 versions, calling them
Legacyversions. A more generic naming schema might be needed in the future if new breaking changes are done. The current one shall suffice for now. It also adds snapshot tests for the fields to prevent this issue in the future.Trade-offs
An extra round-trip is required on the first call to
chain_info()orconsensus_parameters()against a node of either version, since the node version must be fetched before we know which query to send. Subsequent calls within the sameFuelClientinstance pay no extra cost.Checklist
Before requesting review