Skip to content

Commit

Permalink
chore(SwingSet): Improve anachrophobia messages (#10469)
Browse files Browse the repository at this point in the history
## Description
Extracted from an error investigation in #10165.

```diff
-anachrophobia strikes ${vatID} on delivery ${deliveryNum}
+anachrophobia strikes ${vatID} syscalls for delivery ${deliveryNum}
```

```diff
-anachrophobia in ${vatID}: {extra,wrong} syscall
+anachrophobia in ${vatID} delivery ${deliveryNum}: {extra,wrong} syscall at index ${idx}
```

```diff
-anachrophobia in ${vatID}: missing syscalls
+anachrophobia in missing ${missing} syscall(s) at index ${syscallsMade.length}
```

Also capitalizes `WRONG`/`MISSING`/`EXTRA` after `sc[${idx}]:`, for increased visual distinction.

### Security Considerations
None known; any consumer aware of vatIDs should also be allowed to know delivery numbers and constituent syscalls.

### Scaling Considerations
n/a

### Documentation Considerations
n/a

### Testing Considerations
n/a

### Upgrade Considerations
None known; this kernel output should be independent of consensus (and will be consistent across nodes using the same kernel code anyway).
  • Loading branch information
mergify[bot] authored Dec 9, 2024
2 parents 1645d7e + 1b6eb14 commit 56d1c14
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions packages/SwingSet/src/kernel/vat-warehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function makeSyscallSimulator(
deliveryNum,
transcriptEntry,
) {
const context = `anachrophobia in ${vatID} delivery d${deliveryNum}`;
const syscallsExpected = [...transcriptEntry.sc]; // copy
const syscallsMade = [];
// syscallStatus's length will be max(syscallsExpected,
Expand All @@ -107,31 +108,36 @@ export function makeSyscallSimulator(
let replayError; // sticky

const explain = () => {
console.log(`anachrophobia strikes ${vatID} on delivery ${deliveryNum}`);
console.log(
`anachrophobia strikes ${vatID} delivery d${deliveryNum} syscalls`,
);
for (const [idx, status] of syscallStatus.entries()) {
const expected = syscallsExpected[idx];
const got = syscallsMade[idx];
switch (status) {
case 'ok': {
console.log(`sc[${idx}]: ok: ${djson.stringify(got)}`);
console.log(`sc${idx}: ok: ${djson.stringify(got)}`);
break;
}
case 'wrong': {
console.log(`sc[${idx}]: wrong`);
console.log(` expected: ${djson.stringify(expected.s)}`);
console.log(` got : ${djson.stringify(got)}`);
console.log(
`
sc${idx}: WRONG
expected: ${djson.stringify(expected.s)}
got : ${djson.stringify(got)}`.trimStart(),
);
break;
}
case 'extra': {
console.log(`sc[${idx}]: extra: ${djson.stringify(got)}`);
console.log(`sc${idx}: EXTRA: ${djson.stringify(got)}`);
break;
}
case 'missing': {
console.log(`sc[${idx}]: missing: ${djson.stringify(expected.s)}`);
console.log(`sc${idx}: MISSING: ${djson.stringify(expected.s)}`);
break;
}
default:
Fail`bad ${status}`;
Fail`sc${idx}: bad status ${status}`;
}
}
};
Expand All @@ -140,16 +146,16 @@ export function makeSyscallSimulator(
// slog entries have no kernel-translated kso/ksr
const finish = kernelSlog.syscall(vatID, undefined, vso);
const expected = syscallsExpected[syscallsMade.length];
syscallsMade.push(vso);
const idx = syscallsMade.push(vso) - 1;
if (!expected) {
syscallStatus.push('extra');
const error = Error(`anachrophobia in ${vatID}: extra syscall`);
const error = Error(`${context}: extra syscall at index sc${idx}`);
replayError ||= error;
throw error;
}
if (!syscallsAreIdentical(expected.s, vso)) {
syscallStatus.push('wrong');
const error = Error(`anachrophobia in ${vatID}: wrong syscall`);
const error = Error(`${context}: wrong syscall at index sc${idx}`);
replayError ||= error;
throw error;
}
Expand All @@ -159,12 +165,14 @@ export function makeSyscallSimulator(
};

const finishSimulation = () => {
if (syscallsMade.length < syscallsExpected.length) {
const missing = syscallsExpected.length - syscallsMade.length;
const missing = syscallsExpected.length - syscallsMade.length;
if (missing > 0) {
for (let i = 0; i < missing; i += 1) {
syscallStatus.push('missing');
}
const error = Error(`anachrophobia in ${vatID}: missing syscalls`);
const error = Error(
`${context}: missing ${missing} syscall(s) at index sc${syscallsMade.length}`,
);
replayError ||= error;
}

Expand Down

0 comments on commit 56d1c14

Please sign in to comment.