Skip to content

Commit

Permalink
chore: Use batch p2p reqresp for requesting txs in prover node (#11741)
Browse files Browse the repository at this point in the history
Adds a `getTxsByHash` (plural) method to the prover-coordination
interface, implemented by node and p2pclient. In p2p client, uses the
batch reqresp protocol to request txs. Since that already handles
retries and timeouts, the retry mechanism is removed from the prover
node itself.

Once we review node interfaces, we should probably remove `getTxByHash`
(singular) altogether in favor of the plural, and make aztec-node no
longer extend prover-coordination since we are no longer using it for
that purpose.
  • Loading branch information
spalladino authored Feb 5, 2025
1 parent e8cfed7 commit df9e4ec
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 214 deletions.
10 changes: 10 additions & 0 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { computePublicDataTreeLeafSlot, siloNullifier } from '@aztec/circuits.js
import { EpochCache } from '@aztec/epoch-cache';
import { type L1ContractAddresses, createEthereumChain } from '@aztec/ethereum';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { compactArray } from '@aztec/foundation/collection';
import { type Logger, createLogger } from '@aztec/foundation/log';
import { DateProvider, Timer } from '@aztec/foundation/timer';
import { type AztecKVStore } from '@aztec/kv-store';
Expand Down Expand Up @@ -500,6 +501,15 @@ export class AztecNodeService implements AztecNode, Traceable {
return Promise.resolve(this.p2pClient!.getTxByHashFromPool(txHash));
}

/**
* Method to retrieve txs from the mempool or unfinalised chain.
* @param txHash - The transaction hash to return.
* @returns - The txs if it exists.
*/
public async getTxsByHash(txHashes: TxHash[]) {
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
}

/**
* Find the indexes of the given leaves in the given tree.
* @param blockNumber - The block number at which to get the data or 'latest' for latest data
Expand Down
9 changes: 9 additions & 0 deletions yarn-project/circuit-types/src/interfaces/aztec-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ describe('AztecNodeApiSchema', () => {
expect(response).toBeInstanceOf(Tx);
});

it('getTxsByHash', async () => {
const response = await context.client.getTxsByHash([TxHash.random()]);
expect(response[0]).toBeInstanceOf(Tx);
});

it('getPublicStorageAt', async () => {
const response = await context.client.getPublicStorageAt(await AztecAddress.random(), Fr.random(), 1);
expect(response).toBeInstanceOf(Fr);
Expand Down Expand Up @@ -559,6 +564,10 @@ class MockAztecNode implements AztecNode {
expect(txHash).toBeInstanceOf(TxHash);
return Promise.resolve(Tx.random());
}
async getTxsByHash(txHashes: TxHash[]): Promise<Tx[]> {
expect(txHashes[0]).toBeInstanceOf(TxHash);
return [await Tx.random()];
}
getPublicStorageAt(contract: AztecAddress, slot: Fr, _blockNumber: number | 'latest'): Promise<Fr> {
expect(contract).toBeInstanceOf(AztecAddress);
expect(slot).toBeInstanceOf(Fr);
Expand Down
14 changes: 11 additions & 3 deletions yarn-project/circuit-types/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { type SequencerConfig, SequencerConfigSchema } from './configs.js';
import { type L2BlockNumber, L2BlockNumberSchema } from './l2_block_number.js';
import { NullifierMembershipWitness } from './nullifier_membership_witness.js';
import { type ProverConfig, ProverConfigSchema } from './prover-client.js';
import { type ProverCoordination, ProverCoordinationApiSchema } from './prover-coordination.js';
import { type ProverCoordination } from './prover-coordination.js';

/**
* The aztec node.
Expand Down Expand Up @@ -371,6 +371,13 @@ export interface AztecNode
*/
getTxByHash(txHash: TxHash): Promise<Tx | undefined>;

/**
* Method to retrieve multiple pending txs.
* @param txHash - The transaction hashes to return.
* @returns The pending txs if exist.
*/
getTxsByHash(txHashes: TxHash[]): Promise<Tx[]>;

/**
* Gets the storage value at the given contract storage slot.
*
Expand Down Expand Up @@ -453,9 +460,8 @@ export interface AztecNode
}

export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {
...ProverCoordinationApiSchema,

getL2Tips: z.function().args().returns(L2TipsSchema),

findLeavesIndexes: z
.function()
.args(L2BlockNumberSchema, z.nativeEnum(MerkleTreeId), z.array(schemas.Fr))
Expand Down Expand Up @@ -567,6 +573,8 @@ export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {

getTxByHash: z.function().args(TxHash.schema).returns(Tx.schema.optional()),

getTxsByHash: z.function().args(z.array(TxHash.schema)).returns(z.array(Tx.schema)),

getPublicStorageAt: z.function().args(schemas.AztecAddress, schemas.Fr, L2BlockNumberSchema).returns(schemas.Fr),

getBlockHeader: z.function().args(optional(L2BlockNumberSchema)).returns(BlockHeader.schema),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export interface ProverCoordination {
*/
getTxByHash(txHash: TxHash): Promise<Tx | undefined>;

/**
* Returns a set of transactions given their hashes if available.
* @param txHashes - The hashes of the transactions, used as an ID.
* @returns The transactions, if found, 'undefined' otherwise.
*/
getTxsByHash(txHashes: TxHash[]): Promise<Tx[]>;

/**
* Receives a quote for an epoch proof and stores it in its EpochProofQuotePool
* @param quote - The quote to store
Expand All @@ -24,5 +31,6 @@ export interface ProverCoordination {

export const ProverCoordinationApiSchema: ApiSchemaFor<ProverCoordination> = {
getTxByHash: z.function().args(TxHash.schema).returns(Tx.schema.optional()),
getTxsByHash: z.function().args(z.array(TxHash.schema)).returns(z.array(Tx.schema)),
addEpochProofQuote: z.function().args(EpochProofQuote.schema).returns(z.void()),
};
1 change: 1 addition & 0 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ export async function createAndSyncProverNode(
const aztecNodeWithoutStop = {
addEpochProofQuote: aztecNode.addEpochProofQuote.bind(aztecNode),
getTxByHash: aztecNode.getTxByHash.bind(aztecNode),
getTxsByHash: aztecNode.getTxsByHash.bind(aztecNode),
stop: () => Promise.resolve(),
};

Expand Down
Loading

0 comments on commit df9e4ec

Please sign in to comment.