From b63eb1c4964f1a34480e2f1ff3c9609561262f2c Mon Sep 17 00:00:00 2001 From: Kelvin Fichter Date: Sat, 8 May 2021 00:12:26 -0400 Subject: [PATCH 1/3] feat: update and improve AddressSet event --- .../libraries/resolver/Lib_AddressManager.sol | 9 ++++-- packages/core-utils/src/events.ts | 1 + .../src/services/l1-ingestion/service.ts | 29 +++++++------------ 3 files changed, 17 insertions(+), 22 deletions(-) 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..0fc8282612a0 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,13 @@ contract Lib_AddressManager is Ownable { public onlyOwner { + address oldAddress = addresses[_getNameHash(_name)]; addresses[_getNameHash(_name)] = _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 From f2028734ccde80a766ec4ec51249af69643e28c4 Mon Sep 17 00:00:00 2001 From: Kelvin Fichter Date: Wed, 12 May 2021 15:56:45 -0400 Subject: [PATCH 2/3] chore: add changeset --- .changeset/flat-bananas-perform.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/flat-bananas-perform.md 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. From c75c1a44f5bbf5779c5024124ee8f97936f7d380 Mon Sep 17 00:00:00 2001 From: smartcontracts Date: Wed, 12 May 2021 19:09:10 -0400 Subject: [PATCH 3/3] Update Lib_AddressManager.sol --- .../libraries/resolver/Lib_AddressManager.sol | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 0fc8282612a0..fabf6ecc533b 100644 --- a/packages/contracts/contracts/optimistic-ethereum/libraries/resolver/Lib_AddressManager.sol +++ b/packages/contracts/contracts/optimistic-ethereum/libraries/resolver/Lib_AddressManager.sol @@ -43,8 +43,9 @@ contract Lib_AddressManager is Ownable { public onlyOwner { - address oldAddress = addresses[_getNameHash(_name)]; - addresses[_getNameHash(_name)] = _address; + bytes32 nameHash = _getNameHash(_name); + address oldAddress = addresses[nameHash]; + addresses[nameHash] = _address; emit AddressSet( _name,