[Blockchain Watcher] (WORMCHAIN) Improve how create the providers (#1561)

* Improve how create the providers for wormchain

* Remove validation when create a client

* Fix rpcs

* Remove bsc rpcs

* Add default chain

* Throw error when we cant map cosmos chain
This commit is contained in:
Julian 2024-07-25 12:19:30 -03:00 committed by GitHub
parent 615e0e9ff1
commit 911ae24a57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 116 additions and 116 deletions

View File

@ -12,7 +12,6 @@
"rpcs": [
"https://api.securerpc.com/v1",
"https://rpc.mevblocker.io/noreverts",
"https://endpoints.omniatech.io/v1/eth/mainnet/public",
"https://ethereum.publicnode.com"
]
},
@ -38,13 +37,7 @@
"polygon": {
"network": "mainnet",
"chainId": 5,
"rpcs": [
"https://rpc-mainnet.matic.quiknode.pro",
"https://polygon-rpc.com",
"https://rpc-mainnet.maticvigil.com",
"https://endpoints.omniatech.io/v1/matic/mainnet/public",
"https://polygon-bor.publicnode.com"
]
"rpcs": ["https://rpc-mainnet.matic.quiknode.pro", "https://polygon-rpc.com"]
},
"avalanche": {
"network": "mainnet",
@ -137,11 +130,7 @@
"arbitrum": {
"network": "mainnet",
"chainId": 23,
"rpcs": [
"https://endpoints.omniatech.io/v1/arbitrum/one/public",
"https://arbitrum.blockpi.network/v1/rpc/public",
"https://arb1.arbitrum.io/rpc"
]
"rpcs": ["https://arbitrum.blockpi.network/v1/rpc/public", "https://arb1.arbitrum.io/rpc"]
},
"optimism": {
"network": "mainnet",

View File

@ -5,6 +5,6 @@ const chains: Map<number, string> = new Map([
[4002, "kujira"],
]);
export function mapChain(chainId: number) {
export function mapChain(chainId: number): string {
return chains.get(chainId) || "wormchain";
}

View File

@ -15,7 +15,7 @@ export class GetWormchainLogs {
async execute(
range: Range,
opts: { addresses: string[]; chainId: number }
opts: { addresses: string[]; chain: string }
): Promise<WormchainBlockLogs[]> {
const fromBlock = range.fromBlock;
const toBlock = range.toBlock;
@ -34,7 +34,7 @@ export class GetWormchainLogs {
for (let blockNumber = fromBlock; blockNumber <= toBlock; blockNumber++) {
const wormchainLogs = await this.blockRepo.getBlockLogs(
opts.chainId,
opts.chain,
blockNumber,
ATTRIBUTES_TYPES
);

View File

@ -15,7 +15,7 @@ export class GetWormchainRedeems {
async execute(
range: Range,
opts: { addresses: string[]; chainId: number }
opts: { addresses: string[]; chain: string }
): Promise<CosmosRedeem[]> {
let fromBlock = range.fromBlock;
let toBlock = range.toBlock;
@ -35,7 +35,7 @@ export class GetWormchainRedeems {
for (let blockNumber = fromBlock; blockNumber <= toBlock; blockNumber++) {
const wormchainLogs = await this.blockRepo.getBlockLogs(
opts.chainId,
opts.chain,
blockNumber,
ATTRIBUTES_TYPES
);

View File

@ -56,7 +56,7 @@ export class PollWormchain extends RunPollingJob {
}
protected async get(): Promise<any[]> {
this.latestBlockHeight = await this.blockRepo.getBlockHeight(this.cfg.chainId);
this.latestBlockHeight = await this.blockRepo.getBlockHeight(this.cfg.chain);
if (!this.latestBlockHeight) {
throw new Error(`Could not obtain latest block height: ${this.latestBlockHeight}`);
@ -66,7 +66,7 @@ export class PollWormchain extends RunPollingJob {
const records = await this.getWormchain.execute(range, {
addresses: this.cfg.addresses,
chainId: this.cfg.chainId,
chain: this.cfg.chain,
});
this.lastRange = range;

View File

@ -85,9 +85,9 @@ export interface AptosRepository {
}
export interface WormchainRepository {
getBlockHeight(chainId: number): Promise<bigint | undefined>;
getBlockHeight(chain: string): Promise<bigint | undefined>;
getBlockLogs(
chainId: number,
chain: string,
blockNumber: bigint,
attributesTypes: string[]
): Promise<WormchainBlockLogs>;

View File

@ -92,6 +92,7 @@ export class RepositoriesBuilder {
private build(): void {
this.snsClient = this.createSnsClient();
this.repositories.set("sns", new SnsEventRepository(this.snsClient, this.cfg.sns));
this.cfg.influx &&
this.repositories.set(
"infux",
@ -103,18 +104,23 @@ export class RepositoriesBuilder {
this.cfg.influx
)
);
this.cfg.metadata?.dir &&
this.repositories.set("metadata", new FileMetadataRepository(this.cfg.metadata.dir));
this.repositories.set("metrics", new PromStatRepository());
const pools = this.createAllProvidersPool();
this.cfg.enabledPlatforms.forEach((chain) => {
this.buildWormchainRepository(chain);
// Set up all providers because we use various chains
this.buildWormchainRepository(chain, pools);
this.buildCosmosRepository(chain, pools);
this.buildEvmRepository(chain, pools);
// Set up the specific providers for the chain
this.buildAlgorandRepository(chain);
this.buildSolanaRepository(chain);
this.buildCosmosRepository(chain);
this.buildAptosRepository(chain);
this.buildEvmRepository(chain);
this.buildSuiRepository(chain);
});
@ -226,9 +232,8 @@ export class RepositoriesBuilder {
}
}
private buildEvmRepository(chain: string): void {
private buildEvmRepository(chain: string, pools: ProviderPoolMap): void {
if (chain == EVM_CHAIN) {
const pools = this.createAllProvidersPool();
const repoCfg: JsonRPCBlockRepositoryCfg = {
chains: this.cfg.chains,
environment: this.cfg.environment,
@ -286,9 +291,8 @@ export class RepositoriesBuilder {
}
}
private buildCosmosRepository(chain: string): void {
private buildCosmosRepository(chain: string, pools: ProviderPoolMap): void {
if (chain == COSMOS_CHAIN) {
const pools = this.createAllProvidersPool();
const repoCfg: JsonRPCBlockRepositoryCfg = {
chains: this.cfg.chains,
environment: this.cfg.environment,
@ -302,24 +306,15 @@ export class RepositoriesBuilder {
}
}
private buildWormchainRepository(chain: string): void {
private buildWormchainRepository(chain: string, pools: ProviderPoolMap): void {
if (chain == WORMCHAIN_CHAIN) {
const injectivePools = this.createDefaultProviderPools("injective");
const wormchainPools = this.createDefaultProviderPools("wormchain");
const osmosisPools = this.createDefaultProviderPools("osmosis");
const kujiraPools = this.createDefaultProviderPools("kujira");
const evmosPools = this.createDefaultProviderPools("evmos");
const cosmosPools: Map<number, ProviderPool<InstrumentedHttpProvider>> = new Map([
[19, injectivePools],
[20, osmosisPools],
[3104, wormchainPools],
[4001, evmosPools],
[4002, kujiraPools],
]);
const repoCfg: JsonRPCBlockRepositoryCfg = {
chains: this.cfg.chains,
environment: this.cfg.environment,
};
const wormchainRepository = new RateLimitedWormchainJsonRPCBlockRepository(
new WormchainJsonRPCBlockRepository(cosmosPools)
new WormchainJsonRPCBlockRepository(repoCfg, pools)
);
this.repositories.set("wormchain-repo", wormchainRepository);

View File

@ -17,17 +17,17 @@ export class RateLimitedWormchainJsonRPCBlockRepository
this.logger = winston.child({ module: "RateLimitedWormchainJsonRPCBlockRepository" });
}
getBlockHeight(chainId: number): Promise<bigint | undefined> {
return this.breaker.fn(() => this.delegate.getBlockHeight(chainId)).execute();
getBlockHeight(chain: string): Promise<bigint | undefined> {
return this.breaker.fn(() => this.delegate.getBlockHeight(chain)).execute();
}
getBlockLogs(
chainId: number,
chain: string,
blockNumber: bigint,
attributesTypes: string[]
): Promise<WormchainBlockLogs> {
return this.breaker
.fn(() => this.delegate.getBlockLogs(chainId, blockNumber, attributesTypes))
.fn(() => this.delegate.getBlockLogs(chain, blockNumber, attributesTypes))
.execute();
}

View File

@ -1,8 +1,8 @@
import { divideIntoBatches, hexToHash } from "../common/utils";
import { InstrumentedHttpProvider } from "../../rpc/http/InstrumentedHttpProvider";
import { divideIntoBatches, getChainProvider, hexToHash } from "../common/utils";
import { ProviderPoolMap, JsonRPCBlockRepositoryCfg } from "../RepositoriesBuilder";
import { WormchainRepository } from "../../../domain/repositories";
import { ProviderPool } from "@xlabs/rpc-pool";
import { setTimeout } from "timers/promises";
import { mapChain } from "../../../common/wormchain";
import winston from "winston";
import {
WormchainTransaction,
@ -19,25 +19,21 @@ let BLOCK_ENDPOINT = "/block";
const GROW_SLEEP_TIME = 350;
const MAX_ATTEMPTS = 20;
type ProviderPoolMap = ProviderPool<InstrumentedHttpProvider>;
export class WormchainJsonRPCBlockRepository implements WormchainRepository {
private readonly logger: winston.Logger;
protected cosmosPools: Map<number, ProviderPoolMap>;
protected pool: ProviderPoolMap;
protected cfg: JsonRPCBlockRepositoryCfg;
constructor(cosmosPools: Map<number, ProviderPoolMap>) {
constructor(cfg: JsonRPCBlockRepositoryCfg, pool: ProviderPoolMap) {
this.logger = winston.child({ module: "WormchainJsonRPCBlockRepository" });
this.cosmosPools = cosmosPools;
this.pool = pool;
this.cfg = cfg;
}
async getBlockHeight(chainId: number): Promise<bigint | undefined> {
async getBlockHeight(chain: string): Promise<bigint | undefined> {
try {
let results: ResultBlockHeight;
results = await this.cosmosPools
.get(chainId)!
.get()
.get<typeof results>(BLOCK_HEIGHT_ENDPOINT);
results = await getChainProvider(chain, this.pool).get<typeof results>(BLOCK_HEIGHT_ENDPOINT);
if (
results &&
@ -56,7 +52,7 @@ export class WormchainJsonRPCBlockRepository implements WormchainRepository {
}
async getBlockLogs(
chainId: number,
chain: string,
blockNumber: bigint,
attributesTypes: string[]
): Promise<WormchainBlockLogs> {
@ -65,10 +61,10 @@ export class WormchainJsonRPCBlockRepository implements WormchainRepository {
let resultsBlock: ResultBlock;
// Set up cosmos client
const cosmosClient = this.cosmosPools.get(chainId)!;
const cosmosClient = getChainProvider(chain, this.pool);
// Get wormchain block data
resultsBlock = await cosmosClient.get().get<typeof resultsBlock>(blockEndpoint);
resultsBlock = await cosmosClient.get<typeof resultsBlock>(blockEndpoint);
const txs = resultsBlock.result.block.data.txs;
if (!txs || txs.length === 0) {
@ -90,9 +86,9 @@ export class WormchainJsonRPCBlockRepository implements WormchainRepository {
const txEndpoint = `${TRANSACTION_ENDPOINT}?hash=0x${hash}`;
// Get wormchain transactions data
const resultTransaction: ResultTransaction = await cosmosClient
.get()
.get<typeof resultTransaction>(txEndpoint);
const resultTransaction: ResultTransaction = await cosmosClient.get<
typeof resultTransaction
>(txEndpoint);
if (
resultTransaction &&
@ -144,14 +140,8 @@ export class WormchainJsonRPCBlockRepository implements WormchainRepository {
async getRedeems(ibcTransaction: IbcTransaction): Promise<CosmosRedeem[]> {
try {
// Set up cosmos client
const cosmosClient = this.cosmosPools.get(ibcTransaction.targetChain);
if (!cosmosClient) {
this.logger.warn(
`[wormchain] No cosmos client found for chain ${ibcTransaction.targetChain}`
);
return [];
}
const chain = mapChain(ibcTransaction.targetChain);
const cosmosClient = getChainProvider(chain, this.pool);
let resultTransactionSearch: ResultTransactionSearch | undefined;
let isIBCTransferFinalized = false;
@ -170,11 +160,9 @@ export class WormchainJsonRPCBlockRepository implements WormchainRepository {
await this.sleep(sleepTime);
// Get cosmos transactions data
resultTransactionSearch = await cosmosClient
.get()
.get<typeof resultTransactionSearch>(
`${TRANSACTION_SEARCH_ENDPOINT}?query=${query}&prove=false&page=1&per_page=1`
);
resultTransactionSearch = await cosmosClient.get<typeof resultTransactionSearch>(
`${TRANSACTION_SEARCH_ENDPOINT}?query=${query}&prove=false&page=1&per_page=1`
);
if (
resultTransactionSearch &&

View File

@ -64,7 +64,7 @@ describe("GetWormchainLogs", () => {
// Then
await thenWaitForAssertion(() =>
expect(getBlockLogsSpy).toBeCalledWith(3104, 7606614n, ["wasm"])
expect(getBlockLogsSpy).toBeCalledWith("wormchain", 7606614n, ["wasm"])
);
});
@ -123,7 +123,7 @@ describe("GetWormchainLogs", () => {
// Then
await thenWaitForAssertion(() =>
expect(getBlockLogsSpy).toBeCalledWith(3104, 7606615n, ["wasm"])
expect(getBlockLogsSpy).toBeCalledWith("wormchain", 7606615n, ["wasm"])
);
});
});

View File

@ -64,7 +64,7 @@ describe("GetWormchainRedeems", () => {
// Then
await thenWaitForAssertion(() =>
expect(getBlockLogsSpy).toBeCalledWith(3104, 8418529n, ["wasm", "send_packet"])
expect(getBlockLogsSpy).toBeCalledWith("wormchain", 8418529n, ["wasm", "send_packet"])
);
});
@ -174,7 +174,7 @@ describe("GetWormchainRedeems", () => {
// Then
await thenWaitForAssertion(() =>
expect(getBlockLogsSpy).toBeCalledWith(3104, 7606615n, ["wasm", "send_packet"])
expect(getBlockLogsSpy).toBeCalledWith("wormchain", 7606615n, ["wasm", "send_packet"])
);
});
});

View File

@ -93,7 +93,7 @@ describe("PollWormchain", () => {
await thenWaitForAssertion(
() => expect(getBlockHeightSpy).toHaveReturnedTimes(1),
() => expect(getBlockLogsSpy).toHaveBeenCalledWith(3104, currentHeight, ["wasm"])
() => expect(getBlockLogsSpy).toHaveBeenCalledWith("wormchain", currentHeight, ["wasm"])
);
});

View File

@ -12,22 +12,14 @@ const rpc = "http://localhost";
let repo: WormchainJsonRPCBlockRepository;
// Mock pools
const cosmosPools: Map<number, any> = new Map([
[19, () => new InstrumentedHttpProvider({ url: rpc, chain: "injective" })],
[3104, { get: () => new InstrumentedHttpProvider({ url: rpc, chain: "wormchain" }) } as any],
[4001, { get: () => new InstrumentedHttpProvider({ url: rpc, chain: "evmos" }) } as any],
[4002, () => new InstrumentedHttpProvider({ url: rpc, chain: "kujira" })],
]);
describe("WormchainJsonRPCBlockRepository", () => {
describe("getBlockHeight", () => {
it("should be able to get block height", async () => {
const expectedHeight = 9187752n;
givenARepo(cosmosPools);
givenARepo();
givenBlockHeightIs();
const result = await repo.getBlockHeight(3104);
const result = await repo.getBlockHeight("wormchain");
expect(result).toBe(expectedHeight);
});
@ -35,23 +27,23 @@ describe("WormchainJsonRPCBlockRepository", () => {
describe("getBlockLogs", () => {
it("should not process the block because does not have transactions", async () => {
givenARepo(cosmosPools);
givenARepo();
givenBlockLogs([]);
const result = await repo.getBlockLogs(3104, 8453618n, ["wasm", "send_packet"]);
const result = await repo.getBlockLogs("wormchain", 8453618n, ["wasm", "send_packet"]);
expect(result.transactions).toEqual([]);
expect(result.blockHeight).toEqual(8453618n);
});
it("should process the block because have one transaction", async () => {
givenARepo(cosmosPools);
givenARepo();
givenBlockLogs([
"CrYICrMICiQvY29zbXdhc20ud2FzbS52MS5Nc2dFeGVjdXRlQ29udHJhY3QSiggKL3dvcm1ob2xlMTV6ZGFhbjhzN2x0MHgyd2p0d2tsdXowMHB0cGx1a3BqcnZuOGtoEkN3b3JtaG9sZTE0aGoydGF2cThmcGVzZHd4eGN1NDRydHkzaGg5MHZodWpydmNtc3RsNHpyM3R4bWZ2dzlzcnJnNDY1GpEHeyJzdWJtaXRfb2JzZXJ2YXRpb25zIjp7Im9ic2VydmF0aW9ucyI6Ilczc2lkSGhmYUdGemFDSTZJamRXVUM5b1FtazNZalJ4U0Zo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g0LDEyNiwyMDgsMTYsMjIxLDcyLDEyNSw5Myw5OCwxOTcsMTUyLDE4MSwwXX19fRJaClIKRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiECTNU10MWVzKLoEbR3KVeQzNN0RcrBOuz+X/R+8hcjr00SBAoCCAEYhtcEEgQQgIl6GkC6wWnfEe2JArWPIpcypfQ+AhCamp6n+hga87jh07agcAJVuCXS3EgxAc0xdb1y+2TMuapNPwjVDyKctycFVtGn",
]);
givenOneTransaction();
const result = await repo.getBlockLogs(3104, 8453618n, ["wasm", "send_packet"]);
const result = await repo.getBlockLogs("wormchain", 8453618n, ["wasm", "send_packet"]);
expect(result).toEqual({
transactions: [
@ -145,14 +137,14 @@ describe("WormchainJsonRPCBlockRepository", () => {
});
it("should process the block because have more than one transaction", async () => {
givenARepo(cosmosPools);
givenARepo();
givenBlockLogs([
"CrYICrMICiQvY29zbXdhc20ud2FzbS52MS5Nc2dFeGVjdXRlQ29udHJhY3QSiggKL3dvcm1ob2xlMXJtZXJteDZ0ZDZwcHI3eDIzeThtYTc1NjRuYXV6d203bnVrOWUwEkN3b3JtaG9sZTE0aGoydGF2cThmcGVzZHd4eGN1NDRydHkzaGg5MHZodWpydmNtc3RsNHpyM3R4bWZ2dzlzcnJnNDY1GpEHeyJzdWJtaXRfb2JzZXJ2YXRpb25zIjp7Im9ic2VydmF0aW9ucyI6Ilczc2lkSGhmYUdGemFDSTZJa1o1WW5wbGRHNTVhVTVRZGpZNVJucEtUR05sTUVoV2JGUlVSV0pTWm5Wa1ZUaDJZVWd6UlRaS04yczlJaXdpZEdsdFpYTjBZVzF3SWpveE56RTFOelV4TlRNMExDSnViMjVqWlNJNk5UWTRORFl4TVRNekxDSmxiV2wwZEdWeVgyTm9ZV2x1SWpvMExDSmxiV2wwZEdWeVgyRmtaSEpsYzNNaU9pSXdNREF3TURBd01EQXdNREF3TURBd01EQXdNREF3TURCaU5tWTJaRGcyWVRobU9UZzNPV0U1WX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hcmRpYW5fc2V0X2luZGV4Ijo0LCJzaWduYXR1cmUiOnsiaW5kZXgiOjE2LCJzaWduYXR1cmUiOls1NCw5OCwxOTcsMTQyLDEyMSwxNTQsMTI4LDIsMTQ2LDExLDEzNSwxMDMsMTIxLDk1LDE4NSwxOTUsODcsMjAwLDExNCwyMjEsMjIsNCwyMzIsMTQsNCwyMTQsMTUyLDEyNiwxNjMsMjUyLDEyMCwxNzMsMTExLDI0Nyw5NiwyNyw1MSw1NCwxMyw3MSwyMjYsMTQyLDY5LDExLDc0LDc4LDM5LDIyNywzNyw3MSw1Miw2NiwyMjUsMjA4LDIxMSwxNzEsMjA1LDIyNyw0OSwxNzksMTM3LDE5MywxNjQsMTA4LDFdfX19EloKUgpGCh8vY29zbW9zLmNyeXB0by5zZWNwMjU2azEuUHViS2V5EiMKIQPnPs02nEn7crSxHqFZ7k3b8rPU0hWuOjTvlwrU/UIvwRIECgIIARi77XQSBBCAiXoaQK57xFZmOQFdmdkoHKhlYzyoEfBIaYrzqRUBIliUIRW+Nj9faFWJleYBl4WcLeEj5AB2b7iZZGoD2s7dA10aPlE=",
]);
givenTwoTransaction();
const result = await repo.getBlockLogs(3104, 8453618n, ["wasm", "send_packet"]);
const result = await repo.getBlockLogs("wormchain", 8453618n, ["wasm", "send_packet"]);
expect(result).toEqual({
transactions: [
@ -441,29 +433,65 @@ describe("WormchainJsonRPCBlockRepository", () => {
sender: "osmo17zr4md042hn5h84h4ycpk8eq8mwt2rgfp8nug5",
};
it("should not be able to get redeems because do not find the cosmos client", async () => {
givenARepo(cosmosPools);
givenBlockHeightIs();
osmosisRedeem.targetChain = 20;
const result = await repo.getRedeems(osmosisRedeem);
expect(result).toEqual([]);
});
it("should be able to get the redeems and map the information from cosmos transaction", async () => {
givenARepo(cosmosPools);
givenARepo();
givenOneTransactionByQuery();
const result = await repo.getRedeems(osmosisRedeem);
expect(result).toEqual([]);
expect(result.length).toEqual(1);
expect(result[0].chainId).toEqual(4001);
expect(result[0].hash).toEqual(
"1B099AAD307B55CED63DCE877961BF8AB04B0A2E13FFC7EEF7AAC1293AC069A6"
);
expect(result[0].height).toEqual(19255525n);
expect(result[0].blockTimestamp).toEqual(1715751595401);
});
it("should not be able to get redeems because do not find the cosmos client", async () => {
givenARepo();
givenBlockHeightIs();
try {
osmosisRedeem.targetChain = 20;
await repo.getRedeems(osmosisRedeem);
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
});
});
});
const givenARepo = (cosmosPools: any = undefined) => {
repo = new WormchainJsonRPCBlockRepository(cosmosPools);
const givenARepo = () => {
repo = new WormchainJsonRPCBlockRepository(
{
chains: {
injective: {
rpcs: [rpc],
timeout: 100,
name: "injective",
network: "mainnet",
chainId: 19,
},
wormchain: {
rpcs: [rpc],
timeout: 100,
name: "wormchain",
network: "mainnet",
chainId: 3104,
},
evmos: { rpcs: [rpc], timeout: 100, name: "evmos", network: "mainnet", chainId: 4001 },
kujira: { rpcs: [rpc], timeout: 100, name: "kujira", network: "mainnet", chainId: 4002 },
},
environment: "mainnet",
},
{
injective: { get: () => new InstrumentedHttpProvider({ url: rpc, chain: "injective" }) },
wormchain: { get: () => new InstrumentedHttpProvider({ url: rpc, chain: "wormchain" }) },
evmos: { get: () => new InstrumentedHttpProvider({ url: rpc, chain: "evmos" }) },
kujira: { get: () => new InstrumentedHttpProvider({ url: rpc, chain: "kujira" }) },
} as any
);
};
const givenBlockHeightIs = () => {