Skip to content

Commit

Permalink
fix(swingset): make vat-warehouse responsible for slogging deliveries
Browse files Browse the repository at this point in the history
This ensures that the log events for any replayed deliveries (performed while
paging a vat back in) appear before the log events for the post-replay
delivery that needed the vat online.
  • Loading branch information
warner committed Sep 22, 2021
1 parent 722f903 commit e317589
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
9 changes: 2 additions & 7 deletions packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,18 +428,13 @@ export default function buildKernel(
// eslint-disable-next-line no-use-before-define
assert(vatWarehouse.lookup(vatID));
const vatKeeper = kernelKeeper.provideVatKeeper(vatID);
const crankNum = kernelKeeper.getCrankNumber();
const deliveryNum = vatKeeper.nextDeliveryNum(); // increments
const { meterID } = vatKeeper.getOptions();
/** @type { SlogFinishDelivery } */
const finish = kernelSlog.delivery(vatID, crankNum, deliveryNum, kd, vd);
// Ensure that the vatSlogger is available before clist translation.
kernelSlog.provideVatSlogger(vatID);
const vs = kernelSlog.provideVatSlogger(vatID).vatSlog;
try {
// eslint-disable-next-line no-use-before-define
const deliveryResult = await vatWarehouse.deliverToVat(vatID, vd);
const deliveryResult = await vatWarehouse.deliverToVat(vatID, kd, vd, vs);
insistVatDeliveryResult(deliveryResult);
finish(deliveryResult);
const [status, problem] = deliveryResult;
if (status !== 'ok') {
// probably a metering fault, or a bug in the vat's dispatch()
Expand Down
22 changes: 19 additions & 3 deletions packages/SwingSet/src/kernel/vatManager/vat-warehouse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
import { assert, details as X, quote as q } from '@agoric/assert';
import { makeVatTranslators } from '../vatTranslator.js';
import { insistVatDeliveryResult } from '../../message.js';

/** @param { number } max */
export const makeLRU = max => {
Expand Down Expand Up @@ -257,14 +258,29 @@ export function makeVatWarehouse(kernelKeeper, vatLoader, policyOptions) {
/** @type { string | undefined } */
let lastVatID;

/** @type {(vatID: string, d: VatDeliveryObject) => Promise<VatDeliveryResult> } */
async function deliverToVat(vatID, delivery) {
/** @type {(vatID: string, kd: KernelDeliveryObject, d: VatDeliveryObject, vs: VatSlog) => Promise<VatDeliveryResult> } */
async function deliverToVat(vatID, kd, vd, vs) {
await applyAvailabilityPolicy(vatID);
lastVatID = vatID;

const recreate = true; // PANIC in the failure case
// create the worker and replay the transcript, if necessary
const { manager } = await ensureVatOnline(vatID, recreate);
return manager.deliver(delivery);

// then log the delivery so it appears after transcript replay
const vatKeeper = kernelKeeper.provideVatKeeper(vatID);
const crankNum = kernelKeeper.getCrankNumber();
const deliveryNum = vatKeeper.nextDeliveryNum(); // increments
/** @type { SlogFinishDelivery } */
const slogFinish = vs.delivery(crankNum, deliveryNum, kd, vd);

// make the delivery
const deliveryResult = await manager.deliver(vd);
insistVatDeliveryResult(deliveryResult);

// log the delivery results, and return to caller for evaluation
slogFinish(deliveryResult);
return deliveryResult;
}

/**
Expand Down

0 comments on commit e317589

Please sign in to comment.