SIP-100: Resolver & Cache Improvements
| Author | |
|---|---|
| Status | Implemented |
| Type | Governance |
| Network | Ethereum |
| Implementor | TBD |
| Release | TBD |
| Created | 2020-12-03 |
Simple Summary
Improve the AddressResolver to improve protocol upgrades, reduce gas of deployments and further decentralization.
Abstract
Reduce the complexity of Synthetix contracts using the AddressResolver in three ways:
- Have all contracts that use
MixinResolverto be given the immutableReadProxyAddressResolverand no longer requireOwnedfunctionality - Allow all contracts that use
MixinResolverto have their caches rebuilt by anyone - Add to the
AddressResolvera function to batch and forward requests to build caches of a collection ofMixinResolvercontracts - Emit events on address import and cache rebuilding
- No longer build the list of required addresses a contract needs at runtime in the constructor but rather at compile time where possible.
Motivation
There are currently three main issues necessitating this refactor:
First, the protocolDAO upgrades are cumbersome, having a plethora of cache rebuilding transactions to be invoked individually. Better to batch these where possible.
Second, as ReadProxyAddressResolver is now available and immutable, contracts can rely on it being set at construction and never changed, and ownership can be remove for contracts that only have it for the MixinResolver.
Third, as many contracts also need to work on the OVM, we need to keep contracts down in size. As the OVM transpiler adds extra code around opcodes like SSTORE, we want to reduce the use of them in constructors as much as possible.
Finally, more emitted events help determine issues by leaving a paper trail of actions performed to be easily traced back.
Specification
Overview
AddressResolver.importAddresses()to emit an eventAddressImportedfor each address addedAddressResolver.rebuildCaches()is exposed (and non-protected), for ease-of useMixinResolverno longer requiresOwnedas theresolverproperty is set once only on construction (with the expectation thatReadProxyAddressResolverwill be used.MixinResolverhas a predicate viewisResolverCached()MixinResolverhas arebuildCache()function (publicly available) for the contract to rebuild its cache. This function also emits aCacheUpdatedevent for each item added to its private cacheMixinResolver.requireAndGetAddress()uses abi.encodePacked for string concatenation and a simpler API.MixinResolverno longer performs tasks in the constructor. Contracts using the mixin must implement the abstractresolverAddressesRequiredfunction.
Rationale
This approach mimics the same functionality as currently on-chain, and does not add any more gas to Synthetix user transactions.
Technical Specification
contract AddressResolver {
// restricted function
function importAddresses(bytes32[] calldata names, address[] calldata destinations) external // ... emits AddressImported
// public function
function rebuildCaches(MixinResolver[] calldata destinations) external // ... invokes MixinResolver.rebuildCache()
// event
event AddressImported(bytes32 name, address destination);
}
contract MixinResolver {
// public function
function rebuildCache() external // ... emits CacheUpdated
// abstract view
function resolverAddressesRequired() public view returns (bytes32[] memory addresses);
// view
function isResolverCached() external view returns (bool) // ...
// event
event CacheUpdated(bytes32 name, address destination);
}
Test Cases
See PR#904
Configurable Values (Via SCCP)
N/A