Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: reverting accidental changes #5371

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 14 additions & 47 deletions yarn-project/circuit-types/src/l2_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,29 @@ import { makeAppendOnlyTreeSnapshot, makeHeader } from './l2_block_code_to_purge
* The data that makes up the rollup proof, with encoder decoder functions.
*/
export class L2Block {
#l1BlockNumber?: bigint;

constructor(
/** Snapshot of archive tree after the block is applied. */
public archive: AppendOnlyTreeSnapshot,
/** L2 block header. */
public header: Header,
/** L2 block body. */
public body: Body,
/** Associated L1 block num */
l1BlockNumber?: bigint,
) {
this.#l1BlockNumber = l1BlockNumber;
}
) {}

/**
* Constructs a new instance from named fields.
* @param fields - Fields to pass to the constructor.
* @param blockHash - Hash of the block.
* @param l1BlockNumber - The block number of the L1 block that contains this L2 block.
* @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;
},
l1BlockNumber?: bigint,
) {
return new this(fields.archive, fields.header, fields.body, l1BlockNumber);
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);
}

/**
Expand Down Expand Up @@ -117,40 +107,17 @@ export class L2Block {

const txsEffectsHash = body.getTxsEffectsHash();

return L2Block.fromFields(
{
archive: makeAppendOnlyTreeSnapshot(1),
header: makeHeader(0, l2BlockNum, txsEffectsHash, inHash),
body,
},
// just for testing purposes, each random L2 block got emitted in the equivalent L1 block
BigInt(l2BlockNum),
);
return L2Block.fromFields({
archive: makeAppendOnlyTreeSnapshot(1),
header: makeHeader(0, l2BlockNum, txsEffectsHash, inHash),
body,
});
}

get number(): number {
return Number(this.header.globalVariables.blockNumber.toBigInt());
}

/**
* Gets the L1 block number that included this block
*/
public getL1BlockNumber(): bigint {
if (typeof this.#l1BlockNumber === 'undefined') {
throw new Error('L1 block number has to be attached before calling "getL1BlockNumber"');
}

return this.#l1BlockNumber;
}

/**
* Sets the L1 block number that included this block
* @param l1BlockNumber - The block number of the L1 block that contains this L2 block.
*/
public setL1BlockNumber(l1BlockNumber: bigint) {
this.#l1BlockNumber = l1BlockNumber;
}

/**
* Returns the block's hash (hash of block header).
* @returns The block's hash.
Expand Down
Loading