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

chore: Remove sequencer min/max seconds between blocks #10845

Merged
merged 1 commit into from
Dec 18, 2024
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
6 changes: 0 additions & 6 deletions yarn-project/circuit-types/src/interfaces/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export interface SequencerConfig {
maxTxsPerBlock?: number;
/** The minimum number of txs to include in a block. */
minTxsPerBlock?: number;
/** The minimum number of seconds in-between consecutive blocks. */
minSecondsBetweenBlocks?: number;
/** The maximum number of seconds in-between consecutive blocks. Sequencer will produce a block with less than minTxsPerBlock once this threshold is reached. */
maxSecondsBetweenBlocks?: number;
/** Recipient of block reward. */
coinbase?: EthAddress;
/** Address to receive fees. */
Expand Down Expand Up @@ -55,8 +51,6 @@ export const SequencerConfigSchema = z.object({
transactionPollingIntervalMS: z.number().optional(),
maxTxsPerBlock: z.number().optional(),
minTxsPerBlock: z.number().optional(),
minSecondsBetweenBlocks: z.number().optional(),
maxSecondsBetweenBlocks: z.number().optional(),
coinbase: schemas.EthAddress.optional(),
feeRecipient: schemas.AztecAddress.optional(),
acvmWorkingDirectory: z.string().optional(),
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/foundation/src/config/env_var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ export type EnvVar =
| 'ROLLUP_CONTRACT_ADDRESS'
| 'SEQ_ALLOWED_SETUP_FN'
| 'SEQ_MAX_BLOCK_SIZE_IN_BYTES'
| 'SEQ_MAX_SECONDS_BETWEEN_BLOCKS'
| 'SEQ_MAX_TX_PER_BLOCK'
| 'SEQ_MIN_SECONDS_BETWEEN_BLOCKS'
| 'SEQ_MIN_TX_PER_BLOCK'
| 'SEQ_PUBLISH_RETRY_INTERVAL_MS'
| 'SEQ_PUBLISHER_PRIVATE_KEY'
Expand Down
11 changes: 0 additions & 11 deletions yarn-project/sequencer-client/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
description: 'The minimum number of txs to include in a block.',
...numberConfigHelper(1),
},
minSecondsBetweenBlocks: {
env: 'SEQ_MIN_SECONDS_BETWEEN_BLOCKS',
description: 'The minimum number of seconds in-between consecutive blocks.',
...numberConfigHelper(0),
},
maxSecondsBetweenBlocks: {
env: 'SEQ_MAX_SECONDS_BETWEEN_BLOCKS',
description:
'The maximum number of seconds in-between consecutive blocks. Sequencer will produce a block with less than minTxsPerBlock once this threshold is reached.',
...numberConfigHelper(0),
},
coinbase: {
env: 'COINBASE',
parseEnv: (val: string) => EthAddress.fromString(val),
Expand Down
63 changes: 11 additions & 52 deletions yarn-project/sequencer-client/src/sequencer/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export class Sequencer {
private pollingIntervalMs: number = 1000;
private maxTxsPerBlock = 32;
private minTxsPerBLock = 1;
private minSecondsBetweenBlocks = 0;
private maxSecondsBetweenBlocks = 0;
// TODO: zero values should not be allowed for the following 2 values in PROD
private _coinbase = EthAddress.ZERO;
private _feeRecipient = AztecAddress.ZERO;
Expand Down Expand Up @@ -139,12 +137,6 @@ export class Sequencer {
if (config.minTxsPerBlock !== undefined) {
this.minTxsPerBLock = config.minTxsPerBlock;
}
if (config.minSecondsBetweenBlocks !== undefined) {
this.minSecondsBetweenBlocks = config.minSecondsBetweenBlocks;
}
if (config.maxSecondsBetweenBlocks !== undefined) {
this.maxSecondsBetweenBlocks = config.maxSecondsBetweenBlocks;
}
if (config.coinbase) {
this._coinbase = config.coinbase;
}
Expand Down Expand Up @@ -353,15 +345,6 @@ export class Sequencer {
}
}

/** Whether to skip the check of min txs per block if more than maxSecondsBetweenBlocks has passed since the previous block. */
private skipMinTxsPerBlockCheck(historicalHeader: BlockHeader | undefined): boolean {
const lastBlockTime = historicalHeader?.globalVariables.timestamp.toNumber() || 0;
const currentTime = Math.floor(Date.now() / 1000);
const elapsed = currentTime - lastBlockTime;

return this.maxSecondsBetweenBlocks > 0 && elapsed >= this.maxSecondsBetweenBlocks;
}

async mayProposeBlock(tipArchive: Buffer, proposalBlockNumber: bigint): Promise<bigint> {
// This checks that we can propose, and gives us the slot that we are to propose for
try {
Expand Down Expand Up @@ -444,53 +427,29 @@ export class Sequencer {
`Last block mined at ${lastBlockTime} current time is ${currentTime} (elapsed ${elapsedSinceLastBlock})`,
);

// If we haven't hit the maxSecondsBetweenBlocks, we need to have at least minTxsPerBLock txs.
// Do not go forward with new block if not enough time has passed since last block
if (this.minSecondsBetweenBlocks > 0 && elapsedSinceLastBlock < this.minSecondsBetweenBlocks) {
// We need to have at least minTxsPerBLock txs.
if (args.pendingTxsCount != undefined && args.pendingTxsCount < this.minTxsPerBLock) {
this.log.verbose(
`Not creating block because not enough time ${this.minSecondsBetweenBlocks} has passed since last block`,
`Not creating block because not enough txs in the pool (got ${args.pendingTxsCount} min ${this.minTxsPerBLock})`,
);
return false;
}

const skipCheck = this.skipMinTxsPerBlockCheck(historicalHeader);

// If we haven't hit the maxSecondsBetweenBlocks, we need to have at least minTxsPerBLock txs.
if (args.pendingTxsCount != undefined) {
if (args.pendingTxsCount < this.minTxsPerBLock) {
if (skipCheck) {
this.log.debug(
`Creating block with only ${args.pendingTxsCount} txs as more than ${this.maxSecondsBetweenBlocks}s have passed since last block`,
);
} else {
this.log.verbose(
`Not creating block because not enough txs in the pool (got ${args.pendingTxsCount} min ${this.minTxsPerBLock})`,
);
return false;
}
}
}

// Bail if we don't have enough valid txs
if (args.validTxsCount != undefined) {
// Bail if we don't have enough valid txs
if (!skipCheck && args.validTxsCount < this.minTxsPerBLock) {
this.log.verbose(
`Not creating block because not enough valid txs loaded from the pool (got ${args.validTxsCount} min ${this.minTxsPerBLock})`,
);
return false;
}
if (args.validTxsCount != undefined && args.validTxsCount < this.minTxsPerBLock) {
this.log.verbose(
`Not creating block because not enough valid txs loaded from the pool (got ${args.validTxsCount} min ${this.minTxsPerBLock})`,
);
return false;
}

// TODO: This check should be processedTxs.length < this.minTxsPerBLock, so we don't publish a block with
// less txs than the minimum. But that'd cause the entire block to be aborted and retried. Instead, we should
// go back to the p2p pool and load more txs until we hit our minTxsPerBLock target. Only if there are no txs
// we should bail.
if (args.processedTxsCount != undefined) {
if (args.processedTxsCount === 0 && !skipCheck && this.minTxsPerBLock > 0) {
this.log.verbose('No txs processed correctly to build block.');
return false;
}
if (args.processedTxsCount === 0 && this.minTxsPerBLock > 0) {
this.log.verbose('No txs processed correctly to build block.');
return false;
}

return true;
Expand Down
Loading