Skip to content

Commit

Permalink
Improve model clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Nov 1, 2022
1 parent bb9f65b commit 42c2593
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
6 changes: 5 additions & 1 deletion tests/difference/core/model/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ type Undelegate = {

type ConsumerSlash = {
kind: string;
// The validator unique id, corresponds to real validator identity
// ie. the provider indentity
val: Validator;
infractionHeight: number;
isDowntime: boolean;
// The vscid at which the validator was active, used to map
// the validator unique id to a consumer consensus address.
vscid: number;
};

Expand All @@ -108,7 +112,7 @@ type EndAndBeginBlock = {
type SystemSnapshot = {
h: Record<Chain, number>;
t: Record<Chain, number>;
lastVscid: Record<Chain, number>;
latestVscid: Record<Chain, number>;
tokens: number[];
status: Status[];
undelegationQ: Undelegation[];
Expand Down
7 changes: 4 additions & 3 deletions tests/difference/core/model/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ActionGenerator {
// since the last maturity.
return (
this.model.blocks
.getNonMaturedRecentConsumerValidators()
.getConsumerValidatorRecentActiveVSCIDs()
.has((a as ConsumerSlash).val) &&
2 <= this.didSlash.filter((x) => !x).length
);
Expand Down Expand Up @@ -155,14 +155,15 @@ class ActionGenerator {
// Update internal state to prevent jailing all validators
if (a.kind === 'ConsumerSlash') {
const val = (a as ConsumerSlash).val;
// Don't slash the same validator twice
this.didSlash[val] = true;
const vscids = this.model.blocks
.getNonMaturedRecentConsumerValidators()
.getConsumerValidatorRecentActiveVSCIDs()
.get(val);
const items = Array.from(vscids as Set<number>);
// Take a random vscid
const vscid = items[Math.floor(Math.random() * items.length)];
(a as ConsumerSlash).vscid = vscid;
// console.log((a as ConsumerSlash).val, (a as ConsumerSlash).vscid);
}
// Update internal state to prevent expiring light clients
// Client is also updated for Deliver, because this is needed in practice
Expand Down
2 changes: 1 addition & 1 deletion tests/difference/core/model/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ class Model {
return cloneDeep({
h: this.h,
t: this.t,
lastVscid: {
latestVscid: {
provider: this.ccvP.vscID,
consumer: this.ccvC.hToVscID[this.h[C] + 1],
},
Expand Down
12 changes: 7 additions & 5 deletions tests/difference/core/model/src/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CommittedBlock,
Status,
SystemSnapshot,
Validator,
} from './common.js';

/**
Expand Down Expand Up @@ -147,11 +148,12 @@ class BlockHistory {
};

/**
* @returns Get a map of vscid to the set of validators
* who were validating at that vscid on the consumer chain.
* @returns a map of validator id to the set of vscids
* where that validator was validating, since the last
* maturity sent by the consumer
*/
getNonMaturedRecentConsumerValidators = (): Map<
number,
getConsumerValidatorRecentActiveVSCIDs = (): Map<
Validator,
Set<number>
> => {
const greatestCommittedConsumerHeight = _.max(
Expand All @@ -173,7 +175,7 @@ class BlockHistory {
ret.set(i, new Set<number>());
}
const set = ret.get(i);
const vscid = ss.lastVscid[C];
const vscid = ss.latestVscid[C];
set?.add(vscid);
}
});
Expand Down

0 comments on commit 42c2593

Please sign in to comment.