Skip to content

Commit

Permalink
fix: event-replay block parsing outdated and incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Oct 21, 2024
1 parent c389154 commit 68e1f15
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 249 deletions.
37 changes: 0 additions & 37 deletions src/datastore/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,43 +1283,6 @@ export function convertTxQueryResultToDbMempoolTx(txs: TxQueryResult[]): DbMempo
return dbMempoolTxs;
}

export function setTotalBlockUpdateDataExecutionCost(data: DataStoreBlockUpdateData) {
const cost = data.txs.reduce(
(previousValue, currentValue) => {
const {
execution_cost_read_count,
execution_cost_read_length,
execution_cost_runtime,
execution_cost_write_count,
execution_cost_write_length,
} = previousValue;
return {
execution_cost_read_count:
execution_cost_read_count + currentValue.tx.execution_cost_read_count,
execution_cost_read_length:
execution_cost_read_length + currentValue.tx.execution_cost_read_length,
execution_cost_runtime: execution_cost_runtime + currentValue.tx.execution_cost_runtime,
execution_cost_write_count:
execution_cost_write_count + currentValue.tx.execution_cost_write_count,
execution_cost_write_length:
execution_cost_write_length + currentValue.tx.execution_cost_write_length,
};
},
{
execution_cost_read_count: 0,
execution_cost_read_length: 0,
execution_cost_runtime: 0,
execution_cost_write_count: 0,
execution_cost_write_length: 0,
}
);
data.block.execution_cost_read_count = cost.execution_cost_read_count;
data.block.execution_cost_read_length = cost.execution_cost_read_length;
data.block.execution_cost_runtime = cost.execution_cost_runtime;
data.block.execution_cost_write_count = cost.execution_cost_write_count;
data.block.execution_cost_write_length = cost.execution_cost_write_length;
}

export function markBlockUpdateDataAsNonCanonical(data: DataStoreBlockUpdateData): void {
data.block = { ...data.block, canonical: false };
data.microblocks = data.microblocks.map(mb => ({ ...mb, canonical: false }));
Expand Down
2 changes: 0 additions & 2 deletions src/datastore/pg-write-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import {
} from './common';
import {
BLOCK_COLUMNS,
setTotalBlockUpdateDataExecutionCost,
convertTxQueryResultToDbMempoolTx,
markBlockUpdateDataAsNonCanonical,
MICROBLOCK_COLUMNS,
Expand Down Expand Up @@ -210,7 +209,6 @@ export class PgWriteStore extends PgStore {
}));
await this.pruneMempoolTxs(sql, prunableTxs);
}
setTotalBlockUpdateDataExecutionCost(data);

// Insert microblocks, if any. Clear already inserted microblock txs from the anchor-block
// update data to avoid duplicate inserts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const populateBatchInserters = (db: PgWriteStore) => {
write: async (data: CoreNodeBlockMessage, _encoding, next) => {
let dbData: DataStoreBlockUpdateData;
try {
dbData = parseNewBlockMessage(chainID, data);
({ dbData } = parseNewBlockMessage(chainID, data, true));
} catch (err) {
logger.error({ component: 'event-replay' }, 'Error when parsing new_block event');
console.error(err);
Expand Down
Loading

0 comments on commit 68e1f15

Please sign in to comment.