@aztec/p2p 0.56.0 → 0.57.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dest/attestation_pool/attestation_pool.d.ts +2 -1
  2. package/dest/attestation_pool/attestation_pool.d.ts.map +1 -1
  3. package/dest/attestation_pool/memory_attestation_pool.d.ts +2 -1
  4. package/dest/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
  5. package/dest/attestation_pool/memory_attestation_pool.js +42 -10
  6. package/dest/attestation_pool/mocks.d.ts +2 -1
  7. package/dest/attestation_pool/mocks.d.ts.map +1 -1
  8. package/dest/attestation_pool/mocks.js +2 -3
  9. package/dest/client/index.d.ts +4 -1
  10. package/dest/client/index.d.ts.map +1 -1
  11. package/dest/client/index.js +7 -3
  12. package/dest/client/p2p_client.d.ts +25 -6
  13. package/dest/client/p2p_client.d.ts.map +1 -1
  14. package/dest/client/p2p_client.js +28 -13
  15. package/dest/epoch_proof_quote_pool/epoch_proof_quote_pool.d.ts +7 -0
  16. package/dest/epoch_proof_quote_pool/epoch_proof_quote_pool.d.ts.map +1 -0
  17. package/dest/epoch_proof_quote_pool/epoch_proof_quote_pool.js +2 -0
  18. package/dest/epoch_proof_quote_pool/index.d.ts +4 -0
  19. package/dest/epoch_proof_quote_pool/index.d.ts.map +1 -0
  20. package/dest/epoch_proof_quote_pool/index.js +4 -0
  21. package/dest/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.d.ts +10 -0
  22. package/dest/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.d.ts.map +1 -0
  23. package/dest/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.js +22 -0
  24. package/dest/epoch_proof_quote_pool/test_utils.d.ts +8 -0
  25. package/dest/epoch_proof_quote_pool/test_utils.d.ts.map +1 -0
  26. package/dest/epoch_proof_quote_pool/test_utils.js +21 -0
  27. package/dest/index.d.ts +4 -3
  28. package/dest/index.d.ts.map +1 -1
  29. package/dest/index.js +5 -4
  30. package/dest/service/libp2p_service.js +3 -3
  31. package/dest/service/reqresp/reqresp.d.ts +0 -1
  32. package/dest/service/reqresp/reqresp.d.ts.map +1 -1
  33. package/dest/service/reqresp/reqresp.js +7 -4
  34. package/package.json +10 -6
  35. package/src/attestation_pool/attestation_pool.ts +2 -1
  36. package/src/attestation_pool/memory_attestation_pool.ts +50 -12
  37. package/src/attestation_pool/mocks.ts +5 -2
  38. package/src/client/index.ts +20 -3
  39. package/src/client/p2p_client.ts +46 -13
  40. package/src/epoch_proof_quote_pool/epoch_proof_quote_pool.ts +7 -0
  41. package/src/epoch_proof_quote_pool/index.ts +3 -0
  42. package/src/epoch_proof_quote_pool/memory_epoch_proof_quote_pool.ts +26 -0
  43. package/src/epoch_proof_quote_pool/test_utils.ts +26 -0
  44. package/src/index.ts +4 -3
  45. package/src/service/libp2p_service.ts +2 -2
  46. package/src/service/reqresp/reqresp.ts +9 -5
  47. package/dest/client/mocks.d.ts +0 -65
  48. package/dest/client/mocks.d.ts.map +0 -1
  49. package/dest/client/mocks.js +0 -106
  50. package/src/client/mocks.ts +0 -129
@@ -0,0 +1,26 @@
1
+ import { type EpochProofQuote } from '@aztec/circuit-types';
2
+
3
+ import { type EpochProofQuotePool } from './epoch_proof_quote_pool.js';
4
+
5
+ export class MemoryEpochProofQuotePool implements EpochProofQuotePool {
6
+ private quotes: Map<bigint, EpochProofQuote[]>;
7
+ constructor() {
8
+ this.quotes = new Map();
9
+ }
10
+ addQuote(quote: EpochProofQuote) {
11
+ const epoch = quote.payload.epochToProve;
12
+ if (!this.quotes.has(epoch)) {
13
+ this.quotes.set(epoch, []);
14
+ }
15
+ this.quotes.get(epoch)!.push(quote);
16
+ }
17
+ getQuotes(epoch: bigint): EpochProofQuote[] {
18
+ return this.quotes.get(epoch) || [];
19
+ }
20
+ deleteQuotesToEpoch(epoch: bigint): void {
21
+ const expiredEpochs = Array.from(this.quotes.keys()).filter(k => k <= epoch);
22
+ for (const expiredEpoch of expiredEpochs) {
23
+ this.quotes.delete(expiredEpoch);
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,26 @@
1
+ import { EpochProofQuote, EpochProofQuotePayload } from '@aztec/circuit-types';
2
+ import { EthAddress } from '@aztec/circuits.js';
3
+ import { Buffer32 } from '@aztec/foundation/buffer';
4
+ import { Secp256k1Signer, randomBigInt, randomInt } from '@aztec/foundation/crypto';
5
+
6
+ export function makeRandomEpochProofQuotePayload(): EpochProofQuotePayload {
7
+ return EpochProofQuotePayload.from({
8
+ basisPointFee: randomInt(10000),
9
+ bondAmount: 1000000000000000000n,
10
+ epochToProve: randomBigInt(1000000n),
11
+ prover: EthAddress.random(),
12
+ validUntilSlot: randomBigInt(1000000n),
13
+ });
14
+ }
15
+
16
+ export function makeRandomEpochProofQuote(payload?: EpochProofQuotePayload): {
17
+ quote: EpochProofQuote;
18
+ signer: Secp256k1Signer;
19
+ } {
20
+ const signer = Secp256k1Signer.random();
21
+
22
+ return {
23
+ quote: EpochProofQuote.new(Buffer32.random(), payload ?? makeRandomEpochProofQuotePayload(), signer),
24
+ signer,
25
+ };
26
+ }
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
+ export * from './attestation_pool/index.js';
2
+ export * from './bootstrap/bootstrap.js';
1
3
  export * from './client/index.js';
2
4
  export * from './config.js';
3
- export * from './tx_pool/index.js';
4
- export * from './attestation_pool/index.js';
5
+ export * from './epoch_proof_quote_pool/index.js';
5
6
  export * from './service/index.js';
6
- export * from './bootstrap/bootstrap.js';
7
+ export * from './tx_pool/index.js';
7
8
  export * from './tx_validator/index.js';
@@ -182,12 +182,12 @@ export class LibP2PService implements P2PService {
182
182
  await this.discoveryRunningPromise?.stop();
183
183
  this.logger.debug('Stopping peer discovery service...');
184
184
  await this.peerDiscoveryService.stop();
185
+ this.logger.debug('Request response service stopped...');
186
+ await this.reqresp.stop();
185
187
  this.logger.debug('Stopping LibP2P...');
186
188
  await this.stopLibP2P();
187
189
  this.logger.info('LibP2P service stopped');
188
190
  this.logger.debug('Stopping request response service...');
189
- await this.reqresp.stop();
190
- this.logger.debug('Request response service stopped...');
191
191
  }
192
192
 
193
193
  /**
@@ -36,8 +36,6 @@ import { RequestResponseRateLimiter } from './rate_limiter/rate_limiter.js';
36
36
  export class ReqResp {
37
37
  protected readonly logger: Logger;
38
38
 
39
- private abortController: AbortController = new AbortController();
40
-
41
39
  private overallRequestTimeoutMs: number;
42
40
  private individualRequestTimeoutMs: number;
43
41
 
@@ -78,9 +76,16 @@ export class ReqResp {
78
76
  for (const protocol of Object.keys(this.subProtocolHandlers)) {
79
77
  await this.libp2p.unhandle(protocol);
80
78
  }
79
+
80
+ // Close all active connections
81
+ const closeStreamPromises = this.libp2p.getConnections().map(connection => connection.close());
82
+ await Promise.all(closeStreamPromises);
83
+ this.logger.debug('ReqResp: All active streams closed');
84
+
81
85
  this.rateLimiter.stop();
82
- await this.libp2p.stop();
83
- this.abortController.abort();
86
+ this.logger.debug('ReqResp: Rate limiter stopped');
87
+
88
+ // NOTE: We assume libp2p instance is managed by the caller
84
89
  }
85
90
 
86
91
  /**
@@ -187,7 +192,6 @@ export class ReqResp {
187
192
  let stream: Stream | undefined;
188
193
  try {
189
194
  stream = await this.libp2p.dialProtocol(peerId, subProtocol);
190
-
191
195
  this.logger.debug(`Stream opened with ${peerId.toString()} for ${subProtocol}`);
192
196
 
193
197
  // Open the stream with a timeout
@@ -1,65 +0,0 @@
1
- import { L2Block, type L2BlockSource, type TxEffect, type TxHash, TxReceipt } from '@aztec/circuit-types';
2
- import { EthAddress } from '@aztec/circuits.js';
3
- /**
4
- * A mocked implementation of L2BlockSource to be used in p2p tests.
5
- */
6
- export declare class MockBlockSource implements L2BlockSource {
7
- private provenBlockNumber?;
8
- private l2Blocks;
9
- private txEffects;
10
- constructor(numBlocks?: number, provenBlockNumber?: number | undefined);
11
- addBlocks(numBlocks: number): void;
12
- setProvenBlockNumber(provenBlockNumber: number): void;
13
- /**
14
- * Method to fetch the rollup contract address at the base-layer.
15
- * @returns The rollup address.
16
- */
17
- getRollupAddress(): Promise<EthAddress>;
18
- /**
19
- * Method to fetch the registry contract address at the base-layer.
20
- * @returns The registry address.
21
- */
22
- getRegistryAddress(): Promise<EthAddress>;
23
- /**
24
- * Gets the number of the latest L2 block processed by the block source implementation.
25
- * @returns In this mock instance, returns the number of L2 blocks that we've mocked.
26
- */
27
- getBlockNumber(): Promise<number>;
28
- getProvenBlockNumber(): Promise<number>;
29
- /**
30
- * Gets an l2 block.
31
- * @param number - The block number to return (inclusive).
32
- * @returns The requested L2 block.
33
- */
34
- getBlock(number: number): Promise<L2Block>;
35
- /**
36
- * Gets up to `limit` amount of L2 blocks starting from `from`.
37
- * @param from - Number of the first block to return (inclusive).
38
- * @param limit - The maximum number of blocks to return.
39
- * @returns The requested mocked L2 blocks.
40
- */
41
- getBlocks(from: number, limit: number, proven?: boolean): Promise<L2Block[]>;
42
- /**
43
- * Gets a tx effect.
44
- * @param txHash - The hash of a transaction which resulted in the returned tx effect.
45
- * @returns The requested tx effect.
46
- */
47
- getTxEffect(txHash: TxHash): Promise<TxEffect | undefined>;
48
- /**
49
- * Gets a receipt of a settled tx.
50
- * @param txHash - The hash of a tx we try to get the receipt for.
51
- * @returns The requested tx receipt (or undefined if not found).
52
- */
53
- getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined>;
54
- /**
55
- * Starts the block source. In this mock implementation, this is a noop.
56
- * @returns A promise that signals the initialization of the l2 block source on completion.
57
- */
58
- start(): Promise<void>;
59
- /**
60
- * Stops the block source. In this mock implementation, this is a noop.
61
- * @returns A promise that signals the l2 block source is now stopped.
62
- */
63
- stop(): Promise<void>;
64
- }
65
- //# sourceMappingURL=mocks.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../../src/client/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,SAAS,EAAY,MAAM,sBAAsB,CAAC;AACpH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;GAEG;AACH,qBAAa,eAAgB,YAAW,aAAa;IAItB,OAAO,CAAC,iBAAiB,CAAC;IAHvD,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,SAAS,CAAkB;gBAEvB,SAAS,SAAM,EAAU,iBAAiB,CAAC,oBAAQ;IAIxD,SAAS,CAAC,SAAS,EAAE,MAAM;IAS3B,oBAAoB,CAAC,iBAAiB,EAAE,MAAM;IAIrD;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC,UAAU,CAAC;IAIvC;;;OAGG;IACH,kBAAkB,IAAI,OAAO,CAAC,UAAU,CAAC;IAIzC;;;OAGG;IACI,cAAc;IAIR,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIpD;;;;OAIG;IACI,QAAQ,CAAC,MAAM,EAAE,MAAM;IAI9B;;;;;OAKG;IACI,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO;IAQ9D;;;;OAIG;IACI,WAAW,CAAC,MAAM,EAAE,MAAM;IAKjC;;;;OAIG;IACI,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAoB1E;;;OAGG;IACI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B;;;OAGG;IACI,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
@@ -1,106 +0,0 @@
1
- import { L2Block, TxReceipt, TxStatus } from '@aztec/circuit-types';
2
- import { EthAddress } from '@aztec/circuits.js';
3
- /**
4
- * A mocked implementation of L2BlockSource to be used in p2p tests.
5
- */
6
- export class MockBlockSource {
7
- constructor(numBlocks = 100, provenBlockNumber) {
8
- this.provenBlockNumber = provenBlockNumber;
9
- this.l2Blocks = [];
10
- this.txEffects = [];
11
- this.addBlocks(numBlocks);
12
- }
13
- addBlocks(numBlocks) {
14
- for (let i = 0; i < numBlocks; i++) {
15
- const blockNum = this.l2Blocks.length;
16
- const block = L2Block.random(blockNum, blockNum);
17
- this.l2Blocks.push(block);
18
- this.txEffects.push(...block.body.txEffects);
19
- }
20
- }
21
- setProvenBlockNumber(provenBlockNumber) {
22
- this.provenBlockNumber = provenBlockNumber;
23
- }
24
- /**
25
- * Method to fetch the rollup contract address at the base-layer.
26
- * @returns The rollup address.
27
- */
28
- getRollupAddress() {
29
- return Promise.resolve(EthAddress.random());
30
- }
31
- /**
32
- * Method to fetch the registry contract address at the base-layer.
33
- * @returns The registry address.
34
- */
35
- getRegistryAddress() {
36
- return Promise.resolve(EthAddress.random());
37
- }
38
- /**
39
- * Gets the number of the latest L2 block processed by the block source implementation.
40
- * @returns In this mock instance, returns the number of L2 blocks that we've mocked.
41
- */
42
- getBlockNumber() {
43
- return Promise.resolve(this.l2Blocks.length - 1);
44
- }
45
- async getProvenBlockNumber() {
46
- return this.provenBlockNumber ?? (await this.getBlockNumber());
47
- }
48
- /**
49
- * Gets an l2 block.
50
- * @param number - The block number to return (inclusive).
51
- * @returns The requested L2 block.
52
- */
53
- getBlock(number) {
54
- return Promise.resolve(this.l2Blocks[number]);
55
- }
56
- /**
57
- * Gets up to `limit` amount of L2 blocks starting from `from`.
58
- * @param from - Number of the first block to return (inclusive).
59
- * @param limit - The maximum number of blocks to return.
60
- * @returns The requested mocked L2 blocks.
61
- */
62
- getBlocks(from, limit, proven) {
63
- return Promise.resolve(this.l2Blocks
64
- .slice(from, from + limit)
65
- .filter(b => !proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber));
66
- }
67
- /**
68
- * Gets a tx effect.
69
- * @param txHash - The hash of a transaction which resulted in the returned tx effect.
70
- * @returns The requested tx effect.
71
- */
72
- getTxEffect(txHash) {
73
- const txEffect = this.txEffects.find(tx => tx.txHash.equals(txHash));
74
- return Promise.resolve(txEffect);
75
- }
76
- /**
77
- * Gets a receipt of a settled tx.
78
- * @param txHash - The hash of a tx we try to get the receipt for.
79
- * @returns The requested tx receipt (or undefined if not found).
80
- */
81
- getSettledTxReceipt(txHash) {
82
- for (const block of this.l2Blocks) {
83
- for (const txEffect of block.body.txEffects) {
84
- if (txEffect.txHash.equals(txHash)) {
85
- return Promise.resolve(new TxReceipt(txHash, TxStatus.SUCCESS, '', txEffect.transactionFee.toBigInt(), block.hash().toBuffer(), block.number));
86
- }
87
- }
88
- }
89
- return Promise.resolve(undefined);
90
- }
91
- /**
92
- * Starts the block source. In this mock implementation, this is a noop.
93
- * @returns A promise that signals the initialization of the l2 block source on completion.
94
- */
95
- start() {
96
- return Promise.resolve();
97
- }
98
- /**
99
- * Stops the block source. In this mock implementation, this is a noop.
100
- * @returns A promise that signals the l2 block source is now stopped.
101
- */
102
- stop() {
103
- return Promise.resolve();
104
- }
105
- }
106
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9ja3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY2xpZW50L21vY2tzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxPQUFPLEVBQWtELFNBQVMsRUFBRSxRQUFRLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUNwSCxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFFaEQ7O0dBRUc7QUFDSCxNQUFNLE9BQU8sZUFBZTtJQUkxQixZQUFZLFNBQVMsR0FBRyxHQUFHLEVBQVUsaUJBQTBCO1FBQTFCLHNCQUFpQixHQUFqQixpQkFBaUIsQ0FBUztRQUh2RCxhQUFRLEdBQWMsRUFBRSxDQUFDO1FBQ3pCLGNBQVMsR0FBZSxFQUFFLENBQUM7UUFHakMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxTQUFTLENBQUMsQ0FBQztJQUM1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SxRQUFRLElBQUksS0FBSyxDQUFDLElBQUksQ0FBQyxTQUFTLEVBQUUsQ0FBQztnQkFDNUMsSUFBSSxRQUFRLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxNQUFNLENBQUMsRUFBRSxDQUFDO29CQUNuQyxPQUFPLE9BQU8sQ0FBQyxPQUFPLENBQ3BCLElBQUksU0FBUyxDQUNYLE1BQU0sRUFDTixRQUFRLENBQUMsT0FBTyxFQUNoQixFQUFFLEVBQ0YsUUFBUSxDQUFDLGNBQWMsQ0FBQyxRQUFRLEVBQUUsRUFDbEMsS0FBSyxDQUFDLElBQUksRUFBRSxDQUFDLFFBQVEsRUFBRSxFQUN2QixLQUFLLENBQUMsTUFBTSxDQUNiLENBQ0YsQ0FBQztnQkFDSixDQUFDO1lBQ0gsQ0FBQztRQUNILENBQUM7UUFDRCxPQUFPLE9BQU8sQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7SUFDcEMsQ0FBQztJQUVEOzs7T0FHRztJQUNJLEtBQUs7UUFDVixPQUFPLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQztJQUMzQixDQUFDO0lBRUQ7OztPQUdHO0lBQ0ksSUFBSTtRQUNULE9BQU8sT0FBTyxDQUFDLE9BQU8sRUFBRSxDQUFDO0lBQzNCLENBQUM7Q0FDRiJ9
@@ -1,129 +0,0 @@
1
- import { L2Block, type L2BlockSource, type TxEffect, type TxHash, TxReceipt, TxStatus } from '@aztec/circuit-types';
2
- import { EthAddress } from '@aztec/circuits.js';
3
-
4
- /**
5
- * A mocked implementation of L2BlockSource to be used in p2p tests.
6
- */
7
- export class MockBlockSource implements L2BlockSource {
8
- private l2Blocks: L2Block[] = [];
9
- private txEffects: TxEffect[] = [];
10
-
11
- constructor(numBlocks = 100, private provenBlockNumber?: number) {
12
- this.addBlocks(numBlocks);
13
- }
14
-
15
- public addBlocks(numBlocks: number) {
16
- for (let i = 0; i < numBlocks; i++) {
17
- const blockNum = this.l2Blocks.length;
18
- const block = L2Block.random(blockNum, blockNum);
19
- this.l2Blocks.push(block);
20
- this.txEffects.push(...block.body.txEffects);
21
- }
22
- }
23
-
24
- public setProvenBlockNumber(provenBlockNumber: number) {
25
- this.provenBlockNumber = provenBlockNumber;
26
- }
27
-
28
- /**
29
- * Method to fetch the rollup contract address at the base-layer.
30
- * @returns The rollup address.
31
- */
32
- getRollupAddress(): Promise<EthAddress> {
33
- return Promise.resolve(EthAddress.random());
34
- }
35
-
36
- /**
37
- * Method to fetch the registry contract address at the base-layer.
38
- * @returns The registry address.
39
- */
40
- getRegistryAddress(): Promise<EthAddress> {
41
- return Promise.resolve(EthAddress.random());
42
- }
43
-
44
- /**
45
- * Gets the number of the latest L2 block processed by the block source implementation.
46
- * @returns In this mock instance, returns the number of L2 blocks that we've mocked.
47
- */
48
- public getBlockNumber() {
49
- return Promise.resolve(this.l2Blocks.length - 1);
50
- }
51
-
52
- public async getProvenBlockNumber(): Promise<number> {
53
- return this.provenBlockNumber ?? (await this.getBlockNumber());
54
- }
55
-
56
- /**
57
- * Gets an l2 block.
58
- * @param number - The block number to return (inclusive).
59
- * @returns The requested L2 block.
60
- */
61
- public getBlock(number: number) {
62
- return Promise.resolve(this.l2Blocks[number]);
63
- }
64
-
65
- /**
66
- * Gets up to `limit` amount of L2 blocks starting from `from`.
67
- * @param from - Number of the first block to return (inclusive).
68
- * @param limit - The maximum number of blocks to return.
69
- * @returns The requested mocked L2 blocks.
70
- */
71
- public getBlocks(from: number, limit: number, proven?: boolean) {
72
- return Promise.resolve(
73
- this.l2Blocks
74
- .slice(from, from + limit)
75
- .filter(b => !proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber),
76
- );
77
- }
78
-
79
- /**
80
- * Gets a tx effect.
81
- * @param txHash - The hash of a transaction which resulted in the returned tx effect.
82
- * @returns The requested tx effect.
83
- */
84
- public getTxEffect(txHash: TxHash) {
85
- const txEffect = this.txEffects.find(tx => tx.txHash.equals(txHash));
86
- return Promise.resolve(txEffect);
87
- }
88
-
89
- /**
90
- * Gets a receipt of a settled tx.
91
- * @param txHash - The hash of a tx we try to get the receipt for.
92
- * @returns The requested tx receipt (or undefined if not found).
93
- */
94
- public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
95
- for (const block of this.l2Blocks) {
96
- for (const txEffect of block.body.txEffects) {
97
- if (txEffect.txHash.equals(txHash)) {
98
- return Promise.resolve(
99
- new TxReceipt(
100
- txHash,
101
- TxStatus.SUCCESS,
102
- '',
103
- txEffect.transactionFee.toBigInt(),
104
- block.hash().toBuffer(),
105
- block.number,
106
- ),
107
- );
108
- }
109
- }
110
- }
111
- return Promise.resolve(undefined);
112
- }
113
-
114
- /**
115
- * Starts the block source. In this mock implementation, this is a noop.
116
- * @returns A promise that signals the initialization of the l2 block source on completion.
117
- */
118
- public start(): Promise<void> {
119
- return Promise.resolve();
120
- }
121
-
122
- /**
123
- * Stops the block source. In this mock implementation, this is a noop.
124
- * @returns A promise that signals the l2 block source is now stopped.
125
- */
126
- public stop(): Promise<void> {
127
- return Promise.resolve();
128
- }
129
- }