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: use typed events #1030

Merged
merged 19 commits into from
Dec 15, 2022

Conversation

rahulghangas
Copy link
Contributor

@rahulghangas rahulghangas commented Nov 17, 2022

@rahulghangas rahulghangas changed the title Feat/emit typed event feat: switch to emit typed event Nov 17, 2022
@rahulghangas rahulghangas self-assigned this Nov 17, 2022
@rahulghangas rahulghangas added C: Celestia app enhancement New feature or request labels Nov 17, 2022
@rahulghangas rahulghangas changed the title feat: switch to emit typed event feat: switch to using typed events Nov 17, 2022
@rahulghangas rahulghangas changed the title feat: switch to using typed events feat: use typed events Nov 17, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2022

Codecov Report

Merging #1030 (3f5bd02) into main (2f89956) will decrease coverage by 0.03%.
The diff coverage is 11.11%.

@@            Coverage Diff             @@
##             main    #1030      +/-   ##
==========================================
- Coverage   50.50%   50.46%   -0.04%     
==========================================
  Files          71       71              
  Lines        4390     4391       +1     
==========================================
- Hits         2217     2216       -1     
- Misses       1946     1947       +1     
- Partials      227      228       +1     
Impacted Files Coverage Δ
x/blob/types/events.go 0.00% <0.00%> (ø)
x/blob/keeper/keeper.go 80.00% <25.00%> (-11.31%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

x/blob/keeper/keeper.go Outdated Show resolved Hide resolved

// EventPayForBlob defines an event that is emitted with the signer and blob size
// at the end of a pay for blob txn
message EventPayForBlob {
Copy link
Contributor

Choose a reason for hiding this comment

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

So we are changing event.type from payforblob to blob.EventPayForBlob or am I missing something here? If we are changing event type then relevant test (TestSubmitWirePayForBlob) in integration_test.go can be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there's a pending task in this PR for the same

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad, I overlooked the draft status and checklist (used to GitLab PRs 😅 ). My apologies 🙏

@rahulghangas
Copy link
Contributor Author

@evan-forbes since we're changing the event name, in order to follow convention from the typed events ADR in cosmos-sdk, this will be a breaking change

@rahulghangas rahulghangas marked this pull request as ready for review November 18, 2022 11:14
Copy link
Member

@rach-id rach-id left a comment

Choose a reason for hiding this comment

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

Good catch 👍 the older way was deprecated.

proto/blob/events.proto Outdated Show resolved Hide resolved
x/blob/keeper/keeper.go Outdated Show resolved Hide resolved
@@ -61,9 +61,12 @@ func (k Keeper) PayForBlob(goCtx context.Context, msg *types.MsgPayForBlob) (*ty
gasToConsume := uint64(shares.MsgSharesUsed(int(msg.BlobSize)) * GasPerMsgShare)
ctx.GasMeter().ConsumeGas(gasToConsume, payForBlobGasDescriptor)

ctx.EventManager().EmitEvent(
err := ctx.EventManager().EmitTypedEvent(
types.NewPayForBlobEvent(sdk.AccAddress(msg.Signer).String(), msg.GetBlobSize()),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
types.NewPayForBlobEvent(sdk.AccAddress(msg.Signer).String(), msg.GetBlobSize()),
types.NewPayForBlobEvent(msg.Signer, msg.GetBlobSize()),

I guess the msg.Signer already contains the account address in Bech32 format. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

second this, we should be able to just use the signer. We can test manually by looking at the events in one of the integration tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't look like that the conversion is as is, I'll confirm via a test

Copy link
Member

Choose a reason for hiding this comment

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

@rahulghangas Did you manage to check if it is the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sweexordious msg.Signer is the raw form while the .String() method encodes it in bech32. Removing the above logic will be breaking change

Copy link
Member

Choose a reason for hiding this comment

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

I tried an example and apparently the msg.Signer contains:

cosmos1n5c5wmz5s2n0d8zpr5ldcl45nkjclaqktls7gd

while sdk.AccAddress(msg.Signer).String() returns:

cosmos1vdhhxmt0wvckudtrx4mk6734wvexuvry8pa8qu34d3jxxmp5x4hxk6nrd3shz6m5d3enwemycqe9zf

Which one do we want?

Copy link
Collaborator

Choose a reason for hiding this comment

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

After we align on one, should we add a unit test that verifies an event is emitted with the appropriate signer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm leaning towards first, since it's more compact and helps us reduce on-chain storage

Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Refactor integration test

Where does this happen? It doesn't appear applicable to this PR.

@evan-forbes
Copy link
Member

what's left for this? just reviewer feedback?

@rahulghangas
Copy link
Contributor Author

Where does this happen? It doesn't appear applicable to this PR.

It doesn't, I've removed it from the checklist. Initially the idea was to change the test because the attribute key was hardcoded, but I've made it such that it infers the type name from the struct itself

Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

[not blocking] can we please update this section

## Events
- [`NewPayForBlobEvent`](https://github.com/celestiaorg/celestia-app/pull/213/files#diff-1ce55bda42cf160deca2e5ea1f4382b65f3b689c7e00c88085d7ce219e77303dR17-R21) is emitted with the signer's address and size of the message that is paid for.
to remove the permalink to the outdated event? Proposal:

## Events

- `PayForBlobEvent` is emitted with the signer's address and size of the message that is paid for.

Alternatively, we can also copy something like this: https://github.com/cosmos/cosmos-sdk/blob/16c772d900f530d16518491b19f60cfef9d713af/x/bank/README.md?plain=1#L339-L353

proto/blob/events.proto Outdated Show resolved Hide resolved
x/blob/README.md Outdated Show resolved Hide resolved
x/blob/types/events.go Outdated Show resolved Hide resolved
@@ -61,9 +61,12 @@ func (k Keeper) PayForBlob(goCtx context.Context, msg *types.MsgPayForBlob) (*ty
gasToConsume := uint64(shares.MsgSharesUsed(int(msg.BlobSize)) * GasPerMsgShare)
ctx.GasMeter().ConsumeGas(gasToConsume, payForBlobGasDescriptor)

ctx.EventManager().EmitEvent(
err := ctx.EventManager().EmitTypedEvent(
types.NewPayForBlobEvent(sdk.AccAddress(msg.Signer).String(), msg.GetBlobSize()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

After we align on one, should we add a unit test that verifies an event is emitted with the appropriate signer?

Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

LGTM!! thanks for this @rahulghangas

@rahulghangas rahulghangas merged commit c16d6e7 into celestiaorg:main Dec 15, 2022
@rahulghangas rahulghangas deleted the feat/emit-typed-event branch December 15, 2022 11:49
rootulp pushed a commit to rootulp/celestia-app that referenced this pull request Dec 19, 2022
- [x] switch to typed event for `blob` module'
- [ ] ~~Refactor integration test~~
- [x] Closes celestiaorg#968
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch usage from EmitEvent to EmitTypedEvent
6 participants