Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: TransactionRequest FPI support #560

Open
wants to merge 3 commits into
base: igamigo-acc-state-endpoint
Choose a base branch
from

Conversation

igamigo
Copy link
Collaborator

@igamigo igamigo commented Oct 24, 2024

Closes #530

@igamigo igamigo force-pushed the igamigo-fpi branch 3 times, most recently from c58ce85 to 110ec0d Compare October 25, 2024 15:07
@igamigo igamigo marked this pull request as ready for review October 25, 2024 15:07
@igamigo
Copy link
Collaborator Author

igamigo commented Oct 25, 2024

The test is blocked by 0xPolygonMiden/miden-base#934, but otherwise this PR can be reviewed

@bobbinth
Copy link
Contributor

I've merged 0xPolygonMiden/miden-base#936. We should update this PR to use this new method.

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Thank you! Looks good! Not a full review, but I left some comments inline.

I think the biggest thing is to make sure we load account code into the executor based on the changes in 0xPolygonMiden/miden-base#936.

crates/rust-client/src/transactions/request.rs Outdated Show resolved Hide resolved
crates/rust-client/src/transactions/request.rs Outdated Show resolved Hide resolved
crates/rust-client/src/transactions/mod.rs Outdated Show resolved Hide resolved

for account_proof in account_proofs.into_iter() {
let account_header = account_proof.account_header().ok_or_else(|| {
ClientError::RpcError(RpcError::ExpectedDataMissing("AccountHeader".to_string()))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it feels a bit weird to return RPC errors from here - but I guess we do this in quite a few places.

Not for this PR, but I'd probably have a specialized endpoint in NodeRpcClient - e.g., something like get_foreign_account_data() which would internally call get_account_proofs() and would map the response to something like ForeignAccountData structs which don't require this type of validation here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, I'll create an issue before merging.

* Allow to set expiration delta for `TransactionRequest` (#553).
* Implemented `GetAccountProof` endpoint (#556)
* Implemented `GetAccountProof` endpoint (#556).
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this change accidentally got duplicated in the merge

Cargo.toml Outdated Show resolved Hide resolved
tx_args.extend_merkle_store(store.inner_nodes());
foreign_account_codes
.iter()
.for_each(|(_, code)| self.tx_executor.load_account_code(code));
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are permanently mutating the tx_executor here. Wouldn't it be a problem for the executor to have old account code in subsequent executions?

Comment on lines +279 to +286
// Inject foreign account data
let (foreign_data_advice_inputs, foreign_account_codes) = self
.get_foreign_account_inputs(transaction_request.foreign_account_data())
.await?;
let mut tx_args = transaction_request.into_transaction_args(tx_script);
let AdviceInputs { map, store, .. } = foreign_data_advice_inputs;
tx_args.extend_advice_map(map);
tx_args.extend_merkle_store(store.inner_nodes());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like this part should be in TransactionRequest::into_transaction_args but I just realized get_foreign_account_inputs does an rpc call so it would be strange. Maybe we could receive the foreign data advice inputs in with_foreign_public_accounts instead of retrieving it inside new_transaction.

We could even store and expose the account codes so that we don't have to repeat the rpc call when loading the code to the executor.

Copy link
Collaborator Author

@igamigo igamigo Oct 31, 2024

Choose a reason for hiding this comment

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

The RPC call is for more than the account code so we probably cannot avoid it. Also, the endpoint has a mechanism for passing last-known account codes for the requested Account IDs (I added a TODO for this, will create an issue before merging).
Retrieving the foreign account data outside of new_transaction is not really an option because it's relevant only at execution time (ie, if I am some service that serializes a TransactionRequest so that you execute it, it makes sense that you retrieve fresh data when you execute)

let tx = client
.new_transaction(
foreign_account_id,
TransactionRequest::new().with_custom_script(deployment_tx_script).unwrap(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the with_custom_script isn't needed here. If no script or own notes are specified to the TransactionRequest then the script will only have the auth call, like the custom script we created here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, good catch, thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, while it does default to the script, it is built with the assumption that you are consuming notes, which is not the case here so it would error.

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.

3 participants