refactor(feeder): return values instead of pointers from client methods#3774
refactor(feeder): return values instead of pointers from client methods#3774Ehsan-saradar wants to merge 3 commits into
Conversation
Change doRequest and the feeder Client methods to return values rather than pointers, and update the Reader interface and all call sites accordingly. Callers that adapt the responses now take the address locally where a pointer is still required. Closes NethermindEth#3686
There was a problem hiding this comment.
Pull request overview
Refactors the clients/feeder API (and downstream adapters/callers) to return Starknet response structs by value instead of pointers, updating the Reader interface and all affected call sites/tests accordingly.
Changes:
- Updated
doRequestandclients/feederClient/Readermethods to return value types (with local&valuetaken where pointers are still required). - Adjusted
starknetdata/feederadapter and RPC trace/transaction handlers to pass addresses to existing adapter functions. - Regenerated
mocks/mock_feeder.goand updated tests to assert on zero/non-zero values instead of nil/non-nil pointers.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
starknetdata/feeder/feeder.go |
Adapts to feeder client value returns; takes addresses when calling sn2core adapters; preserves deprecated CASM semantics via nil CASM pointer. |
starknetdata/feeder/feeder_test.go |
Updates adapter test expectations to pass &response and handle optional CASM via *starknet.CasmClass. |
starknet/compiler/compiler_test.go |
Updates compiled-class adaptation call to pass &compiledDef. |
rpc/v9/transaction.go |
Passes &txStatus into status adapter after client returns a value. |
rpc/v9/trace.go |
Passes &blockTrace into trace adapter after client returns a value. |
rpc/v8/transaction.go |
Same as v9: uses &txStatus for adaptation. |
rpc/v8/trace.go |
Same as v9: uses &blockTrace for adaptation. |
rpc/v10/transaction.go |
Same as v9: uses &txStatus for adaptation. |
rpc/v10/trace.go |
Same as v9: uses &blockTrace for adaptation. |
mocks/mock_feeder.go |
Regenerated gomock for Reader interface now returning values. |
consensus/p2p/validator/fixtures_test.go |
Updates fixture builder to pass &rawStateUpdate to helpers expecting pointers. |
clients/feeder/request.go |
Changes doRequest to return (T, error) rather than (*T, error). |
clients/feeder/feeder.go |
Updates Reader interface + Client methods to return values; simplifies methods that previously dereferenced doRequest pointers. |
clients/feeder/feeder_test.go |
Updates tests to use assert.Zero/assert.NotZero due to value returns. |
adapters/sn2core/sn2core_test.go |
Updates adapter tests to pass &response / &compiled as needed. |
Files not reviewed (1)
- mocks/mock_feeder.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if err = json.NewDecoder(body).Decode(&result); err != nil { | ||
| return nil, err | ||
| return result, err | ||
| } | ||
|
|
||
| err = V(&result).Validate() | ||
| if err != nil { | ||
| return nil, errors.Join( | ||
| return result, errors.Join( | ||
| ErrInvalidFeederResponse, | ||
| fmt.Errorf("querying %s: %w", fullURL, err), | ||
| ) | ||
| } |
There was a problem hiding this comment.
Good catch, fixed. Now returning the zero value of T on both the decode and validation error paths so callers can never get partial data back.
Avoid returning partially decoded or validation-failed data alongside a non-nil error so callers cannot accidentally consume invalid responses.
rodrodros
left a comment
There was a problem hiding this comment.
LGTM, two small comments and good to merge
| body, err := c.get(ctx, queryURL) | ||
| if err != nil { | ||
| return nil, err | ||
| return class, err |
There was a problem hiding this comment.
return default values by returning starknet.CasmClass{}. Please apply this to all the methods that return by value
There was a problem hiding this comment.
Done — all error paths now return starknet.CasmClass{}. For the doRequest-based methods the helper itself returns the zero value of T on every error path, so this is consistent across all value-returning methods.
| return doRequest[starknet.FeeTokenAddresses](ctx, c, queryURL) | ||
| } | ||
|
|
||
| func (c *Client) PublicKey(ctx context.Context) (*felt.Felt, error) { |
There was a problem hiding this comment.
This one should return by value too, is it possible?
There was a problem hiding this comment.
Done — changed PublicKey to return felt.Felt by value (returns felt.Felt{} on the error path).
- CasmClassDefinition returns starknet.CasmClass{} literal on error paths
- PublicKey returns felt.Felt by value instead of *felt.Felt
| PreConfirmedBlockWithIdentifier( | ||
| ctx context.Context, | ||
| blockNumber string, | ||
| blockIdentifier string, | ||
| knownTransactionCount uint64, | ||
| ) (starknet.PreConfirmedUpdate, error) | ||
| PublicKey(ctx context.Context) (*felt.Felt, error) | ||
| Signature(ctx context.Context, blockID string) (*starknet.Signature, error) | ||
| StateUpdate(ctx context.Context, blockID string) (*starknet.StateUpdate, error) | ||
| StateUpdateWithBlock(ctx context.Context, blockID string) (*starknet.StateUpdateWithBlock, error) | ||
| PublicKey(ctx context.Context) (felt.Felt, error) | ||
| Signature(ctx context.Context, blockID string) (starknet.Signature, error) | ||
| StateUpdate(ctx context.Context, blockID string) (starknet.StateUpdate, error) |
There was a problem hiding this comment.
Good catch — the description was stale. The change to PublicKey is intentional (requested during review), so I've updated the PR description to match the code.
Description
Closes #3686.
Makes the
clients/feederClientmethods (and the shareddoRequesthelper) return values instead of pointers, and updates theReaderinterface and all call sites accordingly.What changed
doRequest[T, V]now returns(T, error)instead of(*T, error).Clientmethods that previously returned*starknet.Xnow returnstarknet.X; theReaderinterface signatures match.BlockHeaderandFeeTokenAddresses, which previously dereferenced the pointer, are simplified to return thedoRequestresult directly.CasmClassDefinitionkeeps its deprecated-class semantics: it still signals "no compiled class" viaErrDeprecatedCompiledClass, and consumers passnilto the adapter on that path instead of relying on a nil pointer return.starknetdata/feederadapter, therpc/v8|v9|v10trace/transaction handlers, and the affected tests.mocks/mock_feeder.goregenerated.Notes
PublicKeynow also returnsfelt.Feltby value (changed during review — it originally kept the pointer return, but there was no reason for the exception).PreConfirmedBlockWithIdentifierstill returns thestarknet.PreConfirmedUpdateinterface, which is unchanged.Testing
golangci-lint(diff + full): cleanmake lint: passgo test ./...: pass