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

Fix/QB-2411: Events optimization #341

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

Xiong-stratos
Copy link
Contributor

No description provided.

@BoThe1K
Copy link
Contributor

BoThe1K commented Feb 7, 2024

This has been done because

func createEvents(events sdk.Events, msg sdk.Msg) sdk.Events {
	eventMsgName := sdk.MsgTypeURL(msg)
	msgEvent := sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, eventMsgName))

	// we set the signer attribute as the sender
	if len(msg.GetSigners()) > 0 && !msg.GetSigners()[0].Empty() {
		msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeySender, msg.GetSigners()[0].String()))
	}

	// verify that events have no module attribute set
	if _, found := events.GetAttributes(sdk.AttributeKeyModule); !found {
		// here we assume that routes module name is the second element of the route
		// e.g. "cosmos.bank.v1beta1.MsgSend" => "bank"
		moduleName := strings.Split(eventMsgName, ".")
		if len(moduleName) > 1 {
			msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeyModule, moduleName[1]))
		}
	}

	return sdk.Events{msgEvent}.AppendEvents(events)
}

when event with module name occured, it will not stored for message.module rather then <module.name.Proto>.module so it is hard to search events through tx_search query

as example

with these removals:

{
"type": "message",
"attributes": [
{
"key": "action",
"value": "/cosmos.gov.v1beta1.MsgSubmitProposal",
"index": true
},
{
"key": "sender",
"value": "st1t9aw4w9tdv3ccj2p53nmta8axcueaewysgujd8",
"index": true
},
{
"key": "module",
"value": "gov",
"index": true
}
]
}

without (before PR)

{
"type": "stratos.pot.v1.EventMessage",
"attributes": [
{
"key": "action",
"value": "",
"index": true
},
{
"key": "module",
"value": "pot",
"index": true
},
{
"key": "sender",
"value": "st1eqmjp3vfknvzzd9zzkx5khkf68hzhwdcyd0n3s",
"index": true
}
]
}

@alexstratos alexstratos merged commit d81c5ed into v0.12.0-prepare Feb 21, 2024
@alexstratos alexstratos deleted the qb-2411-optimize-event branch February 21, 2024 17:31
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