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: consistent block number method naming #1751

Merged
merged 2 commits into from
Aug 23, 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
4 changes: 2 additions & 2 deletions docs/docs/dev_docs/getting_started/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Lets first establish that we are able to communicate with the Sandbox. Most comm
To test communication with the Sandbox, let's run the command:

`% aztec-cli block-number
0`
1`

You should see the current block number (0) printed to the screen!
You should see the current block number (1) printed to the screen!

## Contracts

Expand Down
6 changes: 3 additions & 3 deletions yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Archiver', () => {
1000,
);

let latestBlockNum = await archiver.getBlockHeight();
let latestBlockNum = await archiver.getBlockNumber();
expect(latestBlockNum).toEqual(0);

const blocks = blockNums.map(x => L2Block.random(x, 4, x, x + 1, x * 2, x * 3));
Expand Down Expand Up @@ -95,11 +95,11 @@ describe('Archiver', () => {
await archiver.start(false);

// Wait until block 3 is processed. If this won't happen the test will fail with timeout.
while ((await archiver.getBlockHeight()) !== 3) {
while ((await archiver.getBlockNumber()) !== 3) {
await sleep(100);
}

latestBlockNum = await archiver.getBlockHeight();
latestBlockNum = await archiver.getBlockNumber();
expect(latestBlockNum).toEqual(3);

// Check that only 2 messages (l1ToL2MessageAddedEvents[3][2] and l1ToL2MessageAddedEvents[3][3]) are pending.
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
* Gets the number of the latest L2 block processed by the block source implementation.
* @returns The number of the latest L2 block processed by the block source implementation.
*/
public getBlockHeight(): Promise<number> {
return this.store.getBlockHeight();
public getBlockNumber(): Promise<number> {
return this.store.getBlockNumber();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/archiver/src/archiver/archiver_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export interface ArchiverDataStore {
* Gets the number of the latest L2 block processed.
* @returns The number of the latest L2 block processed.
*/
getBlockHeight(): Promise<number>;
getBlockNumber(): Promise<number>;

/**
* Gets the length of L2 blocks in store.
Expand Down Expand Up @@ -382,7 +382,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
* Gets the number of the latest L2 block processed.
* @returns The number of the latest L2 block processed.
*/
public getBlockHeight(): Promise<number> {
public getBlockNumber(): Promise<number> {
if (this.l2Blocks.length === 0) return Promise.resolve(INITIAL_L2_BLOCK_NUM - 1);
return Promise.resolve(this.l2Blocks[this.l2Blocks.length - 1].number);
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ Example usage:
aztec-cli get-logs 1000 10
```

### block-num
### block-number

Gets the current Aztec L2 block number.

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
.option('-u, --rpcUrl <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
.action(async (options: any) => {
const client = createClient(options.rpcUrl);
const num = await client.getBlockNum();
const num = await client.getBlockNumber();
log(`${num}\n`);
});

Expand Down
10 changes: 5 additions & 5 deletions yarn-project/aztec-node/src/aztec-node/http-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ describe('HttpNode', () => {
});
});

describe('getBlockHeight', () => {
it('should fetch and return the block height', async () => {
const response = { blockHeight: 100 };
describe('getBlockNumber', () => {
it('should fetch and return current block number', async () => {
const response = { blockNumber: 100 };
setFetchMock(response);

const result = await httpNode.getBlockHeight();
const result = await httpNode.getBlockNumber();

expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-block-height`);
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-block-number`);
expect(result).toBe(100);
});
});
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/aztec-node/src/aztec-node/http-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ export class HttpNode implements AztecNode {
}

/**
* Method to fetch the current block height.
* @returns The block height as a number.
* Method to fetch the current block number.
* @returns The current block number.
*/
async getBlockHeight(): Promise<number> {
const url = new URL(`${this.baseUrl}/get-block-height`);
async getBlockNumber(): Promise<number> {
const url = new URL(`${this.baseUrl}/get-block-number`);
const response = await fetch(url.toString());
const respJson = await response.json();
return respJson.blockHeight;
return respJson.blockNumber;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ export class AztecNodeService implements AztecNode {
}

/**
* Method to fetch the current block height.
* @returns The block height as a number.
* Method to fetch the current block number.
* @returns The block number.
*/
public async getBlockHeight(): Promise<number> {
return await this.blockSource.getBlockHeight();
public async getBlockNumber(): Promise<number> {
return await this.blockSource.getBlockNumber();
}

/**
Expand Down Expand Up @@ -382,7 +382,7 @@ export class AztecNodeService implements AztecNode {
* @returns A promise that fulfils once the world state is synced
*/
private async syncWorldState() {
const blockSourceHeight = await this.blockSource.getBlockHeight();
const blockSourceHeight = await this.blockSource.getBlockNumber();
await this.worldStateSynchroniser.syncImmediate(blockSourceHeight);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ export class AztecRPCServer implements AztecRPC {
}

public async getBlock(blockNumber: number): Promise<L2Block | undefined> {
// If a negative block number is provided the current block height is fetched.
// If a negative block number is provided the current block number is fetched.
if (blockNumber < 0) {
blockNumber = await this.node.getBlockHeight();
blockNumber = await this.node.getBlockNumber();
}
return await this.node.getBlock(blockNumber);
}
Expand Down Expand Up @@ -241,8 +241,8 @@ export class AztecRPCServer implements AztecRPC {
return partialReceipt;
}

async getBlockNum(): Promise<number> {
return await this.node.getBlockHeight();
async getBlockNumber(): Promise<number> {
return await this.node.getBlockNumber();
}

public async getContractDataAndBytecode(contractAddress: AztecAddress): Promise<ContractDataAndBytecode | undefined> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function createAztecRpcServer(): Promise<AztecRPC> {
};

// Setup the relevant mocks
node.getBlockHeight.mockResolvedValue(2);
node.getBlockNumber.mockResolvedValue(2);
node.getVersion.mockResolvedValue(1);
node.getChainId.mockResolvedValue(1);
node.getRollupAddress.mockResolvedValue(EthAddress.random());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const aztecRpcTestSuite = (testName: string, aztecRpcSetup: () => Promise
// functions only call AztecNode and these methods are frequently used by the e2e tests.

it('successfully gets a block number', async () => {
const blockNum = await rpc.getBlockNum();
const blockNum = await rpc.getBlockNumber();
expect(blockNum).toBeGreaterThanOrEqual(INITIAL_L2_BLOCK_NUM);
});

Expand Down
10 changes: 5 additions & 5 deletions yarn-project/aztec-rpc/src/note_processor/note_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ export class NoteProcessor {
) {}

/**
* Check if the NoteProcessor is synchronised with the remote block height.
* The function queries the remote block height from the AztecNode and compares it with the syncedToBlock value in the NoteProcessor.
* Check if the NoteProcessor is synchronised with the remote block number.
* The function queries the remote block number from the AztecNode and compares it with the syncedToBlock value in the NoteProcessor.
* If the values are equal, then the NoteProcessor is considered to be synchronised, otherwise not.
*
* @returns A boolean indicating whether the NoteProcessor is synchronised with the remote block height or not.
* @returns A boolean indicating whether the NoteProcessor is synchronised with the remote block number or not.
*/
public async isSynchronised() {
const remoteBlockHeight = await this.node.getBlockHeight();
return this.syncedToBlock === remoteBlockHeight;
const remoteBlockNumber = await this.node.getBlockNumber();
return this.syncedToBlock === remoteBlockNumber;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/aztec-rpc/src/synchroniser/synchroniser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Synchroniser', () => {
});

it('sets tree roots from aztec node on initial sync', async () => {
aztecNode.getBlockHeight.mockResolvedValue(3);
aztecNode.getBlockNumber.mockResolvedValue(3);
aztecNode.getHistoricBlockData.mockResolvedValue(blockData);

await synchroniser.initialSync();
Expand All @@ -52,9 +52,9 @@ describe('Synchroniser', () => {
expect(roots[MerkleTreeId.CONTRACT_TREE]).toEqual(block.endContractTreeSnapshot.root);
});

it('overrides tree roots from initial sync once block height is larger', async () => {
it('overrides tree roots from initial sync once current block number is larger', async () => {
// Initial sync is done on block with height 3
aztecNode.getBlockHeight.mockResolvedValue(3);
aztecNode.getBlockNumber.mockResolvedValue(3);
aztecNode.getHistoricBlockData.mockResolvedValue(blockData);

await synchroniser.initialSync();
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('Synchroniser', () => {
await synchroniser.work();

// Used in synchroniser.isAccountStateSynchronised
aztecNode.getBlockHeight.mockResolvedValueOnce(1);
aztecNode.getBlockNumber.mockResolvedValueOnce(1);

// Manually adding account to database so that we can call synchroniser.isAccountStateSynchronised
const keyStore = new TestKeyStore(await Grumpkin.new());
Expand Down
14 changes: 7 additions & 7 deletions yarn-project/aztec-rpc/src/synchroniser/synchroniser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Synchroniser {
private noteProcessors: NoteProcessor[] = [];
private interruptableSleep = new InterruptableSleep();
private running = false;
private initialSyncBlockHeight = 0;
private initialSyncBlockNumber = 0;
private synchedToBlock = 0;
private log: DebugLogger;
private noteProcessorsToCatchUp: NoteProcessor[] = [];
Expand Down Expand Up @@ -68,11 +68,11 @@ export class Synchroniser {

protected async initialSync() {
const [blockNumber, historicBlockData] = await Promise.all([
this.node.getBlockHeight(),
this.node.getBlockNumber(),
this.node.getHistoricBlockData(),
]);
this.initialSyncBlockHeight = blockNumber;
this.synchedToBlock = this.initialSyncBlockHeight;
this.initialSyncBlockNumber = blockNumber;
this.synchedToBlock = this.initialSyncBlockNumber;
await this.db.setHistoricBlockData(historicBlockData);
}

Expand Down Expand Up @@ -193,7 +193,7 @@ export class Synchroniser {

private async setBlockDataFromBlock(latestBlock: L2BlockContext) {
const { block } = latestBlock;
if (block.number < this.initialSyncBlockHeight) return;
if (block.number < this.initialSyncBlockNumber) return;

const wasm = await CircuitsWasm.get();
const globalsHash = computeGlobalsHash(wasm, latestBlock.block.globalVariables);
Expand Down Expand Up @@ -266,10 +266,10 @@ export class Synchroniser {
* Checks whether all the blocks were processed (tree roots updated, txs updated with block info, etc.).
* @returns True if there are no outstanding blocks to be synched.
* @remarks This indicates that blocks and transactions are synched even if notes are not.
* @remarks Compares local block height with the block height from aztec node.
* @remarks Compares local block number with the block number from aztec node.
*/
public async isGlobalStateSynchronised() {
const latest = await this.node.getBlockHeight();
const latest = await this.node.getBlockNumber();
return latest <= this.synchedToBlock;
}

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/aztec_rpc_client/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export abstract class BaseWallet implements Wallet {
getUnencryptedLogs(from: number, limit: number): Promise<L2BlockL2Logs[]> {
return this.rpc.getUnencryptedLogs(from, limit);
}
getBlockNum(): Promise<number> {
return this.rpc.getBlockNum();
getBlockNumber(): Promise<number> {
return this.rpc.getBlockNumber();
}
getNodeInfo(): Promise<NodeInfo> {
return this.rpc.getNodeInfo();
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/utils/cheat_codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class AztecCheatCodes {
* @returns The current block number
*/
public async blockNumber(): Promise<number> {
return await this.aztecRpc.getBlockNum();
return await this.aztecRpc.getBlockNumber();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_ordering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('e2e_ordering', () => {
let wallet: Wallet;

const expectLogsFromLastBlockToBe = async (logMessages: bigint[]) => {
const l2BlockNum = await aztecRpcServer.getBlockNum();
const l2BlockNum = await aztecRpcServer.getBlockNumber();
const unencryptedLogs = await aztecRpcServer.getUnencryptedLogs(l2BlockNum, 1);
const unrolledLogs = L2BlockL2Logs.unrollLogs(unencryptedLogs);
const bigintLogs = unrolledLogs.map((log: Buffer) => toBigIntBE(log));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('e2e_pending_commitments_contract', () => {
});

const expectCommitmentsSquashedExcept = async (exceptFirstFew: number) => {
const blockNum = await aztecNode!.getBlockHeight();
const blockNum = await aztecNode!.getBlockNumber();
const block = (await aztecNode!.getBlocks(blockNum, 1))[0];

// all new commitments should be zero (should be squashed)
Expand All @@ -44,7 +44,7 @@ describe('e2e_pending_commitments_contract', () => {
};

const expectNullifiersSquashedExcept = async (exceptFirstFew: number) => {
const blockNum = await aztecNode!.getBlockHeight();
const blockNum = await aztecNode!.getBlockNumber();
const block = (await aztecNode!.getBlocks(blockNum, 1))[0];

// 0th nullifier should be nonzero (txHash), all others should be zero (should be squashed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('e2e_public_token_contract', () => {
};

const expectLogsFromLastBlockToBe = async (logMessages: string[]) => {
const l2BlockNum = await aztecRpcServer.getBlockNum();
const l2BlockNum = await aztecRpcServer.getBlockNumber();
const unencryptedLogs = await aztecRpcServer.getUnencryptedLogs(l2BlockNum, 1);
const unrolledLogs = L2BlockL2Logs.unrollLogs(unencryptedLogs);
const asciiLogs = unrolledLogs.map(log => log.toString('ascii'));
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export const expectsNumOfEncryptedLogsInTheLastBlockToBe = async (
// This means we can't perform this check if there is no node
return;
}
const l2BlockNum = await aztecNode.getBlockHeight();
const l2BlockNum = await aztecNode.getBlockNumber();
const encryptedLogs = await aztecNode.getLogs(l2BlockNum, 1, LogType.ENCRYPTED);
const unrolledLogs = L2BlockL2Logs.unrollLogs(encryptedLogs);
expect(unrolledLogs.length).toBe(numEncryptedLogs);
Expand All @@ -439,7 +439,7 @@ export const expectUnencryptedLogsFromLastBlockToBe = async (
// This means we can't perform this check if there is no node
return;
}
const l2BlockNum = await aztecNode.getBlockHeight();
const l2BlockNum = await aztecNode.getBlockNumber();
const unencryptedLogs = await aztecNode.getLogs(l2BlockNum, 1, LogType.UNENCRYPTED);
const unrolledLogs = L2BlockL2Logs.unrollLogs(unencryptedLogs);
const asciiLogs = unrolledLogs.map(log => log.toString('ascii'));
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/p2p/src/client/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class MockBlockSource implements L2BlockSource {
* Gets the number of the latest L2 block processed by the block source implementation.
* @returns In this mock instance, returns the number of L2 blocks that we've mocked.
*/
public getBlockHeight() {
public getBlockNumber() {
return Promise.resolve(this.l2Blocks.length - 1);
}

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 @@ -142,7 +142,7 @@ export class P2PClient implements P2P {
}

// get the current latest block number
this.latestBlockNumberAtStart = await this.l2BlockSource.getBlockHeight();
this.latestBlockNumberAtStart = await this.l2BlockSource.getBlockNumber();

const blockToDownloadFrom = this.currentL2BlockNum + 1;

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/rollup-provider/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ export function appFactory(node: AztecNode, prefix: string) {
ctx.status = 200;
});

router.get('/get-block-height', async (ctx: Koa.Context) => {
router.get('/get-block-number', async (ctx: Koa.Context) => {
ctx.set('content-type', 'application/json');
ctx.body = {
blockHeight: await node.getBlockHeight(),
blockNumber: await node.getBlockNumber(),
};
ctx.status = 200;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('sequencer', () => {
});

l2BlockSource = mock<L2BlockSource>({
getBlockHeight: () => Promise.resolve(lastBlockNumber),
getBlockNumber: () => Promise.resolve(lastBlockNumber),
});

l1ToL2MessageSource = mock<L1ToL2MessageSource>({
Expand Down
Loading