Skip to content

Commit

Permalink
fix(monitor): Add chain ID 1 to monitor chains (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai committed Aug 11, 2023
1 parent 06d7ac6 commit 0a6603d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
15 changes: 9 additions & 6 deletions src/monitor/Monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,27 @@ export class Monitor {
private balanceCache: { [chainId: number]: { [token: string]: { [account: string]: BigNumber } } } = {};
private decimals: { [chainId: number]: { [token: string]: number } } = {};
private balanceAllocator: BalanceAllocator;
// Chains for each spoke pool client.
public monitorChains: number[];
// Chains that we care about inventory manager activity on, so doesn't include Ethereum which doesn't
// have an inventory manager adapter.
public crossChainAdapterSupportedChains: number[];

public constructor(
readonly logger: winston.Logger,
readonly monitorConfig: MonitorConfig,
readonly clients: MonitorClients
) {
const adapterSupportedChains = clients.crossChainTransferClient.adapterManager.supportedChains();
this.monitorChains = Object.values(clients.spokePoolClients)
.map(({ chainId }) => chainId)
.filter((x) => adapterSupportedChains.includes(x));
this.crossChainAdapterSupportedChains = clients.crossChainTransferClient.adapterManager.supportedChains();
this.monitorChains = Object.values(clients.spokePoolClients).map(({ chainId }) => chainId);
for (const chainId of this.monitorChains) {
this.spokePoolsBlocks[chainId] = { startingBlock: undefined, endingBlock: undefined };
}
logger.debug({
at: "Monitor#constructor",
message: "Initialized monitor",
monitorChains: this.monitorChains,
crossChainAdapterSupportedChains: this.crossChainAdapterSupportedChains,
});
this.balanceAllocator = new BalanceAllocator(spokePoolClientsToProviders(clients.spokePoolClients));
}
Expand Down Expand Up @@ -509,7 +512,7 @@ export class Monitor {
}

const allL1Tokens = this.clients.hubPoolClient.getL1Tokens();
for (const chainId of this.monitorChains) {
for (const chainId of this.crossChainAdapterSupportedChains) {
// If chain wasn't active in latest bundle, then skip it.
const chainIndex = this.clients.hubPoolClient.configStoreClient.getChainIdIndicesForBlock().indexOf(chainId);
if (chainIndex >= lastFullyExecutedBundle.bundleEvaluationBlockNumbers.length) {
Expand Down Expand Up @@ -564,7 +567,7 @@ export class Monitor {

updateCrossChainTransfers(relayer: string, relayerBalanceTable: RelayerBalanceTable): void {
const allL1Tokens = this.clients.hubPoolClient.getL1Tokens();
for (const chainId of this.monitorChains) {
for (const chainId of this.crossChainAdapterSupportedChains) {
for (const l1Token of allL1Tokens) {
const transferBalance = this.clients.crossChainTransferClient.getOutstandingCrossChainTransferAmount(
relayer,
Expand Down
21 changes: 12 additions & 9 deletions src/monitor/MonitorClientHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,22 @@ export async function constructMonitorClients(
[baseSigner.address, ...spokePoolAddresses],
commonClients.hubPoolClient.hubPool.address
);
const adapterSupportedChains = adapterManager.supportedChains();
const spokePoolChains = Object.keys(spokePoolClients)
.map((chainId) => Number(chainId))
.filter((chainId) => adapterSupportedChains.includes(chainId));
// The TokenTransferClient and CrossChainTransferClient are dependent on having adapters for all passed in chains
// so we need to filter out any chains that don't have adapters. This means limiting the chains we keep in
// `providerPerChain` when constructing the TokenTransferClient and limiting `spokePoolChains` when constructing
// the CrossChainTransferClient.
const spokePoolChains = Object.keys(spokePoolClients).map((chainId) => Number(chainId));
const providerPerChain = Object.fromEntries(
spokePoolChains.map((chainId) => [chainId, spokePoolClients[chainId].spokePool.provider])
);
const tokenTransferClient = new TokenTransferClient(logger, providerPerChain, config.monitoredRelayers);
const crossChainTransferClient = new CrossChainTransferClient(logger, spokePoolChains, adapterManager);

// The CrossChainTransferClient is dependent on having adapters for all passed in chains
// so we need to filter out any chains that don't have adapters. This means limiting the chains we keep in
// `providerPerChain` when constructing the TokenTransferClient and limiting `spokePoolChains` when constructing
// the CrossChainTransferClient.
const crossChainAdapterSupportedChains = adapterManager.supportedChains();
const crossChainTransferClient = new CrossChainTransferClient(
logger,
spokePoolChains.filter((chainId) => crossChainAdapterSupportedChains.includes(chainId)),
adapterManager
);

return { ...commonClients, bundleDataClient, crossChainTransferClient, spokePoolClients, tokenTransferClient };
}
Expand Down

0 comments on commit 0a6603d

Please sign in to comment.