Skip to content

Commit

Permalink
intersecting
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 11, 2023
1 parent c763f71 commit 4326479
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
11 changes: 0 additions & 11 deletions yarn-project/archiver/src/archiver/archiver_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,6 @@ describe('Archiver Memory Store', () => {
expect(response.maxLogsHit).toEqual(false);
});

it('throws when "fromBlock" is smaller than genesis block', async () => {
const fromBlock = INITIAL_L2_BLOCK_NUM - 1;

await expect(
async () =>
await archiverStore.getUnencryptedLogs({
fromBlock,
}),
).rejects.toThrow(`smaller than genesis block number`);
});

it('does not return more than "maxLogs" logs', async () => {
const maxLogs = 5;
archiverStore = new MemoryArchiverStore(maxLogs);
Expand Down
24 changes: 14 additions & 10 deletions yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,14 @@ export class MemoryArchiverStore implements ArchiverDataStore {
let logIndexInTx = 0;

if (filter.afterLog) {
// Continuation parameter is set: "txHash", "fromBlock" and "toBlock" are ignored.
fromBlockIndex = filter.afterLog.blockNumber - INITIAL_L2_BLOCK_NUM;
txIndexInBlock = filter.afterLog.txIndex;
logIndexInTx = filter.afterLog.logIndex + 1; // We want to start from the next log
// Continuation parameter is set --> tx hash is ignored
if (filter.fromBlock == undefined || filter.fromBlock <= filter.afterLog.blockNumber) {
fromBlockIndex = filter.afterLog.blockNumber - INITIAL_L2_BLOCK_NUM;
txIndexInBlock = filter.afterLog.txIndex;
logIndexInTx = filter.afterLog.logIndex + 1; // We want to start from the next log
} else {
fromBlockIndex = filter.fromBlock - INITIAL_L2_BLOCK_NUM;
}
} else {
txHash = filter.txHash;

Expand All @@ -395,13 +399,13 @@ export class MemoryArchiverStore implements ArchiverDataStore {
if (filter.toBlock !== undefined) {
toBlockIndex = filter.toBlock - INITIAL_L2_BLOCK_NUM;
}
}

if (fromBlockIndex > this.unencryptedLogsPerBlock.length || toBlockIndex < fromBlockIndex) {
return Promise.resolve({
logs: [],
maxLogsHit: false,
});
}
if (fromBlockIndex > this.unencryptedLogsPerBlock.length || toBlockIndex < fromBlockIndex || toBlockIndex <= 0) {
return Promise.resolve({
logs: [],
maxLogsHit: false,
});
}

const contractAddress = filter.contractAddress;
Expand Down
6 changes: 2 additions & 4 deletions yarn-project/types/src/logs/log_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ export type LogFilter = {
*/
export function validateLogFilter(filter: LogFilter) {
if (filter.afterLog) {
// afterLog is a continuation parameter and when it is set, txHash and fromBlock and toBlock are ignored.
// afterLog is a continuation parameter and when it is set, "txHash" is ignored and "fromBlock" and "toBlock" are
// intersected with.
return;
}
if (filter.txHash && (filter.fromBlock || filter.toBlock)) {
throw new Error('Invalid filter: "txHash" is set along with "fromBlock" and or "toBlock".');
}
if (filter.fromBlock !== undefined && filter.fromBlock < INITIAL_L2_BLOCK_NUM) {
throw new Error(`"fromBlock" (${filter.fromBlock}) smaller than genesis block number (${INITIAL_L2_BLOCK_NUM}).`);
}
}

0 comments on commit 4326479

Please sign in to comment.