Skip to content

Commit

Permalink
Snapshot, debugging #232
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Aug 4, 2022
1 parent 3afc9a7 commit 8356085
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions diff-test/core/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ function replay(actions: Action[]) {
const model = new Model(sanity, blocks, events);
for (let i = 0; i < actions.length; i++) {
const a = actions[i];
console.log(`action ${i}, kind : ${a.kind}`);
doAction(model, a);
}
}
Expand Down
22 changes: 22 additions & 0 deletions diff-test/core/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ class Staking {
const oldVals = this.lastVals;
const newVals = this.newVals();
newVals.forEach((i) => {
if (this.status[i] !== Status.BONDED) {
console.log(`${i} : ${this.status[i]}->${Status.BONDED}`);
}
this.status[i] = Status.BONDED;
const before = this.validatorQ.length;
this.validatorQ = this.validatorQ.filter((e) => e.val != i);
Expand All @@ -220,6 +223,11 @@ class Staking {
this.m.events.push(Event.SOME_UNVALS_EXPIRED_BUT_NOT_COMPLETED);
}
completedUnvals.forEach((e: Unval) => {
if (this.status[e.val] !== Status.UNBONDED) {
console.log(
`${e.val} : ${this.status[e.val]}->${Status.UNBONDED}`,
);
}
this.status[e.val] = Status.UNBONDED;
this.m.events.push(Event.COMPLETE_UNVAL_IN_ENDBLOCK);
});
Expand All @@ -238,6 +246,9 @@ class Staking {
newUnvals.push(unval);
this.m.ccvP.afterUnbondingInitiated(this.opID);
this.opID += 1;
if (this.status[i] !== Status.UNBONDING) {
console.log(`${i} : ${this.status[i]}->${Status.UNBONDING}`);
}
this.status[i] = Status.UNBONDING;
});
this.validatorQ = this.validatorQ.filter(
Expand Down Expand Up @@ -341,6 +352,7 @@ class Staking {
return this.delegation[val] + 1 * TOKEN_SCALAR;
};
unbondingCanComplete = (opID) => {
console.log(`can complete ${opID}`);
{
const e = _.find(this.validatorQ, (e) => e.opID === opID);
if (e) {
Expand Down Expand Up @@ -420,6 +432,7 @@ class CCVProvider {
}
};
onReceiveVSCMatured = (data: VscMatured) => {
console.log(`recv maturity ${data.vscID}`);
if (this.vscIDtoOpIDs.has(data.vscID)) {
this.vscIDtoOpIDs.get(data.vscID).forEach((opID) => {
this.m.staking.unbondingCanComplete(opID);
Expand Down Expand Up @@ -482,6 +495,7 @@ class CCVConsumer {
})();
matured.forEach((vscID) => {
const data: VscMatured = { vscID };
console.log(`send maturity ${vscID} at time ${this.m.t[C]}`);
this.m.events.push(Event.CONSUMER_SEND_MATURATION);
this.m.outbox[C].add(data);
this.maturingVscs.delete(vscID);
Expand Down Expand Up @@ -518,6 +532,14 @@ class CCVConsumer {
onReceiveVSC = (data: Vsc) => {
this.hToVscID[this.m.h[C] + 1] = data.vscID;
this.pendingChanges.push(data.updates);
console.log(
`recv vsc `,
data.vscID,
'period ',
UNBONDING_SECONDS_C,
'receive time ',
this.m.t[C],
);
this.maturingVscs.set(data.vscID, this.m.t[C] + UNBONDING_SECONDS_C);
data.slashAcks.forEach((val) => {
this.m.events.push(Event.RECEIVE_DOWNTIME_SLASH_ACK);
Expand Down
17 changes: 14 additions & 3 deletions x/ccv/difftest/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ func executeTrace(s *DTTestSuite, traceNum int, trace difftest.TraceData) {
a := action.Action
s.trace.actionIx = i

fmt.Println(s.trace.diagnostic())

switch a.Kind {
case "Delegate":
s.delegate(
Expand Down Expand Up @@ -789,10 +791,10 @@ func executeTrace(s *DTTestSuite, traceNum int, trace difftest.TraceData) {
}

func (s *DTTestSuite) TestTracesCovering() {
traces := loadTraces("noslash.json")
// traces := loadTraces("/Users/danwt/Documents/work/interchain-security/diff-test/core/replay.json")
// traces := loadTraces("noslash.json")
traces := loadTraces("/Users/danwt/Documents/work/interchain-security/diff-test/core/replay.json")
const start = 0
const end = 9999999999
const end = 1
if len(traces) <= end {
traces = traces[start:]
} else {
Expand All @@ -802,9 +804,18 @@ func (s *DTTestSuite) TestTracesCovering() {
s.Run(fmt.Sprintf("Trace%d", i+start), func() {
fmt.Printf("[start trace %d]\n", i)
s.SetupTest()
for i := 0; i < 4; i++ {
val, found := s.stakingKeeperP().GetValidator(s.ctx(P), s.validator(int64(i)))
if !found {
s.T().Fatal("GetValidator() -> !found")
}
fmt.Println(i, val.OperatorAddress)
}
defer func() {
if r := recover(); r != nil {
fmt.Println(s.trace.diagnostic())
fmt.Println(r)
s.Require().FailNow("Hit the panic")
}
}()
s.trace = Trace{
Expand Down

0 comments on commit 8356085

Please sign in to comment.