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

[Application] Add missing (un)staking events #867

Open
wants to merge 15 commits into
base: issues/612/application/burning
Choose a base branch
from

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Oct 8, 2024

Summary

Adds:

  • EventApplicationStake
  • EventApplicationUnbondingBegin
  • EventApplicationUnbondingEnd
  • EventApplicationUnbondingCanceled
  • EventApplicationUnbondedBelowMinStake

Issue

Type of change

Select one or more from the following:

Testing

  • Documentation: make docusaurus_start; only needed if you make doc changes
  • Unit Tests: make go_develop_and_test
  • LocalNet E2E Tests: make test_e2e
  • DevNet E2E Tests: Add the devnet-test-e2e label to the PR.

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

@bryanchriswhite bryanchriswhite added application Changes related to the Application actor on-chain On-chain business logic code health Cleans up some code labels Oct 8, 2024
@bryanchriswhite bryanchriswhite self-assigned this Oct 8, 2024
@bryanchriswhite bryanchriswhite linked an issue Oct 8, 2024 that may be closed by this pull request
5 tasks
@bryanchriswhite bryanchriswhite marked this pull request as ready for review October 8, 2024 13:02
@bryanchriswhite bryanchriswhite marked this pull request as draft October 10, 2024 11:50
…application

* issues/612/application/burning: (94 commits)
  fix: linter error
  chore: quick fixes
  [DifficultyHash] Prepare for difficulty multiplier usage (#836)
  [Application] Enforce minimum stake when staking (#847)
  Empty commit
  [Tokenomics] Prevent GMR to produce zero values (#866)
  Empty commit
  chore: regenerate protobufs
  fix: linter error
  Empty commit
  chore: review feedback improvements
  Empty commit
  Empty commit
  fix: linter errors
  fix: typo
  chore: review feedback improvements
  chore: reconcile PreGeneratedAccountIterator#MustNext()
  chore: add review feedback TODOs
  Empty commit
  test: simplify coin equality assertions
  ...

# Conflicts:
#	x/application/keeper/msg_server_stake_application_test.go
#	x/application/keeper/msg_server_unstake_application.go
#	x/application/keeper/msg_server_unstake_application_test.go
#	x/application/keeper/unbond_applications.go
@bryanchriswhite bryanchriswhite changed the base branch from main to issues/612/application/burning October 10, 2024 12:07
@bryanchriswhite bryanchriswhite marked this pull request as ready for review October 11, 2024 10:02

// EventApplicationUnbondingCanceled is emitted when an application which was unbonding
// successfully (re-)stakes before the unbonding period has elapsed. An EventApplicationStaked
// event will also be emmitted immediatly after this event.
Copy link
Contributor Author

@bryanchriswhite bryanchriswhite Oct 11, 2024

Choose a reason for hiding this comment

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

Suggested change
// event will also be emmitted immediatly after this event.
// event will also be emitted immediately after this event.

Comment on lines +123 to +129
for _, event := range events {
if err = sdkCtx.EventManager().EmitTypedEvent(event); err != nil {
err = types.ErrAppEmitEvent.Wrapf("(%+v): %s", event, err)
logger.Error(err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
}
Copy link
Contributor Author

@bryanchriswhite bryanchriswhite Oct 11, 2024

Choose a reason for hiding this comment

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

Suggested change
for _, event := range events {
if err = sdkCtx.EventManager().EmitTypedEvent(event); err != nil {
err = types.ErrAppEmitEvent.Wrapf("(%+v): %s", event, err)
logger.Error(err.Error())
return nil, status.Error(codes.Internal, err.Error())
}
}
if err = sdkCtx.EventManager().EmitTypedEvents(events...); err != nil {
err = types.ErrAppEmitEvent.Wrapf("(%+v): %s", events, err)
logger.Error(err.Error())
return nil, status.Error(codes.Internal, err.Error())
}

// EventApplicationUnbondingBegin is emitted when an application unstake message
// is committed, indicating that an application has begun unbonding.
message EventApplicationUnbondingBegin {
string app_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add unbonding_height field for consistency with EventSupplierUnbondingBegin.

// unbonding. The unbonding period is determined by the shared param,
// application_unbonding_period_sessions.
message EventApplicationUnbondingEnd {
string app_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add unbonding_height field for consistency with EventSupplierUnbondingEnd.

// unbonded during settlement because their post-settlement stake dropped below
// the minimum application stake requirement.
message EventApplicationUnbondedBelowMinStake {
string app_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add unbonding_height and application_min_stake fields.

// successfully (re-)stakes before the unbonding period has elapsed. An EventApplicationStaked
// event will also be emmitted immediatly after this event.
message EventApplicationUnbondingCanceled {
string app_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add session_end_height field

Copy link
Contributor

@red-0ne red-0ne left a comment

Choose a reason for hiding this comment

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

An important milestone achieved! 😄

Left some comments w.r.t. the events content but looks good otherwise 👍

import "poktroll/application/types.proto";

// EventApplicationStaked is emitted when an application is staked or up-staked.
message EventApplicationStaked {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just embed the whole application?

// such that prior event emissions are cleared.
func ResetEventManager(ctx context.Context) context.Context {
return cosmostypes.UnwrapSDKContext(ctx).
WithEventManager(cosmostypes.NewEventManager())
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥

@@ -283,6 +283,16 @@ func (k Keeper) ProcessTokenLogicModules(
// TODO_CONSIDERATION: If we support multiple native tokens, we will need to
// start checking the denom here.
if application.Stake.Amount.LT(apptypes.DefaultMinStake.Amount) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
unbondedBelowMinStakeEvent := &apptypes.EventApplicationUnbondedBelowMinStake{
AppAddress: application.GetAddress(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Any opinion on sending the whole application? (at least the stake amount)

// TODO_UPNEXT(@bryanchriswhite): emit a new EventApplicationUnbondingEnd event.
sdkCtx := sdk.UnwrapSDKContext(ctx)
unbondingBeginEvent := &apptypes.EventApplicationUnbondingEnd{
AppAddress: application.GetAddress(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to see the stake being returned to the app account. IMO Adding the whole app to the event is OK.

// TODO_UPNEXT:(@bryanchriswhite): emit a new EventApplicationUnbondingBegin event.
sdkCtx = sdk.UnwrapSDKContext(ctx)
unbondingBeginEvent := &types.EventApplicationUnbondingBegin{
AppAddress: foundApp.GetAddress(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, having a "snapshot" of the application state (current stake) could be useful, in conjunction with the unbonding end event having the same.

We would be able to see how much stake has been deducted in between. We probably have other means to know it though.

events = sdkCtx.EventManager().Events()
require.Equal(t, 1, len(events))
Copy link
Contributor

Choose a reason for hiding this comment

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

This was appearing because the events did not get cleared right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
application Changes related to the Application actor code health Cleans up some code on-chain On-chain business logic
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

[Events] Add missing events
2 participants