From 32444aa3543fd9e9c7f3bdb7c0d8a85d656f20fc Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Wed, 15 Mar 2023 16:50:34 -0300 Subject: [PATCH] Kill PublisherDataEncoder and use the encode method from archive instead --- yarn-project/sequencer-client/package.json | 1 + yarn-project/sequencer-client/src/config.ts | 2 +- .../publisher/aztec-ethereumjs-tx-sender.ts | 13 +++++--- .../sequencer-client/src/publisher/index.ts | 3 +- .../src/publisher/l2-block-publisher.test.ts | 33 +++++++++---------- .../src/publisher/l2-block-publisher.ts | 31 +++++++---------- .../src/publisher/mock-l2-block-encoder.ts | 22 ------------- yarn-project/sequencer-client/src/receiver.ts | 7 ++-- .../test/l2-block-publisher.test.ts | 25 +++++++------- yarn-project/yarn.lock | 3 +- 10 files changed, 55 insertions(+), 85 deletions(-) delete mode 100644 yarn-project/sequencer-client/src/publisher/mock-l2-block-encoder.ts diff --git a/yarn-project/sequencer-client/package.json b/yarn-project/sequencer-client/package.json index fa62ca54d3da..a8e820b35cd3 100644 --- a/yarn-project/sequencer-client/package.json +++ b/yarn-project/sequencer-client/package.json @@ -32,6 +32,7 @@ "rootDir": "./src" }, "dependencies": { + "@aztec/archiver": "workspace:^", "@aztec/ethereum.js": "workspace:^", "@aztec/l1-contracts": "workspace:^", "tslib": "^2.4.0" diff --git a/yarn-project/sequencer-client/src/config.ts b/yarn-project/sequencer-client/src/config.ts index 67f7db421433..d3596f7793bb 100644 --- a/yarn-project/sequencer-client/src/config.ts +++ b/yarn-project/sequencer-client/src/config.ts @@ -1,4 +1,4 @@ -import { L1Addresses, getL1Addresses } from '@aztec/l1-contracts'; +import { L1Addresses } from '@aztec/l1-contracts'; export interface Config extends L1Addresses { sequencerPrivateKey: string; diff --git a/yarn-project/sequencer-client/src/publisher/aztec-ethereumjs-tx-sender.ts b/yarn-project/sequencer-client/src/publisher/aztec-ethereumjs-tx-sender.ts index e1b2cbc315ff..f8e00e2694db 100644 --- a/yarn-project/sequencer-client/src/publisher/aztec-ethereumjs-tx-sender.ts +++ b/yarn-project/sequencer-client/src/publisher/aztec-ethereumjs-tx-sender.ts @@ -4,7 +4,7 @@ import { WalletProvider } from '@aztec/ethereum.js/provider'; import { Rollup } from '@aztec/l1-contracts'; import { Config } from '../config.js'; import { hexStringToBuffer } from '../utils.js'; -import { EncodedL2BlockData, PublisherTxSender } from './l2-block-publisher.js'; +import { L1ProcessRollupArgs, PublisherTxSender } from './l2-block-publisher.js'; /** * Pushes transactions to the L1 rollup contract using the custom aztec/ethereum.js library. @@ -19,7 +19,9 @@ export class AztecEthereumjsTxSender implements PublisherTxSender { const provider = WalletProvider.fromHost(ethereumHost); provider.addAccount(hexStringToBuffer(sequencerPrivateKey)); this.ethRpc = new EthereumRpc(provider); - this.rollupContract = new Rollup(this.ethRpc, EthAddress.fromString(rollupContractAddress), { from: provider.getAccount(0) }); + this.rollupContract = new Rollup(this.ethRpc, EthAddress.fromString(rollupContractAddress), { + from: provider.getAccount(0), + }); this.confirmations = requiredConfirmations; } @@ -29,9 +31,12 @@ export class AztecEthereumjsTxSender implements PublisherTxSender { ); } - async sendTransaction(encodedData: EncodedL2BlockData): Promise { + async sendTransaction(encodedData: L1ProcessRollupArgs): Promise { const methodCall = this.rollupContract.methods.processRollup(encodedData.proof, encodedData.inputs); const gas = await methodCall.estimateGas(); - return methodCall.send({ gas }).getTxHash().then(hash => hash.toString()); + return methodCall + .send({ gas }) + .getTxHash() + .then(hash => hash.toString()); } } diff --git a/yarn-project/sequencer-client/src/publisher/index.ts b/yarn-project/sequencer-client/src/publisher/index.ts index bab069a8e453..b903b10a5205 100644 --- a/yarn-project/sequencer-client/src/publisher/index.ts +++ b/yarn-project/sequencer-client/src/publisher/index.ts @@ -1,10 +1,9 @@ import { Config } from '../config.js'; import { AztecEthereumjsTxSender } from './aztec-ethereumjs-tx-sender.js'; import { L2BlockPublisher } from './l2-block-publisher.js'; -import { MockL2DataEncoder } from './mock-l2-block-encoder.js'; export { L2BlockPublisher } from './l2-block-publisher.js'; export function getL2BlockPublisher(config: Config): L2BlockPublisher { - return new L2BlockPublisher(new AztecEthereumjsTxSender(config), new MockL2DataEncoder()); + return new L2BlockPublisher(new AztecEthereumjsTxSender(config)); } diff --git a/yarn-project/sequencer-client/src/publisher/l2-block-publisher.test.ts b/yarn-project/sequencer-client/src/publisher/l2-block-publisher.test.ts index 67ad85b40003..28eb8ae006f3 100644 --- a/yarn-project/sequencer-client/src/publisher/l2-block-publisher.test.ts +++ b/yarn-project/sequencer-client/src/publisher/l2-block-publisher.test.ts @@ -1,25 +1,22 @@ +import { L2Block, mockRandomL2Block } from '@aztec/archiver'; import { TxHash } from '@aztec/ethereum.js/eth_rpc'; import { mock, MockProxy } from 'jest-mock-extended'; -import { MockL2DataEncoder } from './mock-l2-block-encoder.js'; -import { L2BlockData } from '../receiver.js'; -import { EncodedL2BlockData, L2BlockPublisher, PublisherDataEncoder, PublisherTxSender } from './l2-block-publisher.js'; import { sleep } from '../utils.js'; +import { L2BlockPublisher, PublisherTxSender } from './l2-block-publisher.js'; describe('L2BlockPublisher', () => { - let encoder: PublisherDataEncoder; let txSender: MockProxy; let txHash: string; let txReceipt: { transactionHash: string; status: boolean }; - let l2BlockData: L2BlockData; - let l2EncodedData: EncodedL2BlockData; - + let l2Block: L2Block; + let l2Inputs: Buffer; + let l2Proof: Buffer; let publisher: L2BlockPublisher; beforeEach(() => { - l2BlockData = { id: 42 }; - const mockEncoder = new MockL2DataEncoder(); - l2EncodedData = mockEncoder.mockData; - encoder = mockEncoder; + l2Block = mockRandomL2Block(42); + l2Inputs = l2Block.encode(); + l2Proof = Buffer.alloc(0); txSender = mock(); txHash = TxHash.random().toString(); @@ -27,21 +24,21 @@ describe('L2BlockPublisher', () => { txSender.sendTransaction.mockResolvedValueOnce(txHash); txSender.getTransactionReceipt.mockResolvedValueOnce(txReceipt); - publisher = new L2BlockPublisher(txSender, encoder, { sleepTimeMs: 1 }); + publisher = new L2BlockPublisher(txSender, { sleepTimeMs: 1 }); }); it('publishes l2 block to l1', async () => { - const result = await publisher.processL2Block(l2BlockData); + const result = await publisher.processL2Block(l2Block); expect(result).toEqual(true); - expect(txSender.sendTransaction).toHaveBeenCalledWith(l2EncodedData); + expect(txSender.sendTransaction).toHaveBeenCalledWith({ proof: l2Proof, inputs: l2Inputs }); expect(txSender.getTransactionReceipt).toHaveBeenCalledWith(txHash); }); it('retries if sending a tx fails', async () => { txSender.sendTransaction.mockReset().mockRejectedValueOnce(new Error()).mockResolvedValueOnce(txHash); - const result = await publisher.processL2Block(l2BlockData); + const result = await publisher.processL2Block(l2Block); expect(result).toEqual(true); expect(txSender.sendTransaction).toHaveBeenCalledTimes(2); @@ -50,7 +47,7 @@ describe('L2BlockPublisher', () => { it('retries if fetching the receipt fails', async () => { txSender.getTransactionReceipt.mockReset().mockRejectedValueOnce(new Error()).mockResolvedValueOnce(txReceipt); - const result = await publisher.processL2Block(l2BlockData); + const result = await publisher.processL2Block(l2Block); expect(result).toEqual(true); expect(txSender.getTransactionReceipt).toHaveBeenCalledTimes(2); @@ -59,7 +56,7 @@ describe('L2BlockPublisher', () => { it('returns false if tx reverts', async () => { txSender.getTransactionReceipt.mockReset().mockResolvedValueOnce({ ...txReceipt, status: false }); - const result = await publisher.processL2Block(l2BlockData); + const result = await publisher.processL2Block(l2Block); expect(result).toEqual(false); }); @@ -67,7 +64,7 @@ describe('L2BlockPublisher', () => { it('returns false if interrupted', async () => { txSender.sendTransaction.mockReset().mockImplementationOnce(() => sleep(10, txHash)); - const resultPromise = publisher.processL2Block(l2BlockData); + const resultPromise = publisher.processL2Block(l2Block); publisher.interrupt(); const result = await resultPromise; diff --git a/yarn-project/sequencer-client/src/publisher/l2-block-publisher.ts b/yarn-project/sequencer-client/src/publisher/l2-block-publisher.ts index f029b560d6c4..cae144d5295d 100644 --- a/yarn-project/sequencer-client/src/publisher/l2-block-publisher.ts +++ b/yarn-project/sequencer-client/src/publisher/l2-block-publisher.ts @@ -1,4 +1,5 @@ -import { L2BlockData, L2BlockReceiver } from '../receiver.js'; +import { L2Block } from '@aztec/archiver'; +import { L2BlockReceiver } from '../receiver.js'; // eslint-disable-next-line @typescript-eslint/no-unused-vars const MIN_FEE_DISTRIBUTOR_BALANCE = 5n * 10n ** 17n; @@ -7,25 +8,18 @@ const MIN_FEE_DISTRIBUTOR_BALANCE = 5n * 10n ** 17n; * Component responsible of pushing the txs to the chain and waiting for completion. */ export interface PublisherTxSender { - sendTransaction(encodedData: EncodedL2BlockData): Promise; + sendTransaction(encodedData: L1ProcessRollupArgs): Promise; getTransactionReceipt(txHash: string): Promise<{ status: boolean; transactionHash: string } | undefined>; } /** - * Encoded block data ready to be pushed to the L1 contract. + * Encoded block data and proof ready to be pushed to the L1 contract. */ -export type EncodedL2BlockData = { +export type L1ProcessRollupArgs = { proof: Buffer; inputs: Buffer; }; -/** - * Component responsible of encoding the data of an l2 block to be published to the l1 rollup contract. - */ -export interface PublisherDataEncoder { - encodeL2BlockDataForPublish(l2BlockData: L2BlockData): Promise; -} - /** * Publishes L2 blocks to the L1 rollup contracts. This implementation does *not* retry a transaction in * the event of network congestion. @@ -40,11 +34,7 @@ export class L2BlockPublisher implements L2BlockReceiver { private interruptResolve = () => {}; private sleepTimeMs: number; - constructor( - private txSender: PublisherTxSender, - private encoder: PublisherDataEncoder, - opts?: { sleepTimeMs?: number }, - ) { + constructor(private txSender: PublisherTxSender, opts?: { sleepTimeMs?: number }) { this.interruptPromise = new Promise(resolve => (this.interruptResolve = resolve)); this.sleepTimeMs = opts?.sleepTimeMs ?? 60_000; } @@ -53,8 +43,9 @@ export class L2BlockPublisher implements L2BlockReceiver { * Processes incoming L2 block data by publishing it to the L1 rollup contract. * @returns True once the tx has been confirmed and is successful, false on revert or interrupt, blocks otherwise. */ - public async processL2Block(l2BlockData: L2BlockData): Promise { - const txData = await this.encoder.encodeL2BlockDataForPublish(l2BlockData); + public async processL2Block(l2BlockData: L2Block): Promise { + const proof = Buffer.alloc(0); + const txData = { proof, inputs: l2BlockData.encode() }; while (!this.interrupted) { if (!(await this.checkFeeDistributorBalance())) { @@ -73,7 +64,7 @@ export class L2BlockPublisher implements L2BlockReceiver { if (receipt.status) return true; // Check if someone else moved the block id - if (!(await this.checkNextL2BlockId(l2BlockData.id))) { + if (!(await this.checkNextL2BlockId(l2BlockData.number))) { console.log('Publish failed. Contract changed underfoot.'); break; } @@ -109,7 +100,7 @@ export class L2BlockPublisher implements L2BlockReceiver { return true; } - private async sendTransaction(encodedData: EncodedL2BlockData): Promise { + private async sendTransaction(encodedData: L1ProcessRollupArgs): Promise { while (!this.interrupted) { try { return await this.txSender.sendTransaction(encodedData); diff --git a/yarn-project/sequencer-client/src/publisher/mock-l2-block-encoder.ts b/yarn-project/sequencer-client/src/publisher/mock-l2-block-encoder.ts deleted file mode 100644 index b7f241103410..000000000000 --- a/yarn-project/sequencer-client/src/publisher/mock-l2-block-encoder.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { L2BlockData } from '../receiver.js'; -import { EncodedL2BlockData, PublisherDataEncoder } from './l2-block-publisher.js'; - -/** - * Discards input block data and returns a fixed mock value accepted by the rollup contract. - * TODO: Replace with an actual implementation. - */ -export class MockL2DataEncoder implements PublisherDataEncoder { - // Mock values copied from l1-contracts/test/Decoder.t.sol - public mockData = { - inputs: Buffer.from( - '00000001000000004ced6e4fc963228874c6c5a54fd6a91fdf0a184df1713dc4e7979e11a654e73400000000854f5a221db6ac3769b547567ff7f2e25f702b4fb00bd4ead2f221f1108daf860000000002cbc0663506c402089bb584258b7ff99e6938011759f683dc45c69cf8ec3ced0000000027ffce7770929c47b0b2c02a9aa0c595a75a249e203e9ecddac60fe87d86329000000000cd12438926cbd1120ec292839e2fa2be75585ed6412ea91d137dd21e5d887c6800000020d947c6e58664edf5070a5b178dd20549654e02178bb8bce8dab0d7e039e0a6dd0000002004c6479ef3e68845e9c0c5e8b70694f0b4129171d52c0b0ae41cf6bdaac4bcf200000008d0b6e7c2b6718c60737778df2ba3e5821829c12a33fcb8a174bdb68802ce6dc8000000014b5e621ba5b32b8a659ec4e08b707e09058ac496854dbfe4df8d4413d3f0b84f00000001cc140b1390f031193681fdce48b5d0e228085e8be975fa2708ddab69e894877e00000020f157829e35750b68e913f0e6a3798f3272d6ed14e98d0a91a12f87ca384fa0ee18528d9c33d23a19cee3c8c04b7593d80abec52db7514c791a4872ccd055722134e38eae1ddaf65129fd40cf1cf3323aca4bee8513fb44c00f0ca401a09e3bb15d27ce1bd2929b3ea544ea52165496fae774315db75149a871f0293a2a8cf46d88c0753099b1a42c857959909728a1e152bde8452fbdc7f360bfaa8038d412bbb1893c2660e63cb74ca1ab9fcc9cb88b5cdc34dc74831131cf380114ba163cc5f4097a6642bf4f2adb87b6cebe0ecb5674e891cb48ae84ef76d641158d6ff2b4570ce2c2432f08f51cca7322b1b08a718760121d80b2f20cfd41d4823479c0bf0a228615ae1dd9c743b4b7d06f9d4610ee0dde54b741fa8c38c73214d9da01213fde70297c0d02d4ee7153ad5fe341a838916139e34d867dd416e00844017a63db445e7319a8e80b2078fffe8f9dee669b87055622501c3175061c5bac9846c6be7de7a2e27b8f895081248a3d4ff9ad9376eb51b9e8cc04fcf61394f6b6c7e666dbf3a80ace80da1cbf964136eb5cb99bdd9fc50d4c48f40604051ee0156ac7dc0ee8873eb9c09e16d1910b42d7c1f3fe072c6004688a8bf365dd9c31ac2606ed264a7513c41574765f5180e5a00f6d4c4017cb2cbca1d0140a661aa2fdfb05788fb809724fdf0fbb9b7e2b6c194973792d8da4bc3f59b7317c6667bfd6987f345f8368b61f0646722e55099ee952dac25e926466ca486a7ef6550b8bf4e97c50717d27c95927157448a7a159f3f40a71916e3a952e5dd9263d05385640fbc96ac65da468126c049e47b57c98e97e7d2ee3fbfae37350cd93eb4052d6d73b52a1bd86aa9e62f0f9fbeda924f6d9ae5bc5fbf4fea52f3b9914cb629464dee633301c00e2ebac8a3ed26247231ef6dbc077ced664b6e753189f5e5fc7a7bbe234730d100a7567ed281c8149db8ac20206dc11bbbb39648eeeab7d7bad18a97d323ea8811ff497e364d68eae9819a598e70606962089b01a9ba47d5d681f582b37c1d9fac029d86f81aba848af1cd23bd70eb10f66143d497d1f97d8f6564ac1d64d9065bd60b1059a244ee4ca6d54ae533b82ed5695a4c171c967a782dd45e83b0134cd41a7519152018013039888df7d41b984bcc88e537de574b2bc26b8b1dde22260f66dd864d2758c63ff6706c98a620cfe95d74794e28e722ba79d9ae3fddd48c122471b5738b76d9aa2ef855b37ec5453f567ed89355d604cdc0f0416a55ac382ef2f29749b456f0fc13e10fe85e65e816682c7e381c21a52483e55bf8829d11a4709ca03d3e80c2ef596de37b6cc508a105fd5ac2938f8946c2608706ad842e325f2cc96a536cefdde0503f4aad0ba5f89f1e84586774d8153d98cef0f0ef4c7f291904709c610ed7076419531faecc1fb424f72d4ad194ef34dc4dce40000002078fcdaff5b16d7108a14544d3614ce7515973bdf73e803497986ad232ccd41c568ea6ba8158294041dc8a03f26c31728c7e3abc937121ddc0beaf81cdbb322561d9b54d1cea00c383ca3fa7f61d3209f14aeea5713c157bac42f3b748f7758bbb6a67cd2e8a39da07858ef152eb2a0f646db49a1da371e6a168a3a242a4957975c65aa8ef75d1fa012426765ffeb4b027ab412aad4a7d29c404fb65e5edbbe5d66ae6a328378720fde21aec7c3e3c5f107da499b6c9833c268ac0ecbd1fe67879caa9110f9a3ab39c61fdd895265f616b88990f83fa7524f6fbb679914a229df491c5c1fab6f74427a438a2e8c56cc9517a5cc684ff0c21cc48424fd2517f53d3c9b516b8097fe6168539dfe8fc1b1971f8cdafb97f5d97c3ee8376e132ca24371c67a4c6fbeeb92d341511f61b990e2651e8d9375c50a8879a399031fc5ab133239fcd7aa46a340109756d70ca322640a5f0d5b4266eae65e5e9cc4023a5aea77374f760c8672ef530cba31398dfbcd96015d1abc0089dc7063479c83053584deb729b10d654e17d05ebb5eadb67dbe13f9572df5c6f64c69ea6d8fd628d15eef9d4407f2806766f0e0762596253f1c129cb204fc8286bf7b182fd3d8fa75b3462ec80fa994f0b4c0850ae7e18dd46c51bc100ee0b4f87afc8f50ac0e5656f789f931db2203d4d5080bbfdd4b2c436533de36f00193e5495125542739fa23f1e373a8f04004020e351b7166a5dff3fca272c01bedae77afa8af363ccc9bc199445dd548a5580393a1c3f06d4f412b6e273d7876a114b1ce80ac129a2f26b825ecfb4c3d3e99805267c57e54fd9354857c87a88762c399f8844ec1b0a261f8a75c09bbc218a8a80c60cae7dc8c522ebc3ee1cc1420cfc45f10ac85301b2c96d3d77895eae06946ff05691e975b23680aaddff373ed7df709131a95c6eeee3d39cc2e6e0241f9a03a895ef30a0d298a6eb64feb6d68833b59f5bd856ee267a166c6d762455b4c3fb12d49baac944eeb614db96ecfd9a0f0bb64ce1cdf214e22edd54125241355ba0e3c8a7baf336d50fffb3675770a747404687554773f5a03f9a6ee75e7e8b18d9ff68d2248bd05f5867ce577195a3a2f22d0316d49d93256769f845cb7fc030ccd9a271e5cd4dbc48cae262e9997943bead0e9075d6755897d508b49e7366181505ccd91dbff2ebcff5c9880b6d245a2c37c2e5ae869279da80e7e52df045821a1f2df75aac9d56af4691b80ef9d9681cdf958b6c83e2bc29b6eb92f2560a7a807a27741a7dcc036e09125033f899ae2b576910283c96b9c8e6b3aed59fb2f565773b3240f49f9fb46a5edac9aae5ec1ab309029b58b8d1502465e7a7c9946cdfb33045affd4771ec056b63a3b10d02ac8fa0e1ca2ce72d721c84e02e9765f815e965565cff33e55be902c5bd66323bf1b2cc2ba8209c5020900000008374dbcd64b22603ee64361c7ad45cfe4ad5631253487b416af8e76a07d225512e42cbe87752194cb52232c93ddbfc1378b37e25677ff2ffb08370c5bf97ea5159eef6abbd8cbc30658eb95deb75341483bf7014ebee848dbdef8d20b1e0131d9c20c53a0ba56517e99df8d3cc029aa357350fb004d801bc524888db6e783384c5b653bfca291e73b7a067e1ecf3ebc0c0cb341a3b73afc6e58123fddd5e415c3131ed1fff0bfce14d661f5d4826ccb28caa8a9947b4826969ebdd0387077d60807950f8e82e0cbb975bb06279239d89e5a4aaca05a49adcaaed23bbacbe8bf2f8f165d7801d7a78780314f72f785a34f4798d9d1aafd10dd7849fc5e2d7095ab8bb82ca101e04cb545c79f9c9d57c70203dd92c091ccdf6031b7314d62eaa881cb1e5911277a021a5f6d239257f698f5bf5ef9ac018b51fdecca39a98e36663d486aee16e059098f82d55ecab0563db006af473aea12033c35e0b93939dc41027c29d36504de7c359c2d2808d0b42429d5795ce3c2214f56567ff97aad989f00eba01af1e44dc99c921fda1c5df14ebc402ad05a4f0e71c80d9c37347fa36179ac64c6d9f346ef4c3a499b708224a7e457b909a842b0b18da22be719d32ef3ad7a93cba2657d6fb9b1994775acf0d74ae099844ea8d1d21436164937139df26933ec5aedad78a0b627705981c973c83122b26a946d31fe38e789fb95e58cf727907a694dd931ade1272bfb1a3ef2ad94e6ed4e7bcc2060c2cffdbba6d1ee757098d30a2be3cce87e98a539e88397208b2fd2c1cac82172304e8a29568ee3ae745f4e0ff102d70b81d474950ece60d9874c4d42dd90d728a475b689f0940fd8f9f8dde890e3d0140236ece1cbdb2275c9c7b2f860fd9c367fcd71c7fbadc0a5415761371462720c0855b9350bb89a974caacd5e2777aa0ebeef06356f6e718fbd', - 'hex', - ), - proof: Buffer.alloc(0), - }; - - // eslint-disable-next-line require-await, @typescript-eslint/no-unused-vars - async encodeL2BlockDataForPublish(_l2BlockData: L2BlockData): Promise { - return this.mockData; - } -} diff --git a/yarn-project/sequencer-client/src/receiver.ts b/yarn-project/sequencer-client/src/receiver.ts index 0e3bc8f309bf..ed8949730af8 100644 --- a/yarn-project/sequencer-client/src/receiver.ts +++ b/yarn-project/sequencer-client/src/receiver.ts @@ -1,12 +1,9 @@ -// TODO: Complete definition or import from another package (add txs at least!). -export interface L2BlockData { - id: number; -} +import { L2Block } from '@aztec/archiver'; /** * Given the necessary rollup data, verifies it, and updates the underlying state accordingly to advance the state of the system. * See https://hackmd.io/ouVCnacHQRq2o1oRc5ksNA#RollupReceiver. */ export interface L2BlockReceiver { - processL2Block(l2BlockData: L2BlockData): Promise; + processL2Block(l2BlockData: L2Block): Promise; } diff --git a/yarn-project/sequencer-client/test/l2-block-publisher.test.ts b/yarn-project/sequencer-client/test/l2-block-publisher.test.ts index c6615a1a3a80..eff87471472d 100644 --- a/yarn-project/sequencer-client/test/l2-block-publisher.test.ts +++ b/yarn-project/sequencer-client/test/l2-block-publisher.test.ts @@ -1,12 +1,11 @@ +import { L2Block, mockRandomL2Block } from '@aztec/archiver'; import { EthAddress } from '@aztec/ethereum.js/eth_address'; import { EthereumRpc } from '@aztec/ethereum.js/eth_rpc'; import { WalletProvider } from '@aztec/ethereum.js/provider'; import { Rollup } from '@aztec/l1-contracts'; -import { beforeAll, describe, it, expect } from '@jest/globals'; +import { beforeAll, describe, expect, it } from '@jest/globals'; import { AztecEthereumjsTxSender } from '../src/publisher/aztec-ethereumjs-tx-sender.js'; -import { EncodedL2BlockData, L2BlockPublisher } from '../src/publisher/l2-block-publisher.js'; -import { MockL2DataEncoder } from '../src/publisher/mock-l2-block-encoder.js'; -import { L2BlockData } from '../src/receiver.js'; +import { L2BlockPublisher } from '../src/publisher/l2-block-publisher.js'; import { hexStringToBuffer } from '../src/utils.js'; // Accounts 4 and 5 of Anvil default startup with mnemonic: 'test test test test test test test test test test test junk' @@ -18,16 +17,15 @@ describe('L2BlockPublisher integration', () => { let rollup: Rollup; let ethRpc: EthereumRpc; let publisher: L2BlockPublisher; - let l2BlockData: L2BlockData; - let encodedL2BlockData: EncodedL2BlockData; + let l2Block: L2Block; + let l2Proof: Buffer; beforeAll(async () => { let deployer: EthAddress; ({ ethRpc, rollup, deployer } = await deployRollup()); - const encoder = new MockL2DataEncoder(); - encodedL2BlockData = encoder.mockData; - l2BlockData = { id: 42 }; + l2Block = mockRandomL2Block(42); + l2Proof = Buffer.alloc(0); publisher = new L2BlockPublisher( new AztecEthereumjsTxSender({ @@ -37,7 +35,6 @@ describe('L2BlockPublisher integration', () => { rollupContract: rollup.address.toChecksumString(), sequencerPrivateKey: sequencerPK }), - encoder, { sleepTimeMs: 100 } @@ -46,11 +43,15 @@ describe('L2BlockPublisher integration', () => { it('publishes l2 block data to l1 rollup contract', async () => { const blockNumber = await ethRpc.blockNumber(); - await publisher.processL2Block(l2BlockData); + await publisher.processL2Block(l2Block); const logs = await rollup.getLogs('RollupBlockProcessed', { fromBlock: blockNumber }); expect(logs).toHaveLength(1); - expect(logs[0].args.rollupBlockNumber).toEqual(1n); + expect(logs[0].args.rollupBlockNumber).toEqual(42n); + + const tx = await ethRpc.getTransactionByHash(logs[0].transactionHash!); + const expectedData = rollup.methods.processRollup(l2Proof, l2Block.encode()).encodeABI(); + expect(tx.input).toEqual(expectedData); }); }); diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index cf462b410f56..cbf77ed459c6 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -32,7 +32,7 @@ __metadata: languageName: unknown linkType: soft -"@aztec/archiver@workspace:archiver": +"@aztec/archiver@workspace:^, @aztec/archiver@workspace:archiver": version: 0.0.0-use.local resolution: "@aztec/archiver@workspace:archiver" dependencies: @@ -336,6 +336,7 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/sequencer-client@workspace:sequencer-client" dependencies: + "@aztec/archiver": "workspace:^" "@aztec/eslint-config": "workspace:^" "@aztec/ethereum.js": "workspace:^" "@aztec/l1-contracts": "workspace:^"