Skip to content

Commit

Permalink
chore: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Aug 27, 2024
1 parent add47dd commit 10d2ad6
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ contract Rollup is Leonidas, IRollup, ITestRollup {

// Genesis block
blocks[0] = BlockLog({
archive: bytes32(0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e),
archive: bytes32(Constants.GENESIS_ARCHIVE_ROOT),
blockHash: bytes32(0),
slotNumber: 0,
isProven: true
Expand Down
2 changes: 2 additions & 0 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ library Constants {
uint256 internal constant AZTEC_SLOT_DURATION = 12;
uint256 internal constant AZTEC_EPOCH_DURATION = 48;
uint256 internal constant IS_DEV_NET = 1;
uint256 internal constant GENESIS_ARCHIVE_ROOT =
8142738430000951296386584486068033372964809139261822027365426310856631083550;
uint256 internal constant FEE_JUICE_INITIAL_MINT = 20000000000;
uint256 internal constant MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 20000;
uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000;
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/test/sparta/Sparta.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ contract SpartaTest is DecoderBase {
return;
}

_testBlock("mixed_block_1", false, 3, false); // We run a block before the epoch with validators
_testBlock("mixed_block_2", false, 3, false); // We need signatures!
_testBlock("mixed_block_1", false, 3, false);
_testBlock("mixed_block_2", false, 3, false);
}

function testInvalidProposer() public setup(4) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,13 @@ global INITIALIZATION_SLOT_SEPARATOR: Field = 1000_000_000;
global INITIAL_L2_BLOCK_NUM: Field = 1;
global BLOB_SIZE_IN_BYTES: Field = 31 * 4096;
global ETHEREUM_SLOT_DURATION: u32 = 12;
// AZTEC_SLOT_DURATION should be a multiple of ETHEREUM_SLOT_DURATION
global AZTEC_SLOT_DURATION: u32 = ETHEREUM_SLOT_DURATION * 1;
global AZTEC_EPOCH_DURATION: u32 = 48;
global IS_DEV_NET: bool = true;
// The following is taken from building a block and looking at the `lastArchive` value in it.
// You can run the `integration_l1_publisher.test.ts` and look at the first blocks in the fixtures.
global GENESIS_ARCHIVE_ROOT: Field = 0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e;
// The following and the value in `deploy_l1_contracts´ must match. We should not have the code both places, but
// we are running into circular dependency issues. #3342
global FEE_JUICE_INITIAL_MINT: Field = 20000000000;
Expand Down
1 change: 1 addition & 0 deletions yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const ETHEREUM_SLOT_DURATION = 12;
export const AZTEC_SLOT_DURATION = 12;
export const AZTEC_EPOCH_DURATION = 48;
export const IS_DEV_NET = 1;
export const GENESIS_ARCHIVE_ROOT = 8142738430000951296386584486068033372964809139261822027365426310856631083550n;
export const FEE_JUICE_INITIAL_MINT = 20000000000;
export const MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 20000;
export const MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import {
ETHEREUM_SLOT_DURATION,
EthAddress,
GENESIS_ARCHIVE_ROOT,
GasFees,
type Header,
KernelCircuitPublicInputs,
Expand Down Expand Up @@ -77,9 +78,6 @@ const config = getConfigEnvVars();

const numberOfConsecutiveBlocks = 2;

// The initial archive is what we have in the genesis block in `Rollup.sol`.
const INITIAL_ARCHIVE = Fr.fromString('0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e').toBuffer();

describe('L1Publisher integration', () => {
let publicClient: PublicClient<HttpTransport, Chain>;
let walletClient: WalletClient<HttpTransport, Chain, Account>;
Expand Down Expand Up @@ -351,7 +349,7 @@ describe('L1Publisher integration', () => {

it(`Build ${numberOfConsecutiveBlocks} blocks of 4 bloated txs building on each other`, async () => {
const archiveInRollup_ = await rollup.read.archive();
expect(hexStringToBuffer(archiveInRollup_.toString())).toEqual(INITIAL_ARCHIVE);
expect(hexStringToBuffer(archiveInRollup_.toString())).toEqual(new Fr(GENESIS_ARCHIVE_ROOT).toBuffer());

const blockNumber = await publicClient.getBlockNumber();
// random recipient address, just kept consistent for easy testing ts/sol.
Expand Down Expand Up @@ -469,14 +467,14 @@ describe('L1Publisher integration', () => {
// We wipe the messages from previous iteration
nextL1ToL2Messages = [];

// @todo @LHerskind need to make sure that time have progressed to the next slot!
// Make sure that time have progressed to the next slot!
await progressTimeBySlot();
}
});

it(`Build ${numberOfConsecutiveBlocks} blocks of 2 empty txs building on each other`, async () => {
const archiveInRollup_ = await rollup.read.archive();
expect(hexStringToBuffer(archiveInRollup_.toString())).toEqual(INITIAL_ARCHIVE);
expect(hexStringToBuffer(archiveInRollup_.toString())).toEqual(new Fr(GENESIS_ARCHIVE_ROOT).toBuffer());

const blockNumber = await publicClient.getBlockNumber();

Expand Down
3 changes: 2 additions & 1 deletion yarn-project/ethereum/src/deploy_l1_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ export const deployL1Contracts = async (
client: walletClient,
});

// @note We make a time jump PAST the very first slot to not have to deal with the edge case of the first slot
// @note We make a time jump PAST the very first slot to not have to deal with the edge case of the first slot.
// The edge case being that the genesis block is already occupying slot 0, so we cannot have another block.
try {
// Need to get the time
const currentSlot = (await rollup.read.getCurrentSlot([])) as bigint;
Expand Down
1 change: 1 addition & 0 deletions yarn-project/sequencer-client/src/publisher/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface PublisherConfig {
l1PublishRetryIntervalMS: number;
/**
* Whether the publisher is a time traveler and can warp the underlying chain
* @todo #8153 - Remove this flag once the time traveler is removed
*/
timeTraveler: boolean;
}
Expand Down
21 changes: 15 additions & 6 deletions yarn-project/sequencer-client/src/publisher/l1-publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ export type L1SubmitProofArgs = {
aggregationObject: Buffer;
};

export type MetadataForSlot = {
proposer: EthAddress;
slot: bigint;
pendingBlockNumber: bigint;
archive: Buffer;
};

/**
* Publishes L2 blocks to L1. This implementation does *not* retry a transaction in
* the event of network congestion, but should work for local development.
Expand Down Expand Up @@ -187,7 +194,7 @@ export class L1Publisher {

// @note Assumes that all ethereum slots have blocks
// Using next Ethereum block so we do NOT need to wait for it being mined before seeing the effect
public async getMetadataForSlotAtNextEthBlock(): Promise<[EthAddress, bigint, bigint, Buffer]> {
public async getMetadataForSlotAtNextEthBlock(): Promise<MetadataForSlot> {
const ts = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(ETHEREUM_SLOT_DURATION));

const [submitter, slot, pendingBlockCount, archive] = await Promise.all([
Expand All @@ -197,12 +204,12 @@ export class L1Publisher {
this.rollupContract.read.archive(),
]);

return [
EthAddress.fromString(submitter),
return {
proposer: EthAddress.fromString(submitter),
slot,
pendingBlockCount - 1n,
Buffer.from(archive.replace('0x', ''), 'hex'),
];
pendingBlockNumber: pendingBlockCount - 1n,
archive: Buffer.from(archive.replace('0x', ''), 'hex'),
};
}

public async getCurrentEpochCommittee(): Promise<EthAddress[]> {
Expand Down Expand Up @@ -317,6 +324,8 @@ export class L1Publisher {
// Time jumps only allowed into the future.
//
// If this is run on top of a real chain, the time lords will catch you.
//
// @todo #8153

if (!this.timeTraveler) {
return;
Expand Down
6 changes: 2 additions & 4 deletions yarn-project/sequencer-client/src/sequencer/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class Sequencer {
// Also, we are logging debug messages for checks that fail to make it easier to debug, as we are usually
// catching the errors.

const [submitter, slot, pendingBlockNumber, archive] = await this.publisher.getMetadataForSlotAtNextEthBlock();
const { proposer, slot, pendingBlockNumber, archive } = await this.publisher.getMetadataForSlotAtNextEthBlock();

if (await this.publisher.willSimulationFail(slot)) {
// @note See comment in willSimulationFail for more information
Expand Down Expand Up @@ -362,7 +362,7 @@ export class Sequencer {
}

// Do not go forward with new block if not free for all or my turn
if (!submitter.isZero() && !submitter.equals(await this.publisher.getSenderAddress())) {
if (!proposer.isZero() && !proposer.equals(await this.publisher.getSenderAddress())) {
const msg = 'Not my turn to submit block';
this.log.debug(msg);
throw new Error(msg);
Expand Down Expand Up @@ -440,8 +440,6 @@ export class Sequencer {
return true;
}

async assertCanStillProposeBlock(): Promise<void> {}

@trackSpan(
'Sequencer.buildBlockAndPublish',
(_validTxs, newGlobalVariables, _historicalHeader, _chainTipArchive) => ({
Expand Down

0 comments on commit 10d2ad6

Please sign in to comment.