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

Implement and test AccumulateChanges #468

Closed
wants to merge 3 commits into from

Conversation

jtremback
Copy link

@jtremback jtremback commented Oct 5, 2021

Description

This creates a utility which accumulates validator set changes by updating those validators whose powers have changed. It then uses this utility in the child's OnRecvPacket to update the stored changes instead of overwriting them

closes: https://github.com/cosmos/cosmos-sdk/issues/10123


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@jtremback jtremback changed the title implement and test AccumulateChanges Implement and test AccumulateChanges Oct 5, 2021
Copy link
Member

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

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

Looks good! Just a couple nits

modules/apps/ccv/child/keeper/relay_test.go Outdated Show resolved Hide resolved
modules/apps/ccv/child/keeper/relay_test.go Outdated Show resolved Hide resolved
modules/apps/ccv/child/keeper/relay.go Outdated Show resolved Hide resolved
@jtremback
Copy link
Author

@AdityaSripal A couple questions about the []abci.ValidatorUpdate type: I'm assuming that it is not intended for there to be two updates of the same validator in this slice. Also guessing that the ordering does not matter. Seems like it would be more semantically correct for this data to be kept in a hashmap.

@AdityaSripal
Copy link
Member

A couple questions about the []abci.ValidatorUpdate type: I'm assuming that it is not intended for there to be two updates of the same validator in this slice. Also guessing that the ordering does not matter. Seems like it would be more semantically correct for this data to be kept in a hashmap.

Correct, however the type ABCI expects is []abci.ValidatorUpdate as the Response in EndBlock even though ABCI expects that only one ValidatorUpdates exists for each pubkey and order does not matter. I don't know why ABCI does this instead of asking for a map.

We're keeping this in store as a list both because its easier to just stick to the type expected by ABCI, and because go-maps are not marshalled deterministically which will cause app hash divergence

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Nice work! My main concern is iteration over a map as that is non determinstic in go and usually a source of problems

abci "github.com/tendermint/tendermint/abci/types"
)

func AccumulateChanges(currentChanges, newChanges []abci.ValidatorUpdate) []abci.ValidatorUpdate {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this could go in the types package? I think even just a file on the top level could be fine. I'd recommend avoiding utils/utils.go and go with file naming that is descriptive

Function needs godoc/comments/tests as well


var out []abci.ValidatorUpdate

for _, update := range m {
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 used in the state machine? Iteration over maps is nondeterministic, seems likely this could result in app hash mismatch

name string
packet channeltypes.Packet
newChanges types.ValidatorSetChangePacketData
expectedPendingChanges types.ValidatorSetChangePacketData
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expectedPendingChanges types.ValidatorSetChangePacketData
expPendingChanges types.ValidatorSetChangePacketData

nit: naming consistency

suite.Require().True(ok)
suite.Require().Equal(&pd, actualPd, "pending changes not equal to packet data after successful packet receive. case: %s", tc.name)
// Sort to avoid dumb inequalities
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be better to require pending changes to always be sorted?

@AdityaSripal
Copy link
Member

Closed in favor of cosmos/interchain-security#6

faddat pushed a commit to notional-labs/ibc-go that referenced this pull request Mar 1, 2022
CosmosCar pushed a commit to caelus-labs/ibc-go that referenced this pull request Nov 6, 2023
…github.com/stretchr/testify-1.8.0

build(deps): bump github.com/stretchr/testify from 1.7.5 to 1.8.0
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.

4 participants