Skip to content

refactor(feeder): return values instead of pointers from client methods#3774

Open
Ehsan-saradar wants to merge 3 commits into
NethermindEth:mainfrom
Ehsan-saradar:fix/3686-feeder-return-by-value
Open

refactor(feeder): return values instead of pointers from client methods#3774
Ehsan-saradar wants to merge 3 commits into
NethermindEth:mainfrom
Ehsan-saradar:fix/3686-feeder-return-by-value

Conversation

@Ehsan-saradar

@Ehsan-saradar Ehsan-saradar commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Description

Closes #3686.

Makes the clients/feeder Client methods (and the shared doRequest helper) return values instead of pointers, and updates the Reader interface and all call sites accordingly.

What changed

  • doRequest[T, V] now returns (T, error) instead of (*T, error).
  • All Client methods that previously returned *starknet.X now return starknet.X; the Reader interface signatures match.
  • BlockHeader and FeeTokenAddresses, which previously dereferenced the pointer, are simplified to return the doRequest result directly.
  • CasmClassDefinition keeps its deprecated-class semantics: it still signals "no compiled class" via ErrDeprecatedCompiledClass, and consumers pass nil to the adapter on that path instead of relying on a nil pointer return.
  • Consumers updated to take the address locally where a pointer is still required: the starknetdata/feeder adapter, the rpc/v8|v9|v10 trace/transaction handlers, and the affected tests.
  • mocks/mock_feeder.go regenerated.

Notes

  • PublicKey now also returns felt.Felt by value (changed during review — it originally kept the pointer return, but there was no reason for the exception). PreConfirmedBlockWithIdentifier still returns the starknet.PreConfirmedUpdate interface, which is unchanged.

Testing

  • golangci-lint (diff + full): clean
  • make lint: pass
  • go test ./...: pass

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
@Ehsan-saradar Ehsan-saradar marked this pull request as ready for review July 1, 2026 05:21
Copilot AI review requested due to automatic review settings July 1, 2026 05:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 doRequest and clients/feeder Client/Reader methods to return value types (with local &value taken where pointers are still required).
  • Adjusted starknetdata/feeder adapter and RPC trace/transaction handlers to pass addresses to existing adapter functions.
  • Regenerated mocks/mock_feeder.go and 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.

Comment thread clients/feeder/request.go
Comment on lines 34 to 44
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),
)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 rodrodros left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, two small comments and good to merge

Comment thread clients/feeder/feeder.go Outdated
body, err := c.get(ctx, queryURL)
if err != nil {
return nil, err
return class, err

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

return default values by returning starknet.CasmClass{}. Please apply this to all the methods that return by value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread clients/feeder/feeder.go Outdated
return doRequest[starknet.FeeTokenAddresses](ctx, c, queryURL)
}

func (c *Client) PublicKey(ctx context.Context) (*felt.Felt, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This one should return by value too, is it possible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • mocks/mock_feeder.go: Generated file

Comment thread clients/feeder/feeder.go
Comment on lines 55 to +63
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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • mocks/mock_feeder.go: Generated file

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.

Make clients/feeder/feeder.go methods return by value instead of pointers

3 participants