Skip to content

Commit

Permalink
s/latest/current,add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-kothari committed May 22, 2023
1 parent 3dd7525 commit 4788aa4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ interface IRegistry {
view
returns (DataStructures.RegistrySnapshot memory);

function getLatestSnapshot() external view returns (DataStructures.RegistrySnapshot memory);
function getCurrentSnapshot() external view returns (DataStructures.RegistrySnapshot memory);
}
53 changes: 41 additions & 12 deletions l1-contracts/src/core/messagebridge/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,56 @@ import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
* @notice Keeps track of important information for L1<>L2 communication.
*/
contract Registry is IRegistry {
uint256 public latestVersionNumber;
mapping(uint256 version => DataStructures.RegistrySnapshot snapshot) snapshots;
DataStructures.RegistrySnapshot latestSnapshot;
// starts with version 1. Incremented on each upgrade.
uint256 public currentVersion;
DataStructures.RegistrySnapshot internal currentSnapshot;
mapping(uint256 version => DataStructures.RegistrySnapshot snapshot) internal snapshots;

// todo: this function has to be permissioned.
function upgrade(address _rollup, address _inbox, address _outbox) public {
latestVersionNumber++;
/**
* Creates a new snapshot of the registry
* @dev starts with version 1.
* @param _rollup - The address of the rollup contract
* @param _inbox - The address of the inbox contract
* @param _outbox - The address of the outbox contract
*/
function upgrade(address _rollup, address _inbox, address _outbox) external {
currentVersion++;
DataStructures.RegistrySnapshot memory newSnapshot =
DataStructures.RegistrySnapshot(_rollup, _inbox, _outbox, block.number);
latestSnapshot = newSnapshot;
snapshots[latestVersionNumber] = newSnapshot;
currentSnapshot = newSnapshot;
snapshots[currentVersion] = newSnapshot;
}

/**
* @notice Returns the rollup contract
* @return The rollup contract (of type IRollup)
*/
function getRollup() external view override returns (IRollup) {
return IRollup(latestSnapshot.rollup);
return IRollup(currentSnapshot.rollup);
}

/**
* @notice Returns the inbox contract
* @return The inbox contract (of type IInbox)
*/
function getInbox() external view override returns (IInbox) {
return IInbox(latestSnapshot.inbox);
return IInbox(currentSnapshot.inbox);
}

/**
* @notice Returns the outbox contract
* @return The outbox contract (of type IOutbox)
*/
function getOutbox() external view override returns (IOutbox) {
return IOutbox(latestSnapshot.outbox);
return IOutbox(currentSnapshot.outbox);
}

/**
* Fetches a snapshot of the registry indicated by `version`
* @param _version - The version of the rollup to return (i.e. which snapshot)
* @return the snapshot
*/
function getSnapshot(uint256 _version)
external
view
Expand All @@ -48,12 +73,16 @@ contract Registry is IRegistry {
return snapshots[_version];
}

function getLatestSnapshot()
/**
* @notice Returns the current snapshot of the registry
* @return The current snapshot
*/
function getCurrentSnapshot()
external
view
override
returns (DataStructures.RegistrySnapshot memory)
{
return latestSnapshot;
return currentSnapshot;
}
}

0 comments on commit 4788aa4

Please sign in to comment.