Skip to content

Commit b6551a9

Browse files
authored
refactor: nuking L2Block.fromFields (#8882)
1 parent 84e5e0c commit b6551a9

File tree

5 files changed

+19
-46
lines changed

5 files changed

+19
-46
lines changed

docs/docs/migration_notes.md

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ Aztec is in full-speed development. Literally every version breaks compatibility
88

99
## TBD
1010

11+
### [Aztec.js] Removed `L2Block.fromFields`
12+
`L2Block.fromFields` was a syntactic sugar which is causing [issues](https://github.com/AztecProtocol/aztec-packages/issues/8340) so we've removed it.
13+
14+
```diff
15+
-const l2Block = L2Block.fromFields({ header, archive, body });
16+
+const l2Block = new L2Block(archive, header, body);
17+
```
18+
1119
### [Aztec.nr] Removed `SharedMutablePrivateGetter`
1220

1321
This state variable was deleted due to it being difficult to use safely.

yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class BlockStore {
149149
}
150150
const body = Body.fromBuffer(blockBodyBuffer);
151151

152-
const l2Block = L2Block.fromFields({ header, archive, body });
152+
const l2Block = new L2Block(archive, header, body);
153153
return { data: l2Block, l1: blockStorage.l1 };
154154
}
155155

yarn-project/circuit-types/src/l2_block.ts

+6-29
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,6 @@ export class L2Block {
1919
public body: Body,
2020
) {}
2121

22-
/**
23-
* Constructs a new instance from named fields.
24-
* @param fields - Fields to pass to the constructor.
25-
* @returns A new instance.
26-
*/
27-
static fromFields(fields: {
28-
/** Snapshot of archive tree after the block is applied. */
29-
archive: AppendOnlyTreeSnapshot;
30-
/** L2 block header. */
31-
header: Header;
32-
body: Body;
33-
}) {
34-
return new this(fields.archive, fields.header, fields.body);
35-
}
36-
3722
/**
3823
* Deserializes a block from a buffer
3924
* @returns A deserialized L2 block.
@@ -44,11 +29,7 @@ export class L2Block {
4429
const archive = reader.readObject(AppendOnlyTreeSnapshot);
4530
const body = reader.readObject(Body);
4631

47-
return L2Block.fromFields({
48-
archive,
49-
header,
50-
body,
51-
});
32+
return new L2Block(archive, header, body);
5233
}
5334

5435
/**
@@ -107,23 +88,19 @@ export class L2Block {
10788

10889
const txsEffectsHash = body.getTxsEffectsHash();
10990

110-
return L2Block.fromFields({
111-
archive: makeAppendOnlyTreeSnapshot(l2BlockNum + 1),
112-
header: makeHeader(0, l2BlockNum, slotNumber ?? l2BlockNum, txsEffectsHash, inHash),
91+
return new L2Block(
92+
makeAppendOnlyTreeSnapshot(l2BlockNum + 1),
93+
makeHeader(0, l2BlockNum, slotNumber ?? l2BlockNum, txsEffectsHash, inHash),
11394
body,
114-
});
95+
);
11596
}
11697

11798
/**
11899
* Creates an L2 block containing empty data.
119100
* @returns The L2 block.
120101
*/
121102
static empty(): L2Block {
122-
return L2Block.fromFields({
123-
archive: AppendOnlyTreeSnapshot.zero(),
124-
header: Header.empty(),
125-
body: Body.empty(),
126-
});
103+
return new L2Block(AppendOnlyTreeSnapshot.zero(), Header.empty(), Body.empty());
127104
}
128105

129106
get number(): number {

yarn-project/prover-client/src/orchestrator/orchestrator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ export class ProvingOrchestrator implements EpochProver {
437437

438438
// Assemble the L2 block
439439
const newArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, this.db);
440-
const l2Block = L2Block.fromFields({ archive: newArchive, header, body });
440+
const l2Block = new L2Block(newArchive, header, body);
441441

442442
if (!l2Block.body.getTxsEffectsHash().equals(header.contentCommitment.txsEffectsHash)) {
443443
throw new Error(

yarn-project/pxe/src/synchronizer/synchronizer.test.ts

+3-15
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,9 @@ describe('Synchronizer', () => {
9797
.mockResolvedValueOnce([blocks[1].body.encryptedLogs]);
9898

9999
aztecNode.getBlocks
100-
// called by synchronizer.work, we are testing fromFields in this first call
101-
.mockResolvedValueOnce([
102-
L2Block.fromFields({
103-
archive: blocks[0].archive,
104-
header: blocks[0].header,
105-
body: blocks[0].body,
106-
}),
107-
])
108-
.mockResolvedValueOnce([
109-
L2Block.fromFields({
110-
archive: blocks[1].archive,
111-
header: blocks[1].header,
112-
body: blocks[1].body,
113-
}),
114-
])
100+
// called by synchronizer.work,
101+
.mockResolvedValueOnce([blocks[0]])
102+
.mockResolvedValueOnce([blocks[1]])
115103
// called by synchronizer.workNoteProcessorCatchUp
116104
.mockResolvedValueOnce([blocks[0]])
117105
.mockResolvedValueOnce([blocks[1]]);

0 commit comments

Comments
 (0)