Skip to content

Commit

Permalink
Merge branch 'main' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
rhlsthrm committed Sep 15, 2023
2 parents 10026bb + d22b8cb commit 7855c40
Show file tree
Hide file tree
Showing 30 changed files with 109,220 additions and 164,182 deletions.
12 changes: 8 additions & 4 deletions ops/mainnet/prod/core/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,23 @@ locals {
excludeListFromRelayerFee = ["0x5b9315ce1304df3b2a83b2074cbf849d160642ab"]
},
"1869640809" = {
providers = ["https://optimism-mainnet.blastapi.io/${var.blast_key}", "https://rpc.ankr.com/optimism"]
providers = ["https://optimism-mainnet.blastapi.io/${var.blast_key}", "https://rpc.ankr.com/optimism"],
excludeListFromRelayerFee = ["0x9D9ce29Dc7812ccb63aB14EA987B52d9aF053Eb3"]
},
"1886350457" = {
providers = ["https://polygon-mainnet.blastapi.io/${var.blast_key}", "https://rpc.ankr.com/polygon"]
providers = ["https://polygon-mainnet.blastapi.io/${var.blast_key}", "https://rpc.ankr.com/polygon"],
excludeListFromRelayerFee = ["0x83e8Cf4A51035665BAF97DdB0cf03b565AC76B44"]
}
"1634886255" = {
providers = ["https://arb-mainnet.g.alchemy.com/v2/${var.arbitrum_alchemy_key_0}", "https://rpc.ankr.com/arbitrum"]
providers = ["https://arb-mainnet.g.alchemy.com/v2/${var.arbitrum_alchemy_key_0}", "https://rpc.ankr.com/arbitrum"],
excludeListFromRelayerFee = ["0xE6B7aB9EBCfBF1A72E489ff00CdF9C6473ff6224"]
}
"6450786" = {
providers = ["https://bsc-mainnet.blastapi.io/${var.blast_key}", "https://bsc-dataseed1.binance.org", "https://bsc-dataseed2.binance.org", "https://rpc.ankr.com/bsc"]
}
"6778479" = {
providers = ["https://gnosis-mainnet.blastapi.io/${var.blast_key}", "https://rpc.gnosischain.com", "https://rpc.ankr.com/gnosis"]
providers = ["https://gnosis-mainnet.blastapi.io/${var.blast_key}", "https://rpc.gnosischain.com", "https://rpc.ankr.com/gnosis"],
excludeListFromRelayerFee = ["0x6D4D82aE73DC9059Ac83B085b2505e00b5eF8511"]
}
}
web3SignerUrl = "https://${module.sequencer_web3signer.service_endpoint}"
Expand Down
4 changes: 2 additions & 2 deletions ops/mainnet/prod/core/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ module "sequencer_cache" {
sg_id = module.network.ecs_task_sg
vpc_id = module.network.vpc_id
cache_subnet_group_subnet_ids = module.network.public_subnets
node_type = "cache.t2.medium"
node_type = "cache.r4.large"
public_redis = true
}

Expand All @@ -592,7 +592,7 @@ module "relayer_cache" {
sg_id = module.network.ecs_task_sg
vpc_id = module.network.vpc_id
cache_subnet_group_subnet_ids = module.network.public_subnets
node_type = "cache.t2.medium"
node_type = "cache.r4.large"
public_redis = true
}

Expand Down
2 changes: 1 addition & 1 deletion ops/testnet/prod/core/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ locals {
}
"9991" = {
providers = ["https://rpc.ankr.com/polygon_mumbai", "https://polygon-testnet.blastapi.io/${var.blast_key}"]
excludeListFromRelayerFee = ["0x6c461C0296eBE3715820F1Cbde856219e06ac3B8", "0x5Ee7Acd9E57f81a08d361b3Dc516f30964601068"]
excludeListFromRelayerFee = ["0x6c461C0296eBE3715820F1Cbde856219e06ac3B8", "0x5Ee7Acd9E57f81a08d361b3Dc516f30964601068", "0xcD7dE973264D5967D930Ef5144C59E9811ce5787"]
}
"1734439522" = {
providers = ["https://arb-goerli.g.alchemy.com/v2/${var.arbgoerli_alchemy_key_0}", "https://goerli-rollup.arbitrum.io/rpc"]
Expand Down
2 changes: 1 addition & 1 deletion ops/testnet/prod/core/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ module "relayer_cache" {
sg_id = module.network.ecs_task_sg
vpc_id = module.network.vpc_id
cache_subnet_group_subnet_ids = module.network.public_subnets
node_type = "cache.t2.medium"
node_type = "cache.r4.large"
public_redis = true
}

Expand Down
77 changes: 76 additions & 1 deletion packages/adapters/cache/src/lib/caches/messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExecStatus, XMessage, getNtpTimeSeconds } from "@connext/nxtp-utils";
import { ExecStatus, RelayerType, XMessage, getNtpTimeSeconds } from "@connext/nxtp-utils";

import { Cache } from "./cache";

Expand Down Expand Up @@ -144,6 +144,81 @@ export class MessagesCache extends Cache {
else return false;
}

/**
* Add pending task to the `tasks` list.
*
* @param taskId - The taskId.
* @param relayer - The relayer type which can be either Gelato or Connext.
* @param leaves - The leaves that the task includes.
*/
public async addTaskPending(
taskId: string,
relayer: RelayerType,
originDomain: string,
destinationDomain: string,
leaves: string[],
) {
await this.data.rpush(`${this.prefix}:tasks`, taskId);
return await this.data.hset(
`${this.prefix}:task`,
taskId,
JSON.stringify({
relayer,
originDomain,
destinationDomain,
leaves,
}),
);
}

/**
* Retrieves pending tasks in a range.
*
* @param offset - The starting point.
* @param limit - The number of tasks you're gonna retrieve
*/
public async getPendingTasks(
offset = 0,
limit = 100,
): Promise<{ taskId: string; relayer: string; originDomain: string; destinationDomain: string; leaves: string[] }[]> {
const result: {
taskId: string;
relayer: string;
originDomain: string;
destinationDomain: string;
leaves: string[];
}[] = [];
const tasks = await this.data.lrange(`${this.prefix}:tasks`, offset, offset + limit - 1);
for (const task of tasks) {
const rawTask = await this.data.hget(`${this.prefix}:task`, task);
if (!rawTask) continue;
const taskDetail = JSON.parse(rawTask) as {
relayer: string;
originDomain: string;
destinationDomain: string;
leaves: string[];
};
result.push({ taskId: task, ...taskDetail });
}
return result;
}

/**
* Remove pending tasks from both `tasks` and `task` data.
* @param taskIds - The list of task you wanna remove from the store
* @returns 1 if anything deleted, 0 if nothing
*/
public async removePendingTasks(taskIds: string[]): Promise<boolean> {
let sum = 0;
for (const taskId of taskIds) {
const res = await this.data.lrem(`${this.prefix}:tasks`, 0, taskId);
await this.data.hdel(`${this.prefix}:task`, taskId);
sum += res;
}
if (sum > 0) return true;
else return false;
}

/**
* Stores leaf of a domain at index.
*
Expand Down
39 changes: 39 additions & 0 deletions packages/adapters/cache/src/lib/caches/transfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,45 @@ export class TransfersCache extends Cache {
else return false;
}

/**
* Add a list of nonces missing from the subgraph result for the secondary poller.
* @param domain - The domain where the missing txs happened.
* @param nonces - The list of nonce.
*/
public async addMissingNonces(domain: string, nonces: number[]) {
for (const nonce of nonces) {
await this.data.rpush(`${this.prefix}:missing:${domain}`, nonce.toString());
}
}

/**
* Get the missing nonces on a given domain.
*
* @param domain - The domain where the missing txs happened.
* @param offset - The start index.
* @param limit - The number of records you wanna get.
* @returns The list of nonce.
*/
public async getMissingNonces(domain: string, offset = 0, limit = 100): Promise<string[]> {
const nonces = await this.data.lrange(`${this.prefix}:missing:${domain}`, offset, offset + limit - 1);
return nonces;
}

/**
* Remove missing nonces in the cache.
* @param domain - The target domain.
* @param nonces - The list of nonces you're gonna remove.
* @returns - The number of items removed in the cache.
*/
public async removeMissingNonces(domain: string, nonces: number[]): Promise<number> {
let sum = 0;
for (const nonce of nonces) {
const res = await this.data.lrem(`${this.prefix}:missing:${domain}`, 0, nonce.toString());
sum += res;
}
return sum;
}

/// MARK - Errors
/**
* Returns a list of all error strings for the specified transfer ID.
Expand Down
32 changes: 31 additions & 1 deletion packages/adapters/cache/test/lib/caches/messages.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExecStatus, Logger, XMessage, expect, mkBytes32, mock } from "@connext/nxtp-utils";
import { ExecStatus, Logger, RelayerType, XMessage, expect, mkBytes32, mock } from "@connext/nxtp-utils";
import { MessagesCache } from "../../../src/index";

const logger = new Logger({ level: "debug" });
Expand Down Expand Up @@ -158,6 +158,36 @@ describe("MessagesCache", () => {
});
});

describe("#task", () => {
beforeEach(async () => {
await messagesCache.clear();
});

it("should store tasks", async () => {
const taskId = mkBytes32("0x123123");
const leaves = [mkBytes32("0x111"), mkBytes32("0x222")];
const originDomain = "13337";
const destinationDomain = "13338";
await messagesCache.addTaskPending(taskId, RelayerType.Mock, originDomain, destinationDomain, leaves);

const tasks = await messagesCache.getPendingTasks();
expect(tasks).to.be.deep.eq([{ taskId, relayer: RelayerType.Mock, originDomain, destinationDomain, leaves }]);
});

it("should remove tasks", async () => {
const taskId = mkBytes32("0x123123");
const leaves = [mkBytes32("0x111"), mkBytes32("0x222")];
const originDomain = "13337";
const destinationDomain = "13338";
await messagesCache.addTaskPending(taskId, RelayerType.Mock, originDomain, destinationDomain, leaves);

await messagesCache.removePendingTasks([taskId]);

const tasks = await messagesCache.getPendingTasks();
expect(tasks.length).to.be.eq(0);
});
});

describe("#lock", () => {
beforeEach(async () => {
await messagesCache.clear();
Expand Down
Loading

0 comments on commit 7855c40

Please sign in to comment.