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

Fix parity between local blockchain and network APIs #1422

Merged
merged 63 commits into from
Feb 21, 2024

Conversation

MartinMinkov
Copy link
Contributor

@MartinMinkov MartinMinkov commented Feb 8, 2024

…o PendingTransaction

A simple rename from `TransactionId` to `PendingTransaction`. This
rename provides better clarity on what is returned after sending a
transaction.
PendingTransaction adds the `data` and `errors` property in the Network
version. We now specify the properties inside `PendingTransaction` by
making data be return type of sendZkApp which is a `SendZkAppResponse`.

Also, this fixes a current bug where the `txnId` can be undefined when
executing the polling for requests.
…ta from any block at the best tip

This change was made because the issue o1-labs/Archive-Node-API#7 has been resolved, making the temporary fix redundant.
Adds graphql.ts which is a module to hold all response type and graphql
query resources when interacting with the mina daemon graphql. We remove
these from fetch.ts as fetch was starting to get bloated and harder to
read. This aims to be a refactor that offers a cleaner seperation of
concerns between the graphql resources and the actual requests being
sent
…at have been included in the blockchain

This new type extends the PendingTransaction type with an additional 'isIncluded' boolean property. This will allow us to easily distinguish between pending and included transactions in our code.
@dfstio
Copy link

dfstio commented Feb 11, 2024

Can you please also check #1426 and #1427

@mitschabaude
Copy link
Collaborator

Can you please also check #1426 and #1427

These are issues to be fixed for sure, but neither of them is in scope for this PR imo

This method sends the Transaction to the network and throws an error if internal errors are detected. This provides a more robust way of handling transaction failures.
…unt-update.js' to maintain file naming consistency
…and accountQuery from account.ts to graphql.ts
…SlotResponse type to fetch current slot data from the server

This change allows the application to fetch the current slot data from the server, which is necessary for the application's functionality.
This commit introduces a new test suite for the zkApp transaction flow. The tests cover various scenarios including local and remote tests, transaction verification, zkApp deployment, method calls, event emission and fetching, and action rollups. The tests are designed to ensure the correct behavior of the zkApp and its interaction with the Mina protocol.
@@ -20,6 +35,11 @@ export {
activeInstance,
setActiveInstance,
ZkappStateLength,
reportGetAccountError,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved these methods here as they are shared between local-blockchain and remote

Copy link
Collaborator

Choose a reason for hiding this comment

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

hm, so this is not ideal, because it (re)creates a dependency cycle between this module and account-update.ts.
maybe add yet another new module with the methods you added here - something like validate-transaction.ts or transaction-validation.ts?

Copy link
Collaborator

@mitschabaude mitschabaude left a comment

Choose a reason for hiding this comment

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

This is fantastic work, huge step towards v1 readiness!

I have a few comments that I think need addressing

@@ -20,6 +35,11 @@ export {
activeInstance,
setActiveInstance,
ZkappStateLength,
reportGetAccountError,
Copy link
Collaborator

Choose a reason for hiding this comment

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

hm, so this is not ideal, because it (re)creates a dependency cycle between this module and account-update.ts.
maybe add yet another new module with the methods you added here - something like validate-transaction.ts or transaction-validation.ts?

src/lib/mina.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's so much cleaner with this file broken up into digestible pieces!

src/lib/fetch.ts Show resolved Hide resolved
src/lib/mina/errors.ts Outdated Show resolved Hide resolved
src/lib/mina/errors.ts Outdated Show resolved Hide resolved
src/lib/mina/local-blockchain.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,291 @@
import {
Copy link
Collaborator

Choose a reason for hiding this comment

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

great that you added this!

…etter readability and performance

fix(run-live.ts): correct the usage of hash in console.log statements to ensure accurate transaction hash display
if (accountUpdateErrors.length === n) {
let errorsForFeePayer = errors[0];
if (errors.length > n) {
let errorsForFeePayer = errors.shift() ?? [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

damn I always mix up shift and unshift

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not the best naming imo :P

Copy link
Collaborator

@mitschabaude mitschabaude left a comment

Choose a reason for hiding this comment

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

From my side, this only needs a changelog entry and then it's good to go!

- Add fix for parity between `Mina.LocalBlockchain` and `Mina.Network` to ensure consistent behaviors
- Include changes to `TransactionId`, `transaction.send()`, and `transaction.wait()` for better error handling and transaction state representation
…ina.ts to mina-instance.ts for better code organization and maintainability
…ction

The changes related to transaction handling in `Mina.LocalBlockchain` and `Mina.Network` are significant and can potentially break existing implementations. Therefore, they have been moved from the 'Fixed' section to a new 'Breaking changes' section to highlight their importance and potential impact.
@MartinMinkov MartinMinkov merged commit b2639e8 into main Feb 21, 2024
13 checks passed
@MartinMinkov MartinMinkov deleted the feat/transaction-flow-txn-type branch February 21, 2024 21:16
- Changed the `TransactionId` type to `Transaction`. Additionally added `PendingTransaction` and `RejectedTransaction` types to better represent the state of a transaction.
- `transaction.send()` no longer throws an error if the transaction was not successful for `Mina.LocalBlockchain` and `Mina.Network`. Instead, it returns a `PendingTransaction` object that contains the error. Use `transaction.sendOrThrowIfError` to throw the error if the transaction was not successful.
- `transaction.wait()` no longer throws an error if the transaction was not successful for `Mina.LocalBlockchain` and `Mina.Network`. Instead, it returns either a `IncludedTransaction` or `RejectedTransaction`. Use `transaction.waitOrThrowIfError` to throw the error if the transaction was not successful.
- `transaction.hash()` is no longer a function, it is now a property that returns the hash of the transaction.
Copy link
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants