Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: renamed take to limit #1361

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
}

/**
* Gets the `take` amount of L2 blocks starting from `from`.
* Gets up to `limit` amount of L2 blocks starting from `from`.
* @param from - Number of the first block to return (inclusive).
* @param take - The number of blocks to return.
* @param limit - The number of blocks to return.
* @returns The requested L2 blocks.
*/
public getL2Blocks(from: number, take: number): Promise<L2Block[]> {
return this.store.getL2Blocks(from, take);
public getL2Blocks(from: number, limit: number): Promise<L2Block[]> {
return this.store.getL2Blocks(from, limit);
}

/**
Expand Down Expand Up @@ -322,14 +322,14 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
}

/**
* Gets the `take` amount of logs starting from `from`.
* Gets up to `limit` amount of logs starting from `from`.
* @param from - Number of the L2 block to which corresponds the first logs to be returned.
* @param take - The number of logs to return.
* @param limit - The number of logs to return.
* @param logType - Specifies whether to return encrypted or unencrypted logs.
* @returns The requested logs.
*/
public getLogs(from: number, take: number, logType: LogType): Promise<L2BlockL2Logs[]> {
return this.store.getLogs(from, take, logType);
public getLogs(from: number, limit: number, logType: LogType): Promise<L2BlockL2Logs[]> {
return this.store.getLogs(from, limit, logType);
}

/**
Expand All @@ -341,12 +341,12 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
}

/**
* Gets the `take` amount of pending L1 to L2 messages.
* @param take - The number of messages to return.
* Gets up to `limit` amount of pending L1 to L2 messages.
* @param limit - The number of messages to return.
* @returns The requested L1 to L2 messages' keys.
*/
getPendingL1ToL2Messages(take: number): Promise<Fr[]> {
return this.store.getPendingL1ToL2MessageKeys(take);
getPendingL1ToL2Messages(limit: number): Promise<Fr[]> {
return this.store.getPendingL1ToL2MessageKeys(limit);
}

/**
Expand Down
42 changes: 21 additions & 21 deletions yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export interface ArchiverDataStore {
addL2Blocks(blocks: L2Block[]): Promise<boolean>;

/**
* Gets the `take` amount of L2 blocks starting from `from`.
* Gets up to `limit` amount of L2 blocks starting from `from`.
* @param from - Number of the first block to return (inclusive).
* @param take - The number of blocks to return.
* @param limit - The number of blocks to return.
* @returns The requested L2 blocks.
*/
getL2Blocks(from: number, take: number): Promise<L2Block[]>;
getL2Blocks(from: number, limit: number): Promise<L2Block[]>;

/**
* Append new logs to the store's list.
Expand Down Expand Up @@ -63,11 +63,11 @@ export interface ArchiverDataStore {
confirmL1ToL2Messages(messageKeys: Fr[]): Promise<boolean>;

/**
* Gets the `take` amount of pending L1 to L2 messages, sorted by fee
* @param take - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
* Gets up to `limit` amount of pending L1 to L2 messages, sorted by fee
* @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
* @returns The requested L1 to L2 message keys.
*/
getPendingL1ToL2MessageKeys(take: number): Promise<Fr[]>;
getPendingL1ToL2MessageKeys(limit: number): Promise<Fr[]>;

/**
* Gets the confirmed L1 to L2 message corresponding to the given message key.
Expand All @@ -77,13 +77,13 @@ export interface ArchiverDataStore {
getConfirmedL1ToL2Message(messageKey: Fr): Promise<L1ToL2Message>;

/**
* Gets the `take` amount of logs starting from `from`.
* Gets up to `limit` amount of logs starting from `from`.
* @param from - Number of the L2 block to which corresponds the first logs to be returned.
* @param take - The number of logs to return.
* @param limit - The number of logs to return.
* @param logType - Specifies whether to return encrypted or unencrypted logs.
* @returns The requested logs.
*/
getLogs(from: number, take: number, logType: LogType): Promise<L2BlockL2Logs[]>;
getLogs(from: number, limit: number, logType: LogType): Promise<L2BlockL2Logs[]>;

/**
* Store new Contract Public Data from an L2 block to the store's list.
Expand Down Expand Up @@ -250,30 +250,30 @@ export class MemoryArchiverStore implements ArchiverDataStore {
}

/**
* Gets the `take` amount of L2 blocks starting from `from`.
* Gets up to `limit` amount of L2 blocks starting from `from`.
* @param from - Number of the first block to return (inclusive).
* @param take - The number of blocks to return.
* @param limit - The number of blocks to return.
* @returns The requested L2 blocks.
*/
public getL2Blocks(from: number, take: number): Promise<L2Block[]> {
public getL2Blocks(from: number, limit: number): Promise<L2Block[]> {
if (from < INITIAL_L2_BLOCK_NUM) {
throw new Error(`Invalid block range ${from}`);
}
if (from > this.l2Blocks.length) {
return Promise.resolve([]);
}
const startIndex = from - INITIAL_L2_BLOCK_NUM;
const endIndex = from + take;
const endIndex = from + limit;
return Promise.resolve(this.l2Blocks.slice(startIndex, endIndex));
}

/**
* Gets the `take` amount of pending L1 to L2 messages, sorted by fee
* @param take - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
* Gets up to `limit` amount of pending L1 to L2 messages, sorted by fee
* @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
* @returns The requested L1 to L2 message keys.
*/
public getPendingL1ToL2MessageKeys(take: number = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP): Promise<Fr[]> {
return Promise.resolve(this.pendingL1ToL2Messages.getMessageKeys(take));
public getPendingL1ToL2MessageKeys(limit: number = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP): Promise<Fr[]> {
return Promise.resolve(this.pendingL1ToL2Messages.getMessageKeys(limit));
}

/**
Expand All @@ -290,13 +290,13 @@ export class MemoryArchiverStore implements ArchiverDataStore {
}

/**
* Gets the `take` amount of logs starting from `from`.
* Gets up to `limit` amount of logs starting from `from`.
* @param from - Number of the L2 block to which corresponds the first logs to be returned.
* @param take - The number of logs to return.
* @param limit - The number of logs to return.
* @param logType - Specifies whether to return encrypted or unencrypted logs.
* @returns The requested logs.
*/
getLogs(from: number, take: number, logType: LogType): Promise<L2BlockL2Logs[]> {
getLogs(from: number, limit: number, logType: LogType): Promise<L2BlockL2Logs[]> {
if (from < INITIAL_L2_BLOCK_NUM) {
throw new Error(`Invalid block range ${from}`);
}
Expand All @@ -305,7 +305,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
return Promise.resolve([]);
}
const startIndex = from - INITIAL_L2_BLOCK_NUM;
const endIndex = from + take;
const endIndex = from + limit;
return Promise.resolve(logs.slice(startIndex, endIndex));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ describe('pending_l1_to_l2_message_store', () => {
expect(store.getMessageKeys(10)).toEqual([]);
});

it('getMessageKeys returns an empty array if take is 0', () => {
it('getMessageKeys returns an empty array if limit is 0', () => {
store.addMessage(entryKey, msg);
expect(store.getMessageKeys(0)).toEqual([]);
});

it('get messages for a non-empty store when take > number of messages in store', () => {
it('get messages for a non-empty store when limit > number of messages in store', () => {
const entryKeys = [1, 2, 3, 4, 5].map(x => new Fr(x));
entryKeys.forEach(entryKey => {
store.addMessage(entryKey, L1ToL2Message.random());
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/archiver/src/archiver/l1_to_l2_message_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ export class L1ToL2MessageStore {
* for removing messages or fetching multiple messages.
*/
export class PendingL1ToL2MessageStore extends L1ToL2MessageStore {
getMessageKeys(take: number): Fr[] {
if (take < 1) {
getMessageKeys(limit: number): Fr[] {
if (limit < 1) {
return [];
}
// fetch `take` number of messages from the store with the highest fee.
// fetch `limit` number of messages from the store with the highest fee.
// Note the store has multiple of the same message. So if a message has count 2, include both of them in the result:
const messages: Fr[] = [];
const sortedMessages = Array.from(this.store.values()).sort((a, b) => b.message.fee - a.message.fee);
for (const messageAndCount of sortedMessages) {
for (let i = 0; i < messageAndCount.count; i++) {
messages.push(messageAndCount.message.entryKey!);
if (messages.length === take) {
if (messages.length === limit) {
return messages;
}
}
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ Gets all the unencrypted logs from L2 blocks in the specified range.
Syntax:

```shell
aztec-cli get-logs <from> <take> [options]
aztec-cli get-logs <from> <limit> [options]
```

- `from`: Block number to start fetching logs from.
- `take`: Number of block logs to fetch.
- `limit`: Maximum number of block logs to obtain.

Options:

Expand Down
10 changes: 5 additions & 5 deletions yarn-project/aztec-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,22 +216,22 @@ async function main() {
.command('get-logs')
.description('Gets all the unencrypted logs from L2 blocks in the range specified.')
.argument('<from>', 'Block num start for getting logs.')
.argument('<take>', 'How many block logs to fetch.')
.argument('<limit>', 'How many block logs to fetch.')
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
.action(async (_from, _take, options) => {
let from: number;
let take: number;
let limit: number;
try {
from = parseInt(_from);
take = parseInt(_take);
limit = parseInt(_take);
} catch {
log(`Invalid integer value(s) passed: ${_from}, ${_take}`);
return;
}
const client = createAztecRpcClient(options.rpcUrl);
const logs = await client.getUnencryptedLogs(from, take);
const logs = await client.getUnencryptedLogs(from, limit);
if (!logs.length) {
log(`No logs found in blocks ${from} to ${from + take}`);
log(`No logs found in blocks ${from} to ${from + limit}`);
} else {
log('Logs found: \n');
L2BlockL2Logs.unrollLogs(logs).forEach(fnLog => log(`${fnLog.toString('ascii')}\n`));
Expand Down
18 changes: 10 additions & 8 deletions yarn-project/aztec-node/src/aztec-node/http-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('HttpNode', () => {

const result = await httpNode.getBlocks(0, 3);

expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-blocks?from=0&take=3`);
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-blocks?from=0&limit=3`);
expect(result).toEqual([block1, block2]);
});

Expand All @@ -79,7 +79,7 @@ describe('HttpNode', () => {

const result = await httpNode.getBlocks(0, 2);

expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-blocks?from=0&take=2`);
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-blocks?from=0&limit=2`);
expect(result).toEqual([]);
});
});
Expand Down Expand Up @@ -157,17 +157,17 @@ describe('HttpNode', () => {
const processedLogType = logType === 'encrypted' ? LogType.ENCRYPTED : LogType.UNENCRYPTED;

const from = 0;
const take = 3;
const limit = 3;
const log1 = L2BlockL2Logs.random(2, 3, 4);
const log2 = L2BlockL2Logs.random(1, 5, 2);
const response = {
logs: [log1.toBuffer(), log2.toBuffer()],
};
setFetchMock(response);

const result = await httpNode.getLogs(from, take, processedLogType);
const result = await httpNode.getLogs(from, limit, processedLogType);

expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-logs?from=${from}&take=${take}&logType=${processedLogType}`);
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-logs?from=${from}&limit=${limit}&logType=${processedLogType}`);
expect(result).toEqual([log1, log2]);
});

Expand All @@ -177,13 +177,15 @@ describe('HttpNode', () => {
const processedLogType = logType === 'encrypted' ? LogType.ENCRYPTED : LogType.UNENCRYPTED;

const from = 0;
const take = 2;
const limit = 2;
const response = {};
setFetchMock(response);

const result = await httpNode.getLogs(from, take, processedLogType);
const result = await httpNode.getLogs(from, limit, processedLogType);

expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-logs?from=${from}&take=${take}&logType=${processedLogType}`);
expect(fetch).toHaveBeenCalledWith(
`${TEST_URL}get-logs?from=${from}&limit=${limit}&logType=${processedLogType}`,
);
expect(result).toEqual([]);
},
);
Expand Down
16 changes: 8 additions & 8 deletions yarn-project/aztec-node/src/aztec-node/http-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export class HttpNode implements AztecNode {
/**
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
* @param from - The start of the range of blocks to return.
* @param take - The number of blocks desired.
* @param limit - Maximum number of blocks to obtain.
* @returns The blocks requested.
*/
async getBlocks(from: number, take: number): Promise<L2Block[]> {
async getBlocks(from: number, limit: number): Promise<L2Block[]> {
const url = new URL(`${this.baseUrl}/get-blocks`);
url.searchParams.append('from', from.toString());
if (take !== undefined) {
url.searchParams.append('take', take.toString());
if (limit !== undefined) {
url.searchParams.append('limit', limit.toString());
}
const response = await (await fetch(url.toString())).json();
const blocks = response.blocks as string[];
Expand Down Expand Up @@ -114,17 +114,17 @@ export class HttpNode implements AztecNode {
}

/**
* Gets the `take` amount of logs starting from `from`.
* Gets up to `limit` amount of logs starting from `from`.
* @param from - Number of the L2 block to which corresponds the first logs to be returned.
* @param take - The number of logs to return.
* @param limit - The maximum number of logs to return.
* @param logType - Specifies whether to return encrypted or unencrypted logs.
* @returns The requested logs.
*/
public async getLogs(from: number, take: number, logType: LogType): Promise<L2BlockL2Logs[]> {
public async getLogs(from: number, limit: number, logType: LogType): Promise<L2BlockL2Logs[]> {
const url = new URL(`${this.baseUrl}/get-logs`);

url.searchParams.append('from', from.toString());
url.searchParams.append('take', take.toString());
url.searchParams.append('limit', limit.toString());
url.searchParams.append('logType', logType.toString());

const response = await (await fetch(url.toString())).json();
Expand Down
14 changes: 7 additions & 7 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ export class AztecNodeService implements AztecNode {
/**
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
* @param from - The start of the range of blocks to return.
* @param take - The number of blocks desired.
* @param limit - The maximum number of blocks to obtain.
* @returns The blocks requested.
*/
public async getBlocks(from: number, take: number): Promise<L2Block[]> {
return (await this.blockSource.getL2Blocks(from, take)) ?? [];
public async getBlocks(from: number, limit: number): Promise<L2Block[]> {
return (await this.blockSource.getL2Blocks(from, limit)) ?? [];
}

/**
Expand Down Expand Up @@ -170,15 +170,15 @@ export class AztecNodeService implements AztecNode {
}

/**
* Gets the `take` amount of logs starting from `from`.
* Gets up to `limit` amount of logs starting from `from`.
* @param from - Number of the L2 block to which corresponds the first logs to be returned.
* @param take - The number of logs to return.
* @param limit - The maximum number of logs to return.
* @param logType - Specifies whether to return encrypted or unencrypted logs.
* @returns The requested logs.
*/
public getLogs(from: number, take: number, logType: LogType): Promise<L2BlockL2Logs[]> {
public getLogs(from: number, limit: number, logType: LogType): Promise<L2BlockL2Logs[]> {
const logSource = logType === LogType.ENCRYPTED ? this.encryptedLogsSource : this.unencryptedLogsSource;
return logSource.getLogs(from, take, logType);
return logSource.getLogs(from, limit, logType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ export class AztecRPCServer implements AztecRPC {
return await this.node.getContractInfo(contractAddress);
}

public async getUnencryptedLogs(from: number, take: number): Promise<L2BlockL2Logs[]> {
return await this.node.getLogs(from, take, LogType.UNENCRYPTED);
public async getUnencryptedLogs(from: number, limit: number): Promise<L2BlockL2Logs[]> {
return await this.node.getLogs(from, limit, LogType.UNENCRYPTED);
}

async #getExecutionRequest(
Expand Down
Loading