Skip to content

Commit

Permalink
refactor: nuking L2Block.fromFields (#8882)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Sep 30, 2024
1 parent 84e5e0c commit b6551a9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 46 deletions.
8 changes: 8 additions & 0 deletions docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ Aztec is in full-speed development. Literally every version breaks compatibility

## TBD

### [Aztec.js] Removed `L2Block.fromFields`
`L2Block.fromFields` was a syntactic sugar which is causing [issues](https://github.com/AztecProtocol/aztec-packages/issues/8340) so we've removed it.

```diff
-const l2Block = L2Block.fromFields({ header, archive, body });
+const l2Block = new L2Block(archive, header, body);
```

### [Aztec.nr] Removed `SharedMutablePrivateGetter`

This state variable was deleted due to it being difficult to use safely.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class BlockStore {
}
const body = Body.fromBuffer(blockBodyBuffer);

const l2Block = L2Block.fromFields({ header, archive, body });
const l2Block = new L2Block(archive, header, body);
return { data: l2Block, l1: blockStorage.l1 };
}

Expand Down
35 changes: 6 additions & 29 deletions yarn-project/circuit-types/src/l2_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,6 @@ export class L2Block {
public body: Body,
) {}

/**
* Constructs a new instance from named fields.
* @param fields - Fields to pass to the constructor.
* @returns A new instance.
*/
static fromFields(fields: {
/** Snapshot of archive tree after the block is applied. */
archive: AppendOnlyTreeSnapshot;
/** L2 block header. */
header: Header;
body: Body;
}) {
return new this(fields.archive, fields.header, fields.body);
}

/**
* Deserializes a block from a buffer
* @returns A deserialized L2 block.
Expand All @@ -44,11 +29,7 @@ export class L2Block {
const archive = reader.readObject(AppendOnlyTreeSnapshot);
const body = reader.readObject(Body);

return L2Block.fromFields({
archive,
header,
body,
});
return new L2Block(archive, header, body);
}

/**
Expand Down Expand Up @@ -107,23 +88,19 @@ export class L2Block {

const txsEffectsHash = body.getTxsEffectsHash();

return L2Block.fromFields({
archive: makeAppendOnlyTreeSnapshot(l2BlockNum + 1),
header: makeHeader(0, l2BlockNum, slotNumber ?? l2BlockNum, txsEffectsHash, inHash),
return new L2Block(
makeAppendOnlyTreeSnapshot(l2BlockNum + 1),
makeHeader(0, l2BlockNum, slotNumber ?? l2BlockNum, txsEffectsHash, inHash),
body,
});
);
}

/**
* Creates an L2 block containing empty data.
* @returns The L2 block.
*/
static empty(): L2Block {
return L2Block.fromFields({
archive: AppendOnlyTreeSnapshot.zero(),
header: Header.empty(),
body: Body.empty(),
});
return new L2Block(AppendOnlyTreeSnapshot.zero(), Header.empty(), Body.empty());
}

get number(): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export class ProvingOrchestrator implements EpochProver {

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

if (!l2Block.body.getTxsEffectsHash().equals(header.contentCommitment.txsEffectsHash)) {
throw new Error(
Expand Down
18 changes: 3 additions & 15 deletions yarn-project/pxe/src/synchronizer/synchronizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,9 @@ describe('Synchronizer', () => {
.mockResolvedValueOnce([blocks[1].body.encryptedLogs]);

aztecNode.getBlocks
// called by synchronizer.work, we are testing fromFields in this first call
.mockResolvedValueOnce([
L2Block.fromFields({
archive: blocks[0].archive,
header: blocks[0].header,
body: blocks[0].body,
}),
])
.mockResolvedValueOnce([
L2Block.fromFields({
archive: blocks[1].archive,
header: blocks[1].header,
body: blocks[1].body,
}),
])
// called by synchronizer.work,
.mockResolvedValueOnce([blocks[0]])
.mockResolvedValueOnce([blocks[1]])
// called by synchronizer.workNoteProcessorCatchUp
.mockResolvedValueOnce([blocks[0]])
.mockResolvedValueOnce([blocks[1]]);
Expand Down

0 comments on commit b6551a9

Please sign in to comment.