@metamask/ocap-kernel
Version:
OCap kernel core components
1 lines • 18.7 kB
Source Map (JSON)
{"version":3,"file":"VatHandle.cjs","sourceRoot":"","sources":["../src/VatHandle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,2DAA2E;AAC3E,qEAAqE;AAOrE,6CAA0C;AAE1C,2CAA2E;AAI3E,8CAAoE;AAEpE,qEAA+D;AAU/D,oDAA6C;AAe7C,MAAa,SAAS;IA6BpB;;;;;;;;;;OAUG;IACH,gDAAgD;IAChD,YAAoB,EAClB,KAAK,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,WAAW,EACX,MAAM,GACc;;QA5CtB,wDAAwD;QAC/C,uCAAsB;QAK/B,qEAAqE;QAC5D,oCAAgB;QAEzB,oDAAoD;QAC3C,yCAA0B;QAEnC,kDAAkD;QACzC,sCAAoB;QAE7B,wBAAwB;QACf,wCAAwB;QAEjC,yBAAyB;QAChB,yCAA0B;QAE1B,uCAA6C;QAE7C,wCAAmD;QAsB1D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,uBAAA,IAAI,qBAAW,MAAM,IAAI,IAAI,eAAM,CAAC,QAAQ,KAAK,GAAG,CAAC,MAAA,CAAC;QACtD,uBAAA,IAAI,wBAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,0BAAgB,WAAW,MAAA,CAAC;QAChC,uBAAA,IAAI,uBAAa,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,MAAA,CAAC;QACjD,uBAAA,IAAI,0BAAgB,WAAW,MAAA,CAAC;QAChC,uBAAA,IAAI,yBAAe,IAAI,0BAAU,CAAC;YAChC,KAAK;YACL,WAAW;YACX,WAAW;YACX,MAAM,EAAE,uBAAA,IAAI,yBAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC;SACtD,CAAC,MAAA,CAAC;QAEH,uBAAA,IAAI,w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,MAAM,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import type {\n VatOneResolution,\n VatSyscallObject,\n} from '@agoric/swingset-liveslots';\nimport { VatDeletedError, StreamReadError } from '@metamask/kernel-errors';\nimport { RpcClient, RpcService } from '@metamask/kernel-rpc-methods';\nimport type {\n ExtractParams,\n ExtractResult,\n} from '@metamask/kernel-rpc-methods';\nimport type { VatStore } from '@metamask/kernel-store';\nimport type { JsonRpcMessage } from '@metamask/kernel-utils';\nimport { Logger } from '@metamask/logger';\nimport type { DuplexStream } from '@metamask/streams';\nimport { isJsonRpcNotification, isJsonRpcResponse } from '@metamask/utils';\nimport type { JsonRpcNotification, JsonRpcResponse } from '@metamask/utils';\n\nimport type { KernelQueue } from './KernelQueue.ts';\nimport { vatMethodSpecs, vatSyscallHandlers } from './rpc/index.ts';\nimport type { PingVatResult, VatMethod } from './rpc/index.ts';\nimport { kser, makeError } from './services/kernel-marshal.ts';\nimport type { KernelStore } from './store/index.ts';\nimport type {\n Message,\n VatId,\n VatConfig,\n VRef,\n CrankResults,\n VatDeliveryResult,\n} from './types.ts';\nimport { VatSyscall } from './VatSyscall.ts';\n\ntype MessageFromVat = JsonRpcResponse | JsonRpcNotification;\n\ntype VatStream = DuplexStream<MessageFromVat, JsonRpcMessage>;\n\ntype VatConstructorProps = {\n vatId: VatId;\n vatConfig: VatConfig;\n vatStream: VatStream;\n kernelStore: KernelStore;\n kernelQueue: KernelQueue;\n logger?: Logger | undefined;\n};\n\nexport class VatHandle {\n /** The ID of the vat this is the VatHandle for */\n readonly vatId: VatId;\n\n /** Communications channel to and from the vat itself */\n readonly #vatStream: VatStream;\n\n /** The vat's configuration */\n readonly config: VatConfig;\n\n /** Logger for outputting messages (such as errors) to the console */\n readonly #logger: Logger;\n\n /** Storage holding the kernel's persistent state */\n readonly #kernelStore: KernelStore;\n\n /** Storage holding this vat's persistent state */\n readonly #vatStore: VatStore;\n\n /** The vat's syscall */\n readonly #vatSyscall: VatSyscall;\n\n /** The kernel's queue */\n readonly #kernelQueue: KernelQueue;\n\n readonly #rpcClient: RpcClient<typeof vatMethodSpecs>;\n\n readonly #rpcService: RpcService<typeof vatSyscallHandlers>;\n\n /**\n * Construct a new VatHandle instance.\n *\n * @param params - Named constructor parameters.\n * @param params.vatId - Our vat ID.\n * @param params.vatConfig - The configuration for this vat.\n * @param params.vatStream - Communications channel connected to the vat worker.\n * @param params.kernelStore - The kernel's persistent state store.\n * @param params.kernelQueue - The kernel's queue.\n * @param params.logger - Optional logger for error and diagnostic output.\n */\n // eslint-disable-next-line no-restricted-syntax\n private constructor({\n vatId,\n vatConfig,\n vatStream,\n kernelStore,\n kernelQueue,\n logger,\n }: VatConstructorProps) {\n this.vatId = vatId;\n this.config = vatConfig;\n this.#logger = logger ?? new Logger(`[vat ${vatId}]`);\n this.#vatStream = vatStream;\n this.#kernelStore = kernelStore;\n this.#vatStore = kernelStore.makeVatStore(vatId);\n this.#kernelQueue = kernelQueue;\n this.#vatSyscall = new VatSyscall({\n vatId,\n kernelQueue,\n kernelStore,\n logger: this.#logger.subLogger({ tags: ['syscall'] }),\n });\n\n this.#rpcClient = new RpcClient(\n vatMethodSpecs,\n async (request) => {\n await this.#vatStream.write(request);\n },\n `${this.vatId}:`,\n );\n this.#rpcService = new RpcService(vatSyscallHandlers, {\n handleSyscall: (params) => {\n this.#vatSyscall.handleSyscall(params as VatSyscallObject);\n },\n });\n }\n\n /**\n * Create a new VatHandle instance.\n *\n * @param params - Named constructor parameters.\n * @param params.vatId - Our vat ID.\n * @param params.vatConfig - The configuration for this vat.\n * @param params.vatStream - Communications channel connected to the vat worker.\n * @param params.kernelStore - The kernel's persistent state store.\n * @param params.kernelQueue - The kernel's queue.\n * @param params.logger - Optional logger for error and diagnostic output.\n * @returns A promise for the new VatHandle instance.\n */\n static async make(params: VatConstructorProps): Promise<VatHandle> {\n const vat = new VatHandle(params);\n await vat.#init();\n return vat;\n }\n\n /**\n * Initializes the vat.\n *\n * @returns A promise that resolves when the vat is initialized.\n */\n async #init(): Promise<void> {\n Promise.all([this.#vatStream.drain(this.#handleMessage.bind(this))]).catch(\n async (error) => {\n this.#logger.error(`Unexpected read error`, error);\n await this.terminate(\n true,\n new StreamReadError({ vatId: this.vatId }, error),\n );\n },\n );\n\n await this.sendVatCommand({\n method: 'initVat',\n params: {\n vatConfig: this.config,\n state: this.#vatStore.getKVData(),\n },\n });\n }\n\n /**\n * Ping the vat.\n *\n * @returns A promise that resolves to the result of the ping.\n */\n async ping(): Promise<PingVatResult> {\n return await this.sendVatCommand({\n method: 'ping',\n params: [],\n });\n }\n\n /**\n * Handle a message from the vat.\n *\n * @param message - The message to handle.\n * @param message.id - The id of the message.\n * @param message.payload - The payload (i.e., the message itself) to handle.\n */\n async #handleMessage(message: JsonRpcMessage): Promise<void> {\n if (isJsonRpcResponse(message)) {\n this.#rpcClient.handleResponse(message.id as string, message);\n } else if (isJsonRpcNotification(message)) {\n this.#rpcService.assertHasMethod(message.method);\n await this.#rpcService.execute(message.method, message.params);\n } else {\n // We don't expect any JSON-RPC requests from the vat, but the stream may permit them\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Received unexpected message: ${message}`);\n }\n }\n\n /**\n * Make a 'message' delivery to the vat.\n *\n * @param target - The VRef of the object to which the message is addressed.\n * @param message - The message to deliver.\n * @returns The crank results.\n */\n async deliverMessage(target: VRef, message: Message): Promise<CrankResults> {\n await this.sendVatCommand({\n method: 'deliver',\n params: ['message', target, message],\n });\n return this.#getDeliveryCrankResults();\n }\n\n /**\n * Make a 'notify' delivery to the vat.\n *\n * @param resolutions - One or more promise resolutions to deliver.\n * @returns The crank results.\n */\n async deliverNotify(resolutions: VatOneResolution[]): Promise<CrankResults> {\n await this.sendVatCommand({\n method: 'deliver',\n params: ['notify', resolutions],\n });\n return this.#getDeliveryCrankResults();\n }\n\n /**\n * Make a 'dropExports' delivery to the vat.\n *\n * @param vrefs - The VRefs of the exports to be dropped.\n * @returns The crank results.\n */\n async deliverDropExports(vrefs: VRef[]): Promise<CrankResults> {\n await this.sendVatCommand({\n method: 'deliver',\n params: ['dropExports', vrefs],\n });\n return this.#getDeliveryCrankResults();\n }\n\n /**\n * Make a 'retireExports' delivery to the vat.\n *\n * @param vrefs - The VRefs of the exports to be retired.\n * @returns The crank results.\n */\n async deliverRetireExports(vrefs: VRef[]): Promise<CrankResults> {\n await this.sendVatCommand({\n method: 'deliver',\n params: ['retireExports', vrefs],\n });\n return this.#getDeliveryCrankResults();\n }\n\n /**\n * Make a 'retireImports' delivery to the vat.\n *\n * @param vrefs - The VRefs of the imports to be retired.\n * @returns The crank results.\n */\n async deliverRetireImports(vrefs: VRef[]): Promise<CrankResults> {\n await this.sendVatCommand({\n method: 'deliver',\n params: ['retireImports', vrefs],\n });\n return this.#getDeliveryCrankResults();\n }\n\n /**\n * Make a 'bringOutYourDead' delivery to the vat.\n *\n * @returns The crank results.\n */\n async deliverBringOutYourDead(): Promise<CrankResults> {\n await this.sendVatCommand({\n method: 'deliver',\n params: ['bringOutYourDead'],\n });\n return this.#getDeliveryCrankResults();\n }\n\n /**\n * Terminates the vat.\n *\n * @param terminating - If true, the vat is being killed permanently, so clean\n * up its state and reject any promises that would be left dangling.\n * @param error - The error to terminate the vat with.\n */\n async terminate(terminating: boolean, error?: Error): Promise<void> {\n await this.#vatStream.end(error);\n const terminationError = error ?? new VatDeletedError(this.vatId);\n if (terminating) {\n // Reject promises exported to other vats for which this vat is the decider\n const failure = kser(terminationError);\n for (const kpid of this.#kernelStore.getPromisesByDecider(this.vatId)) {\n this.#kernelQueue.resolvePromises(this.vatId, [[kpid, true, failure]]);\n }\n this.#rpcClient.rejectAll(terminationError);\n this.#kernelStore.deleteVat(this.vatId);\n }\n }\n\n /**\n * Send a command into the vat.\n *\n * @param payload - The payload of the command.\n * @param payload.method - The method to call.\n * @param payload.params - The parameters to pass to the method.\n * @returns A promise that resolves the response to the command.\n */\n async sendVatCommand<Method extends VatMethod>({\n method,\n params,\n }: {\n method: Method;\n params: ExtractParams<Method, typeof vatMethodSpecs>;\n }): Promise<ExtractResult<Method, typeof vatMethodSpecs>> {\n const result = await this.#rpcClient.call(method, params);\n if (method === 'initVat' || method === 'deliver') {\n const [[sets, deletes], deliveryError] = result as VatDeliveryResult;\n this.#vatSyscall.deliveryError = deliveryError ?? undefined;\n const noErrors = !deliveryError && !this.#vatSyscall.illegalSyscall;\n // On errors, we neither update this vat's KV data nor rollback previous changes.\n // This is safe because vats are always terminated when errors occur\n // and they have their own databases, which are deleted when the vat is terminated.\n // The main kernel database will be rolled back.\n if (noErrors) {\n this.#vatStore.updateKVData(sets, deletes);\n }\n }\n return result;\n }\n\n /**\n * Get the crank outcome for a given checkpoint result.\n *\n * @returns The crank outcome.\n */\n async #getDeliveryCrankResults(): Promise<CrankResults> {\n const results: CrankResults = {\n didDelivery: this.vatId,\n };\n\n // These conditionals express a priority order: the consequences of an\n // illegal syscall take precedence over a vat requesting termination, etc.\n if (this.#vatSyscall.illegalSyscall) {\n results.abort = true;\n const { info } = this.#vatSyscall.illegalSyscall;\n // TODO: For now, vat errors both rewind changes and terminate the vat.\n // Some day, they might rewind changes and retry the syscall.\n // We should terminate the vat only after a certain # of failed retries.\n results.terminate = { vatId: this.vatId, reject: true, info };\n } else if (this.#vatSyscall.deliveryError) {\n results.abort = true;\n const info = makeError(this.#vatSyscall.deliveryError);\n results.terminate = { vatId: this.vatId, reject: true, info };\n } else if (this.#vatSyscall.vatRequestedTermination) {\n if (this.#vatSyscall.vatRequestedTermination.reject) {\n results.abort = true; // vatPowers.exitWithFailure wants rewind\n }\n results.terminate = {\n vatId: this.vatId,\n ...this.#vatSyscall.vatRequestedTermination,\n };\n }\n\n return harden(results);\n }\n}\n"]}