diff --git a/.changeset/flat-bananas-perform.md b/.changeset/flat-bananas-perform.md new file mode 100644 index 000000000000..620d6955ad06 --- /dev/null +++ b/.changeset/flat-bananas-perform.md @@ -0,0 +1,6 @@ +--- +'@eth-optimism/contracts': minor +'@eth-optimism/data-transport-layer': minor +--- + +Update AddressSet event to speed search up a bit. Breaks AddressSet API. diff --git a/packages/contracts/contracts/optimistic-ethereum/libraries/resolver/Lib_AddressManager.sol b/packages/contracts/contracts/optimistic-ethereum/libraries/resolver/Lib_AddressManager.sol index 606f2cef3005..fabf6ecc533b 100644 --- a/packages/contracts/contracts/optimistic-ethereum/libraries/resolver/Lib_AddressManager.sol +++ b/packages/contracts/contracts/optimistic-ethereum/libraries/resolver/Lib_AddressManager.sol @@ -14,8 +14,9 @@ contract Lib_AddressManager is Ownable { **********/ event AddressSet( - string _name, - address _newAddress + string indexed _name, + address _newAddress, + address _oldAddress ); @@ -42,11 +43,14 @@ contract Lib_AddressManager is Ownable { public onlyOwner { - addresses[_getNameHash(_name)] = _address; + bytes32 nameHash = _getNameHash(_name); + address oldAddress = addresses[nameHash]; + addresses[nameHash] = _address; emit AddressSet( _name, - _address + _address, + oldAddress ); } diff --git a/packages/core-utils/src/events.ts b/packages/core-utils/src/events.ts index c7fa940fb68d..b0a2306a171b 100644 --- a/packages/core-utils/src/events.ts +++ b/packages/core-utils/src/events.ts @@ -3,6 +3,7 @@ import { ethers } from 'ethers' export interface EventArgsAddressSet { _name: string _newAddress: string + _oldAddress: string } export interface EventArgsTransactionEnqueued { diff --git a/packages/data-transport-layer/src/services/l1-ingestion/service.ts b/packages/data-transport-layer/src/services/l1-ingestion/service.ts index daf5a8e448c0..5ef5e0b7916f 100644 --- a/packages/data-transport-layer/src/services/l1-ingestion/service.ts +++ b/packages/data-transport-layer/src/services/l1-ingestion/service.ts @@ -233,13 +233,11 @@ export class L1IngestionService extends BaseService { // We need to figure out how to make this work without Infura. Mark and I think that infura is // doing some indexing of events beyond Geth's native capabilities, meaning some event logic // will only work on Infura and not on a local geth instance. Not great. - const addressSetEvents = ((await this.state.contracts.Lib_AddressManager.queryFilter( - this.state.contracts.Lib_AddressManager.filters.AddressSet(), + const addressSetEvents = await this.state.contracts.Lib_AddressManager.queryFilter( + this.state.contracts.Lib_AddressManager.filters.AddressSet(contractName), fromL1Block, toL1Block - )) as TypedEthersEvent[]).filter((event) => { - return event.args._name === contractName - }) + ) // We're going to parse things out in ranges because the address of a given contract may have // changed in the range provided by the user. @@ -317,21 +315,14 @@ export class L1IngestionService extends BaseService { contractName: string, blockNumber: number ): Promise { - // TODO: Should be much easier than this. Need to change the params of this event. - const relevantAddressSetEvents = ( - await this.state.contracts.Lib_AddressManager.queryFilter( - this.state.contracts.Lib_AddressManager.filters.AddressSet(), - this.state.startingL1BlockNumber - ) - ).filter((event) => { - return ( - event.args._name === contractName && event.blockNumber < blockNumber - ) - }) + const events = await this.state.contracts.Lib_AddressManager.queryFilter( + this.state.contracts.Lib_AddressManager.filters.AddressSet(contractName), + this.state.startingL1BlockNumber, + blockNumber + ) - if (relevantAddressSetEvents.length > 0) { - return relevantAddressSetEvents[relevantAddressSetEvents.length - 1].args - ._newAddress + if (events.length > 0) { + return events[events.length - 1].args._newAddress } else { // Address wasn't set before this. return constants.AddressZero