Skip to content

Commit

Permalink
Merge pull request #191 from OffchainLabs/proxy-cache-manager
Browse files Browse the repository at this point in the history
Upgradeable cache manager
  • Loading branch information
gzeoneth authored Jul 1, 2024
2 parents b8fd7cd + 6ec09ad commit d021be2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 6 deletions.
2 changes: 1 addition & 1 deletion slither.db.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/chain/CacheManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ pragma solidity ^0.8.0;
import "../precompiles/ArbOwnerPublic.sol";
import "../precompiles/ArbWasm.sol";
import "../precompiles/ArbWasmCache.sol";
import "../libraries/DelegateCallAware.sol";
import "solady/src/utils/MinHeapLib.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract CacheManager {
contract CacheManager is Initializable, DelegateCallAware {
using MinHeapLib for MinHeapLib.Heap;

ArbOwnerPublic internal constant ARB_OWNER_PUBLIC = ArbOwnerPublic(address(0x6b));
Expand Down Expand Up @@ -47,7 +49,7 @@ contract CacheManager {
uint192 bid;
}

constructor(uint64 initCacheSize, uint64 initDecay) {
function initialize(uint64 initCacheSize, uint64 initDecay) external initializer onlyDelegated {
cacheSize = initCacheSize;
decay = initDecay;
}
Expand Down
15 changes: 14 additions & 1 deletion test/foundry/CacheManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity ^0.8.4;

import "forge-std/Test.sol";
import "../../src/chain/CacheManager.sol";
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

contract CacheManagerTest is Test {
CacheManager public cacheManager;
Expand All @@ -14,9 +16,20 @@ contract CacheManagerTest is Test {
ArbWasmCacheMock internal constant ARB_WASM_CACHE = ArbWasmCacheMock(address(0x72));

constructor() {
ProxyAdmin proxyAdmin = new ProxyAdmin();
CacheManager cacheManagerImpl = new CacheManager();
cacheManager = CacheManager(
address(
new TransparentUpgradeableProxy(
address(cacheManagerImpl),
address(proxyAdmin),
""
)
)
);
uint64 cacheSize = 1_000_000;
uint64 decay = 100;
cacheManager = new CacheManager(cacheSize, decay);
cacheManager.initialize(cacheSize, decay);
require(cacheManager.cacheSize() == cacheSize, "wrong cache size");
require(cacheManager.decay() == decay, "wrong decay rate");

Expand Down
22 changes: 22 additions & 0 deletions test/signatures/CacheManager
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"cacheSize()": "674a64e0",
"decay()": "54fac919",
"entries(uint256)": "b30906d4",
"evictAll()": "5c32e943",
"evictPrograms(uint256)": "cadb43e2",
"getEntries()": "17be85c3",
"getMinBid(address)": "32052a9b",
"getMinBid(bytes32)": "c565a208",
"getMinBid(uint64)": "d29b303e",
"getSmallestEntries(uint256)": "e9c1bc0f",
"initialize(uint64,uint64)": "20f2f345",
"isPaused()": "b187bd26",
"makeSpace(uint64)": "c1c013c4",
"paused()": "5c975abb",
"placeBid(address)": "e4940157",
"queueSize()": "bae6c2ad",
"setCacheSize(uint64)": "2dd4f566",
"setDecayRate(uint64)": "c77ed13e",
"sweepFunds()": "a8d6fe04",
"unpause()": "3f4ba83a"
}
2 changes: 1 addition & 1 deletion test/signatures/test-sigs.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
output_dir="./test/signatures"
for CONTRACTNAME in Bridge Inbox Outbox RollupCore RollupUserLogic RollupAdminLogic SequencerInbox ChallengeManager ERC20Bridge ERC20Inbox ERC20Outbox BridgeCreator DeployHelper RollupCreator OneStepProofEntry
for CONTRACTNAME in Bridge Inbox Outbox RollupCore RollupUserLogic RollupAdminLogic SequencerInbox ChallengeManager ERC20Bridge ERC20Inbox ERC20Outbox BridgeCreator DeployHelper RollupCreator OneStepProofEntry CacheManager
do
echo "Checking for signature changes in $CONTRACTNAME"
[ -f "$output_dir/$CONTRACTNAME" ] && mv "$output_dir/$CONTRACTNAME" "$output_dir/$CONTRACTNAME-old"
Expand Down
10 changes: 10 additions & 0 deletions test/storage/CacheManager
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
| Name | Type | Slot | Offset | Bytes | Contract |
|---------------|-----------------------------|------|--------|-------|-----------------------------------------|
| _initialized | bool | 0 | 0 | 1 | src/chain/CacheManager.sol:CacheManager |
| _initializing | bool | 0 | 1 | 1 | src/chain/CacheManager.sol:CacheManager |
| bids | struct MinHeapLib.Heap | 1 | 0 | 32 | src/chain/CacheManager.sol:CacheManager |
| entries | struct CacheManager.Entry[] | 2 | 0 | 32 | src/chain/CacheManager.sol:CacheManager |
| cacheSize | uint64 | 3 | 0 | 8 | src/chain/CacheManager.sol:CacheManager |
| queueSize | uint64 | 3 | 8 | 8 | src/chain/CacheManager.sol:CacheManager |
| decay | uint64 | 3 | 16 | 8 | src/chain/CacheManager.sol:CacheManager |
| isPaused | bool | 3 | 24 | 1 | src/chain/CacheManager.sol:CacheManager |
2 changes: 1 addition & 1 deletion test/storage/test.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
output_dir="./test/storage"
for CONTRACTNAME in Bridge Inbox Outbox RollupCore RollupUserLogic RollupAdminLogic SequencerInbox ChallengeManager ERC20Bridge ERC20Inbox ERC20Outbox
for CONTRACTNAME in Bridge Inbox Outbox RollupCore RollupUserLogic RollupAdminLogic SequencerInbox ChallengeManager ERC20Bridge ERC20Inbox ERC20Outbox CacheManager
do
echo "Checking storage change of $CONTRACTNAME"
[ -f "$output_dir/$CONTRACTNAME" ] && mv "$output_dir/$CONTRACTNAME" "$output_dir/$CONTRACTNAME-old"
Expand Down

0 comments on commit d021be2

Please sign in to comment.