SIP-100: Resolver & Cache Improvements
Author | |
---|---|
Discussions-To | https://research.synthetix.io/ |
Status | Implemented |
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
MixinResolver
to be given the immutableReadProxyAddressResolver
and no longer requireOwned
functionality - Allow all contracts that use
MixinResolver
to have their caches rebuilt by anyone - Add to the
AddressResolver
a function to batch and forward requests to build caches of a collection ofMixinResolver
contracts - 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 eventAddressImported
for each address addedAddressResolver.rebuildCaches()
is exposed (and non-protected), for ease-of useMixinResolver
no longer requiresOwned
as theresolver
property is set once only on construction (with the expectation thatReadProxyAddressResolver
will be used.MixinResolver
has a predicate viewisResolverCached()
MixinResolver
has arebuildCache()
function (publicly available) for the contract to rebuild its cache. This function also emits aCacheUpdated
event for each item added to its private cacheMixinResolver.requireAndGetAddress()
uses abi.encodePacked for string concatenation and a simpler API.MixinResolver
no longer performs tasks in the constructor. Contracts using the mixin must implement the abstractresolverAddressesRequired
function.
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