Skip to content
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
2 changes: 1 addition & 1 deletion apps/indexer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indexer",
"version": "1.1.4",
"version": "1.1.5",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
47 changes: 27 additions & 20 deletions apps/indexer/src/chain/chainSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
transactionEventAttribute
} from "database";
import { BlockType, EventType } from "@src/shared/types";
import { parseRawLog } from "@cosmjs/stargate/build/logs";

export const setMissingBlock = (height: number) => (missingBlock = height);
let missingBlock: number | null;
Expand Down Expand Up @@ -228,7 +229,7 @@ async function insertBlocks(startHeight: number, endHeight: number) {

for (let txIndex = 0; txIndex < txs.length; ++txIndex) {
const tx = txs[txIndex];
const hash = sha256(Buffer.from(tx, "base64")).toUpperCase();
const hash = sha256(new Uint8Array(Buffer.from(tx, "base64"))).toUpperCase();
const txId = uuid.v4();

const decodedTx = decodeTxRaw(fromBase64(tx));
Expand Down Expand Up @@ -265,25 +266,31 @@ async function insertBlocks(startHeight: number, endHeight: number) {
gasWanted: parseInt(txJson.gas_wanted)
});

if (msgs.some((x) => x.typeUrl.startsWith("/cosmwasm"))) {
for (const [index, event] of blockResults.txs_results[txIndex].events.entries()) {
const eventId = uuid.v4();
txsEventsToAdd.push({
id: eventId,
height: i,
txId: txId,
index: index,
type: event.type
});

txsEventAttributesToAdd.push(
...event.attributes.map((attr, i) => ({
transactionEventId: eventId,
index: i,
key: atob(attr.key),
value: attr.value ? atob(attr.value) : attr.value
}))
);
// Only indexing events for successful cosmwasm txs
if (msgs.some((x) => x.typeUrl.startsWith("/cosmwasm")) && !txJson.code) {
const parsedEvents = parseRawLog(txJson.log);

for (const eventGroup of parsedEvents) {
for (const [index, event] of eventGroup.events.entries()) {
const eventId = uuid.v4();
txsEventsToAdd.push({
id: eventId,
height: i,
txId: txId,
msgIndex: eventGroup.msg_index,
index: index,
type: event.type
});

txsEventAttributesToAdd.push(
...event.attributes.map((attr, i) => ({
transactionEventId: eventId,
index: i,
key: attr.key,
value: attr.value
}))
);
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions apps/indexer/src/chain/statsProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class StatsProcessor {

for (const transaction of block.transactions) {
const decodeTimer = benchmark.startTimer("decodeTx");
const tx = blockData.block.data.txs.find((t) => sha256(Buffer.from(t, "base64")).toUpperCase() === transaction.hash);
const tx = blockData.block.data.txs.find((t) => sha256(new Uint8Array(Buffer.from(t, "base64"))).toUpperCase() === transaction.hash);

if (!tx) throw new Error(`Transaction ${transaction.hash} not found in block ${block.height}`);

Expand All @@ -123,8 +123,10 @@ class StatsProcessor {

const encodedMessage = decodedTx.body.messages[msg.index].value;

const messageEvents = transaction.events.filter((event) => event.msgIndex === msg.index);

await benchmark.measureAsync("processMessage", async () => {
await this.processMessage(msg, encodedMessage, block.height, blockGroupTransaction, transaction.hasProcessingError, transaction.events);
await this.processMessage(msg, encodedMessage, block.height, blockGroupTransaction, transaction.hasProcessingError, messageEvents);
});

if (msg.amount) {
Expand Down Expand Up @@ -205,12 +207,12 @@ class StatsProcessor {
height: number,
blockGroupTransaction: DbTransaction,
hasProcessingError: boolean,
txEvents: TransactionEventWithAttributes[]
msgEvents: TransactionEventWithAttributes[]
) {
for (const indexer of activeIndexers) {
if (indexer.hasHandlerForType(msg.type) && (!hasProcessingError || indexer.processFailedTxs)) {
const decodedMessage = decodeMsg(msg.type, encodedMessage);
await indexer.processMessage(decodedMessage, height, blockGroupTransaction, msg, txEvents);
await indexer.processMessage(decodedMessage, height, blockGroupTransaction, msg, msgEvents);
}
}
}
Expand Down
Loading