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

chore: Improve external events format #169

Merged
merged 6 commits into from
Oct 11, 2024
Merged

Conversation

gitferry
Copy link
Member

This PR flattened the external events and changed all the event fields to string so that it's easier for subscribers to parse them

@gitferry gitferry changed the title fix: External events format chore: Improve external events format Oct 11, 2024
@gitferry gitferry marked this pull request as ready for review October 11, 2024 03:08
@gitferry gitferry requested a review from a team as a code owner October 11, 2024 03:08
@gitferry gitferry requested review from Lazar955, RafilxTenfen, KonradStaniec and jrwbabylonlab and removed request for a team October 11, 2024 03:08
@gitferry gitferry added api breaking breaks grpc api in non-compatible way backport/v0.12.x labels Oct 11, 2024
@gitferry gitferry force-pushed the fix/external-events-format branch 3 times, most recently from aa31ddb to 492a9be Compare October 11, 2024 04:09
@SebastianElvis
Copy link
Member

It seems that the label should be backport v0.12.x (space in between) as per https://github.com/marketplace/actions/backporting?

@KonradStaniec
Copy link
Collaborator

KonradStaniec commented Oct 11, 2024

@jrwbabylonlab does primitive numbers as strings also improve situation on api side ?

From my point of view this is a bit bad 😅 as now I am looking at number in some events and see string and I do not not know:

  • does this number is in hex bytes ?
  • does this number is in string decimal representation ?
  • does this number is in string binary representatin ?

I.e proto file loses any documentation qualities about numbers.

EDIT: It seems cosmos-sdk use events this way, so probably every tooling here is expects string in events. Example: https://github.com/cosmos/cosmos-sdk/blob/main/x/staking/keeper/msg_server.go#L559. Lets leave it as it is 👍

@gitferry gitferry force-pushed the fix/external-events-format branch from 492a9be to 4fb9bfd Compare October 11, 2024 07:06
@jrwbabylonlab
Copy link

Just adding a note here as already discussed in DM:
We should review the fields with omitemty as not all fields are optional. such as btcPk across all types.

// btc_pk_hex is the hex string of Bitcoin secp256k1 PK of this finality provider
string btc_pk_hex = 1 [(amino.dont_omitempty) = true];
// commission defines the commission rate of the finality provider in decimals.
string commission = 2 [(amino.dont_omitempty) = true];

Choose a reason for hiding this comment

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

why does commission is none-optional in the edit mode?

Copy link
Member Author

Choose a reason for hiding this comment

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

commission is a required field when a fp is registered on babylon

Choose a reason for hiding this comment

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

sure, but for the edit event, why does it need to be here? if FP's commission was not updated, we don't emit it, right?

BTCDelegationStatus state = 4;
string end_height = 3 [(amino.dont_omitempty) = true];
// new_state of the BTC delegation
string new_state = 4 [(amino.dont_omitempty) = true];
}

// EventBTCDelgationUnbondedEarly is the event emitted when a BTC delegation
// is unbonded by staker sending unbonding tx to BTC
message EventBTCDelgationUnbondedEarly {

Choose a reason for hiding this comment

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

@gitferry just to confirm my assumption: we’re splitting the unbonded state into two separate events for natural unbonding and the unbonding path. This means the API no longer needs to differentiate between a transaction event and a block event.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, they are separate events EventBTCDelgationUnbondedEarly and EventBTCDelegationExpired but with the same state UNBONDED. They are both emitted as block events

@@ -263,11 +263,11 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents(
if _, ok := slashedFPs[fpBTCPKHex]; ok {
fp.IsSlashed = true

statusChangeEvent := types.NewFinalityProviderStatusChangeEvent(fp.BtcPk, types.FinalityProviderStatus_STATUS_SLASHED)
statusChangeEvent := types.NewFinalityProviderStatusChangeEvent(fp.BtcPk, types.FinalityProviderStatus_FINALITY_PROVIDER_STATUS_SLASHED)
if err := sdkCtx.EventManager().EmitTypedEvent(statusChangeEvent); err != nil {

Choose a reason for hiding this comment

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

nit:
IMO, it might be more performant if each of the event type come with .toEvent method which will turn your custom event struct into the cosmos event type. https://pkg.go.dev/github.com/cometbft/[email protected]/abci/types#Event
Then use the EmitEvent instead of EmitTypedEvent to save some json marshal/unmarshl

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure this is good to use EmitEvent because cosmos has listed EmitEvent as deprecated https://github.com/cosmos/cosmos-sdk/blob/v0.50.6/types/events.go#L45-L49

@gitferry gitferry merged commit 86f6bc5 into main Oct 11, 2024
20 checks passed
gitferry added a commit that referenced this pull request Oct 11, 2024
This PR flattened the external events and changed all the event fields
to string so that it's easier for subscribers to parse them
gitferry added a commit that referenced this pull request Oct 11, 2024
This is a manual backport as the automatic backport failed
// ACTIVE -> INACTIVE.
// Note that it is impossible for a SLASHED finality provider to
// transition to other status
message EventFinalityProviderStatusChange {

Choose a reason for hiding this comment

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

@gitferry ouch. we still using status here. but anyway, not a big deal. let's leave it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api breaking breaks grpc api in non-compatible way backport release/v0.12.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants