refactor(paymaster): paymaster component as a tower layer#195
Open
refactor(paymaster): paymaster component as a tower layer#195
Conversation
944d536 to
0881ed6
Compare
54b5ee7 to
53bcec8
Compare
ecbaf09 to
37c9a36
Compare
e3bd68b to
e897bbb
Compare
37c9a36 to
0aa1f33
Compare
8dbe0d5 to
8ba4471
Compare
8ba4471 to
3a3ad78
Compare
Collaborator
|
I rebased this PR + fixed tests / clippy. I updated the PR description to give some details about the implementation and some points to check/clarify/confirm. I also squashed commits to ease review and rebase 😅 I kept the first commit (the tower layer setup from @kariy) and the second commit (what I added). I just see that a new rebase is needed. I will try to do it tomorrow... |
Member
Author
Collaborator
Hey @kariy, yes, I just discovered this refactor this morning. Yes, it will be more efficient if you can rebase it 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Instead of having Cartridge paymaster and VRF management strongly linked to Katana node/rpc, this PR implements paymaster/vrf as a tower layer of the Katana RPC server (i.e as a an optional middleware).
This tower layer is injected in the Katana RPC server when the cartridge feature is enabled.
The layer handles 2 enpoints:
starknet_estimateFeecartridge_addExecuteOutsideTransactionThe global mechanism is almost the same for
estimateFeeandaddExecuteOutsideTransaction. Each time one this endpoint is called, we check if:request_randomas first call. If yes, we just transform the call list to [VRFsubmit_randomcall, original calls, VRFassert_consumedcall].But there are some specificities to clarify/confirm:
when Katana is launched with
-dev --dev.no-fee,starknet_estimateFeestill returns a non-zero fee estimation. So, when we want to deploy/upgrade the controller account, the Cartridge controller UI shows a message telling the user to add funds to its controller account. But the user should be able to upgrade without any fee. To patch that, at the moment, the paymaster layer uses abuild_no_fee_response()function to return zero fee.=> this point should be clarify.
when
cartridge_addExecuteOutsideTransaction()is called, a signature built in the Cartridge controller UI is provided. In the normal flow (without the paymaster layer), thisoutside_execution + signatureinput data is converted into an invoke transactionexecute_from_outside_vXwhere the calldata are just the serialized outside_execution joined with the serialized signature.In the paymaster layer, in case of VRF
request_randomcall, we have to modify theoutside_executionto inject 2 VRF calls (submit_randomandassert_consumed) and so, we should generate another signature. The thing is that the signature format is not just a classic [r, s, v] signature. So, at the end, to avoid having to generate a new signature, I decided to return an empty signature and use the outside_execution as a way to the call vector to use to build the final invoke tx. So, in cartridge/rpc, you will see a specific process when the signature is empty.To validate this PR, I create a tiny web app with the Cartridge controller:
contractsfolder, using scripts),pnpm run dev,