Skip to content

Conversation

thiagodeev
Copy link
Collaborator

@thiagodeev thiagodeev commented Oct 13, 2025

Part 2 of the effort to break down the Paymaster PR for better review.

This PR:

  • implement the paymaster_buildTransaction method
  • new test helpers

@thiagodeev thiagodeev changed the title Paymster-pr-2 Paymaster PR 2: add paymaster_buildTransaction method + tests Oct 13, 2025
@thiagodeev thiagodeev marked this pull request as ready for review October 13, 2025 19:41
Copy link
Contributor

@rodrigo-pino rodrigo-pino left a comment

Choose a reason for hiding this comment

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

Initial quick scan.

Please set escape analysis in your editor so you are aware of variables that escape to heap

Copy link
Contributor

@rodrigo-pino rodrigo-pino left a comment

Choose a reason for hiding this comment

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

Pre-liminary review. The code looks correct, but inefficient.

It was done with no regard for resource usage, such as memory, and it should improve in that regard.

The main resource hog is using string enum values which is unnecessary. Logic changes have to be done to make sure they are cleaned from the rest of the code.

Small resource usage in one function returning by reference, when it should return by value.

Finally, there are types that hold references to other types. This creates double indirection and might make the GC work more. Nonetheless, it is not straightforward to me in this first review whether those are wrong or right. We can discuss the details of this in the next daily

Comment on lines +326 to +377
type FeeEstimate struct {
GasTokenPriceInStrk *felt.Felt `json:"gas_token_price_in_strk"`
EstimatedFeeInStrk *felt.Felt `json:"estimated_fee_in_strk"`
EstimatedFeeInGasToken *felt.Felt `json:"estimated_fee_in_gas_token"`
SuggestedMaxFeeInStrk *felt.Felt `json:"suggested_max_fee_in_strk"`
SuggestedMaxFeeInGasToken *felt.Felt `json:"suggested_max_fee_in_gas_token"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all of these fields optional, or are some of them optional?

@rodrigo-pino
Copy link
Contributor

@thiagodeev why is this not targetting main?

// - error: An error if the request fails
func (p *Paymaster) BuildTransaction(
ctx context.Context,
request BuildTransactionRequest,
Copy link
Contributor

Choose a reason for hiding this comment

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

Pass request by reference, please. There is no need to copy the entire value every time this function is called.

if err := p.c.CallContextWithSliceArgs(
ctx, &response, "paymaster_buildTransaction", request,
); err != nil {
return response, rpcerr.UnwrapToRPCErr(
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 is better to return a default value

return BuildTransactionResponse{}, rpcerr....

The same way you return nil on an error when returning a reference, you return the default zero value in this case

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But if there's an error, the var response will be the zero value

Comment on lines +131 to +138
// An enum representing the Cairo version of the account contract
// to be deployed. Cairo 0 is not supported.
type CairoVersion int

const (
// Represents the Cairo 1 version
Cairo1 CairoVersion = 1
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have an enum of just one variant? If it is just one variant then is redundant holding information of it as far as I can see

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm just following the snip. Since it says it's an enum, I believe it's better to leave it as is.
https://github.com/starknet-io/SNIPs/blob/906b19074038005dc26d3574b6853a7c68d14e02/assets/snip-29/paymaster_api.json#L1128

Comment on lines +174 to +180
// An enum representing the version of the execution parameters
type UserParamVersion int

const (
// Represents the v1 of the execution parameters ("0x1")
UserParamV1 UserParamVersion = iota + 1
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment regarding this, are there more versions planned? Can you share the source?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the snip-29 API spec.
It's an enum with a single option

@github-project-automation github-project-automation bot moved this to 👀 In review in [Nubia] Starknet.go Oct 21, 2025
@thiagodeev thiagodeev merged commit 62e6749 into temp-paymaster-branch Oct 21, 2025
8 checks passed
@thiagodeev thiagodeev deleted the paymster-pr-2 branch October 21, 2025 19:03
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in [Nubia] Starknet.go Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants