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

Fixed already initialized error when upgrading L1 Messenger #133

Merged
merged 1 commit into from
Apr 9, 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
26 changes: 20 additions & 6 deletions packages/contracts-bedrock/src/oasys/L1/build/L1BuildAgent.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ILegacyL1BuildAgent } from "src/oasys/L1/build/interfaces/ILegacyL1Buil
import { IOasysL2OutputOracleVerifier } from "src/oasys/L1/interfaces/IOasysL2OutputOracleVerifier.sol";
import { PortalSender } from "src/oasys/L1/build/PortalSender.sol";
import { OptimismPortal } from "src/L1/OptimismPortal.sol";
import { L1CrossDomainMessenger } from "src/L1/L1CrossDomainMessenger.sol";

/// @notice The 2nd version of L1BuildAgent
/// Regarding the build step, referred to the build script of Opstack
Expand Down Expand Up @@ -547,13 +548,26 @@ contract L1BuildAgent is IL1BuildAgent, ISemver {
keccak256(bytes(proxyAdmin.implementationName(l1CrossDomainMessengerProxy)))
== keccak256(bytes(contractName))
);
// When upgrading from a Legacy, since it is already initialized,
// it is sufficient to just upgrade the implementation.
proxyAdmin.upgrade({ _proxy: payable(l1CrossDomainMessengerProxy), _implementation: impl });
// But just to be sure, will check to see if it's initialized.
try L1CrossDomainMessenger(l1CrossDomainMessengerProxy).initialize() { }
catch Error(string memory reason) {
require(
keccak256(abi.encodePacked(reason)) == keccak256("Initializable: contract is already initialized"),
string.concat("L1BuildAgent: unexpected error initializing L1XDM: ", reason)
);
} catch {
revert("L1BuildAgent: unexpected error initializing L1XDM (no reason)");
}
} else {
proxyAdmin.upgradeAndCall({
_proxy: payable(l1CrossDomainMessengerProxy),
_implementation: impl,
_data: BUILD_L1CROSS_DOMAIN_MESSENGER.initializeData()
});
}

proxyAdmin.upgradeAndCall({
_proxy: payable(l1CrossDomainMessengerProxy),
_implementation: impl,
_data: BUILD_L1CROSS_DOMAIN_MESSENGER.initializeData()
});
}

/// @notice Initialize the OasysL2OutputOracle
Expand Down