Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ pub contract Benchmarking {
fn broadcast(owner: AztecAddress) {
context.emit_public_log(storage.balances.at(owner).read());
}

// Does a bunch of heavy compute
#[public]
fn sha256_hash_2048(data: [u8; 2048]) -> [u8; 32] {
std::hash::sha256(data)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is ok if you want just any heavy compute, but looks like Tom has been migrating things: #11696 to another sha?

}
}
9 changes: 8 additions & 1 deletion yarn-project/end-to-end/src/bench/bench_build_block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ describe('benchmarks/build_block', () => {
});

const TX_COUNT = 32;
it(`builds a block with ${TX_COUNT} txs`, async () => {
it(`builds a block with ${TX_COUNT} standard txs`, async () => {
await sequencer.updateSequencerConfig({ minTxsPerBlock: TX_COUNT });
const sentTxs = await sendTxs(TX_COUNT, context, contract);
await waitTxs(sentTxs, context);
});

const TX_COUNT_HEAVY_COMPUTE = 8;
it(`builds a block with ${TX_COUNT_HEAVY_COMPUTE} compute-heavy txs`, async () => {
await sequencer.updateSequencerConfig({ minTxsPerBlock: TX_COUNT_HEAVY_COMPUTE });
const sentTxs = await sendTxs(TX_COUNT_HEAVY_COMPUTE, context, contract, /*heavyPublicComput=*/ true);
await waitTxs(sentTxs, context);
});
});
30 changes: 24 additions & 6 deletions yarn-project/end-to-end/src/bench/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,27 @@ export function getFolderSize(path: string): number {
* @param index - Index of the call within a block.
* @param context - End to end context.
* @param contract - Benchmarking contract.
* @param heavyPublicCompute - Whether the transactions include heavy public compute (like a big sha256).
* @returns A BatchCall instance.
*/
export async function makeCall(index: number, context: EndToEndContext, contract: BenchmarkingContract) {
export async function makeCall(
index: number,
context: EndToEndContext,
contract: BenchmarkingContract,
heavyPublicCompute: boolean,
) {
const owner = context.wallet.getAddress();
const sender = owner;
return new BatchCall(context.wallet, [
await contract.methods.create_note(owner, sender, index + 1).request(),
await contract.methods.increment_balance(owner, index + 1).request(),
]);
if (heavyPublicCompute) {
return new BatchCall(context.wallet, [
await contract.methods.sha256_hash_2048(randomBytesAsBigInts(2048)).request(),
]);
} else {
return new BatchCall(context.wallet, [
await contract.methods.create_note(owner, sender, index + 1).request(),
await contract.methods.increment_balance(owner, index + 1).request(),
]);
}
}

/**
Expand All @@ -144,14 +156,16 @@ export async function makeCall(index: number, context: EndToEndContext, contract
* @param txCount - How many txs to send
* @param context - End to end context.
* @param contract - Target contract.
* @param heavyPublicCompute - Whether the transactions include heavy public compute (like a big sha256).
* @returns Array of sent txs.
*/
export async function sendTxs(
txCount: number,
context: EndToEndContext,
contract: BenchmarkingContract,
heavyPublicCompute: boolean = false,
): Promise<SentTx[]> {
const calls = await timesParallel(txCount, index => makeCall(index, context, contract));
const calls = await timesParallel(txCount, index => makeCall(index, context, contract, heavyPublicCompute));
context.logger.info(`Creating ${txCount} txs`);
const provenTxs = await Promise.all(calls.map(call => call.prove({ skipPublicSimulation: true })));
context.logger.info(`Sending ${txCount} txs`);
Expand Down Expand Up @@ -191,3 +205,7 @@ export async function createNewPXE(
await pxe.registerContract(contract);
return pxe;
}

function randomBytesAsBigInts(length: number): bigint[] {
return [...Array(length)].map(_ => BigInt(Math.floor(Math.random() * 255)));
}