Skip to content

Commit

Permalink
refactor: consistent block functions names
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 12, 2023
1 parent c42833e commit f20461a
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 30 deletions.
10 changes: 5 additions & 5 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource

// store retrieved L2 blocks after removing new logs information.
// remove logs to serve "lightweight" block information. Logs can be fetched separately if needed.
await this.store.addL2Blocks(
await this.store.addBlocks(
retrievedBlocks.retrievedData.map(block =>
L2Block.fromFields(omit(block, ['newEncryptedLogs', 'newUnencryptedLogs']), block.getBlockHash()),
),
Expand Down Expand Up @@ -306,21 +306,21 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
* @param limit - The number of blocks to return.
* @returns The requested L2 blocks.
*/
public getL2Blocks(from: number, limit: number): Promise<L2Block[]> {
return this.store.getL2Blocks(from, limit);
public getBlocks(from: number, limit: number): Promise<L2Block[]> {
return this.store.getBlocks(from, limit);
}

/**
* Gets an l2 block.
* @param number - The block number to return (inclusive).
* @returns The requested L2 block.
*/
public async getL2Block(number: number): Promise<L2Block | undefined> {
public async getBlock(number: number): Promise<L2Block | undefined> {
// If the number provided is -ve, then return the latest block.
if (number < 0) {
number = this.store.getBlocksLength();
}
const blocks = await this.store.getL2Blocks(number, 1);
const blocks = await this.store.getBlocks(number, 1);
return blocks.length === 0 ? undefined : blocks[0];
}

Expand Down
16 changes: 8 additions & 8 deletions yarn-project/archiver/src/archiver/archiver_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Archiver Memory Store', () => {
const blocks = Array(10)
.fill(0)
.map((_, index) => L2Block.random(index));
await archiverStore.addL2Blocks(blocks);
await archiverStore.addBlocks(blocks);
// Offset indices by INITIAL_L2_BLOCK_NUM to ensure we are correctly aligned
for (const [from, limit] of [
[0 + INITIAL_L2_BLOCK_NUM, 10],
Expand All @@ -35,7 +35,7 @@ describe('Archiver Memory Store', () => {
[11 + INITIAL_L2_BLOCK_NUM, 1],
]) {
const expected = blocks.slice(from - INITIAL_L2_BLOCK_NUM, from - INITIAL_L2_BLOCK_NUM + limit);
const actual = await archiverStore.getL2Blocks(from, limit);
const actual = await archiverStore.getBlocks(from, limit);
expect(expected).toEqual(actual);
}
});
Expand Down Expand Up @@ -64,16 +64,16 @@ describe('Archiver Memory Store', () => {
const blocks = Array(10)
.fill(0)
.map((_, index) => L2Block.random(index));
await archiverStore.addL2Blocks(blocks);
await expect(async () => await archiverStore.getL2Blocks(1, 0)).rejects.toThrow(`Invalid limit: 0`);
await archiverStore.addBlocks(blocks);
await expect(async () => await archiverStore.getBlocks(1, 0)).rejects.toThrow(`Invalid limit: 0`);
});

it('returns from the beginning when "from" < genesis block', async () => {
const blocks = Array(10)
.fill(0)
.map((_, index) => L2Block.random(index));
await archiverStore.addL2Blocks(blocks);
const retrievedBlocks = await archiverStore.getL2Blocks(-5, 1);
await archiverStore.addBlocks(blocks);
const retrievedBlocks = await archiverStore.getBlocks(-5, 1);
expect(retrievedBlocks.length).toEqual(1);
expect(retrievedBlocks[0]).toEqual(blocks[0]);
});
Expand All @@ -97,7 +97,7 @@ describe('Archiver Memory Store', () => {
.fill(0)
.map((_, index: number) => L2Block.random(index + 1, 4, 2, 3, 2, 2));

await archiverStore.addL2Blocks(blocks);
await archiverStore.addBlocks(blocks);
await archiverStore.addLogs(
blocks.map(block => block.newUnencryptedLogs!),
LogType.UNENCRYPTED,
Expand All @@ -124,7 +124,7 @@ describe('Archiver Memory Store', () => {
L2Block.random(index + 1, txsPerBlock, 2, numPublicFunctionCalls, 2, numUnencryptedLogs),
);

await archiverStore.addL2Blocks(blocks);
await archiverStore.addBlocks(blocks);
await archiverStore.addLogs(
blocks.map(block => block.newUnencryptedLogs!),
LogType.UNENCRYPTED,
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ export interface ArchiverDataStore {
* @param blocks - The L2 blocks to be added to the store.
* @returns True if the operation is successful.
*/
addL2Blocks(blocks: L2Block[]): Promise<boolean>;
addBlocks(blocks: L2Block[]): Promise<boolean>;

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

/**
* Gets an l2 tx.
Expand Down Expand Up @@ -215,7 +215,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
* @param blocks - The L2 blocks to be added to the store.
* @returns True if the operation is successful (always in this implementation).
*/
public addL2Blocks(blocks: L2Block[]): Promise<boolean> {
public addBlocks(blocks: L2Block[]): Promise<boolean> {
this.l2BlockContexts.push(...blocks.map(block => new L2BlockContext(block)));
this.l2Txs.push(...blocks.flatMap(b => b.getTxs()));
return Promise.resolve(true);
Expand Down Expand Up @@ -301,7 +301,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
* @returns The requested L2 blocks.
* @remarks When "from" is smaller than genesis block number, blocks from the beginning are returned.
*/
public getL2Blocks(from: number, limit: number): Promise<L2Block[]> {
public getBlocks(from: number, limit: number): Promise<L2Block[]> {
// Return an empty array if we are outside of range
if (limit < 1) {
throw new Error(`Invalid limit: ${limit}`);
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class AztecNodeService implements AztecNode {
* @returns The blocks requested.
*/
public async getBlock(number: number): Promise<L2Block | undefined> {
return await this.blockSource.getL2Block(number);
return await this.blockSource.getBlock(number);
}

/**
Expand All @@ -169,7 +169,7 @@ export class AztecNodeService implements AztecNode {
* @returns The blocks requested.
*/
public async getBlocks(from: number, limit: number): Promise<L2Block[]> {
return (await this.blockSource.getL2Blocks(from, limit)) ?? [];
return (await this.blockSource.getBlocks(from, limit)) ?? [];
}

/**
Expand Down Expand Up @@ -401,7 +401,7 @@ export class AztecNodeService implements AztecNode {
this.log.info(`Simulating tx ${await tx.getTxHash()}`);
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(new Fr(blockNumber));
const prevGlobalVariables = (await this.blockSource.getL2Block(-1))?.globalVariables ?? GlobalVariables.empty();
const prevGlobalVariables = (await this.blockSource.getBlock(-1))?.globalVariables ?? GlobalVariables.empty();

// Instantiate merkle trees so uncommitted updates by this simulation are local to it.
// TODO we should be able to remove this after https://github.com/AztecProtocol/aztec-packages/issues/1869
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/p2p/src/client/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class MockBlockSource implements L2BlockSource {
* @param number - The block number to return (inclusive).
* @returns The requested L2 block.
*/
public getL2Block(number: number) {
public getBlock(number: number) {
return Promise.resolve(this.l2Blocks[number]);
}

Expand All @@ -55,7 +55,7 @@ export class MockBlockSource implements L2BlockSource {
* @param limit - The maximum number of blocks to return.
* @returns The requested mocked L2 blocks.
*/
public getL2Blocks(from: number, limit: number) {
public getBlocks(from: number, limit: number) {
return Promise.resolve(this.l2Blocks.slice(from, from + limit));
}

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/p2p/src/client/p2p_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class P2PClient implements P2P {
// start looking for further blocks
const blockProcess = async () => {
while (!this.stopping) {
const blocks = await this.blockDownloader.getL2Blocks();
const blocks = await this.blockDownloader.getBlocks();
await this.handleL2Blocks(blocks);
}
};
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/sequencer-client/src/sequencer/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class Sequencer {
this.state = SequencerState.CREATING_BLOCK;

const newGlobalVariables = await this.globalsBuilder.buildGlobalVariables(new Fr(blockNumber));
const prevGlobalVariables = (await this.l2BlockSource.getL2Block(-1))?.globalVariables ?? GlobalVariables.empty();
const prevGlobalVariables = (await this.l2BlockSource.getBlock(-1))?.globalVariables ?? GlobalVariables.empty();

// Process txs and drop the ones that fail processing
// We create a fresh processor each time to reset any cached state (eg storage writes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class L2BlockDownloader {
private async collectBlocks() {
let totalBlocks = 0;
while (true) {
const blocks = await this.l2BlockSource.getL2Blocks(this.from, 10);
const blocks = await this.l2BlockSource.getBlocks(this.from, 10);
if (!blocks.length) {
return totalBlocks;
}
Expand All @@ -87,7 +87,7 @@ export class L2BlockDownloader {
* @param timeout - optional timeout value to prevent permanent blocking
* @returns The next batch of blocks from the queue.
*/
public async getL2Blocks(timeout?: number) {
public async getBlocks(timeout?: number): Promise<L2Block[]> {
try {
const blocks = await this.blockQueue.get(timeout);
if (!blocks) {
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/types/src/l2_block_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export interface L2BlockSource {
* @param number - The block number to return (inclusive).
* @returns The requested L2 block.
*/
getL2Block(number: number): Promise<L2Block | undefined>;
getBlock(number: number): Promise<L2Block | undefined>;

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

/**
* Gets an l2 tx.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const log = createDebugLogger('aztec:server_world_state_synchronizer_test');
describe('server_world_state_synchronizer', () => {
const rollupSource = mock<L2BlockSource>({
getBlockNumber: jest.fn(getLatestBlockNumber),
getL2Blocks: jest.fn(consumeNextBlocks),
getBlocks: jest.fn(consumeNextBlocks),
});

const merkleTreeDb = mock<MerkleTreeDb>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class ServerWorldStateSynchronizer implements WorldStateSynchronizer {
*/
private async collectAndProcessBlocks() {
// This request for blocks will timeout after 1 second if no blocks are received
const blocks = await this.l2BlockDownloader.getL2Blocks(1);
const blocks = await this.l2BlockDownloader.getBlocks(1);
await this.handleL2Blocks(blocks);
await this.commitCurrentL2BlockNumber();
}
Expand Down

0 comments on commit f20461a

Please sign in to comment.