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: api events #153

Merged
merged 66 commits into from
Aug 14, 2024
Merged

feat: api events #153

merged 66 commits into from
Aug 14, 2024

Conversation

Daanvdplas
Copy link
Collaborator

@Daanvdplas Daanvdplas commented Jul 31, 2024

Added events to contract library and pallet, including tests for the pallet.

Note: the weight for increase allowance has changed due to an extra storage read.

The events in the contract library will have to be demonstrated in an example contract. This will have to be done in a different PR.

Copy link
Collaborator

@evilrobot-01 evilrobot-01 left a comment

Choose a reason for hiding this comment

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

Hmmm, not sure about the id removal from the events. See inline comments for more context.

pop-api/src/v0/assets/fungibles.rs Show resolved Hide resolved
pop-api/src/v0/assets/fungibles.rs Outdated Show resolved Hide resolved
pop-api/src/v0/assets/fungibles.rs Outdated Show resolved Hide resolved
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Event emitted when allowance by `owner` to `spender` changes.
Approval {
/// Token ID.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sadly I think this is problematic. I understand it was probably removed to conform to the standard, but does ommitting it effectively make it useless? The events are emitted from a pallet managing multiple assets, so without knowing which asset id had an approval, is there any point? A contract call might be able to correlate the resulting events based on the extrinsic events, but if contract makes two calls to the fungibles pallet to create an allowance, for two different assets, how can we tell from the events which value matches which asset?

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 perhaps this brings us back to this comment.

In short, reason for adding events to the fungible pallet:

  • standard compliance - the problem is that the events are not useful though (see frank's comment). In addition, when we do add the asset_id the events become the same as in pallet assets (e.g. Transferred)
  • pallet usage - we have an indicator how often the pallet is used. More interesting is how often the API is used

Would it be oke to start without events in the pallet?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be oke to start without events in the pallet?

I would rather we start with something, even super simple events so we can be aware of if the API is being used on testnet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alright I will then add the asset id back in the Transfer and Approval event

@evilrobot-01
Copy link
Collaborator

A general heads up that all these PRs to the api branch do not seem to include any test coverage stats, meaning that there might still be some work to do before the branch is merged to main. I will take a look at that branch first to see why.

@evilrobot-01
Copy link
Collaborator

A general heads up that all these PRs to the api branch do not seem to include any test coverage stats, meaning that there might still be some work to do before the branch is merged to main. I will take a look at that branch first to see why.

FYI - the daan/api branch is missing a number of commits from main, with the ci one perhaps the most important. I suggest getting this addressed soon so that you can get a feel for how much code is untested before assuming that the initial api work is done.

image

@Daanvdplas
Copy link
Collaborator Author

FYI - the daan/api branch is missing a number of commits from main, with the ci one perhaps the most important. I suggest getting this addressed soon so that you can get a feel for how much code is untested before assuming that the initial api work is done.

On it right away

@codecov-commenter
Copy link

codecov-commenter commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 93.77778% with 14 lines in your changes missing coverage. Please review.

Project coverage is 33.62%. Comparing base (545bd33) to head (3b3ae9f).
Report is 1 commits behind head on daan/api.

Files Patch % Lines
pallets/api/src/fungibles/mod.rs 85.56% 1 Missing and 13 partials ⚠️
@@             Coverage Diff              @@
##           daan/api     #153      +/-   ##
============================================
+ Coverage     32.45%   33.62%   +1.16%     
============================================
  Files            33       34       +1     
  Lines          2915     2995      +80     
  Branches       2915     2995      +80     
============================================
+ Hits            946     1007      +61     
- Misses         1946     1956      +10     
- Partials         23       32       +9     
Files Coverage Δ
pallets/api/src/fungibles/tests.rs 100.00% <100.00%> (ø)
pallets/api/src/mock.rs 100.00% <ø> (ø)
runtime/devnet/src/config/api.rs 0.00% <ø> (ø)
pallets/api/src/fungibles/mod.rs 82.46% <85.56%> (-0.19%) ⬇️

... and 7 files with indirect coverage changes

Copy link
Collaborator

@peterwht peterwht left a comment

Choose a reason for hiding this comment

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

LGTM! Left a small comment, good with whatever you decide.

pallets/api/src/fungibles/mod.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@evilrobot-01 evilrobot-01 left a comment

Choose a reason for hiding this comment

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

Just one more optimisation and a variable rename for consistency. Peter has a good point in terms of emitting events to determine usage, so hopefully a quick add.

pallets/api/src/fungibles/mod.rs Outdated Show resolved Hide resolved
pallets/api/src/fungibles/mod.rs Outdated Show resolved Hide resolved
pallets/api/src/fungibles/mod.rs Outdated Show resolved Hide resolved
pallets/api/src/fungibles/tests.rs Outdated Show resolved Hide resolved
@peterwht
Copy link
Collaborator

peterwht commented Aug 14, 2024

[sc-1124]

Copy link
Collaborator

@evilrobot-01 evilrobot-01 left a comment

Choose a reason for hiding this comment

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

One last minor refactor then good for me.

@Daanvdplas Daanvdplas merged commit 8b4f595 into daan/api Aug 14, 2024
8 checks passed
@Daanvdplas Daanvdplas deleted the daan/feat-api_events branch August 14, 2024 08:00
@Daanvdplas Daanvdplas mentioned this pull request Aug 14, 2024
chungquantin pushed a commit that referenced this pull request Sep 6, 2024
Co-authored-by: Frank Bell <frank@r0gue.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants