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(sozo): add --receipt transaction option #1647

Merged
merged 3 commits into from
Mar 14, 2024

Conversation

remybar
Copy link
Contributor

@remybar remybar commented Mar 11, 2024

Related to DOJ-215, #1627.

Modify the --wait transaction option to show the execution status and the transaction hash only.
Then, add the --receipt transaction option to be used with the --wait flag to show the full
receipt after the transaction execution.

Copy link

codecov bot commented Mar 11, 2024

Codecov Report

Attention: Patch coverage is 9.43396% with 48 lines in your changes are missing coverage. Please review.

Project coverage is 69.54%. Comparing base (ae8db10) to head (840b628).
Report is 1 commits behind head on main.

Files Patch % Lines
bin/sozo/src/utils.rs 0.00% 27 Missing ⚠️
bin/sozo/src/ops/auth.rs 0.00% 9 Missing ⚠️
crates/dojo-world/src/utils.rs 0.00% 8 Missing ⚠️
bin/sozo/src/ops/register.rs 0.00% 2 Missing ⚠️
bin/sozo/src/commands/options/transaction.rs 0.00% 1 Missing ⚠️
bin/sozo/src/ops/execute.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1647      +/-   ##
==========================================
- Coverage   69.59%   69.54%   -0.06%     
==========================================
  Files         266      267       +1     
  Lines       27312    27339      +27     
==========================================
+ Hits        19009    19013       +4     
- Misses       8303     8326      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@kariy kariy left a comment

Choose a reason for hiding this comment

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

hmmm i don't quite like having --wait-no-receipt flag to handle this case... much prefer if we have a --receipt flag and choose whether to print out the receipt based on that instead.

@glihm any idea?

@remybar
Copy link
Contributor Author

remybar commented Mar 11, 2024

hmmm i don't quite like having --wait-no-receipt flag to handle this case... much prefer if we have a --receipt flag and choose whether to print out the receipt based on that instead.

@glihm any idea?

Yes, good idea 👍
But that means the --wait flag won't show the receipt anymore. I think it's not a big deal except if an user uses the actual output to do something :)

@glihm
Copy link
Collaborator

glihm commented Mar 11, 2024

hmmm i don't quite like having --wait-no-receipt flag to handle this case... much prefer if we have a --receipt flag and choose whether to print out the receipt based on that instead.

--receipt => 💯

But that means the --wait flag won't show the receipt anymore. I think it's not a big deal except if an user uses the actual output to do something :)

Yup, this is I think the intention of Val, not having too much information by default. Somehow, when polling explicitly a transaction with sozo, it's good to have details. But as the TransactionOptions may be used in a command that already generates several prints, having a short representation by default is better.

bin/sozo/src/utils.rs Outdated Show resolved Hide resolved
@remybar
Copy link
Contributor Author

remybar commented Mar 11, 2024

hmmm i don't quite like having --wait-no-receipt flag to handle this case... much prefer if we have a --receipt flag and choose whether to print out the receipt based on that instead.

--receipt => 💯

But that means the --wait flag won't show the receipt anymore. I think it's not a big deal except if an user uses the actual output to do something :)

Yup, this is I think the intention of Val, not having too much information by default. Somehow, when polling explicitly a transaction with sozo, it's good to have details. But as the TransactionOptions may be used in a command that already generates several prints, having a short representation by default is better.

Ok, thanks !

For you @glihm and @kariy, to wait and see the receipt we just pass --receipt or we have to pass --wait also ? I mean, is --receipt means "wait and show the receipt" or is it just a flag for the --wait option to show the receipt instead of a short status and hash ?

@glihm
Copy link
Collaborator

glihm commented Mar 12, 2024

For you @glihm and @kariy, to wait and see the receipt we just pass --receipt or we have to pass --wait also ? I mean, is --receipt means "wait and show the receipt" or is it just a flag for the --wait option to show the receipt instead of a short status and hash ?

In the current proposal, I would say:

  1. User has to pass --wait to explicitly wait the transaction.
  2. If --receipt is passed along with --wait, then the receipt is printed.
  3. --receipt without --wait will have no effect, at least for now.

@remybar remybar changed the title feat: add --wait-no-receipt transaction option feat: add --receipt transaction option Mar 12, 2024
Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for the update @remybar! Will let @kariy confirming the final review. 👍

@kariy
Copy link
Member

kariy commented Mar 12, 2024

In the current proposal, I would say:

  1. User has to pass --wait to explicitly wait the transaction.
  2. If --receipt is passed along with --wait, then the receipt is printed.
  3. --receipt without --wait will have no effect, at least for now.

Yes, this is good.

Copy link
Member

@kariy kariy left a comment

Choose a reason for hiding this comment

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

Looks good. I've added some suggestions on what to print if the --wait flag is set without --receipt.

bin/sozo/src/commands/options/transaction.rs Outdated Show resolved Hide resolved
bin/sozo/src/utils.rs Outdated Show resolved Hide resolved
@remybar
Copy link
Contributor Author

remybar commented Mar 13, 2024

Hi @glihm and @kariy !

I tried to test with a reverted transaction to see how the log looks like but I was not able to get a reverted transaction 😅

I changed the grant_writer function in world.cairo to call panic! but the error is directly catched there, with the error "Failed to send transaction" ...

let res = account
.execute(calls)
.send()
.await
.with_context(|| "Failed to send transaction")?;

I also tried to add a loop before the call to panic! to have a function which takes some times but it does not work.

Any idea ?

@glihm
Copy link
Collaborator

glihm commented Mar 13, 2024

Hi @glihm and @kariy !

I tried to test with a reverted transaction to see how the log looks like but I was not able to get a reverted transaction 😅

I changed the grant_writer function in world.cairo to call panic! but the error is directly catched there, with the error "Failed to send transaction" ...

let res = account
.execute(calls)
.send()
.await
.with_context(|| "Failed to send transaction")?;

I also tried to add a loop before the call to panic! to have a function which takes some times but it does not work.

Any idea ?

Ah yes.. this is because of the fee estimation.
When we don't give a fix max_fee, starknet-rs is attempting to estimate the fee first. And doing so, the execution fails, and we got an error instead of the transaction hash.

If you want to see the output as expected, you can do that for instance:

let res = account
  .execute(vec![Call {
      calldata,
      to: contract_address,
      selector: get_selector_from_name(&entrypoint)?,
}])
.max_fee(starknet::core::types::FieldElement::from_hex_be("0xfffffffffffffffffffffff").unwrap())
.send()
.await?;

And here you'll have the expected output.

@kariy should we add to the TransactionOptions a max_fee field actually?
@remybar if the estimation of the fee fails, there's no transaction at all, hence the text you've seen with Failed to send transaction.

@remybar
Copy link
Contributor Author

remybar commented Mar 13, 2024

After some tests, I think the following format is more convenient for all the possible cases. What do you think ?

Without flags:

Transaction hash: 0x5ef861cc4b1e451febb614b0792c5ba81d94931df99e1d4ba2841d51e2d1f1f

With --wait:

Transaction hash: 0x5ef861cc4b1e451febb614b0792c5ba81d94931df99e1d4ba2841d51e2d1f1f
Status: OK
Transaction hash: 0x5ef861cc4b1e451febb614b0792c5ba81d94931df99e1d4ba2841d51e2d1f1f
Status: REVERTED
Reason:
Error in the called contract (0x06162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03):
Error at pc=0:4573:
Got an exception while executing a hint: Hint Error: Requested contract address ContractAddress(PatriciaKey(StarkFelt("0x01385f25d20a724edc9c7b3bd9636c59af64cbaf9fcd12f33b3af96b2452f295"))) is not deployed.

With --wait --receipt:

Transaction hash: 0x5ef861cc4b1e451febb614b0792c5ba81d94931df99e1d4ba2841d51e2d1f1f
Receipt:
{
...
}

@kariy
Copy link
Member

kariy commented Mar 13, 2024

After some tests, I think the following format is more convenient for all the possible cases. What do you think ?

Without flags:

Transaction hash: 0x5ef861cc4b1e451febb614b0792c5ba81d94931df99e1d4ba2841d51e2d1f1f

With --wait:

Transaction hash: 0x5ef861cc4b1e451febb614b0792c5ba81d94931df99e1d4ba2841d51e2d1f1f
Status: OK
Transaction hash: 0x5ef861cc4b1e451febb614b0792c5ba81d94931df99e1d4ba2841d51e2d1f1f
Status: REVERTED
Reason:
Error in the called contract (0x06162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03):
Error at pc=0:4573:
Got an exception while executing a hint: Hint Error: Requested contract address ContractAddress(PatriciaKey(StarkFelt("0x01385f25d20a724edc9c7b3bd9636c59af64cbaf9fcd12f33b3af96b2452f295"))) is not deployed.

i like this formats, these look good.

With --wait --receipt:

Transaction hash: 0x5ef861cc4b1e451febb614b0792c5ba81d94931df99e1d4ba2841d51e2d1f1f
Receipt:
{
...
}

maybe we don't need to show the tx hash because the receipt already includes it

@kariy
Copy link
Member

kariy commented Mar 13, 2024

@remybar there's a conflict now that #1644 is merged

EDIT: wrong PR

Modify the `--wait` transaction option to show execution status and transaction hash only.
Then, add the --receipt transaction option to be used with the --wait flag to show the full
receipt after the transaction execution.
@remybar
Copy link
Contributor Author

remybar commented Mar 13, 2024

maybe we don't need to show the tx hash because the receipt already includes it

I would keep the same format for all the cases, even if the tx hash is already in the receipt. If you want to get the tx hash, you can copy/paste it really quickly whatever the given flags. What do you think ? If you strongly want to remove it when we display the full receipt, I do it :)

Another argument is that when you provide --wait --receipt you immediately see the tx hash and, if the tx takes time, you will see the full receipt some seconds/minutes after.

@kariy
Copy link
Member

kariy commented Mar 13, 2024

Another argument is that when you provide --wait --receipt you immediately see the tx hash and, if the tx takes time, you will see the full receipt some seconds/minutes after.

Ah I agree, this does seems nice...

Copy link
Member

@kariy kariy left a comment

Choose a reason for hiding this comment

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

I think this looks good, I just have one last request and then we're good.

bin/sozo/src/utils.rs Outdated Show resolved Hide resolved
Co-authored-by: Ammar Arif <evergreenkary@gmail.com>
@kariy kariy changed the title feat: add --receipt transaction option feat(sozo): add --receipt transaction option Mar 13, 2024
Copy link
Member

@kariy kariy left a comment

Choose a reason for hiding this comment

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

nice work, thanks!

@kariy
Copy link
Member

kariy commented Mar 13, 2024

@remybar there's conflicts now due to #1576 🙏

@glihm glihm merged commit 6f72e33 into dojoengine:main Mar 14, 2024
10 of 12 checks passed
glihm added a commit that referenced this pull request Mar 25, 2024
* fix: handle primitive and custom types for enum introspect (#1643)

The function `handle_introspect_enum` handles the derive Introspect attribute for an enum.
At the moment, two cases are supported: tuples and type paths.

A type path may be a primitive type or a custom type (struct or enum).
A tuple may be composed of primitive and/or custom types.

This PR updates the function `handle_introspect_enum` to handle all these cases properly.

* fix: remove old reference to submodule (#1612)

* fix: remove old reference to submodule

* Update submodule

* Will this now work?

* Removed old files

* Correctly updated gitmodules

* chore: update forge std

---------

Co-authored-by: glihm <dev@glihm.net>

* fix(sozo): ensure warnings don't stop tests build (#1648)

* fix: ensure warnings are not blocking the test build

* fix: update default world address for spawn and move example

* fix: [torii/graphql] Added timezone information to timestamps strings (#1657)

* Check model exists on `sozo auth` (#1644)

* feat: check model name and address before granting write access

* Update crates/dojo-world/src/contracts/model.rs

Co-authored-by: glihm <dev@glihm.net>

* Update bin/sozo/src/ops/auth.rs

Co-authored-by: glihm <dev@glihm.net>

---------

Co-authored-by: glihm <dev@glihm.net>

* fix: error on `world.model()` call gets mapped wrongly (#1661)

* sozo: check existing class-hashes before registering model (#1576)

* check existing class-hashes before registering model

* update checking if models registered logic

* apply review feedback

* add initial test fixture for reregister

* check if models need reregistering using remote manifest

* test ouput of the reregister command

* apply further review feedback

* allow dead code for test utils

* feat: add transaction_hash and block_number in the manifest file (#1651)

* feat: add transaction_hash and block_number in the manifest file

Store the `transaction_hash` and the `block_number` of the World deployment in the
manifest file.

* merge transaction_hash and block_number from previous deployed manifest if exists

* update spawn-and-move example

* fix fmt issues

* refactor(sozo): make event parsing logic modular and reusable (#1556)

* refacto: using cainome parser in order to parse events in sozo

* refacto: clean logs + add tests

* fix: clippy error

* refacto: best error handling

* update how felt are displayed + remove  unnecessary expect in tests

* fix tests

* fix: fmt and artifacts parsing for missing events

* fix: adjust event count as now world and base are included

* return error from parse_and_print_events function

* fix: ensure world address is always present to filter events

---------

Co-authored-by: glihm <dev@glihm.net>

* feat(sozo): add `--receipt` transaction option (#1647)

* feat(katana): add simulate transactions (#1590)

* add simulation to the RPC

* simulate transaction on sequencer

* add `new_query`

* add fee type

* lint

* update to `simulate_transactions`

* remove `simulation.rs`

* individual parameters for `simulate_transactions`

* lint rebase

* update to fit spec

* pin link

* Prepare release: v0.6.0-alpha.6 (#1666)

* feat(relay): persist and expose messages through grpc (#1526)

* feat(libp2p): start working on persistence & grpc

* feat: add relay proto and db migration

* feat(libp2p): relaystorage for message persistence

* feat(libp2p): relay subscription service

* refactor: start implementing models/ty for libp2p

* refactor(torii-core): generic set ty query

* feat: use models for libp2p messages

* feat: rpcs for subscring and retrieving messages

* refactor(torii-core): arc rwlock for sql database & work on messages for models

* refactor: tests & write message to db

* refactor(grpc): grpc service & subscription

* refactor: use entitiy type and models for messages

* chore: fmt & clippy

* refactor: unused async

* chore: world descriptor

* refactor: unused deps & fmt

* chore: remove post types

* chore: unused libp2p deps

* chore: non wasm deps

* chore

* chore: fmt

* fix: test

* refactor: check if entity already exists for libp2p messages

* chore: fmt & clippy

* feat(libp2p): start working on identity and signatures for messages

* refactor(libp2p): use array for signature type and check its ocmponents

* refactor: decouple logic

* refactor(libpo2p): extract identity & signature from validate message

* feat(libp2p): eip 712 typed data

* feat(libp2p): start workling on typed data structure snip-12

* refactor: change name

* feat: handle type encoding

* feat: typed data message encoding

* refactor: rework in progress for using snip-12

* feat(libp2p): testing typed data with mocks & tests

* fix: typed data passing test for enums

* feat: test for presets and refactor type primitives

* refactor: string parsing for felts

* fix: dont include type hash on children objects

* fix: json ordering issue with serde_json

* fix: typed data for shortstring

* fix: message encoding - passes all tests

* feat: start supporting enums

* feat: handle enum variant types

* chore: rebase and fix db rwlock

* refactor: encode all object types & start fixing enums

* fix: enum test

* fix: preset types. full compatibility with starknet js

* refactor: more optimized approach for preset types

* feat(libp2p): valid message signature & identity

* refactor: wip identity and verifying message

* refactor: get entity model identity & check

* wip: start working on encoding typed data to Ty

* refactor: implement ty types for encode typed data

* refactor: parse object to ty function

* refactor: set entity from relay w verification

* feat: sign last signature and check signed last sig against last sig in db

* chore: fmt

* fix: torii grpc

* refactor: sqlx onlyu server side

* chore: clippy

* chore: use char

* refactor: sql reference

* chore: fmt & clippy

* refactor: typed data payload

* fix: clippy

* use RESOURCE_METADATA_MODEL constant

* fix fmt

* skip old ModelRegistered events

* fix(torii): Added timezone informations to naive datetime strings (#1668)

* fix(torii): Added timezone informations to naive datetimes

* fix(torii_naive_datetimes): Quick parameters renaming

* fix(torii_naive_datetimes): Used rust fmt script

* fix(torii_naive_datetimes): Naive datetime refacto

* fix(torii_naive_datetimes): Quick refacotring

* fix(torii_naive_datetimes): Fixed cargo clippy error

* fix(torii_naive_datetimes): Updated datetime retrieval

* get version from dojo::model attribute

* take version into account to generate selector and version functions

* refactor: write manifest file even if migration failed (#1652)

* refactor: write manifest file before trying to deploy them

* fix lints

* sort fs entries for deterministic order in manifest

* write migration output for partial migrations

* make suggested changes

* feat(sozo): add seed to manifest (#1674)

* feat(sozo): add seed to manifest

* make suggested changes

* fix(sozo): don't upload to ipfs if in offline mode (#1678)

* Torii fix queries with keys regex (#1609)

* [sozo] Detect and manage manifests and artifacts discrepancies  (#1672)

feat: detect and manage manifests and artifacts discrepancies

`sozo` uses several file types (previously generated by `sozo build` and `sozo migrate`)
as input for migration. All of these files may be corrupt or may have discrepancies due
to an older format version.

This PR introduces a new `sozo clean` command to clean the project of these files.
`sozo clean --manifest-abis` cleans only manifest and ABI files.
`sozo clean --artifacts` cleans only artifacts.

When an anomaly is detected in a file, the user is informed of the problem
and advised to run `sozo clean` to clean up the project.

* Prepare release: v0.6.0-alpha.7 (#1680)

Co-authored-by: glihm <glihm@users.noreply.github.com>

* Add explorer flag to open World Explorer in browser (#1581)

* Add explorer flag to open World Explorer

* Log error message instead of unwrap when fail to open world explorer on browser

* fix typo

* fix typo 2

---------

Co-authored-by: glihm <dev@glihm.net>

* after review

* refactor(torii): retrieve events and store only relevant txns (#1631)

* feat(torii): parallelize torii sync_range func

* refactor: retrieve events & store only relevant txns

* refactor: fix chunk size overflow & handle next events pages

* chore: fmt

* chore: clippy

* chore: fmt

* refactor: execute all txns at end of sync

* chore: code

* chroe: suggested changes

* feat: configure events page chunk size

* fmt

* refactor: include chink size in config

* fix

* Split sozo ops into its own crate (#1546)

* Split sozo ops into its own crate

* fix: minor fixes and adjust commands documentation

* fix: add missing file

* fix: ensure migration failure is not silent

---------

Co-authored-by: Jonatan Chaverri <jonatan.chaverri@kyndryl.com>
Co-authored-by: glihm <dev@glihm.net>

* fix base_test error

* feat: add eventmessage for emitting models & start refactoring emit macro (#1656)

* feat: add eventmessage for emitting models & start refactoring emit macro

* refactor: emit multiple models event

* feat: event message processor

* feat: emit_message world func emit event mssage

* refactor: catch all event processor

* refactor: check model key as name

* feat: model name keccak as id & rework model events

* fix: storing entities with model hash

* refactor: catch all event message  and store

* feat: emit model evrnt from spawn and move spawn

* fix: pass keys as array

* feat: fix emit macro and correctly index model events

* feat: event messages migrations & set

* feat: store events messages and new id system

* chore: fmt

* fix: keys array

* feat: add grpc endpoint for event messages

* feat: graphql schema for event messages

* cadd comments for moel name hash

* revert world.cario changes

* fix: graphql entity and model connection

* refactor: only test models name ordering

* fix: entity/modeldata relation

* refactor: remove event testing

* fix: cairo code

* refactor: add back event rxample

* fix: merge

* chore: migration

* fix: subscription test

* fix: tests

* fix: subscription test

* fix: sql test

* chore: format model id correctly in test

* fix: model subscription with id

* fix: schema for model

* chore: revert modelmmeber type

* fix: event message query

* fix: ensure sozo clean only affect base (#1685)

The overlays are managed by the user. We don't want to clean them.
The deployments are only output, and can't cause any conflict.
For this reason, only base should be clean.

* sozo: add dry-run mode (#1686)

* fix: rebuild artifacts

---------

Co-authored-by: RareSecond <jasper@codictive.be>
Co-authored-by: glihm <dev@glihm.net>
Co-authored-by: akhercha <akherchache@pm.me>
Co-authored-by: Ammar Arif <evergreenkary@gmail.com>
Co-authored-by: kwkr <kawka.maciej.93@gmail.com>
Co-authored-by: Matthias <matthias.monnier@gmail.com>
Co-authored-by: greged93 <82421016+greged93@users.noreply.github.com>
Co-authored-by: Tarrence van As <tarrencev@users.noreply.github.com>
Co-authored-by: Larko <59736843+Larkooo@users.noreply.github.com>
Co-authored-by: lambda-0x <0xlambda@protonmail.com>
Co-authored-by: Yun <broody@gmail.com>
Co-authored-by: glihm <glihm@users.noreply.github.com>
Co-authored-by: Junichi Sugiura <jun.sugiura.jp@gmail.com>
Co-authored-by: Jonatan Chaverri <jonathan.chaverri12@gmail.com>
Co-authored-by: Jonatan Chaverri <jonatan.chaverri@kyndryl.com>
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