Skip to content

Commit

Permalink
feat: improve hot loop logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Oct 11, 2024
1 parent fb59456 commit 6a88c54
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 27 deletions.
24 changes: 8 additions & 16 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
EmptyL1RollupConstants,
type FromLogType,
type GetUnencryptedLogsResponse,
type InboxLeaf,
type L1RollupConstants,
type L1ToL2MessageSource,
type L2Block,
type L2BlockId,
Expand All @@ -16,6 +18,12 @@ import {
type TxReceipt,
type UnencryptedL2Log,
} from '@aztec/circuit-types';
import {
getEpochNumberAtTimestamp,
getSlotAtTimestamp,
getSlotRangeForEpoch,
getTimestampRangeForEpoch,
} from '@aztec/circuit-types';
import {
ContractClassRegisteredEvent,
ContractInstanceDeployedEvent,
Expand Down Expand Up @@ -60,12 +68,6 @@ import {
import { type ArchiverDataStore, type ArchiverL1SynchPoint } from './archiver_store.js';
import { type ArchiverConfig } from './config.js';
import { retrieveBlockFromRollup, retrieveL1ToL2Messages } from './data_retrieval.js';
import {
getEpochNumberAtTimestamp,
getSlotAtTimestamp,
getSlotRangeForEpoch,
getTimestampRangeForEpoch,
} from './epoch_helpers.js';
import { ArchiverInstrumentation } from './instrumentation.js';
import { type DataRetrieval } from './structs/data_retrieval.js';
import { type L1Published } from './structs/published.js';
Expand Down Expand Up @@ -931,13 +933,3 @@ class ArchiverStoreHelper
return this.store.getTotalL1ToL2MessageCount();
}
}

export type L1RollupConstants = {
l1StartBlock: bigint;
l1GenesisTime: bigint;
};

export const EmptyL1RollupConstants: L1RollupConstants = {
l1StartBlock: 0n,
l1GenesisTime: 0n,
};
1 change: 0 additions & 1 deletion yarn-project/archiver/src/archiver/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './archiver.js';
export * from './config.js';
export * from './epoch_helpers.js';
export { type L1Published, type L1PublishedData } from './structs/published.js';
export { MemoryArchiverStore } from './memory_archiver_store/memory_archiver_store.js';
export { ArchiverDataStore } from './archiver_store.js';
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/archiver/src/test/mock_l2_block_source.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { L2Block, type L2BlockSource, type L2Tips, type TxHash, TxReceipt, TxStatus } from '@aztec/circuit-types';
import { getSlotRangeForEpoch } from '@aztec/circuit-types';
import { EthAddress, type Header } from '@aztec/circuits.js';
import { createDebugLogger } from '@aztec/foundation/log';

import { getSlotRangeForEpoch } from '../archiver/epoch_helpers.js';

/**
* A mocked implementation of L2BlockSource to be used in tests.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ export function getTimestampRangeForEpoch(epochNumber: bigint, constants: { l1Ge
constants.l1GenesisTime + endSlot * BigInt(AZTEC_SLOT_DURATION),
];
}

export type L1RollupConstants = {
l1StartBlock: bigint;
l1GenesisTime: bigint;
};

export const EmptyL1RollupConstants: L1RollupConstants = {
l1StartBlock: 0n,
l1GenesisTime: 0n,
};
1 change: 1 addition & 0 deletions yarn-project/circuit-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ export * from './simulation_error.js';
export * from './tx/index.js';
export * from './tx_effect.js';
export * from './tx_execution_request.js';
export * from './epoch_helpers/index.js';
9 changes: 5 additions & 4 deletions yarn-project/sequencer-client/src/publisher/l1-publisher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
ConsensusPayload,
EmptyL1RollupConstants,
type EpochProofClaim,
type EpochProofQuote,
type L1RollupConstants,
type L2Block,
type TxHash,
getHashedSignaturePayload,
Expand Down Expand Up @@ -139,7 +141,7 @@ export class L1Publisher {
private sleepTimeMs: number;
private interrupted = false;
private metrics: L1PublisherMetrics;
public l1ContractConstants: L1RollupConstants;
public l1ContractConstants: L1RollupConstants = EmptyL1RollupConstants;

protected log = createDebugLogger('aztec:sequencer:publisher');

Expand Down Expand Up @@ -211,7 +213,6 @@ export class L1Publisher {
this.l1ContractConstants = { l1StartBlock, l1GenesisTime };
}


public getSenderAddress(): EthAddress {
return EthAddress.fromString(this.account.address);
}
Expand Down Expand Up @@ -250,7 +251,7 @@ export class L1Publisher {
* @return blockNumber - The L2 block number of the next L2 block
*/
public async canProposeAtNextEthBlock(archive: Buffer): Promise<[bigint, bigint]> {
const ts = await this.getL1Timestamp() + BigInt(ETHEREUM_SLOT_DURATION);
const ts = (await this.getL1Timestamp()) + BigInt(ETHEREUM_SLOT_DURATION);
const [slot, blockNumber] = await this.rollupContract.read.canProposeAtTime([ts, `0x${archive.toString('hex')}`]);
return [slot, blockNumber];
}
Expand Down Expand Up @@ -326,7 +327,7 @@ export class L1Publisher {
signatures: [],
},
): Promise<void> {
const ts = await this.getL1Timestamp() + BigInt(ETHEREUM_SLOT_DURATION);
const ts = (await this.getL1Timestamp()) + BigInt(ETHEREUM_SLOT_DURATION);

const formattedSignatures = attestationData.signatures.map(attest => attest.toViemSignature());
const flags = { ignoreDA: true, ignoreSignatures: formattedSignatures.length == 0 };
Expand Down
12 changes: 8 additions & 4 deletions yarn-project/sequencer-client/src/sequencer/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
type TxValidator,
type WorldStateSynchronizer,
} from '@aztec/circuit-types';
import { getSlotAtTimestamp } from '@aztec/circuit-types';
import {
type AllowedElement,
BlockProofError,
Expand All @@ -27,7 +28,7 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
import { Signature } from '@aztec/foundation/eth-signature';
import { Fr } from '@aztec/foundation/fields';
import { createDebugLogger } from '@aztec/foundation/log';
import { type Logger, createDebugLogger } from '@aztec/foundation/log';
import { RunningPromise } from '@aztec/foundation/running-promise';
import { Timer, elapsed } from '@aztec/foundation/timer';
import { type P2P } from '@aztec/p2p';
Expand All @@ -44,7 +45,6 @@ import { prettyLogViemError } from '../publisher/utils.js';
import { type TxValidatorFactory } from '../tx_validator/tx_validator_factory.js';
import { type SequencerConfig } from './config.js';
import { SequencerMetrics } from './metrics.js';
import { getSlotAtTimestamp } from '@aztec/archiver';

export type ShouldProposeArgs = {
pendingTxsCount?: number;
Expand Down Expand Up @@ -86,6 +86,8 @@ export class Sequencer {
private metrics: SequencerMetrics;
private isFlushing: boolean = false;

private log: Logger;

/**
* The logging context is attached to every log message from this class
* It will be updated on each invocation of work()
Expand All @@ -110,8 +112,10 @@ export class Sequencer {
private txValidatorFactory: TxValidatorFactory,
telemetry: TelemetryClient,
private config: SequencerConfig = {},
private log = createDebugLogger('aztec:sequencer', this.loggingContext),
) {
// Logging context is set within work() and will be attached to all log messages from this class.
this.log = createDebugLogger('aztec:sequencer', this.loggingContext);

this.updateConfig(config);
this.metrics = new SequencerMetrics(telemetry, () => this.state, 'Sequencer');
this.log.verbose(`Initialized sequencer with ${this.minTxsPerBLock}-${this.maxTxsPerBlock} txs per block.`);
Expand Down Expand Up @@ -243,7 +247,7 @@ export class Sequencer {
const chainTipArchive =
chainTip == undefined ? new Fr(GENESIS_ARCHIVE_ROOT).toBuffer() : chainTip?.archive.root.toBuffer();

let currentL1Timestamp = await this.publisher.getL1Timestamp();
const currentL1Timestamp = await this.publisher.getL1Timestamp();
let slot = getSlotAtTimestamp(currentL1Timestamp, this.publisher.l1ContractConstants);

// Values that will be included in all logs from this point forward.
Expand Down

0 comments on commit 6a88c54

Please sign in to comment.