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

Adds Validator Set Replication property check to core diff model #589

Merged
merged 16 commits into from
Jan 5, 2023

Conversation

danwt
Copy link
Contributor

@danwt danwt commented Dec 13, 2022

Description

Adds the validator set replicatoin property as a checkable property to the diff test core model, and checks it.

Linked issues

Closes: #320

Type of change

Please delete options that are not relevant.

  • Non-breaking changes
  • New feature (adding functionality)
  • Testing

How was the feature tested?

  • Custom difference tests

Checklist:

Please delete options that are not relevant.

@danwt danwt force-pushed the danwt/diff-test-core-validator-set-replication branch from 6d47f23 to 4445454 Compare December 13, 2022 11:44
@danwt danwt changed the title Danwt/diff test core validator set replication Adds Validator Set Replication property check to core diff model Dec 13, 2022
@@ -42,7 +42,11 @@ const MODEL_INIT_STATE: ModelInitState = {
h: { provider: 0, consumer: 0 },
t: { provider: 0, consumer: 0 },
ccvC: {
hToVscID: { 0: 0, 1: 0 },
// The initial provider height is 0 but there must have been
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you give more context in this comment?

Maybe explain why a "phantom" vscId is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Please see change.

// make sense to try to check the property for height 0.
return
}
const statusP = blocks[P].get(hP - 1)!.invariantSnapshot.status;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe refactor and explain why 1 is subtracted from provider height?

// Note: explain why subtraction happens
const hP = ss.vscIDtoH[vscid] - 1;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Please see change.

// The model starts at provider height 0, so there is
// no committed block at height - 1. This means it does not
// make sense to try to check the property for height 0.
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I find it less error prone to employ for (const element of array1) pattern instead of object.forEach if you have cases that would skip over an array element if some condition is met.

.forEach is only cleaner when you always process each element in the same way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! I've changed it.

@shaspitz
Copy link
Contributor

Great stuff! I can take a better look later, but just checked throttle doesn't break this prop https://github.com/cosmos/interchain-security/tree/circuit-breaker-w-test

@shaspitz shaspitz mentioned this pull request Dec 16, 2022
Copy link
Contributor

@mpoke mpoke 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 @danwt. As general feedback, we need to keep the model and these properties maintainable. This means that other contributors need to easily understand the reasoning.

tests/difference/core/model/src/properties.ts Show resolved Hide resolved
Comment on lines 204 to 209
// Get the vscid of the last update which dictated
// the consumer valset valsetC committed at hC-1
const vscid = ss.hToVscID[hC];
// The VSU packet was sent at height hP-1
const hP = ss.vscIDtoH[vscid];
// Compare the validator sets at hC-1 and hP-1
Copy link
Contributor

Choose a reason for hiding this comment

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

Explain better the logic here. You can refer to the spec on how ss.hToVscID and ss.vscIDtoH are set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The function is pretty extensively documented in the latest commit with link to the spec

https://github.com/cosmos/interchain-security/blob/danwt/diff-test-core-validator-set-replication/tests/difference/core/model/src/properties.ts#L185-L192

I think I had not pushed the last commits when you reviewed

@cosmos cosmos deleted a comment from mpoke Dec 16, 2022
@danwt
Copy link
Contributor Author

danwt commented Dec 16, 2022

I accidentally deleted a comment in vscode. My bad!

@danwt danwt requested a review from mpoke January 3, 2023 15:00
Copy link
Contributor

@mpoke mpoke left a comment

Choose a reason for hiding this comment

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

I expanded the comment to add more clarity.

tests/difference/core/model/src/properties.ts Outdated Show resolved Hide resolved
// the consumer valset valsetC committed at hC-1
const vscid = snapshotC.hToVscID[hC];
// The VSU packet was sent at height hP-1
const hP = snapshotC.vscIDtoH[vscid];
Copy link
Contributor

Choose a reason for hiding this comment

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

Im probably misunderstanding the model but can you explain how you get a provider height from a consumer block history (snapshotC)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, the snapshotC is a snapshot of a committed block state on the consumer. Maybe it should be renamed. I've noted this down so when do a larger refactor I'll try to make this more clear.

@sainoe sainoe self-requested a review January 4, 2023 15:22
Copy link
Contributor

@sainoe sainoe left a comment

Choose a reason for hiding this comment

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

My knowledge of the diff testing mechanism is still limited so it's hard to give a thorough review for me. However, the testing logic of the valset replication property looks solid. Great work @danwt .

@danwt danwt merged commit bf9ed8f into main Jan 5, 2023
@danwt danwt deleted the danwt/diff-test-core-validator-set-replication branch January 5, 2023 08:54
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.

difftest core: check Validator Set Replication theoretical property
5 participants