-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Handle reorgs in world state synchronizer
- Loading branch information
1 parent
9afd190
commit 1363b84
Showing
36 changed files
with
1,177 additions
and
571 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './mock_l2_block_source.js'; | ||
export * from './mock_l1_to_l2_message_source.js'; | ||
export * from './mock_archiver.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { type L1ToL2MessageSource, type L2Block, type L2BlockSource } from '@aztec/circuit-types'; | ||
import { type Fr } from '@aztec/circuits.js'; | ||
|
||
import { MockL1ToL2MessageSource } from './mock_l1_to_l2_message_source.js'; | ||
import { MockL2BlockSource } from './mock_l2_block_source.js'; | ||
|
||
/** | ||
* A mocked implementation of the archiver that implements L2BlockSource and L1ToL2MessageSource. | ||
*/ | ||
export class MockArchiver extends MockL2BlockSource implements L2BlockSource, L1ToL2MessageSource { | ||
private messageSource = new MockL1ToL2MessageSource(0); | ||
|
||
public setL1ToL2Messages(blockNumber: number, msgs: Fr[]) { | ||
this.messageSource.setL1ToL2Messages(blockNumber, msgs); | ||
} | ||
|
||
getL1ToL2Messages(blockNumber: bigint): Promise<Fr[]> { | ||
return this.messageSource.getL1ToL2Messages(blockNumber); | ||
} | ||
|
||
getL1ToL2MessageIndex(_l1ToL2Message: Fr, _startIndex: bigint): Promise<bigint | undefined> { | ||
return this.messageSource.getL1ToL2MessageIndex(_l1ToL2Message, _startIndex); | ||
} | ||
} | ||
|
||
/** | ||
* A mocked implementation of the archiver with a set of precomputed blocks and messages. | ||
*/ | ||
export class MockPrefilledArchiver extends MockArchiver { | ||
constructor(private precomputed: L2Block[], private messages: Fr[][]) { | ||
super(); | ||
messages.forEach((msgs, i) => this.setL1ToL2Messages(i + 1, msgs)); | ||
} | ||
|
||
public override createBlocks(numBlocks: number) { | ||
if (this.l2Blocks.length + numBlocks > this.precomputed.length) { | ||
throw new Error( | ||
`Not enough precomputed blocks to create ${numBlocks} more blocks (already at ${this.l2Blocks.length})`, | ||
); | ||
} | ||
|
||
const fromBlock = this.l2Blocks.length; | ||
this.addBlocks(this.precomputed.slice(fromBlock, fromBlock + numBlocks)); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
yarn-project/archiver/src/test/mock_l1_to_l2_message_source.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { type L1ToL2MessageSource } from '@aztec/circuit-types'; | ||
import { type Fr } from '@aztec/circuits.js'; | ||
|
||
/** | ||
* A mocked implementation of L1ToL2MessageSource to be used in tests. | ||
*/ | ||
export class MockL1ToL2MessageSource implements L1ToL2MessageSource { | ||
private messagesPerBlock = new Map<number, Fr[]>(); | ||
|
||
constructor(private blockNumber: number) {} | ||
|
||
public setL1ToL2Messages(blockNumber: number, msgs: Fr[]) { | ||
this.messagesPerBlock.set(blockNumber, msgs); | ||
} | ||
|
||
public setBlockNumber(blockNumber: number) { | ||
this.blockNumber = blockNumber; | ||
} | ||
|
||
getL1ToL2Messages(blockNumber: bigint): Promise<Fr[]> { | ||
return Promise.resolve(this.messagesPerBlock.get(Number(blockNumber)) ?? []); | ||
} | ||
|
||
getL1ToL2MessageIndex(_l1ToL2Message: Fr, _startIndex: bigint): Promise<bigint | undefined> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
getBlockNumber(): Promise<number> { | ||
return Promise.resolve(this.blockNumber); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './l2_block_downloader.js'; | ||
export * from './l2_block_stream.js'; |
Oops, something went wrong.