Skip to content

refactor(e2e): change *Node to string in keys of some maps#4141

Merged
sergio-mena merged 11 commits intomainfrom
sergio/2458-no-pointers-as-map-keys
Sep 24, 2024
Merged

refactor(e2e): change *Node to string in keys of some maps#4141
sergio-mena merged 11 commits intomainfrom
sergio/2458-no-pointers-as-map-keys

Conversation

@sergio-mena
Copy link
Copy Markdown
Collaborator

@sergio-mena sergio-mena commented Sep 20, 2024

Partially addresses #2458

Change the *Node as keys of some maps in e2e and replace them by the node's name.

Having pointers as keys of a map brings about subtleties (how comparison is done) that we don't need. Code is much clearer with node names, even if it takes a bit longer to execute some loops (we need to look up the nodes). But this is test code, so clarity and robustness comes before performance of the testing code.

I decided to tackle this refactor in an different PR, rather than piggybacking it to #2283


PR checklist

  • Tests written/updated
  • [ ] Changelog entry added in .changelog (we use unclog to manage our changelog)
  • [ ] Updated relevant documentation (docs/ or spec/) and code comments

@sergio-mena sergio-mena requested a review from a team as a code owner September 20, 2024 16:42
@sergio-mena sergio-mena requested a review from a team September 20, 2024 16:42
Copy link
Copy Markdown
Collaborator

@andynog andynog left a comment

Choose a reason for hiding this comment

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

lgtm, had one comment but I think it is irrelevant to the current logic so feel free to disregard.

Copy link
Copy Markdown

@cason cason left a comment

Choose a reason for hiding this comment

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

Following #3964, we should remove the two refactored fields from Testnet type, since they match the version on Manifest.

Copy link
Copy Markdown

@cason cason left a comment

Choose a reason for hiding this comment

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

Legit.

// It includes all fields from the associated Manifest instance.
type Testnet struct {
Manifest
*Manifest
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Are you sure this doesn't break anything?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It was breaking when not used as a pointer, because we would copy some fields (non-pointer fields) but not others. A total mess.
As we are now modifying the Manifest down below in this function, those modifications didn't propagate (hence I needed to turn it into a pointer)

for valName, power := range *testnet.Manifest.ValidatorsMap {
validator := testnet.LookupNode(valName)
if validator == nil {
return types.GenesisDoc{}, fmt.Errorf("unknown validator %q for genesis doc", valName)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should never happen, right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but as suggested by @alesforz and @andynog , it's cleaner code if we check for nil.

for valName, power := range validators {
validator := node.Testnet.LookupNode(valName)
if validator == nil {
return nil, fmt.Errorf("unknown validator %q for validator updates in testnet, height %d", valName, height)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should never happen too, should we panic?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'd rather return the error and have the callsite(s) decide whether they want to panic or not

@cason
Copy link
Copy Markdown

cason commented Sep 24, 2024

Consider merging #4166 into this.

mergify bot and others added 2 commits September 24, 2024 07:58
As per title.

It was like this before #3964,
so restoring original name.

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@sergio-mena sergio-mena added this pull request to the merge queue Sep 24, 2024
Merged via the queue into main with commit 09bbba1 Sep 24, 2024
@sergio-mena sergio-mena deleted the sergio/2458-no-pointers-as-map-keys branch September 24, 2024 17:55
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.

5 participants