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(evmengine): refactor evmmsgs #106

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

zsystm
Copy link
Collaborator

@zsystm zsystm commented Sep 11, 2024

refactored evmmsgs for better code quailty and testability.

issue: #105

Before: the evmEvents function handled
- Fetching logs from ethereum client
- Converting those logs to EVMEvent objects
- Verifying the converted events
- Sorting the events

After: The evmEvents function
- Fetching logs from ethereum client
- Delegates conversion and verification to types.EthLogToEVMEvent.
- Delegates sorting to types.SortEVMEvents.
slashingAbi, err := bindings.IPTokenSlashingMetaData.GetAbi()
require.NoError(t, err, "failed to load ABI")
slashingAddr := common.HexToAddress(predeploys.IPTokenSlashing)
require.Negative(t, bytes.Compare(stakingAddr.Bytes(), slashingAddr.Bytes()), "stakingAddr should be less than slashingAddr")
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean stakingAddr should be less than slashingAddr for a compare? (+ same for below error messages)

Copy link
Collaborator Author

@zsystm zsystm Sep 13, 2024

Choose a reason for hiding this comment

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

@jdubpark
Thanks for the feedback! The message is somewhat unclear and difficult to understand.
I have removed it and added more detailed comments in the code explaining why these comparisons are necessary and included examples to illustrate the expected behavior.
Please take a look at the updated comments, and let me know if there’s anything else I can clarify.

Note:
The reason for checking that stakingAddr is less than slashingAddr is to ensure a known initial order before testing the sorting logic.
This precondition is necessary because we want to verify that if the addresses are input in the wrong order, the sorting function will correctly reorder them.
Similarly, the same check is applied for the event topics (withdrawEv and depositEv) to confirm the function’s behavior.

@zsystm zsystm changed the title chore(evmengine/keeper): refactor evmmsgs chore(evmengine): refactor evmmsgs Sep 18, 2024
}

// IsSortedEVMEvents check if the events are sorted by ascending order of address, topics, and data.
func IsSortedEVMEvents(events []*EVMEvent) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this only used in the test? If so, we should move it to the test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@edisonz0718

applied it in 828cb40

thanks for your comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@edisonz0718
Could you review this PR when you have time? I applied your comment. Thanks in advance.

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