Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[contracts]: Update Lib_AddressManager.AddressSet event to speed up data transport layer #820

Merged
merged 3 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
public
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 @@ -233,13 +233,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 @@ -317,21 +315,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