Skip to content

Commit

Permalink
feat[contracts]: Update Lib_AddressManager.AddressSet event to speed …
Browse files Browse the repository at this point in the history
…up data transport layer (#820)

* feat: update and improve AddressSet event

* chore: add changeset

* Update Lib_AddressManager.sol
  • Loading branch information
smartcontracts committed May 28, 2021
1 parent db0dbfb commit 2e72fd9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .changeset/flat-bananas-perform.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ contract Lib_AddressManager is Ownable {
**********/

event AddressSet(
string _name,
address _newAddress
string indexed _name,
address _newAddress,
address _oldAddress
);


Expand All @@ -42,11 +43,14 @@ contract Lib_AddressManager is Ownable {
external
onlyOwner
{
addresses[_getNameHash(_name)] = _address;
bytes32 nameHash = _getNameHash(_name);
address oldAddress = addresses[nameHash];
addresses[nameHash] = _address;

emit AddressSet(
_name,
_address
_address,
oldAddress
);
}

Expand Down
1 change: 1 addition & 0 deletions packages/core-utils/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ethers } from 'ethers'
export interface EventArgsAddressSet {
_name: string
_newAddress: string
_oldAddress: string
}

export interface EventArgsTransactionEnqueued {
Expand Down
29 changes: 10 additions & 19 deletions packages/data-transport-layer/src/services/l1-ingestion/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,11 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
// 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<EventArgsAddressSet>[]).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.
Expand Down Expand Up @@ -320,21 +318,14 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
contractName: string,
blockNumber: number
): Promise<string> {
// 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
Expand Down

0 comments on commit 2e72fd9

Please sign in to comment.