Skip to content

Commit

Permalink
fix units
Browse files Browse the repository at this point in the history
  • Loading branch information
just-mitch committed Nov 6, 2024
1 parent c701096 commit b2f1fa3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion yarn-project/sequencer-client/src/sequencer/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class SequencerMetrics {
this.setCurrentBlock(blockNumber, txCount);
}

recordStateTransitionBuffer(durationMs: number, state: SequencerState) {
recordStateTransitionBufferMs(durationMs: number, state: SequencerState) {
this.stateTransitionBufferDuration.record(durationMs, {
[Attributes.SEQUENCER_STATE]: state,
});
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/sequencer-client/src/sequencer/sequencer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('sequencer', () => {
new TxValidatorFactory(merkleTreeOps, contractSource, false),
new NoopTelemetryClient(),
);
sequencer.setL1GenesisTime(BigInt(Math.floor(Date.now() / 1000)));
sequencer.setL1GenesisTime(Math.floor(Date.now() / 1000));
});

it('builds a block out of a single tx', async () => {
Expand Down Expand Up @@ -229,7 +229,7 @@ describe('sequencer', () => {
'does not build a block if it does not have enough time left in the slot',
async ({ previousState, delayedState, maxTime }) => {
// trick the sequencer into thinking that we are just too far into the slot
sequencer.setL1GenesisTime(BigInt(Math.floor(Date.now() / 1000)) - BigInt(maxTime + 1));
sequencer.setL1GenesisTime(Math.floor(Date.now() / 1000) - (maxTime + 1));

const tx = mockTxForRollup();
tx.data.constants.txContext.chainId = chainId;
Expand Down Expand Up @@ -826,7 +826,7 @@ describe('sequencer', () => {
});

class TestSubject extends Sequencer {
public setL1GenesisTime(l1GenesisTime: bigint) {
public setL1GenesisTime(l1GenesisTime: number) {
this.l1GenesisTime = l1GenesisTime;
}
public override work() {
Expand Down
20 changes: 9 additions & 11 deletions yarn-project/sequencer-client/src/sequencer/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Sequencer {
private maxBlockSizeInBytes: number = 1024 * 1024;
private metrics: SequencerMetrics;
private isFlushing: boolean = false;
protected l1GenesisTime: bigint;
protected l1GenesisTime: number;

constructor(
private publisher: L1Publisher,
Expand All @@ -89,7 +89,7 @@ export class Sequencer {
private config: SequencerConfig = {},
private log = createDebugLogger('aztec:sequencer'),
) {
this.l1GenesisTime = BigInt(0);
this.l1GenesisTime = 0;
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 @@ -145,7 +145,7 @@ export class Sequencer {
public async start() {
const rollup = this.publisher.getRollupContract();
const [l1GenesisTime] = await Promise.all([rollup.read.GENESIS_TIME()] as const);
this.l1GenesisTime = l1GenesisTime;
this.l1GenesisTime = Number(l1GenesisTime);
this.runningPromise = new RunningPromise(this.work.bind(this), this.pollingIntervalMs);
this.runningPromise.start();
this.setState(SequencerState.PROPOSER_CHECK, true /** force */);
Expand Down Expand Up @@ -329,20 +329,18 @@ export class Sequencer {
return true;
}

const timeInSlot = Number(
(BigInt(Math.floor(Date.now() / 1000)) - this.l1GenesisTime) % BigInt(AZTEC_SLOT_DURATION),
);
const buffer = MAX_SECONDS_INTO_SLOT_PER_STATE[proposedState] - timeInSlot;
this.metrics.recordStateTransitionBuffer(buffer, proposedState);
const secondsIntoSlot = (Date.now() / 1000 - this.l1GenesisTime) % AZTEC_SLOT_DURATION;
const bufferSeconds = MAX_SECONDS_INTO_SLOT_PER_STATE[proposedState] - secondsIntoSlot;
this.metrics.recordStateTransitionBufferMs(bufferSeconds * 1000, proposedState);

if (buffer < 0) {
if (bufferSeconds < 0) {
this.log.warn(
`Too far into slot to transition to ${proposedState}. max allowed: ${MAX_SECONDS_INTO_SLOT_PER_STATE[proposedState]}s, time into slot: ${timeInSlot}s`,
`Too far into slot to transition to ${proposedState}. max allowed: ${MAX_SECONDS_INTO_SLOT_PER_STATE[proposedState]}s, time into slot: ${secondsIntoSlot}s`,
);
return false;
}
this.log.debug(
`Enough time to transition to ${proposedState}, max allowed: ${MAX_SECONDS_INTO_SLOT_PER_STATE[proposedState]}s, time into slot: ${timeInSlot}s`,
`Enough time to transition to ${proposedState}, max allowed: ${MAX_SECONDS_INTO_SLOT_PER_STATE[proposedState]}s, time into slot: ${secondsIntoSlot}s`,
);
return true;
}
Expand Down

0 comments on commit b2f1fa3

Please sign in to comment.