-
Notifications
You must be signed in to change notification settings - Fork 138
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
Changes from 5 commits
1b39d21
0ba99e8
92939cd
78336bd
4445454
95840c4
7d917e9
f8fb19d
62f3b10
1c9ccc5
c3a26e2
a41dd42
de04624
15d0796
4f8e0a3
7f7e8ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,6 +182,65 @@ function stakingWithoutSlashing(hist: BlockHistory): boolean { | |
return true; | ||
} | ||
|
||
/** | ||
* Checks the validator set replication property as defined | ||
* https://github.com/cosmos/ibc/blob/main/spec/app/ics-028-cross-chain-validation/system_model_and_properties.md#system-properties | ||
* | ||
* @param hist A history of blocks. | ||
* @returns Is the property satisfied? | ||
*/ | ||
function validatorSetReplication(hist: BlockHistory): boolean { | ||
// return true; | ||
const blocks = hist.blocks; | ||
let good = true; | ||
blocks[C].forEach((b: CommittedBlock, hC: number) => { | ||
if (hC < 1) { | ||
mpoke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// The model starts at consumer 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 | ||
} | ||
const ss = b.invariantSnapshot; | ||
// 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 I think I had not pushed the last commits when you reviewed |
||
const valsetC = blocks[C].get(hC - 1)!.invariantSnapshot.consumerPower; | ||
// The provider set is implicitly defined by the status and tokens (power) | ||
if (hP < 1) { | ||
// 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I find it less error prone to employ
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! I've changed it. |
||
} | ||
const statusP = blocks[P].get(hP - 1)!.invariantSnapshot.status; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! Please see change. |
||
const tokensP = blocks[P].get(hP - 1)!.invariantSnapshot.tokens; | ||
assert(valsetC.length === statusP.length, 'this should never happen.'); | ||
assert(valsetC.length === tokensP.length, 'this should never happen.'); | ||
valsetC.forEach((power, i) => { | ||
if (power !== undefined) { // undefined means the validator is not in the set | ||
// Check that the consumer power is strictly equal to the provider power | ||
good = good && (tokensP[i] === power); | ||
} | ||
}) | ||
statusP.forEach((status, i) => { | ||
if (status === Status.BONDED) { | ||
const power = tokensP[i]; | ||
// Check that the consumer power is strictly equal to the provider power | ||
good = good && (valsetC[i] === power); | ||
} | ||
else { | ||
// Ensure that the consumer validator set does not contain a non-bonded validator | ||
good = good && (valsetC[i] === undefined); | ||
} | ||
}) | ||
|
||
}) | ||
return good; | ||
} | ||
|
||
/** | ||
* Checks the bond-based consumer voting power property as defined | ||
* in https://github.com/cosmos/ibc/blob/main/spec/app/ics-028-cross-chain-validation/system_model_and_properties.md#system-properties | ||
|
@@ -277,4 +336,5 @@ export { | |
BlockHistory, | ||
stakingWithoutSlashing, | ||
bondBasedConsumerVotingPower, | ||
validatorSetReplication, | ||
}; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.