Skip to content

Commit

Permalink
better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 12, 2023
1 parent 3d094d6 commit df1a603
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
/**
* Next L1 block number to fetch `L2BlockProcessed` logs from (i.e. `fromBlock` in eth_getLogs).
*/
private nextL2BlockFromBlock = 0n;
private nextL2BlockFromL1Block = 0n;

/**
* Last Processed Block Number
*/
private lastProcessedBlockNumber = 0n;
private lastProcessedL1BlockNumber = 0n;

/**
* Use this to track logged block in order to avoid repeating the same message.
*/
private lastLoggedBlockNumber = 0n;
private lastLoggedL1BlockNumber = 0n;

/**
* Creates a new instance of the Archiver.
Expand All @@ -84,8 +84,8 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
private readonly pollingIntervalMs = 10_000,
private readonly log: DebugLogger = createDebugLogger('aztec:archiver'),
) {
this.nextL2BlockFromBlock = BigInt(searchStartBlock);
this.lastProcessedBlockNumber = BigInt(searchStartBlock);
this.nextL2BlockFromL1Block = BigInt(searchStartBlock);
this.lastProcessedL1BlockNumber = BigInt(searchStartBlock);
}

/**
Expand Down Expand Up @@ -139,12 +139,12 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
* @param blockUntilSynced - If true, blocks until the archiver has fully synced.
*/
private async sync(blockUntilSynced: boolean) {
const currentBlockNumber = await this.publicClient.getBlockNumber();
if (currentBlockNumber <= this.lastProcessedBlockNumber) {
const currentL1BlockNumber = await this.publicClient.getBlockNumber();
if (currentL1BlockNumber <= this.lastProcessedL1BlockNumber) {
// reducing logs, otherwise this gets triggered on every loop (1s)
if (currentBlockNumber !== this.lastLoggedBlockNumber) {
this.log(`No new blocks to process, current block number: ${currentBlockNumber}`);
this.lastLoggedBlockNumber = currentBlockNumber;
if (currentL1BlockNumber !== this.lastLoggedL1BlockNumber) {
this.log(`No new blocks to process, current block number: ${currentL1BlockNumber}`);
this.lastLoggedL1BlockNumber = currentL1BlockNumber;
}
return;
}
Expand Down Expand Up @@ -183,15 +183,15 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
this.publicClient,
this.inboxAddress,
blockUntilSynced,
this.lastProcessedBlockNumber + 1n, // + 1 to prevent re-including messages from the last processed block
currentBlockNumber,
this.lastProcessedL1BlockNumber + 1n, // + 1 to prevent re-including messages from the last processed block
currentL1BlockNumber,
);
const retrievedCancelledL1ToL2Messages = await retrieveNewCancelledL1ToL2Messages(
this.publicClient,
this.inboxAddress,
blockUntilSynced,
this.lastProcessedBlockNumber + 1n,
currentBlockNumber,
this.lastProcessedL1BlockNumber + 1n,
currentL1BlockNumber,
);

// TODO (#717): optimise this - there could be messages in confirmed that are also in pending.
Expand All @@ -203,21 +203,21 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
this.log('Removing pending l1 to l2 messages from store where messages were cancelled');
await this.store.cancelPendingL1ToL2Messages(retrievedCancelledL1ToL2Messages.retrievedData);

this.lastProcessedBlockNumber = currentBlockNumber;
this.lastProcessedL1BlockNumber = currentL1BlockNumber;

// ********** Events that are processed per block **********

// Read all data from chain and then write to our stores at the end
const nextExpectedL2BlockNum = BigInt((await this.store.getBlockNumber()) + 1);
this.log(
`Retrieving chain state from L1 block: ${this.nextL2BlockFromBlock}, next expected l2 block number: ${nextExpectedL2BlockNum}`,
`Retrieving chain state from L1 block: ${this.nextL2BlockFromL1Block}, next expected l2 block number: ${nextExpectedL2BlockNum}`,
);
const retrievedBlocks = await retrieveBlocks(
this.publicClient,
this.rollupAddress,
blockUntilSynced,
this.nextL2BlockFromBlock,
currentBlockNumber,
this.nextL2BlockFromL1Block,
currentL1BlockNumber,
nextExpectedL2BlockNum,
);

Expand All @@ -230,8 +230,8 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
this.publicClient,
this.contractDeploymentEmitterAddress,
blockUntilSynced,
this.nextL2BlockFromBlock,
currentBlockNumber,
this.nextL2BlockFromL1Block,
currentL1BlockNumber,
blockHashMapping,
);
if (retrievedBlocks.retrievedData.length === 0) {
Expand Down Expand Up @@ -276,7 +276,7 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource
);

// set the L1 block for the next search
this.nextL2BlockFromBlock = retrievedBlocks.nextEthBlockNumber;
this.nextL2BlockFromL1Block = retrievedBlocks.nextEthBlockNumber;
}

/**
Expand Down

0 comments on commit df1a603

Please sign in to comment.