Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ export class PrivateExecutionOracle extends UtilityExecutionOracle implements IP
// This is a tagging secret we've not yet used in this tx, so first sync our store to make sure its indices
// are up to date. We do this here because this store is not synced as part of the global sync because
// that'd be wasteful as most tagging secrets are not used in each tx.
await syncSenderTaggingIndexes(secret, this.contractAddress, this.aztecNode, this.senderTaggingStore);
await syncSenderTaggingIndexes(secret, this.contractAddress, this.aztecNode, this.senderTaggingStore, this.jobId);

const lastUsedIndex = await this.senderTaggingStore.getLastUsedIndex(secret);
const lastUsedIndex = await this.senderTaggingStore.getLastUsedIndex(secret, this.jobId);
// If lastUsedIndex is undefined, we've never used this secret, so start from 0
// Otherwise, the next index to use is one past the last used index
return lastUsedIndex === undefined ? 0 : lastUsedIndex + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
this.recipientTaggingStore,
this.senderAddressBookStore,
this.addressStore,
this.jobId,
);

await logService.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
Expand Down Expand Up @@ -385,11 +386,11 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
// We read all note and event validation requests and process them all concurrently. This makes the process much
// faster as we don't need to wait for the network round-trip.
const noteValidationRequests = (
await this.capsuleStore.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot)
await this.capsuleStore.readCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, this.jobId)
).map(NoteValidationRequest.fromFields);

const eventValidationRequests = (
await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot)
await this.capsuleStore.readCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, this.jobId)
).map(EventValidationRequest.fromFields);

const noteService = new NoteService(this.noteStore, this.aztecNode, this.anchorBlockStore);
Expand Down Expand Up @@ -424,8 +425,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
await Promise.all([...noteDeliveries, ...eventDeliveries]);

// Requests are cleared once we're done.
await this.capsuleStore.setCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, []);
await this.capsuleStore.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, []);
await this.capsuleStore.setCapsuleArray(contractAddress, noteValidationRequestsArrayBaseSlot, [], this.jobId);
await this.capsuleStore.setCapsuleArray(contractAddress, eventValidationRequestsArrayBaseSlot, [], this.jobId);
}

public async utilityBulkRetrieveLogs(
Expand All @@ -441,7 +442,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
// We read all log retrieval requests and process them all concurrently. This makes the process much faster as we
// don't need to wait for the network round-trip.
const logRetrievalRequests = (
await this.capsuleStore.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot)
await this.capsuleStore.readCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, this.jobId)
).map(LogRetrievalRequest.fromFields);

const logService = new LogService(
Expand All @@ -452,18 +453,20 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
this.recipientTaggingStore,
this.senderAddressBookStore,
this.addressStore,
this.jobId,
);

const maybeLogRetrievalResponses = await logService.bulkRetrieveLogs(logRetrievalRequests);

// Requests are cleared once we're done.
await this.capsuleStore.setCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, []);
await this.capsuleStore.setCapsuleArray(contractAddress, logRetrievalRequestsArrayBaseSlot, [], this.jobId);

// The responses are stored as Option<LogRetrievalResponse> in a second CapsuleArray.
await this.capsuleStore.setCapsuleArray(
contractAddress,
logRetrievalResponsesArrayBaseSlot,
maybeLogRetrievalResponses.map(LogRetrievalResponse.toSerializedOption),
this.jobId,
);
}

Expand All @@ -472,7 +475,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
}
return this.capsuleStore.storeCapsule(this.contractAddress, slot, capsule);
this.capsuleStore.storeCapsule(this.contractAddress, slot, capsule, this.jobId);
return Promise.resolve();
}

public async utilityLoadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null> {
Expand All @@ -483,7 +487,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
return (
// TODO(#12425): On the following line, the pertinent capsule gets overshadowed by the transient one. Tackle this.
this.capsules.find(c => c.contractAddress.equals(contractAddress) && c.storageSlot.equals(slot))?.data ??
(await this.capsuleStore.loadCapsule(this.contractAddress, slot))
(await this.capsuleStore.loadCapsule(this.contractAddress, slot, this.jobId))
);
}

Expand All @@ -492,7 +496,8 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
}
return this.capsuleStore.deleteCapsule(this.contractAddress, slot);
this.capsuleStore.deleteCapsule(this.contractAddress, slot, this.jobId);
return Promise.resolve();
}

public utilityCopyCapsule(
Expand All @@ -505,7 +510,7 @@ export class UtilityExecutionOracle implements IMiscOracle, IUtilityExecutionOra
// TODO(#10727): instead of this check that this.contractAddress is allowed to access the external DB
throw new Error(`Contract ${contractAddress} is not allowed to access ${this.contractAddress}'s PXE DB`);
}
return this.capsuleStore.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries);
return this.capsuleStore.copyCapsule(this.contractAddress, srcSlot, dstSlot, numEntries, this.jobId);
}

// TODO(#11849): consider replacing this oracle with a pure Noir implementation of aes decryption.
Expand Down
1 change: 1 addition & 0 deletions yarn-project/pxe/src/logs/log_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('LogService', () => {
recipientTaggingStore,
senderAddressBookStore,
addressStore,
'test',
);

aztecNode.getPrivateLogsByTags.mockReset();
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/pxe/src/logs/log_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class LogService {
private readonly recipientTaggingStore: RecipientTaggingStore,
private readonly senderAddressBookStore: SenderAddressBookStore,
private readonly addressStore: AddressStore,
private readonly jobId: string,
) {}

public async bulkRetrieveLogs(logRetrievalRequests: LogRetrievalRequest[]): Promise<(LogRetrievalResponse | null)[]> {
Expand Down Expand Up @@ -122,6 +123,7 @@ export class LogService {
this.aztecNode,
this.recipientTaggingStore,
anchorBlockNumber,
this.jobId,
),
),
);
Expand Down Expand Up @@ -186,7 +188,7 @@ export class LogService {
});

// TODO: This looks like it could belong more at the oracle interface level
return this.capsuleStore.appendToCapsuleArray(contractAddress, capsuleArrayBaseSlot, pendingTaggedLogs);
return this.capsuleStore.appendToCapsuleArray(contractAddress, capsuleArrayBaseSlot, pendingTaggedLogs, this.jobId);
}

async #getCompleteAddress(account: AztecAddress): Promise<CompleteAddress> {
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/pxe/src/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export class PXE {
);

const jobCoordinator = new JobCoordinator(store);
jobCoordinator.registerStores([capsuleStore, senderTaggingStore, recipientTaggingStore]);

const debugUtils = new PXEDebugUtils(contractStore, noteStore);

Expand Down Expand Up @@ -744,7 +745,7 @@ export class PXE {
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
const txHash = (await txProvingResult.toTx()).txHash;

await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash);
await this.senderTaggingStore.storePendingIndexes(preTagsUsedInTheTx, txHash, jobId);
this.log.debug(`Stored used pre-tags as sender for the tx`, {
preTagsUsedInTheTx,
});
Expand Down
Loading