Skip to content

Commit a068f12

Browse files
committed
fix: bugs found by Rafa
1 parent 3988ba6 commit a068f12

File tree

6 files changed

+45
-42
lines changed

6 files changed

+45
-42
lines changed

indexer/src/cache/init.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const MEMORY_CACHE = new NodeCache({ stdTTL: 0 });
1111

1212
const CACHE_TTL = 1000 * 60 * 5; // 5 minutes
1313

14-
export default function initCache(context: ResolverContext) {
14+
export default async function initCache(context: ResolverContext) {
1515
const { blockRepository, networkRepository } = context;
1616

1717
async function getHashRateAndTotalDifficulty() {
@@ -30,7 +30,7 @@ export default function initCache(context: ResolverContext) {
3030
};
3131
MEMORY_CACHE.set(HASH_RATE_AND_TOTAL_DIFFICULTY_KEY, newValue);
3232
} catch (err) {
33-
console.log("Error getting hash rate and total difficulty");
33+
console.log("Error getting hash rate and total difficulty", err);
3434
}
3535
}
3636

@@ -39,7 +39,7 @@ export default function initCache(context: ResolverContext) {
3939
const networkStatistics = await networkRepository.getNetworkStatistics();
4040
MEMORY_CACHE.set(NETWORK_STATISTICS_KEY, networkStatistics);
4141
} catch (err) {
42-
console.log("Error getting network statistics");
42+
console.log("Error getting network statistics", err);
4343
}
4444
}
4545

@@ -48,18 +48,18 @@ export default function initCache(context: ResolverContext) {
4848
const nodeInfo = await networkRepository.getNodeInfo();
4949
MEMORY_CACHE.set(NODE_INFO_KEY, nodeInfo);
5050
} catch (err) {
51-
console.log("Error getting node info");
51+
console.log("Error getting node info", err);
5252
}
5353
}
5454

5555
MEMORY_CACHE.set(HASH_RATE_AND_TOTAL_DIFFICULTY_KEY, {
5656
totalDifficulty: -1,
5757
});
5858

59-
const getAllInfo = () => {
60-
getHashRateAndTotalDifficulty();
61-
getNetworkStatistics();
62-
getNodeInfo();
59+
const getAllInfo = async () => {
60+
await getNetworkStatistics();
61+
await getNodeInfo();
62+
await getHashRateAndTotalDifficulty();
6363
};
6464

6565
getAllInfo();

indexer/src/kadena-server/repository/infra/repository/block-db-repository.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import { blockValidator } from "../schema-validator/block-schema-validator";
1212
import Balance from "../../../../models/balance";
1313
import { handleSingleQuery } from "../../../utils/raw-query";
1414
import { formatGuard_NODE } from "../../../../utils/chainweb-node";
15+
import { MEMORY_CACHE } from "../../../../cache/init";
16+
import { NODE_INFO_KEY } from "../../../../cache/keys";
17+
import { GetNodeInfo } from "../../application/network-repository";
1518

1619
export default class BlockDbRepository implements BlockRepository {
1720
async getBlockByHash(hash: string) {
@@ -127,12 +130,8 @@ export default class BlockDbRepository implements BlockRepository {
127130
}
128131

129132
async getChainIds() {
130-
const query = `
131-
SELECT DISTINCT b."chainId"
132-
FROM "Blocks" b
133-
`;
134-
const { rows } = await rootPgPool.query(query);
135-
return rows.map((r) => Number(r.chainId));
133+
const nodeInfo = MEMORY_CACHE.get(NODE_INFO_KEY) as GetNodeInfo;
134+
return nodeInfo.nodeChains.map((chainId) => Number(chainId));
136135
}
137136

138137
async getCompletedBlocks(params: GetCompletedBlocksParams) {

indexer/src/kadena-server/repository/infra/repository/event-db-repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export default class EventDbRepository implements EventRepository {
159159

160160
if (requestKey) {
161161
queryParams.push(requestKey);
162-
conditions += `\nAND e."requestkey" = $${queryParams.length}`;
162+
conditions += `\nAND t."requestkey" = $${queryParams.length}`;
163163
}
164164

165165
if (before) {
@@ -174,7 +174,7 @@ export default class EventDbRepository implements EventRepository {
174174

175175
const query = `
176176
select e.id as id,
177-
e.requestkey as "requestKey",
177+
t.requestkey as "requestKey",
178178
b."chainId" as "chainId",
179179
b.height as height,
180180
e.module as "moduleName",

indexer/src/kadena-server/repository/infra/repository/transaction-db-repository.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import TransactionRepository, {
44
GetTransactionsByRequestKey,
55
GetTransactionsCountParams,
66
GetTransactionsParams,
7-
SignerOutput,
87
TransactionOutput,
98
} from "../../application/transaction-repository";
109
import { getPageInfo } from "../../pagination";
@@ -257,7 +256,7 @@ export default class TransactionDbRepository implements TransactionRepository {
257256
t.requestkey as "requestKey"
258257
FROM "Transactions" t
259258
JOIN "Blocks" b on t."blockId" = b.id
260-
WHERE t.requestkey = $1
259+
WHERE t.requestkey::text = $1
261260
${conditions}
262261
`;
263262

@@ -290,32 +289,33 @@ export default class TransactionDbRepository implements TransactionRepository {
290289
}
291290

292291
const query = `
293-
SELECT t.id as id,
294-
t.hash as "hashTransaction",
295-
t.nonce as "nonceTransaction",
296-
t.sigs as sigs,
297-
t.continuation as continuation,
298-
t.num_events as "eventCount",
299-
t.pactid as "pactId",
300-
t.proof as proof,
301-
t.rollback as rollback,
302-
b.height as "height",
303-
b."hash" as "blockHash",
304-
b."chainId" as "chainId",
305-
t.gas as "gas",
306-
t.step as step,
307-
t.data as data,
308-
t.code as code,
309-
t.logs as "logs",
310-
t.result as "result",
311-
t.requestkey as "requestKey"
292+
SELECT
293+
t.id as id,
294+
t.hash as "hashTransaction",
295+
t.nonce as "nonceTransaction",
296+
t.sigs as sigs,
297+
t.continuation as continuation,
298+
t.num_events as "eventCount",
299+
t.pactid as "pactId",
300+
t.proof as proof,
301+
t.rollback as rollback,
302+
b.height as "height",
303+
b."hash" as "blockHash",
304+
b."chainId" as "chainId",
305+
t.gas as "gas",
306+
t.step as step,
307+
t.data as data,
308+
t.code as code,
309+
t.logs as "logs",
310+
t.result as "result",
311+
t.requestkey as "requestKey"
312312
FROM "Transactions" t
313-
JOIN "Blocks" b on t."blockId" = b.id
314-
WHERE t.id IN (
313+
JOIN "Blocks" b ON t."blockId" = b.id
314+
JOIN (
315315
SELECT DISTINCT s."transactionId"
316316
FROM "Signers" s
317317
WHERE s."pubkey" = $2
318-
)
318+
) filtered_signers ON t.id = filtered_signers."transactionId"
319319
${cursorCondition}
320320
ORDER BY t.id ${before ? "DESC" : "ASC"}
321321
LIMIT $1;
@@ -508,7 +508,7 @@ export default class TransactionDbRepository implements TransactionRepository {
508508
t.requestkey as "requestKey"
509509
FROM "Signers" s
510510
JOIN "Transactions" t on s."transactionId" = t.id
511-
WHERE s."transactionId" = $1
511+
WHERE t.id = $1
512512
`;
513513

514514
if (orderIndex) {

indexer/src/kadena-server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ export async function useKadenaGraphqlServer() {
139139
});
140140
});
141141

142+
await initCache(context);
142143
await new Promise<void>((resolve) =>
143144
httpServer.listen({ port: KADENA_GRAPHQL_API_PORT }, resolve),
144145
);
145-
initCache(context);
146146
console.log(`Server running on port ${KADENA_GRAPHQL_API_PORT}.`);
147147
}

indexer/src/models/signer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ Signer.init(
8080
name: "signers_pubkey_transactionid_idx",
8181
fields: ["pubkey", "transactionId"],
8282
},
83+
{
84+
name: "signers_transaction_id_idx",
85+
fields: ["transactionId"],
86+
},
8387
],
8488
},
8589
);

0 commit comments

Comments
 (0)