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

fix: Fetch Headers and Bodies separately #4167 #4632

Merged
merged 125 commits into from
Mar 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
2a9d399
test
sklppy88 Feb 7, 2024
bc37c35
why does this fix
sklppy88 Feb 10, 2024
f19757d
good
sklppy88 Feb 12, 2024
94bc65d
Readding test
sklppy88 Feb 12, 2024
3dad335
Yarn format
sklppy88 Feb 12, 2024
da70a99
Revert "why does this fix"
sklppy88 Feb 12, 2024
70cea40
fix
sklppy88 Feb 12, 2024
8b505e3
some reorganizing
sklppy88 Feb 12, 2024
b8f442f
more reorg
sklppy88 Feb 12, 2024
7756734
more cleanup
sklppy88 Feb 12, 2024
ae39116
Merge branch 'master' into ek/fix/align-block-structs-with-yp
sklppy88 Feb 12, 2024
f0362d7
formatting and fixing imports
sklppy88 Feb 12, 2024
bc551e6
Merge remote-tracking branch 'origin/ek/fix/align-block-structs-with-…
sklppy88 Feb 12, 2024
aef101f
more
sklppy88 Feb 12, 2024
6d3a980
test
sklppy88 Feb 12, 2024
f277bbc
Merge branch 'master' into ek/fix/align-block-structs-with-yp
sklppy88 Feb 12, 2024
ba62405
Merge branch 'master' into ek/fix/align-block-structs-with-yp
sklppy88 Feb 13, 2024
c8b343f
Merge branch 'master' into ek/fix/align-block-structs-with-yp
sklppy88 Feb 13, 2024
90cadf3
initial
sklppy88 Feb 13, 2024
7099ff6
Comments
sklppy88 Feb 13, 2024
58eae75
more organizing
sklppy88 Feb 13, 2024
a3db555
yarn format
sklppy88 Feb 13, 2024
f55a7a6
comments
sklppy88 Feb 13, 2024
107cccc
address comments
sklppy88 Feb 13, 2024
841f0c9
initial
sklppy88 Feb 13, 2024
9574cf8
Merge branch 'master' into ek/fix/align-block-structs-with-yp
sklppy88 Feb 13, 2024
2f69022
Merge branch 'ek/fix/align-block-structs-with-yp' into ek/fix/fetch-h…
sklppy88 Feb 13, 2024
acd0dab
next
sklppy88 Feb 13, 2024
1861272
modify a bit
sklppy88 Feb 14, 2024
9ce8d61
Merge branch 'ek/fix/align-block-structs-with-yp' into ek/fix/fetch-h…
sklppy88 Feb 14, 2024
81d2a7e
kinda working
sklppy88 Feb 14, 2024
ac78531
Merge branch 'master' into ek/fix/align-block-structs-with-yp
sklppy88 Feb 14, 2024
785c16d
Fix formatting and addressing comments
sklppy88 Feb 14, 2024
8fb5976
Yarn format
sklppy88 Feb 14, 2024
8b76426
Merge branch 'master' into ek/fix/align-block-structs-with-yp
sklppy88 Feb 14, 2024
d0414f8
test
sklppy88 Feb 14, 2024
e377156
test
sklppy88 Feb 14, 2024
7b2a632
Address comments
sklppy88 Feb 15, 2024
46444b5
Fix
sklppy88 Feb 15, 2024
3bbd1f7
Fix formatting
sklppy88 Feb 15, 2024
92c49ab
Addressing comments
sklppy88 Feb 15, 2024
a3e738e
Addressing comments
sklppy88 Feb 15, 2024
29e064d
Address comments
sklppy88 Feb 16, 2024
8a0d4bb
Formatting fix
sklppy88 Feb 16, 2024
47580cb
Fix test
sklppy88 Feb 16, 2024
243280f
Merge branch 'ek/fix/align-block-structs-with-yp' into ek/fix/fetch-h…
sklppy88 Feb 16, 2024
1a7cc41
Merge branch 'master' into ek/fix/align-block-structs-with-yp
sklppy88 Feb 16, 2024
62957da
next
sklppy88 Feb 16, 2024
14bbaa5
Merge branch 'master' into ek/fix/align-block-structs-with-yp
sklppy88 Feb 16, 2024
3e8aac3
Address comments
sklppy88 Feb 16, 2024
db9f3ea
Merge remote-tracking branch 'origin/ek/fix/align-block-structs-with-…
sklppy88 Feb 16, 2024
645b8f2
Address comments
sklppy88 Feb 16, 2024
1869a34
Merge branch 'master' into ek/fix/align-block-structs-with-yp
sklppy88 Feb 16, 2024
16cde68
fixing broken tests
sklppy88 Feb 17, 2024
9b211b2
yarn fmt
sklppy88 Feb 17, 2024
0a459a9
Merge branch 'ek/fix/align-block-structs-with-yp' into ek/fix/fetch-h…
sklppy88 Feb 17, 2024
cbb14e2
test
sklppy88 Feb 17, 2024
e5d83bb
Fixing tests
sklppy88 Feb 17, 2024
bc10ec1
Merge branch 'ek/fix/align-block-structs-with-yp' into ek/fix/fetch-h…
sklppy88 Feb 17, 2024
f87e5b3
fix formatting
sklppy88 Feb 17, 2024
8ae3931
asdf
sklppy88 Feb 17, 2024
c1d9e46
Merge branch 'ek/fix/align-block-structs-with-yp' into ek/fix/fetch-h…
sklppy88 Feb 17, 2024
198c068
Merge branch 'master' into ek/fix/align-block-structs-with-yp
sklppy88 Feb 17, 2024
d798290
Address comments
sklppy88 Feb 17, 2024
b64d79b
test
sklppy88 Feb 17, 2024
2e624c9
Merge branch 'ek/fix/align-block-structs-with-yp' into ek/fix/fetch-h…
sklppy88 Feb 17, 2024
56331da
formatting fix
sklppy88 Feb 17, 2024
555e468
yarn fmt
sklppy88 Feb 17, 2024
cc5a1f2
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Feb 22, 2024
72bd82d
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Feb 22, 2024
51b9a4b
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Feb 23, 2024
90ccc41
asdf
sklppy88 Feb 27, 2024
6e47010
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Feb 27, 2024
66f241f
fix
sklppy88 Feb 27, 2024
2b92022
asdf
sklppy88 Feb 27, 2024
1afb545
asdf
sklppy88 Feb 27, 2024
47a6e09
asdf
sklppy88 Feb 27, 2024
1c2b9c8
fix typing
sklppy88 Feb 27, 2024
62393cc
asdf
sklppy88 Feb 27, 2024
4f7573b
sdf
sklppy88 Feb 27, 2024
7cd83de
asdf
sklppy88 Feb 28, 2024
0cb3ad9
yarn fmt and fix
sklppy88 Feb 28, 2024
8d81aa7
working
sklppy88 Feb 28, 2024
6f73e5b
edit
sklppy88 Feb 28, 2024
84bcd01
fix archiver tests
sklppy88 Feb 28, 2024
4be5cf2
add block body add/retrieve test
sklppy88 Feb 28, 2024
bb201ce
yarn fmt
sklppy88 Feb 28, 2024
b694441
fix
sklppy88 Feb 28, 2024
7036dfa
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Feb 28, 2024
fb0bf04
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Feb 28, 2024
e30f97c
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Feb 28, 2024
c196348
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Feb 28, 2024
5fde53a
address comments 1
sklppy88 Feb 28, 2024
a520e8f
Merge remote-tracking branch 'origin/ek/fix/fetch-headers-and-bodies-…
sklppy88 Feb 28, 2024
d283bb3
Addressing commments
sklppy88 Feb 28, 2024
c2bd595
Addressing comments
sklppy88 Feb 28, 2024
a16fd06
address
sklppy88 Feb 28, 2024
7365473
addressing
sklppy88 Feb 28, 2024
97748ba
lint
sklppy88 Feb 28, 2024
c5940a0
comments
sklppy88 Feb 29, 2024
ce9b7b8
Update yarn-project/archiver/src/archiver/archiver_store.ts
sklppy88 Feb 29, 2024
130b3ec
Update yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiv…
sklppy88 Feb 29, 2024
80d7cad
Update yarn-project/archiver/src/archiver/data_retrieval.ts
sklppy88 Feb 29, 2024
c65cc38
Merge remote-tracking branch 'origin/ek/fix/fetch-headers-and-bodies-…
sklppy88 Feb 29, 2024
8f9483a
comments
sklppy88 Feb 29, 2024
997de35
fix
sklppy88 Feb 29, 2024
2534514
more fixes
sklppy88 Feb 29, 2024
89724bd
comments
sklppy88 Feb 29, 2024
db4e687
comments
sklppy88 Feb 29, 2024
8a1b830
asdf
sklppy88 Feb 29, 2024
4f6fbc6
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Feb 29, 2024
2379f7d
fix
sklppy88 Feb 29, 2024
31e4543
yarn fmt
sklppy88 Feb 29, 2024
2c70e95
remove
sklppy88 Feb 29, 2024
ff5bf52
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Feb 29, 2024
733ec31
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Feb 29, 2024
0562ac0
stale comment
sklppy88 Feb 29, 2024
7e1eaeb
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Mar 1, 2024
6ce30f2
Address comments
sklppy88 Mar 1, 2024
ac91763
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Mar 1, 2024
c2712ff
Merge branch 'master' into ek/fix/fetch-headers-and-bodies-separately
sklppy88 Mar 1, 2024
b997964
fix
sklppy88 Mar 1, 2024
bfa273d
Merge remote-tracking branch 'origin/ek/fix/fetch-headers-and-bodies-…
sklppy88 Mar 1, 2024
80e881b
address comments
sklppy88 Mar 1, 2024
3b6f99e
comments
sklppy88 Mar 1, 2024
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
Prev Previous commit
Next Next commit
Addressing commments
sklppy88 committed Feb 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit d283bb30844f2b31d6e3fcd1c78e7aa54dbe542d
28 changes: 14 additions & 14 deletions yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ describe('Archiver', () => {
const rollupAddress = EthAddress.ZERO.toString();
const inboxAddress = EthAddress.ZERO.toString();
const registryAddress = EthAddress.ZERO.toString();
const dataAvailabilityAddress = EthAddress.ZERO.toString();
const availabilityOracleAddress = EthAddress.ZERO.toString();
const contractDeploymentEmitterAddress = '0x0000000000000000000000000000000000000001';
const blockNumbers = [1, 2, 3];
let publicClient: MockProxy<PublicClient<HttpTransport, Chain>>;
@@ -33,7 +33,7 @@ describe('Archiver', () => {
const archiver = new Archiver(
publicClient,
EthAddress.fromString(rollupAddress),
EthAddress.fromString(dataAvailabilityAddress),
EthAddress.fromString(availabilityOracleAddress),
EthAddress.fromString(inboxAddress),
EthAddress.fromString(registryAddress),
EthAddress.fromString(contractDeploymentEmitterAddress),
@@ -52,7 +52,7 @@ describe('Archiver', () => {
return block;
});

const daTxs = blocks.map(makeDaTx);
const aoTxs = blocks.map(makeAoTx);
const rollupTxs = blocks.map(makeRollupTx);

// `L2Block.random(x)` creates some l1 to l2 messages. We add those,
@@ -106,10 +106,10 @@ describe('Archiver', () => {
])
.mockResolvedValueOnce([makeContractDeploymentEvent(2540n, blocks[1])])
.mockResolvedValue([]);
publicClient.getTransaction.mockResolvedValueOnce(daTxs[0]);
publicClient.getTransaction.mockResolvedValueOnce(aoTxs[0]);
publicClient.getTransaction.mockResolvedValueOnce(rollupTxs[0]);

daTxs.slice(1).forEach(tx => publicClient.getTransaction.mockResolvedValueOnce(tx));
aoTxs.slice(1).forEach(tx => publicClient.getTransaction.mockResolvedValueOnce(tx));
rollupTxs.slice(1).forEach(tx => publicClient.getTransaction.mockResolvedValueOnce(tx));

await archiver.start(false);
@@ -158,7 +158,7 @@ describe('Archiver', () => {
const archiver = new Archiver(
publicClient,
EthAddress.fromString(rollupAddress),
EthAddress.fromString(dataAvailabilityAddress),
EthAddress.fromString(availabilityOracleAddress),
EthAddress.fromString(inboxAddress),
EthAddress.fromString(registryAddress),
EthAddress.fromString(contractDeploymentEmitterAddress),
@@ -181,7 +181,7 @@ describe('Archiver', () => {
return block;
});

const daTxs = blocks.map(makeDaTx);
const aoTxs = blocks.map(makeAoTx);
const rollupTxs = blocks.map(makeRollupTx);

// `L2Block.random(x)` creates some l1 to l2 messages. We add those,
@@ -226,7 +226,7 @@ describe('Archiver', () => {
makeL2BlockProcessedEvent(80n, 2n, blocks[1].body.getCalldataHash()),
])
.mockResolvedValue([]);
daTxs.slice(0, numL2BlocksInTest).forEach(tx => publicClient.getTransaction.mockResolvedValueOnce(tx));
aoTxs.slice(0, numL2BlocksInTest).forEach(tx => publicClient.getTransaction.mockResolvedValueOnce(tx));
rollupTxs.slice(0, numL2BlocksInTest).forEach(tx => publicClient.getTransaction.mockResolvedValueOnce(tx));

await archiver.start(false);
@@ -253,7 +253,7 @@ describe('Archiver', () => {
const archiver = new Archiver(
publicClient,
EthAddress.fromString(rollupAddress),
EthAddress.fromString(dataAvailabilityAddress),
EthAddress.fromString(availabilityOracleAddress),
EthAddress.fromString(inboxAddress),
EthAddress.fromString(registryAddress),
EthAddress.fromString(contractDeploymentEmitterAddress),
@@ -269,7 +269,7 @@ describe('Archiver', () => {
const txsHash = block.body.getCalldataHash();
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
block.header.contentCommitment.txsHash = txsHash;
const rollupTx = makeRollupTx(block);
const daTx = makeDaTx(block);
const aoTx = makeAoTx(block);

publicClient.getBlockNumber.mockResolvedValueOnce(2500n);
// logs should be created in order of how archiver syncs.
@@ -284,7 +284,7 @@ describe('Archiver', () => {
.mockResolvedValueOnce([makeL2TxsPublishedEvent(101n, txsHash)])
.mockResolvedValueOnce([makeL2BlockProcessedEvent(101n, 1n, txsHash)])
.mockResolvedValue([]);
publicClient.getTransaction.mockResolvedValueOnce(daTx);
publicClient.getTransaction.mockResolvedValueOnce(aoTx);
publicClient.getTransaction.mockResolvedValueOnce(rollupTx);

await archiver.start(false);
@@ -424,11 +424,11 @@ function makeRollupTx(l2Block: L2Block) {
}

/**
* Makes a fake rollup tx for testing purposes.
* Makes a fake availability oracle tx for testing purposes.
* @param block - The L2Block.
* @returns A fake tx with calldata that corresponds to calling process in the Rollup contract.
* @returns A fake tx with calldata that corresponds to calling process in the Availbility Oracle contract.
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
*/
function makeDaTx(l2Block: L2Block) {
function makeAoTx(l2Block: L2Block) {
const body = toHex(l2Block.body.toBuffer());
const input = encodeFunctionData({
abi: AvailabilityOracleAbi,
8 changes: 4 additions & 4 deletions yarn-project/archiver/src/archiver/archiver.ts
Original file line number Diff line number Diff line change
@@ -38,8 +38,8 @@ import { Chain, HttpTransport, PublicClient, createPublicClient, http } from 'vi
import { ArchiverDataStore } from './archiver_store.js';
import { ArchiverConfig } from './config.js';
import {
retrieveBlockBodiesFromDataAvailability,
retrieveBlockHashesFromRollup,
retrieveBlockBodiesFromAvailabilityOracle,
retrieveBlockMetadataFromRollup,
retrieveNewCancelledL1ToL2Messages,
retrieveNewContractData,
retrieveNewPendingL1ToL2Messages,
@@ -238,7 +238,7 @@ export class Archiver implements ArchiveSource {
// Read all data from chain and then write to our stores at the end
const nextExpectedL2BlockNum = BigInt((await this.store.getBlockNumber()) + 1);

const retrievedBlockBodies = await retrieveBlockBodiesFromDataAvailability(
const retrievedBlockBodies = await retrieveBlockBodiesFromAvailabilityOracle(
this.publicClient,
this.availabilityOracleAddress,
blockUntilSynced,
@@ -250,7 +250,7 @@ export class Archiver implements ArchiveSource {

await this.store.addBlockBodies(blockBodies);

const retrievedBlockMetadata = await retrieveBlockHashesFromRollup(
const retrievedBlockMetadata = await retrieveBlockMetadataFromRollup(
this.publicClient,
this.rollupAddress,
blockUntilSynced,
23 changes: 11 additions & 12 deletions yarn-project/archiver/src/archiver/data_retrieval.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import {
getL2TxsPublishedLogs,
getPendingL1ToL2MessageLogs,
processBlockBodyLogs,
processBlockLogs,
processBlockMetadataLogs,
processCancelledL1ToL2MessagesLogs,
processContractDeploymentLogs,
processPendingL1ToL2MessageAddedLogs,
@@ -32,16 +32,16 @@ export type DataRetrieval<T> = {
};

/**
* Fetches new L2 Blocks.
* Fetches new L2 block metadata (header, archive root).
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
* @param publicClient - The viem public client to use for transaction retrieval.
* @param rollupAddress - The address of the rollup contract.
* @param blockUntilSynced - If true, blocks until the archiver has fully synced.
* @param searchStartBlock - The block number to use for starting the search.
* @param searchEndBlock - The highest block number that we should search up to.
* @param expectedNextL2BlockNum - The next L2 block number that we expect to find.
* @returns An array of L2 Blocks and the next eth block to search from
* @returns An array of tuples representing block metadata including the header, archive tree root, and associated l1 block number; as well as the next eth block to search from
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
*/
export async function retrieveBlockHashesFromRollup(
export async function retrieveBlockMetadataFromRollup(
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
publicClient: PublicClient,
rollupAddress: EthAddress,
blockUntilSynced: boolean,
@@ -64,7 +64,7 @@ export async function retrieveBlockHashesFromRollup(
break;
}

const newBlockMetadata = await processBlockLogs(publicClient, expectedNextL2BlockNum, l2BlockProcessedLogs);
const newBlockMetadata = await processBlockMetadataLogs(publicClient, expectedNextL2BlockNum, l2BlockProcessedLogs);
retrievedBlockMetadata.push(...newBlockMetadata);
searchStartBlock = l2BlockProcessedLogs[l2BlockProcessedLogs.length - 1].blockNumber! + 1n;
expectedNextL2BlockNum += BigInt(newBlockMetadata.length);
@@ -73,18 +73,17 @@ export async function retrieveBlockHashesFromRollup(
}

/**
* Fetches new L2 Blocks.
* Fetches new L2 block bodies and their hashes.
* @param publicClient - The viem public client to use for transaction retrieval.
* @param dataAvailabilityAddress - The address of the rollup contract.
* @param availabilityOracleAddress - The address of the availability oracle contract.
* @param blockUntilSynced - If true, blocks until the archiver has fully synced.
* @param searchStartBlock - The block number to use for starting the search.
* @param searchEndBlock - The highest block number that we should search up to.
* @param expectedNextL2BlockNum - The next L2 block number that we expect to find.
* @returns An array of L2 Blocks and the next eth block to search from
* @returns A array of tuples of L2 block bodies and their associated hash as well as the next eth block to search from
*/
export async function retrieveBlockBodiesFromDataAvailability(
export async function retrieveBlockBodiesFromAvailabilityOracle(
publicClient: PublicClient,
dataAvailabilityAddress: EthAddress,
availabilityOracleAddress: EthAddress,
blockUntilSynced: boolean,
searchStartBlock: bigint,
searchEndBlock: bigint,
@@ -97,7 +96,7 @@ export async function retrieveBlockBodiesFromDataAvailability(
}
const l2TxsPublishedLogs = await getL2TxsPublishedLogs(
publicClient,
dataAvailabilityAddress,
availabilityOracleAddress,
searchStartBlock,
searchEndBlock,
);
26 changes: 11 additions & 15 deletions yarn-project/archiver/src/archiver/eth_log_handlers.ts
Original file line number Diff line number Diff line change
@@ -64,8 +64,9 @@ export function processCancelledL1ToL2MessagesLogs(
* @param publicClient - The viem public client to use for transaction retrieval.
* @param expectedL2BlockNumber - The next expected L2 block number.
* @param logs - L2BlockProcessed logs.
* @returns - An array of tuples representing block metadata including the header, archive tree root, and associated l1 block number
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
*/
export async function processBlockLogs(
export async function processBlockMetadataLogs(
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
publicClient: PublicClient,
expectedL2BlockNumber: bigint,
logs: Log<bigint, number, false, undefined, true, typeof RollupAbi, 'L2BlockProcessed'>[],
@@ -77,7 +78,7 @@ export async function processBlockLogs(
throw new Error('Block number mismatch. Expected: ' + expectedL2BlockNumber + ' but got: ' + blockNum + '.');
}
// TODO: Fetch blocks from calldata in parallel
const [header, archive] = await getBlockHashFromCallData(publicClient, log.transactionHash!, log.args.blockNumber);
const [header, archive] = await getBlockMetadataFromRollupTx(publicClient, log.transactionHash!, log.args.blockNumber);

retrievedBlockMetadata.push([header, archive, log.blockNumber!]);
expectedL2BlockNumber++;
@@ -92,27 +93,23 @@ export async function processBlockBodyLogs(
): Promise<[Body, Buffer][]> {
const retrievedBlockBodies: [Body, Buffer][] = [];
for (const log of logs) {
// // TODO: Fetch blocks from calldata in parallel
const newBlockBody = await getBlockBodiesFromCallData(publicClient, log.transactionHash!);
// newBlock.setL1BlockNumber(log.blockNumber!);
// retrievedBlocks.push(newBlock);
// expectedL2BlockNumber++;
const newBlockBody = await getBlockBodiesFromAvailabilityOracleTx(publicClient, log.transactionHash!);
retrievedBlockBodies.push([newBlockBody, Buffer.from(hexToBytes(log.args.txsHash))]);
}

return retrievedBlockBodies;
}

/**
* Builds an L2 block out of calldata from the tx that published it.
* Gets block metadata (header and archive root) from the calldata of a L1 transaction
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
* Assumes that the block was published from an EOA.
* TODO: Add retries and error management.
* @param publicClient - The viem public client to use for transaction retrieval.
* @param txHash - Hash of the tx that published it.
* @param l2BlockNum - L2 block number.
* @returns An L2 block deserialized from the calldata.
* @returns L2 block metadata (header and archive) from the calldata, deserialized
*/
async function getBlockHashFromCallData(
async function getBlockMetadataFromRollupTx(
publicClient: PublicClient,
txHash: `0x${string}`,
l2BlockNum: bigint,
@@ -147,15 +144,14 @@ async function getBlockHashFromCallData(
}

/**
* Builds an L2 block out of calldata from the tx that published it.
* Gets block bodies from calldata of a L1 transaction, and deserializes them into Body objects
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
* Assumes that the block was published from an EOA.
* TODO: Add retries and error management.
* @param publicClient - The viem public client to use for transaction retrieval.
* @param txHash - Hash of the tx that published it.
* @param l2BlockNum - L2 block number.
* @returns An L2 block deserialized from the calldata.
* @returns An L2 block body from the calldata, deserialized
*/
async function getBlockBodiesFromCallData(publicClient: PublicClient, txHash: `0x${string}`): Promise<Body> {
async function getBlockBodiesFromAvailabilityOracleTx(publicClient: PublicClient, txHash: `0x${string}`): Promise<Body> {
const { input: data } = await publicClient.getTransaction({ hash: txHash });
const { functionName, args } = decodeFunctionData({
abi: AvailabilityOracleAbi,
@@ -204,7 +200,7 @@ export function getL2BlockProcessedLogs(
* @param dataAvailabilityOracleAddress - The address of the availability oracle contract.
* @param fromBlock - First block to get logs from (inclusive).
* @param toBlock - Last block to get logs from (inclusive).
* @returns An array of `L2BlockProcessed` logs.
* @returns An array of `TxsPublished` logs.
*/
export function getL2TxsPublishedLogs(
sklppy88 marked this conversation as resolved.
Show resolved Hide resolved
publicClient: PublicClient,
2 changes: 1 addition & 1 deletion yarn-project/noir-contracts.js/package.json
Original file line number Diff line number Diff line change
@@ -49,4 +49,4 @@
"engines": {
"node": ">=18"
}
}
}
4 changes: 2 additions & 2 deletions yellow-paper/docs/gas-and-fees/fee-payments-and-metering.md
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ The private kernel circuits will output 8 `Gas` values. The 6 `GasLimit`'s repre
| `L2FeeDistributionGas` | The quantity of L2 gas the sequencer can charge for executing the fee distribution function |
| `DAFeeDistributionGas` | The quantity of DA gas the sequencer can charge for publishing state updates and events, which are produced as part of fee distribution |
| `DAAmortizedGasLimit` | The maximum quantity of gas permitted for use in amortized Data Availability operations |
| `DATxGasLimit` | The maximum quantity of DA gas permitted for use in transaction specific Data Availability functions |
| `aoTxGasLimit` | The maximum quantity of DA gas permitted for use in transaction specific Data Availability functions |

By constraining each of these values individually, the transaction sender is protected from a dishonest sequencer allocating an unfairly high amount of gas to one category and leaving insufficient gas for other categories causing a transaction to erroneously be deemed 'out of gas' and a fee taken for improper execution.

@@ -127,7 +127,7 @@ The total fees provided with a transaction can now be derived.
```
L1Fee = (L1AmortizedGasLimit + L1TxGasLimit) * feePerL1Gas
L2Fee = (L2AmortizedGasLimit + L2TxGasLimit + L2FeeDistributionGas) * feePerL2Gas
DAFee = (DAAmortizedGasLimit + DATxGasLimit + DAFeeDistributionGas) * feePerDAGas
DAFee = (DAAmortizedGasLimit + aoTxGasLimit + DAFeeDistributionGas) * feePerDAGas

TotalFee = L1Fee + L2Fee + DAFee
```