Skip to content

Commit 346ce2a

Browse files
Feat/94 emit version updated event (#98)
* Emit LineaRollupVersionChanged on upgrade * make padded hex bytes generic
1 parent 5777e29 commit 346ce2a

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

contracts/contracts/LineaRollup.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ contract LineaRollup is
125125
* @param _unpauseTypeRoles The list of unpause type roles.
126126
* @param _gatewayOperator The address of the gateway operator.
127127
*/
128-
function reinitializePauseTypesAndPermissions(
128+
function reinitializeLineaRollupV6(
129129
RoleAddress[] calldata _roleAddresses,
130130
PauseTypeRole[] calldata _pauseTypeRoles,
131131
PauseTypeRole[] calldata _unpauseTypeRoles,
@@ -134,6 +134,9 @@ contract LineaRollup is
134134
__Permissions_init(_roleAddresses);
135135
__PauseManager_init(_pauseTypeRoles, _unpauseTypeRoles);
136136
gatewayOperator = _gatewayOperator;
137+
138+
/// @dev using the constants requires string memory and more complex code.
139+
emit LineaRollupVersionChanged(bytes8("5.0"), bytes8("6.0"));
137140
}
138141

139142
/**

contracts/contracts/interfaces/l1/ILineaRollup.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ interface ILineaRollup {
131131
bytes l2MessagingBlocksOffsets;
132132
}
133133

134+
/**
135+
* @notice Emitted when the LineaRollup contract version has changed.
136+
* @dev All bytes8 values are string based SemVer in the format M.m - e.g. "6.0";
137+
* @param previousVersion The previous version.
138+
* @param newVersion The new version.
139+
*/
140+
event LineaRollupVersionChanged(bytes8 indexed previousVersion, bytes8 indexed newVersion);
141+
134142
/**
135143
* @notice Emitted when the gateway operator role is granted.
136144
* @param caller The address that granted the role.

contracts/test/LineaRollup.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
generateBlobDataSubmission,
6565
generateBlobParentShnarfData,
6666
ShnarfDataGenerator,
67+
convertStringToPaddedHexBytes,
6768
} from "./utils/helpers";
6869
import { CalldataSubmissionData } from "./utils/types";
6970
import aggregatedProof1To81 from "./testData/compressedData/multipleProofs/aggregatedProof-1-81.json";
@@ -2244,7 +2245,7 @@ describe("Linea Rollup contract", () => {
22442245
const NewLineaRollupFactory = await ethers.getContractFactory("contracts/LineaRollup.sol:LineaRollup");
22452246
const newLineaRollup = await upgrades.upgradeProxy(lineaRollup, NewLineaRollupFactory);
22462247

2247-
await newLineaRollup.reinitializePauseTypesAndPermissions(
2248+
const upgradeCall = newLineaRollup.reinitializeLineaRollupV6(
22482249
[
22492250
{ addressWithRole: securityCouncil.address, role: DEFAULT_ADMIN_ROLE },
22502251
{ addressWithRole: securityCouncil.address, role: VERIFIER_SETTER_ROLE },
@@ -2254,10 +2255,18 @@ describe("Linea Rollup contract", () => {
22542255
multiCallAddress,
22552256
);
22562257

2258+
const expectedVersion5Bytes8 = convertStringToPaddedHexBytes("5.0", 8);
2259+
const expectedVersion6Bytes8 = convertStringToPaddedHexBytes("6.0", 8);
2260+
2261+
await expectEvent(newLineaRollup, upgradeCall, "LineaRollupVersionChanged", [
2262+
expectedVersion5Bytes8,
2263+
expectedVersion6Bytes8,
2264+
]);
2265+
22572266
expect(await newLineaRollup.currentL2BlockNumber()).to.equal(0);
22582267
});
22592268

2260-
it("Should revert with ZeroAddressNotAllowed when addressWithRole is zero address in reinitializePauseTypesAndPermissions", async () => {
2269+
it("Should revert with ZeroAddressNotAllowed when addressWithRole is zero address in reinitializeLineaRollupV6", async () => {
22612270
// Deploy new implementation
22622271
const NewLineaRollupFactory = await ethers.getContractFactory("contracts/LineaRollup.sol:LineaRollup");
22632272
const newLineaRollup = await upgrades.upgradeProxy(lineaRollup, NewLineaRollupFactory);
@@ -2270,12 +2279,7 @@ describe("Linea Rollup contract", () => {
22702279

22712280
await expectRevertWithCustomError(
22722281
newLineaRollup,
2273-
newLineaRollup.reinitializePauseTypesAndPermissions(
2274-
roleAddresses,
2275-
pauseTypeRoles,
2276-
unpauseTypeRoles,
2277-
multiCallAddress,
2278-
),
2282+
newLineaRollup.reinitializeLineaRollupV6(roleAddresses, pauseTypeRoles, unpauseTypeRoles, multiCallAddress),
22792283
"ZeroAddressNotAllowed",
22802284
);
22812285
});

contracts/test/utils/helpers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,15 @@ export async function expectEvent(contract: any, asyncCall: Promise<any>, eventN
496496
.to.emit(contract, eventName)
497497
.withArgs(...eventArgs);
498498
}
499+
500+
export function convertStringToPaddedHexBytes(strVal: string, paddedSize: number): string {
501+
if (strVal.length > paddedSize) {
502+
throw "Length is longer than padded size!";
503+
}
504+
505+
const strBytes = ethers.toUtf8Bytes(strVal);
506+
const bytes = ethers.zeroPadBytes(strBytes, paddedSize);
507+
const bytes8Hex = ethers.hexlify(bytes);
508+
509+
return bytes8Hex;
510+
}

0 commit comments

Comments
 (0)