Skip to content

Commit

Permalink
caching latest version to save gas (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
minghinmatthewlam authored Jan 9, 2024
1 parent 8cdfd96 commit 9fcdf42
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 12 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions contracts/src/Teleporter/upgrades/TeleporterRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@ contract TeleporterRegistry {
"TeleporterRegistry: version already exists"
);
require(entry.protocolAddress != address(0), "TeleporterRegistry: zero protocol address");

uint256 latestVersion_ = latestVersion;
require(
entry.version <= latestVersion + MAX_VERSION_INCREMENT,
entry.version <= latestVersion_ + MAX_VERSION_INCREMENT,
"TeleporterRegistry: version increment too high"
);

Expand All @@ -192,10 +194,9 @@ contract TeleporterRegistry {
emit AddProtocolVersion(entry.version, entry.protocolAddress);

// Set latest version if the version is greater than the current latest version.
if (entry.version > latestVersion) {
uint256 oldLatestVersion = latestVersion;
if (entry.version > latestVersion_) {
latestVersion = entry.version;
emit LatestVersionUpdated(oldLatestVersion, latestVersion);
emit LatestVersionUpdated(latestVersion_, entry.version);
}
}
}

0 comments on commit 9fcdf42

Please sign in to comment.