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

feat: dependency set refactor #170

Open
wants to merge 2 commits into
base: sc-feat/add-shared-lockbox
Choose a base branch
from

Conversation

agusduha
Copy link
Member

The rationale behind this PR is found in the following PR

The SuperchainConfig is now the only source for storing the dependencySet

The changes have impact in L1BlockInterop, SystemConfigInterop, CrossL2Inbox and L2toL2CDM

@agusduha agusduha self-assigned this Dec 26, 2024

/// @notice Thrown when the input chain is already added to the dependency set.
error ChainAlreadyAdded();
error DependencyAlreadyAdded();

/// @notice Semantic version.
/// @custom:semver 1.1.1-beta.5
string public constant version = "1.1.1-beta.5";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have to upgrade this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to because it is updated in the main PR that has not been merged to develop yet

SET_GAS_PAYING_TOKEN,
ADD_DEPENDENCY,
REMOVE_DEPENDENCY
SET_GAS_PAYING_TOKEN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using a enum with just one member?

@@ -109,10 +72,6 @@ contract L1BlockInterop is L1Block {

if (_type == ConfigType.SET_GAS_PAYING_TOKEN) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, are we expecting to add new members to ConfigType?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a good question we could ask to them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is how it works, OptimismPortal.setConfig() can send multiple types, so this has to be extensible.

We will be using this feature in another PR so it should stay like this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm... I think that the enum is right cause it will be easier to expand if needed... but this is no needed cause if you have to add another member you have to modify the function too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the if any call to setConfig means calling _setGasPayingToken and it shouldn't be like that

Copy link

@0xDiscotech 0xDiscotech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing job ser, left only few small comments on the code.
Besides them, 1 more question and 1 suggestion:

  • On the PoC, Mark wrote a function to remove dependencies on L1. Do we need to implement it?
  • If maintaining the dependencySetSize() function, missing its tests (the other view functions have tests as well)

@@ -47,17 +47,18 @@ contract ManageDependenciesInput is BaseDeployIO {
}

contract ManageDependencies is Script {
// TODO: Fix dependency management since SystemConfig does not handle them anymore

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing TODO?


/// @notice Returns the size of the dependency set.
/// @return The size of the dependency set.
function dependencySetSize() external view returns (uint8) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this function?

error DependencySetTooLarge();

/// @notice Thrown when the input chain ID is the same as the current chain ID.
error InvalidChainID();

/// @notice Thrown when the input chain is already added to the dependency set.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// @notice Thrown when the input chain is already added to the dependency set.
/// @notice Thrown when the input dependency is already added to the set.

abi.encode(numberOfDependencies)
);
/// @notice Tests that `addDependency` reverts when the chain is already in the dependency set.
function test_addDependency_chainAlreadyExists_reverts(uint256 _chainId) external {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: For the code order, this should go below test_addDependency_sameChainID_reverts

Comment on lines +168 to +176
uint256 i;
for (i; i < type(uint8).max; i++) {
superchainConfig.addDependency(i, address(systemConfig));
}

assertEq(superchainConfig.dependencySetSize(), type(uint8).max);

vm.prank(superchainConfig.upgrader());
vm.expectRevert(SuperchainConfig.ChainAlreadyAdded.selector);
superchainConfig.addChain(_chainId, _systemConfig);
vm.expectRevert(SuperchainConfig.DependencySetTooLarge.selector);
superchainConfig.addDependency(i + 1, address(systemConfig));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: adding some comments and vars for readability

        // Add the maximum number of dependencies to the dependency set
        for (uint256 i; i < type(uint8).max; i++) {
            superchainConfig.addDependency(i, address(systemConfig));
        }

        // Check that the dependency set is full and that expect the next call to revert
        assertEq(superchainConfig.dependencySetSize(), type(uint8).max);
        vm.expectRevert(SuperchainConfig.DependencySetTooLarge.selector);

        // Try to add another dependency to the dependency set
        uint256 chainId = i + 1;
        superchainConfig.addDependency(i + 1, address(systemConfig));
        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants