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

indexer only counts address to package and transaction to package once #1581

Merged
merged 2 commits into from
Dec 9, 2024
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
16 changes: 0 additions & 16 deletions packages/indexer/Dockerfile

This file was deleted.

40 changes: 24 additions & 16 deletions packages/indexer/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@usecannon/builder';
import CannonRegistryAbi from '@usecannon/builder/dist/src/abis/CannonRegistry';
import _ from 'lodash';
import { RedisClientType, SchemaFieldTypes } from 'redis';
import { RedisClientType, SchemaFieldTypes, TimeSeriesDuplicatePolicies } from 'redis';
/* eslint no-console: "off" */
import * as viem from 'viem';
import * as viemChains from 'viem/chains';
Expand Down Expand Up @@ -245,16 +245,8 @@ export async function handleCannonPublish(

if (contract.deployTxnHash) {
// note: we dont include chainId in the index here because transaction ids are almost always unique
batch.hSetNX(rkey.RKEY_TRANSACTION_TO_PACKAGE, contract.deployTxnHash, packageRef);
batch.ts.incrBy(`${rkey.RKEY_TS_TRANSACTION_COUNT}:${chainId}`, 1, {
TIMESTAMP: timestamp - (timestamp % 3600000),
LABELS: { chainId: `${chainId}`, kind: rkey.RKEY_TS_TRANSACTION_COUNT },
});
batch.hSetNX(rkey.RKEY_TRANSACTION_TO_PACKAGE + ':' + chainId, contract.deployTxnHash, packageRef);
}
batch.ts.incrBy(`${rkey.RKEY_TS_CONTRACT_COUNT}:${chainId}`, 1, {
TIMESTAMP: timestamp - (timestamp % 3600000),
LABELS: { chainId: `${chainId}`, kind: rkey.RKEY_TS_CONTRACT_COUNT },
});

// process the contract abi as well
for (const abiItem of contract.abi) {
Expand All @@ -278,18 +270,34 @@ export async function handleCannonPublish(
}
}
for (const txn of Object.values(state.artifacts.txns || {})) {
batch.hSetNX(rkey.RKEY_TRANSACTION_TO_PACKAGE, txn.hash, packageRef);
batch.ts.incrBy(`${rkey.RKEY_TS_TRANSACTION_COUNT}:${chainId}`, 1, {
TIMESTAMP: timestamp - (timestamp % 3600000),
LABELS: { chainId: `${chainId}`, kind: rkey.RKEY_TS_TRANSACTION_COUNT },
});
batch.hSetNX(rkey.RKEY_TRANSACTION_TO_PACKAGE + ':' + chainId, txn.hash, packageRef);
}
batch.incr(`${rkey.RKEY_COUNTER_STEP_TYPE_PREFIX}:${type}`);
} else {
console.log('[warn] step data not found:', actionName);
}

await batch.exec();
batch.hLen(rkey.RKEY_ADDRESS_TO_PACKAGE + ':' + chainId);
batch.hLen(rkey.RKEY_TRANSACTION_TO_PACKAGE + ':' + chainId);

const result = await batch.exec();

const contractCount = result[result.length - 2] as number;
const transactionCount = result[result.length - 1] as number;

const tsBatch = redis.multi();

tsBatch.ts.add(`${rkey.RKEY_TS_CONTRACT_COUNT}:${chainId}`, timestamp, contractCount, {
LABELS: { chainId: `${chainId}`, kind: rkey.RKEY_TS_CONTRACT_COUNT },
ON_DUPLICATE: TimeSeriesDuplicatePolicies.LAST,
});

tsBatch.ts.add(`${rkey.RKEY_TS_TRANSACTION_COUNT}:${chainId}`, timestamp, transactionCount, {
LABELS: { chainId: `${chainId}`, kind: rkey.RKEY_TS_TRANSACTION_COUNT },
ON_DUPLICATE: TimeSeriesDuplicatePolicies.LAST,
});

await tsBatch.exec();
}
}

Expand Down
Loading